ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitConversions/Mods/src/ConversionRemoval.cc
Revision: 1.1
Committed: Wed Dec 16 18:10:38 2009 UTC (15 years, 4 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Log Message:
updated MitConversions

File Contents

# User Rev Content
1 bendavid 1.1 // $Id: ConversionRemoval.cc,v 1.3 2009/01/12 10:26:47 bendavid Exp $
2     #include <TH1.h>
3     #include <TH1F.h>
4     #include <TH2F.h>
5     #include <TCanvas.h>
6    
7     #include "MitConversions/Mods/interface/ConversionRemoval.h"
8     #include "MitAna/DataTree/interface/Electron.h"
9     #include "MitAna/DataTree/interface/Track.h"
10     #include "MitAna/DataCont/interface/ObjArray.h"
11     #include "MitAna/DataTree/interface/Names.h"
12     #include "MitCommon/MathTools/interface/MathUtils.h"
13    
14     using namespace mithep;
15    
16     ClassImp(mithep::ConversionRemoval)
17    
18     //__________________________________________________________________________________________________
19     ConversionRemoval::ConversionRemoval(const char *name, const char *title) :
20     BaseMod (name,title),
21     fPtMin (0),
22     fEtaMax (0),
23     fProbMin (0),
24     fNHitsMin(0),
25     fNStereoHitsMin(0),
26     fNPixelHitsMin(0),
27     fExcludePXB1(false),
28     fMassMax(0),
29     fMissedHitsMax(0),
30     fWrongHitsMax(0),
31     fElectronPtMin(0),
32     fElectronEtaMax(0),
33     fComputeEff(kFALSE),
34     fHitBasedMatching(kFALSE),
35     fRequireCleanElectron(kFALSE),
36     fTrackQualityFirstOnly(kFALSE),
37     fMatchWe(kFALSE),
38     fMatchSimConv(kFALSE),
39     fRequireGoodPv(kFALSE),
40     fMaxTrackDzPv(999.99),
41     fMinClusterVtxQual(0.0),
42     fMaxNSharedHits(999),
43     fMinNSharedHits(0),
44     fTracks (0),
45     fGsfTracks (0),
46     fInOutTracks (0),
47     fOutInTracks (0),
48     fElectrons (0),
49     fTrkElectrons(0),
50     fPhotons (0),
51     fMCParticles (0),
52     fMvfConversions (0),
53     fMvfConversionsUnconstrained (0),
54     fPrimaryVertexes(0),
55     fEvtSel(0),
56     fCleanElectrons(0),
57     fMCPartName (Names::gkMCPartBrn),
58     fTrackName (Names::gkTrackBrn),
59     fConvElectronName ("Electrons"),
60     fPhotonName (Names::gkPhotonBrn),
61     fMvfConvName("ConversionRemoval"),
62     fMvfConvUnconstrainedName("ConversionRemovalUnconstrained"),
63     fElectronName(Names::gkElectronBrn),
64     fTrkElectronName("TrackerElectrons"),
65     fGoodElectronsName("ConversionElectrons"),
66     fGoodTwoClusterElectronsName("TwoClusterConversionElectrons"),
67     fBadElectronsName("ConversionRemovedElectrons"),
68     fFakingConversionsName("fakingConversions"),
69     fRemovedElectronsName("removedElectrons"),
70     fAllConversionElectronsName("allConversionElectrons"),
71     hConversionRadius (0),
72     hConversionRadiusBarrel(0),
73     hConversionZ(0),
74     hConversionRPhi (0),
75     hConversionRZ(0),
76     hConversionFoldedRZ(0),
77     hGammaPt (0),
78     hGammaEta (0),
79     hGammaPhi(0),
80     hGammaMass (0),
81     hSimMatchedGammaMass(0),
82     hConvProb (0),
83     hConvChi2 (0),
84     hSimMatchedConvChi2(0),
85     hConvDCotTheta (0),
86     hConvDCotThetaPreCut (0),
87     hConvEOverP (0),
88     hElectronPt (0),
89     hMinElectronPt (0),
90     hSimMinElectronPt (0),
91     hSimMatchedMinElectronPt (0),
92     hSimMatchedMinElectronSimPt (0),
93     hElectronEta (0),
94     hEPairMass (0),
95     hEPairDeltaPhi (0),
96     hGenNumDaughters (0),
97     hGenDaughterPt (0),
98     hGenDecayRadius (0),
99     hSimPt (0),
100     hSimEta(0),
101     hSimConvRadius (0),
102     hSimConvPosition(0),
103     hTrackSimMatchType (0),
104     hParentSimMatchType (0),
105     hSimMatchedConvRadius (0),
106     hSimMatchedConvProb (0),
107     hSimMatchedEPairMass (0),
108     hSimMatchedEPairDeltaPhi (0),
109     hSimMatchedSimConvRadius (0),
110     hSimMatchedConvResolution (0),
111     hSimMatchedConvPhiRes (0),
112     hSimMatchedConvEOverP (0),
113     hSimMatchedElectronPt (0),
114     hSimMatchedGammaPt (0),
115     hSimMatchedGammaEta (0),
116     hSimMatchedSimGammaPt (0),
117     hSimMatchedSimGammaEta (0),
118     hTrackChi2 (0),
119     hTrackProb (0),
120     hTrackNHits (0),
121     hTrackNWrongHits(0),
122     hTrackNMissingHits(0),
123     hNSharedHits(0),
124     hTrackNHitsProb (0),
125     hTrackD0 (0),
126     hTrackDzPv(0),
127     hUnMatchedTrackChi2 (0),
128     hUnMatchedTrackProb (0),
129     hUnMatchedTrackNHits (0),
130     hUnMatchedTrackNHitsProb (0),
131     hUnMatchedTrackD0 (0),
132     hSimMatchedTrackChi2 (0),
133     hSimMatchedTrackProb (0),
134     hSimMatchedTrackNHits (0),
135     hSimMatchedTrackNHitsProb (0),
136     hSimMatchedTrackD0 (0),
137     hLxy(0),
138     hLxyOverLxyErr(0),
139     hLz(0),
140     hLzOverLzErr(0),
141     hDxy(0),
142     hSimMatchedLxy(0),
143     hSimMatchedLz(0),
144     hSimMatchedDxy(0),
145     hNTracks(0),
146     hSimMatchedNTracks(0),
147     hIsolation(0),
148     hSimMatchedIsolation(0),
149     hNConversions(0),
150     hDoubleConvMass(0),
151     hConvGammaMass(0),
152     hPiPiMass(0),
153     hAllConversionElectronChargeAssign(0),
154     hRemovedElectronChargeAssign(0),
155     hTrackAlgo(0),
156     hCharge(0),
157     hPt1Pt2(0),
158     hClusVtxDiff(0),
159     hClusVtxQual(0)
160     {
161     // Constructor.
162     }
163    
164     //__________________________________________________________________________________________________
165     void ConversionRemoval::Begin()
166     {
167     // Run startup code on the client machine. For this module, we dont do anything here.
168     }
169    
170     //__________________________________________________________________________________________________
171     void ConversionRemoval::SlaveBegin()
172     {
173     // Run startup code on the computer (slave) doing the actual analysis. Here, we typically
174     // initialize histograms and other analysis objects and request branches. For this module, we
175     // request a branch of the MitTree.
176    
177     // Request the branches
178     ReqBranch(fTrackName, fTracks);
179     ReqBranch("ConversionInOutTracks", fInOutTracks);
180     ReqBranch("ConversionOutInTracks", fOutInTracks);
181     //ReqBranch(fElectronName, fElectrons);
182     //ReqBranch(fTrkElectronName, fTrkElectrons);
183     ReqBranch(fPhotonName, fPhotons);
184     ReqBranch(fMCPartName, fMCParticles);
185     ReqBranch(fMvfConvName, fMvfConversions);
186     ReqBranch(fMvfConvUnconstrainedName, fMvfConversionsUnconstrained);
187     ReqBranch("PrimaryVertexes",fPrimaryVertexes);
188     ReqBranch("EvtSelData",fEvtSel);
189    
190     // Book our histograms
191    
192     hConversionRPhi = new TH2F("Photon Conversion Position R-Phi","Conversion Position R-Phi (cm)", 100, -100.0,100.0,100,-100.0,100.0);
193     AddOutput(hConversionRPhi);
194    
195     hConversionRZ = new TH2F("Photon Conversion Position R-Z","Conversion Position R-Z (cm)", 1000, -100.0,100.0,1000,-100.0,100.0);
196     AddOutput(hConversionRZ);
197    
198     hConversionFoldedRZ = new TH2F("hConversionFoldedRZ","Conversion Position R-Z (cm)", 1000, -100.0,100.0,500,-0.0,100.0);
199     AddOutput(hConversionFoldedRZ);
200    
201     hSimConvPosition = new TH2F("Sim Photon Conversion Position","Sim Photon Conversion Position", 200, -200.0,200.0,200,-200.0,200.0);
202     AddOutput(hSimConvPosition);
203    
204    
205     //TH1::SetDefaultSumw2(kTRUE);
206    
207     hConversionRadius = new TH1F("Photon Conversion Radius","Radius (cm)",800,0,200.0);
208     AddOutput(hConversionRadius);
209    
210     hConversionRadiusBarrel = new TH1F("hConversionRadiusBarrel","Radius (cm)",800,0,200.0);
211     AddOutput(hConversionRadiusBarrel);
212    
213     hConversionZ = new TH1F("Photon Conversion Z position", "Conversion Z position (cm)", 200, -200.0, 200.0);
214     AddOutput(hConversionZ);
215    
216     hGammaPt = new TH1F("Photon Pt","Photon Pt (GeV)",400,0,200.0);
217     AddOutput(hGammaPt);
218    
219     hGammaEta = new TH1F("Photon Eta","Photon Eta",200,-5.0,5.0);
220     AddOutput(hGammaEta);
221    
222     hGammaPhi = new TH1F("hGammaPhi","Photon Phi",200,-1.0*TMath::Pi(),1.0*TMath::Pi());
223     AddOutput(hGammaPhi);
224    
225    
226     hGammaMass = new TH1F("Photon Invariant Mass","Photon Invariant Mass",200,0,2.0);
227     AddOutput(hGammaMass);
228    
229     hSimMatchedGammaMass = new TH1F("SimMatched Photon Invariant Mass","SimMatched Photon Invariant Mass",200,0,20.0);
230     AddOutput(hSimMatchedGammaMass);
231    
232     hConvProb = new TH1F("Conversion Vertex fit probability", "Vertex Fit Probability",200,0.0,1.0);
233     AddOutput(hConvProb);
234    
235     hConvChi2 = new TH1F("Conversion Vertex fit Chi squared", "Vertex Fit Chi Squared",2000,0.0,100.0);
236     AddOutput(hConvChi2);
237    
238     hSimMatchedConvChi2 = new TH1F("Sim Matched Conversion Vertex fit Chi squared", "Sim Matched Vertex Fit Chi Squared",2000,0.0,100.0);
239     AddOutput(hSimMatchedConvChi2);
240    
241     hConvDCotTheta = new TH1F("Conversion DCotTheta", "DCotTheta",10001,-10.0,10.0);
242     AddOutput(hConvDCotTheta);
243    
244     hConvDCotThetaPreCut = new TH1F("Conversion DCotTheta before fit prob cut", "DCotThetaPreCut",1000,-10.0,10.0);
245     AddOutput(hConvDCotThetaPreCut);
246    
247     hConvEOverP = new TH1F("Conversion E over P", "Conversion E over P",200,0.0,50.0);
248     AddOutput(hConvEOverP);
249    
250     hElectronPt = new TH1F("Electron Pt","Electron Pt (GeV)",400,0,200.0);
251     AddOutput(hElectronPt);
252    
253     hMinElectronPt = new TH1F("Min Electron Pt","Min Electron Pt (GeV)",2000,0,200.0);
254     AddOutput(hMinElectronPt);
255    
256     hSimMatchedMinElectronPt = new TH1F("Sim Matched Min Electron Pt","Sim Matched Min Electron Pt (GeV)",2000,0,200.0);
257     AddOutput(hSimMatchedMinElectronPt);
258    
259     hSimMatchedMinElectronSimPt = new TH1F("Sim Matched Min Electron Sim Pt","Sim Matched Min Electron Sim Pt (GeV)",2000,0,200.0);
260     AddOutput(hSimMatchedMinElectronSimPt);
261    
262     hSimMinElectronPt = new TH1F("Sim Min Electron Pt","Sim Min Electron Pt (GeV)",2000,0,200.0);
263     AddOutput(hSimMinElectronPt);
264    
265     hElectronEta = new TH1F("Electron Eta","Electron Eta",200,-5.0,5.0);
266     AddOutput(hElectronEta);
267    
268     hEPairMass = new TH1F("Electron Pair Invariant Mass","Electron Pair Invariant Mass",200,0.0,10);
269     AddOutput(hEPairMass);
270    
271     hEPairDeltaPhi = new TH1F("Electron Pair Delta Phi","Electron Pair Delta Phi",200,-4.0,4.0);
272     AddOutput(hEPairDeltaPhi);
273    
274     hGenNumDaughters = new TH1F("Number of Decay daughters - gen level","Number of Decay daughters - gen level",10,-0.5,9.5);
275     AddOutput(hGenNumDaughters);
276    
277     hGenDaughterPt = new TH1F("Pt of decay daugthers - gen level","Pt of decay daugthers - gen level",2000,0,200.0);
278     AddOutput(hGenDaughterPt);
279    
280     hGenDecayRadius = new TH1F("Decay vertex radius - gen level","Decay vertex radius - gen level",800,0,200.0);
281     AddOutput(hGenDecayRadius);
282    
283     hSimPt = new TH1F("Pt - sim level","Pt - sim level",2000,0,200.0);
284     AddOutput(hSimPt);
285    
286     hSimEta = new TH1F("Sim Photon Eta","Photon Eta",200,-5.0,5.0);
287     AddOutput(hSimEta);
288    
289     hSimConvRadius = new TH1F("Sim Photon Conversion Radius","Sim Photon Conversion Radius",800,0,200.0);
290     AddOutput(hSimConvRadius);
291    
292     // hTrackD0 = new TH1F("general track D0","general track D0",2000,0,200.0);
293     // AddOutput(hTrackD0);
294    
295     hTrackSimMatchType = new TH1F("Conversion Electron matched sim pdg","Conversion Electron matched sim pdg",10001,-5000.5,5000.5);
296     AddOutput(hTrackSimMatchType);
297    
298     hParentSimMatchType = new TH1F("Conversion Parent matched sim pdg","Conversion Parent matched sim pdg",10001,-5000.5,5000.5);
299     AddOutput(hParentSimMatchType);
300    
301     hSimMatchedConvRadius = new TH1F("Sim Matched Photon Conversion Radius","Sim Matched Photon Conversion Radius",800,0,200.0);
302     AddOutput(hSimMatchedConvRadius);
303    
304     hSimMatchedConvProb = new TH1F("Sim Matched Conversion Vertex fit probability", "Sim Matched Vertex Fit Probability",200,0.0,1.0);
305     AddOutput(hSimMatchedConvProb);
306    
307     hSimMatchedEPairMass = new TH1F("Sim Matched Electron Pair Invariant Mass","Sim Matched Electron Pair Invariant Mass",200,0.0,10);
308     AddOutput(hSimMatchedEPairMass);
309    
310     hSimMatchedEPairDeltaPhi = new TH1F("Sim Matched Electron Pair Delta Phi","Sim Matched Electron Pair Delta Phi",200,-4.0,4.0);
311     AddOutput(hSimMatchedEPairDeltaPhi);
312    
313     hSimMatchedSimConvRadius = new TH1F("Sim Matched Photon Sim Conversion Radius","Sim Matched Photon Conversion Sim Radius",800,0,200.0);
314     AddOutput(hSimMatchedSimConvRadius);
315    
316     hSimMatchedConvResolution = new TH1F("Sim Matched Photon Conversion Radius Resolution","Sim Matched Photon Conversion Radius Resolution",300,-30.0,30.0);
317     AddOutput(hSimMatchedConvResolution);
318    
319     hSimMatchedConvPhiRes = new TH1F("Sim Matched Photon Conversion Phi Resolution","Sim Matched Photon Conversion Phi Resolution",1000,-3.5,3.5);
320     AddOutput(hSimMatchedConvPhiRes);
321    
322     hSimMatchedConvEOverP = new TH1F("Sim Matched Conversion E over P", "Sim Matched Conversion E over P",200,0.0,50.0);
323     AddOutput(hSimMatchedConvEOverP);
324    
325     hSimMatchedElectronPt = new TH1F("Sim Matched Electron Pt","Sim Matched Electron Pt (GeV)",2000,0,200.0);
326     AddOutput(hSimMatchedElectronPt);
327    
328     hSimMatchedGammaPt = new TH1F("Sim Matched Photon Pt","Sim Matched Photon Pt (GeV)",2000,0,200.0);
329     AddOutput(hSimMatchedGammaPt);
330    
331     hSimMatchedGammaEta = new TH1F("Sim Matched Photon Eta","Sim Matched Photon Eta",200,-5.0,5.0);
332     AddOutput(hSimMatchedGammaEta);
333    
334     hSimMatchedSimGammaPt = new TH1F("Sim Matched Sim Photon Pt","Sim Matched Sim Photon Pt (GeV)",2000,0,200.0);
335     AddOutput(hSimMatchedSimGammaPt);
336    
337     hSimMatchedSimGammaEta = new TH1F("Sim Matched Sim Photon Eta","Sim Matched Sim Photon Eta",200,-5.0,5.0);
338     AddOutput(hSimMatchedSimGammaEta);
339    
340     hTrackChi2 = new TH1F("Conversion Track RChi squared", "Track RChi Squared",200,0.0,10.0);
341     AddOutput(hTrackChi2);
342    
343     hTrackProb = new TH1F("Conversion Track fit probability", "Track Fit Probability",200,0.0,1.0);
344     AddOutput(hTrackProb);
345    
346     hTrackNHits = new TH1F("Conversion Track NHits", "Track NHits",37,-0.5,36.5);
347     AddOutput(hTrackNHits);
348    
349     hTrackNMissingHits = new TH1F("hTrackNMissingHits", "Track NMissingHits",37,-0.5,36.5);
350     AddOutput(hTrackNMissingHits);
351    
352     hTrackNWrongHits = new TH1F("hTrackNWrongHits", "Track NWrongHits",37,-0.5,36.5);
353     AddOutput(hTrackNWrongHits);
354    
355     hNSharedHits = new TH1F("hNSharedHits", "hNSharedHits",37,-0.5,36.5);
356     AddOutput(hNSharedHits);
357    
358     hTrackNHitsProb = new TH2F("Track NHits-RChi2","Track NHits-RChi2", 37,-0.5,36.5,50,0.0,10.0);
359     AddOutput(hTrackNHitsProb);
360    
361     hTrackD0 = new TH1F("Conversion track D0","Conversion track D0",100,-5.0,5.0);
362     AddOutput(hTrackD0);
363    
364     hTrackDzPv = new TH1F("hTrackDzPv","Conversion track DZ wrt PV",100,-20.0,20.0);
365     AddOutput(hTrackDzPv);
366    
367     hUnMatchedTrackChi2 = new TH1F("UnMatched Conversion Track RChi squared", "UnMatched Track RChi Squared",200,0.0,10.0);
368     AddOutput(hUnMatchedTrackChi2);
369    
370     hUnMatchedTrackProb = new TH1F("UnMatched Conversion Track fit probability", "UnMatched Track Fit Probability",200,0.0,1.0);
371     AddOutput(hUnMatchedTrackProb);
372    
373     hUnMatchedTrackNHits = new TH1F("UnMatched Conversion Track NHits", "UnMatched Track NHits",37,-0.5,36.5);
374     AddOutput(hUnMatchedTrackNHits);
375    
376     hUnMatchedTrackNHitsProb = new TH2F("UnMatched Track NHits-RChi2","UnMatched Track NHits-RChi2", 37,-0.5,36.5,50,0.0,10.0);
377     AddOutput(hUnMatchedTrackNHitsProb);
378    
379     hUnMatchedTrackD0 = new TH1F("UnMatched Conversion track D0","UnMatched Conversion track D0",100,-5.0,5.0);
380     AddOutput(hUnMatchedTrackD0);
381    
382     hSimMatchedTrackChi2 = new TH1F("SimMatched Conversion Track RChi squared", "SimMatched Track RChi Squared",200,0.0,10.0);
383     AddOutput(hSimMatchedTrackChi2);
384    
385     hSimMatchedTrackProb = new TH1F("SimMatched Conversion Track fit probability", "SimMatched Track Fit Probability",200,0.0,1.0);
386     AddOutput(hSimMatchedTrackProb);
387    
388     hSimMatchedTrackNHits = new TH1F("SimMatched Conversion Track NHits", "SimMatched Track NHits",37,-0.5,36.5);
389     AddOutput(hSimMatchedTrackNHits);
390    
391     hSimMatchedTrackNHitsProb = new TH2F("SimMatched Track NHits-RChi2","SimMatched Track NHits-RChi2", 37,-0.5,36.5,50,0.0,10.0);
392     AddOutput(hSimMatchedTrackNHitsProb);
393    
394     hSimMatchedTrackD0 = new TH1F("SimMatched Conversion track D0","SimMatched Conversion track D0",100,-5.0,5.0);
395     AddOutput(hSimMatchedTrackD0);
396    
397     hLxy = new TH1F("Conversion Lxy","Conversion Lxy",240,-30.0,30.0);
398     AddOutput(hLxy);
399    
400     hLxyOverLxyErr = new TH1F("Conversion Lxy/LxyErr","Conversion Lxy/LxyErr",200,-100.0,100.0);
401     AddOutput(hLxyOverLxyErr);
402    
403     hLz = new TH1F("Conversion Lz","Conversion Lz",200,-50.0,50.0);
404     AddOutput(hLz);
405    
406     hLzOverLzErr = new TH1F("Conversion Lz/LzErr","Conversion Lz/LzErr",200,-100.0,100.0);
407     AddOutput(hLzOverLzErr);
408    
409     hDxy = new TH1F("Conversion Dxy","Conversion Dxy",200,-5.0,5.0);
410     AddOutput(hDxy);
411    
412     hSimMatchedLxy = new TH1F("SimMatched Conversion Lxy","SimMatched Conversion Lxy",100,-30.0,30.0);
413     AddOutput(hSimMatchedLxy);
414    
415     hSimMatchedLz = new TH1F("SimMatched Conversion Lz","SimMatched Conversion Lz",200,-50.0,50.0);
416     AddOutput(hSimMatchedLz);
417    
418     hSimMatchedDxy = new TH1F("SimMatched Conversion Dxy","SimMatched Conversion Dxy",200,-5.0,5.0);
419     AddOutput(hSimMatchedDxy);
420    
421     hNTracks = new TH1F("Number of Tracks in the event", "Number of tracks in the event", 401, -0.5,400.5);
422     AddOutput(hNTracks);
423    
424     hSimMatchedNTracks = new TH1F("SimMatched Number of Tracks in the event", "SimMatched Number of tracks in the event", 401, -0.5,400.5);
425     AddOutput(hSimMatchedNTracks);
426    
427     hIsolation = new TH1F("Track Isolation of Conversion", "Track Isolation of Conversion", 201, -0.5,200.5);
428     AddOutput(hIsolation);
429    
430     hSimMatchedIsolation = new TH1F("SimMatched Track Isolation of Conversion", "SimMatched Track Isolation of Conversion", 201, -0.5,200.5);
431     AddOutput(hSimMatchedIsolation);
432    
433     hNConversions = new TH1F("Number of Conversions", "Number of Conversions",10,-0.5,10.5);
434     AddOutput(hNConversions);
435    
436     hDoubleConvMass = new TH1F("Double Conversion Mass", "Double Conversion Mass", 1000, 0.0, 10.0);
437     AddOutput(hDoubleConvMass);
438    
439     hConvGammaMass = new TH1F("Conversion plus Photon Mass", "Conversion plus Photon Mass", 1000, 0.0, 10.0);
440     AddOutput(hConvGammaMass);
441    
442     hPiPiMass = new TH1F("Conversion two pion Mass", "Conversion two pion Mass", 1000,0.0,10.0);
443     AddOutput(hPiPiMass);
444    
445     hAllConversionElectronPt = new TH1F("hAllConversionElectronPt","Electron Pt (GeV)",2000,0,200.0);
446     AddOutput(hAllConversionElectronPt);
447    
448     hAllConversionElectronEta = new TH1F("hAllConversionElectronEta","Electron Eta",200,-5.0,5.0);
449     AddOutput(hAllConversionElectronEta);
450    
451     hRemovedElectronPt = new TH1F("hRemovedElectronPt","Electron Pt (GeV)",2000,0,200.0);
452     AddOutput(hRemovedElectronPt);
453    
454     hRemovedElectronEta = new TH1F("hRemovedElectronEta","Electron Eta",200,-5.0,5.0);
455     AddOutput(hRemovedElectronEta);
456    
457     hAllConversionElectronPtWrongCharge = new TH1F("hAllConversionElectronPtWrongCharge","Electron Pt (GeV)",2000,0,200.0);
458     AddOutput(hAllConversionElectronPtWrongCharge);
459    
460     hAllConversionElectronEtaWrongCharge = new TH1F("hAllConversionElectronEtaWrongCharge","Electron Eta",200,-5.0,5.0);
461     AddOutput(hAllConversionElectronEtaWrongCharge);
462    
463     hRemovedElectronPtWrongCharge = new TH1F("hRemovedElectronPtWrongCharge","Electron Pt (GeV)",2000,0,200.0);
464     AddOutput(hRemovedElectronPtWrongCharge);
465    
466     hRemovedElectronEtaWrongCharge = new TH1F("hRemovedElectronEtaWrongCharge","Electron Eta",200,-5.0,5.0);
467     AddOutput(hRemovedElectronEtaWrongCharge);
468    
469     hAllConversionElectronChargeAssign = new TH1F("hAllConversionElectronChargeAssign","Electron Charge Assignment",3.0,-1.5,1.5);
470     AddOutput(hAllConversionElectronChargeAssign);
471    
472     hRemovedElectronChargeAssign = new TH1F("hRemovedElectronChargeAssign","Electron Charge Assignment",3.0,-1.5,1.5);
473     AddOutput(hRemovedElectronChargeAssign);
474    
475     hTrackAlgo = new TH1F("hTrackAlgo","Conversion Track Algorithm",101,-0.5,100.5);
476     AddOutput(hTrackAlgo);
477    
478     hCharge = new TH1F("hCharge","Candidate Charge",5.0,-2.5,2.5);
479     AddOutput(hCharge);
480    
481     hPt1Pt2 = new TH2F("hPt1Pt2","Pt1 vs Pt2", 500,0,10.0,500,0.0,10.0);
482     AddOutput(hPt1Pt2);
483    
484     hClusVtxDiff = new TH1F("hClusVtxDiff","hClusVtxDiff",201,-0.5,200.5);
485     AddOutput(hClusVtxDiff);
486    
487     hClusVtxQual = new TH1F("hClusVtxQual","hClusVtxQual",200,0.0,20);
488     AddOutput(hClusVtxQual);
489    
490     fTimer.Start(1e8);
491    
492     }
493    
494     //__________________________________________________________________________________________________
495     void ConversionRemoval::Process()
496     {
497     // Process entries of the tree. For this module, we just load the branch and fill the histograms.
498     // --> Why is this done on the basis of the name? should be the pointer!
499    
500     // BitMask64 testMask;
501     // testMask.SetBit(Track::TIB1S);
502     // testMask.SetBit(Track::TIB2S);
503     // testMask.SetBit(Track::TID1S);
504     // testMask.SetBit(Track::TID2S);
505     // testMask.SetBit(Track::TID3S);
506     // testMask.SetBit(Track::TOB1S);
507     // testMask.SetBit(Track::TOB2S);
508     // testMask.SetBit(Track::TEC1S);
509     // testMask.SetBit(Track::TEC2S);
510     // testMask.SetBit(Track::TEC3S);
511     // testMask.SetBit(Track::TEC4S);
512     // testMask.SetBit(Track::TEC5S);
513     // testMask.SetBit(Track::TEC6S);
514     // testMask.SetBit(Track::TEC7S);
515     // testMask.SetBit(Track::TEC8S);
516     // testMask.SetBit(Track::TEC9S);
517     //
518     // const Long64_t *maskVal = reinterpret_cast<const Long64_t*>(testMask.Bits());
519     //
520     // printf("HitMaskVal = %lli\n",*maskVal);
521     //
522     // Track testTrack;
523     // if (testMask == testTrack.StereoLayers())
524     // printf("stereo mask match\n");
525     // else
526     // printf("stereo mask mismatch\n");
527     //
528    
529     LoadBranch(fTrackName);
530     LoadBranch("PrimaryVertexes");
531     LoadBranch("EvtSelData");
532    
533     fCleanElectrons = GetObjThisEvt<ElectronCol>(fCleanElectronsName);
534     ObjArray<Electron> *allConversionElectrons = new ObjArray<Electron>;
535     AddObjThisEvt(allConversionElectrons,fAllConversionElectronsName);
536    
537     //printf("first loop\n")
538     if (fComputeEff && (!fRequireCleanElectron || fCleanElectrons->GetEntries())) {
539     LoadBranch(fMCPartName);
540     for (UInt_t i=0; i<fCleanElectrons->GetEntries(); ++i) {
541     const Electron *e = fCleanElectrons->At(i);
542     if ( !fMatchSimConv && fMatchWe && SimWeMatch(e) )
543     allConversionElectrons->Add(e);
544     else if (fMatchSimConv && !fMatchWe && SimConversionMatch(e))
545     allConversionElectrons->Add(e);
546     else if (!fMatchSimConv && !fMatchWe)
547     allConversionElectrons->Add(e);
548     }
549    
550     for (UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
551     const MCParticle* p = fMCParticles->At(i);
552     const BitMask16 simFailed = FailedSimCuts(p);
553    
554     BitMask16 simPtFailed = simFailed;
555     simPtFailed.ClearBit(eSimPt);
556     if (!simPtFailed.NBitsSet())
557     hSimPt->Fill(p->Pt());
558    
559     BitMask16 simEtaFailed = simFailed;
560     simEtaFailed.ClearBit(eSimEta);
561     if (!simEtaFailed.NBitsSet())
562     hSimEta->Fill(p->Eta());
563    
564     BitMask16 simRhoFailed = simFailed;
565     simRhoFailed.ClearBit(eSimRho);
566     if ( !simRhoFailed.NBitsSet() ) {
567     hSimConvRadius->Fill(p->DecayVertex().Rho());
568     hSimConvPosition->Fill(p->DecayVertex().X(),p->DecayVertex().Y());
569     }
570     Double_t minPt=999;
571     for (UInt_t j=0; j<p->NDaughters(); ++j) {
572     const MCParticle *d = p->Daughter(j);
573     if (TMath::Abs(d->PdgId())==11) {
574     if (d->Pt()<minPt)
575     minPt = d->Pt();
576     }
577     }
578    
579     BitMask16 simElectronPtFailed = simFailed;
580     simElectronPtFailed.ClearBit(eSimElectronPt);
581     if ( !simElectronPtFailed.NBitsSet() )
582     hSimMinElectronPt->Fill(minPt);
583    
584     }
585     }
586    
587     //printf("second loop\n")
588     ObjArray<DecayParticle> *fakingConversions = new ObjArray<DecayParticle>;
589     AddObjThisEvt(fakingConversions,fFakingConversionsName);
590     if (!fRequireCleanElectron || allConversionElectrons->GetEntries()) {
591     LoadBranch(fMvfConvName);
592     for (UInt_t i=0; i<fMvfConversions->GetEntries(); ++i) {
593     const DecayParticle* d = fMvfConversions->At(i);
594     if (!fRequireCleanElectron || ElectronMatch(d,allConversionElectrons))
595     fakingConversions->Add(d);
596     }
597     }
598    
599    
600     //printf("third loop\n")
601     ObjArray<DecayParticle> goodConversions;
602     ObjArray<Electron> *removedElectrons = new ObjArray<Electron>;
603     AddObjThisEvt(removedElectrons,fRemovedElectronsName);
604     UInt_t nConversions = 0;
605     for (UInt_t i=0; i<fakingConversions->GetEntries(); ++i) {
606     //if (nConversions>=1) continue;
607     const DecayParticle* c = fakingConversions->At(i);
608     const BitMask16 failed = FailedCuts(c);
609    
610     // printf("Looking for sim match\n");
611     const MCParticle *simPhoton = SimMatch(c);
612     UInt_t nSimFailed=0;
613     BitMask16 simFailed;
614     //printf("Checking sim cuts\n");
615     if (simPhoton)
616     simFailed = FailedSimCuts(simPhoton);
617    
618     //make N-2 plots for decay length
619     BitMask16 decayLengthFailed = failed;
620     decayLengthFailed.ClearBit(eRho);
621     decayLengthFailed.ClearBit(eL);
622     if (!decayLengthFailed.NBitsSet()) {
623     hLxy->Fill(c->Lxy());
624     hLxyOverLxyErr->Fill(c->Lxy()/c->LxyError());
625     hLzOverLzErr->Fill(c->Lz()/c->LzError());
626     hLz->Fill(c->Lz());
627     if (simPhoton && !simFailed.NBitsSet()) {
628     hSimMatchedLxy->Fill(c->Lxy());
629     hSimMatchedLz->Fill(c->Lz());
630     }
631     }
632    
633     //make N-1 plots
634     //printf("Make N-1 plots\n");
635    
636     BitMask16 ptFailed = failed;
637     ptFailed.ClearBit(ePt);
638     if (!ptFailed.NBitsSet()) {
639     hGammaPt->Fill(c->Pt());
640     if (simPhoton) {
641     BitMask16 simPtFailed = simFailed;
642     simPtFailed.ClearBit(eSimPt);
643     if (!simPtFailed.NBitsSet()) {
644     hSimMatchedGammaPt->Fill(c->Pt());
645     hSimMatchedSimGammaPt->Fill(simPhoton->Pt());
646     }
647     }
648     }
649    
650     BitMask16 etaFailed = failed;
651     etaFailed.ClearBit(eEta);
652     if (!etaFailed.NBitsSet()) {
653     hGammaEta->Fill(c->Eta());
654     if (simPhoton) {
655     BitMask16 simEtaFailed = simFailed;
656     simEtaFailed.ClearBit(eSimEta);
657     if (!simEtaFailed.NBitsSet()) {
658     hSimMatchedGammaEta->Fill(c->Eta());
659     hSimMatchedSimGammaEta->Fill(simPhoton->Eta());
660     }
661     }
662     }
663    
664     BitMask16 rhoFailed = failed;
665     rhoFailed.ClearBit(eRho);
666     if ( !rhoFailed.NBitsSet() ) {
667     hConversionRadius->Fill(c->Position().Rho());
668     hConversionRPhi->Fill(c->Position().X(), c->Position().Y());
669     hConversionRZ->Fill(c->Position().Z(), c->Position().Rho()*c->Position().Y()/TMath::Abs(c->Position().Y()));
670     hConversionFoldedRZ->Fill(c->Position().Z(), c->Position().Rho());
671     if (c->AbsEta()<1.2)
672     hConversionRadiusBarrel->Fill(c->Position().Rho());
673     if (simPhoton) {
674     BitMask16 simRhoFailed = simFailed;
675     simRhoFailed.ClearBit(eSimRho);
676     if ( !simRhoFailed.NBitsSet() ) {
677     hSimMatchedConvRadius->Fill(c->Position().Rho());
678     hSimMatchedSimConvRadius->Fill(simPhoton->DecayVertex().Rho());
679     }
680     }
681     }
682    
683     BitMask16 dxyFailed = failed;
684     dxyFailed.ClearBit(eDxy);
685     if ( !dxyFailed.NBitsSet() ) {
686     hDxy->Fill(c->Dxy());
687     if (simPhoton && !simFailed.NBitsSet() )
688     hSimMatchedDxy->Fill(c->Dxy());
689     }
690    
691     BitMask16 probFailed = failed;
692     probFailed.ClearBit(eProb);
693     if (!probFailed.NBitsSet()) {
694     hConvProb->Fill(c->Prob());
695     hConvChi2->Fill(c->Chi2());
696     if (simPhoton && !simFailed.NBitsSet() )
697     hSimMatchedConvProb->Fill(c->Prob());
698     }
699    
700     BitMask16 clusVtxFailed = failed;
701     clusVtxFailed.ClearBit(eClusVtx);
702     if (!clusVtxFailed.NBitsSet()) {
703     hClusVtxDiff->Fill(fEvtSel->ClusVtxDiff());
704     hClusVtxQual->Fill(fEvtSel->ClusVtxQual());
705     }
706    
707     BitMask16 sharedHitsFailed = failed;
708     sharedHitsFailed.ClearBit(eSharedHits);
709     if (!sharedHitsFailed.NBitsSet()) {
710     hNSharedHits->Fill(c->NSharedHits());
711     }
712    
713    
714     //printf("Loop over daughters\n");
715    
716     BitMask16 daughtersFailed = failed;
717     daughtersFailed.ClearBit(eDaughters);
718     if ( !daughtersFailed.NBitsSet() ) {
719     Double_t minElectronPt = c->Daughter(0)->Pt();
720     Double_t maxElectronPt = c->Daughter(1)->Pt();
721     if (c->Daughter(1)->Pt() < c->Daughter(0)->Pt()) {
722     minElectronPt = c->Daughter(1)->Pt();
723     maxElectronPt = c->Daughter(0)->Pt();
724     }
725    
726     const Particle *minPtElectron = c->Daughter(0);
727     BitMask16 minPtElectronFailed;
728     for (UInt_t j=0; j<1; ++j) {
729     const DaughterData* d = c->DaughterDat(j);
730     const StableData *s = dynamic_cast<const StableData*>(d);
731     if (!s)
732     Fatal("FailedElectronCuts", "DaughterData not a StableData");
733    
734     const ChargedParticle* dc = dynamic_cast<const ChargedParticle*>(c->Daughter(j));
735     if (!dc)
736     Fatal("FailedElectronCuts", "Daughter not a ChargedParticle");
737    
738     const Track* t = dc->Trk();
739    
740     const BitMask16 electronFailed = FailedElectronCuts(d);
741    
742     if (d->Pt() < minElectronPt) {
743     minPtElectron = dc;
744     minPtElectronFailed = electronFailed;
745     }
746    
747     BitMask16 failedEPt = electronFailed;
748     failedEPt.ClearBit(eEPt);
749     if (!failedEPt.NBitsSet())
750     hElectronPt->Fill(d->Pt());
751    
752     BitMask16 failedEEta = electronFailed;
753     failedEEta.ClearBit(eEEta);
754     if (!failedEEta.NBitsSet())
755     hElectronEta->Fill(d->Eta());
756    
757     BitMask16 failedENHits = electronFailed;
758     failedENHits.ClearBit(eENHits);
759     if (!failedENHits.NBitsSet()) {
760     hTrackNHits->Fill(t->NHits());
761     if (1 )
762     hSimMatchedTrackNHits->Fill(t->NHits());
763     }
764    
765     BitMask16 failedENMissingHits = electronFailed;
766     failedENMissingHits.ClearBit(eENMissingHits);
767     if (!failedENMissingHits.NBitsSet()) {
768     hTrackNMissingHits->Fill(s->NMissedHits());
769     }
770    
771     BitMask16 failedENWrongHits = electronFailed;
772     failedENWrongHits.ClearBit(eENWrongHits);
773     if (!failedENWrongHits.NBitsSet()) {
774     hTrackNWrongHits->Fill(s->NWrongHits());
775     }
776    
777     BitMask16 failedEProb = electronFailed;
778     failedEProb.ClearBit(eEProb);
779     if (!failedEProb.NBitsSet()) {
780     hTrackProb->Fill(t->Prob());
781     if (1 ) {
782     hSimMatchedTrackChi2->Fill(t->Chi2()/((Double_t)t->Ndof()));
783     hSimMatchedTrackProb->Fill(t->Prob());
784     }
785     }
786    
787     BitMask16 failedEProbNHits = electronFailed;
788     failedEProbNHits.ClearBit(eEProb);
789     failedEProbNHits.ClearBit(eENHits);
790     if ( !failedEProbNHits.NBitsSet() ) {
791     hTrackNHitsProb->Fill(t->NHits(),t->RChi2());
792     hTrackChi2->Fill(t->Chi2()/((Double_t)t->Ndof()));
793     if (1)
794     hSimMatchedTrackNHitsProb->Fill(t->NHits(),t->RChi2());
795     }
796    
797     const mithep::Vertex *pv = fPrimaryVertexes->At(0);
798    
799     BitMask16 failedEDzPv = electronFailed;
800     failedEDzPv.ClearBit(eDz);
801     if (!failedEDzPv.NBitsSet()) {
802     hTrackDzPv->Fill(t->Z0()-pv->Z());
803     }
804    
805     if ( !electronFailed.NBitsSet()) {
806     hTrackD0->Fill(t->D0());
807     }
808     }
809    
810     minPtElectronFailed.ClearBit(eEPt);
811     if (!minPtElectronFailed.NBitsSet()) {
812     hMinElectronPt->Fill(minElectronPt);
813     hPt1Pt2->Fill(maxElectronPt,minElectronPt);
814     if (simPhoton) {
815     BitMask16 simElectronPtFailed = simFailed;
816     simElectronPtFailed.ClearBit(eSimElectronPt);
817     if ( !simElectronPtFailed.NBitsSet() ) {
818     // if (!minPtElectron)
819     // printf("no minptelectron");
820     const ChargedParticle* minElectronC = dynamic_cast<const ChargedParticle*>(minPtElectron);
821     // if (!minElectronC)
822     // printf("no minelectronC\n");
823     const Track *t = minElectronC->Trk();
824     // if (!t)
825     // printf("no t\n");
826     if (t->MCPart())
827     hSimMatchedMinElectronSimPt->Fill(t->MCPart()->Pt());
828     hSimMatchedMinElectronPt->Fill(minElectronPt);
829     }
830     }
831     }
832     }
833    
834     //printf("Good conversions only\n");
835     if ( !failed.NBitsSet() ) {
836     goodConversions.Add(c);
837     ++nConversions;
838     //fill photon histograms
839     hConversionZ->Fill(c->Position().Z());
840     hConvDCotTheta->Fill(DCotTheta(c));
841     hGammaMass->Fill(c->Mass());
842     hCharge->Fill(c->Charge());
843     hGammaPhi->Fill(c->Phi());
844    
845     for (UInt_t j=0; j<1; ++j) {
846     const Particle* d = c->Daughter(j);
847     const ChargedParticle* dc = dynamic_cast<const ChargedParticle*>(d);
848     if (dc) {
849     const Track* t = dc->Trk();
850     hTrackAlgo->Fill(t->Algo());
851     }
852     }
853    
854     const Electron *removedElectron = ElectronMatch(c,allConversionElectrons);
855     if (removedElectron) {
856     removedElectrons->Add(removedElectron);
857     }
858    
859     if (simPhoton && !simFailed.NBitsSet()) {
860    
861     //if (c->Position().Rho() < fRhoMax)
862     hSimMatchedGammaMass->Fill(c->Mass());
863     hSimMatchedConvResolution->Fill(c->Position().Rho() - simPhoton->DecayVertex().Rho());
864     hSimMatchedConvPhiRes->Fill(c->Position().Phi() - simPhoton->DecayVertex().Phi());
865    
866     for (UInt_t j=0; j<1; ++j) {
867     const Particle* d = c->Daughter(j);
868     const ChargedParticle* dc = dynamic_cast<const ChargedParticle*>(d);
869     if (dc) {
870     const Track* t = dc->Trk();
871     hSimMatchedTrackD0->Fill(t->D0());
872     }
873     }
874     }
875     }
876     }
877     hNConversions->Fill(nConversions);
878     if (nConversions>0)
879     printf("bx number = %i, nConversions = %i\n", GetEventHeader()->BunchCrossing(), nConversions);
880    
881     //loop over good conversions only
882     for (UInt_t i=0; i<goodConversions.GetEntries(); ++i) {
883     for (UInt_t j=i+1; j<goodConversions.GetEntries(); ++j) {
884     CompositeParticle *p0 = new CompositeParticle;
885     p0->AddDaughter(goodConversions.At(i));
886     p0->AddDaughter(goodConversions.At(j));
887     hPiPiMass->Fill(p0->Mass());
888     delete p0;
889     }
890     }
891    
892    
893     for (UInt_t i=0; i<allConversionElectrons->GetEntries(); ++i) {
894     const Electron *e = allConversionElectrons->At(i);
895     hAllConversionElectronPt->Fill(e->Pt());
896     hAllConversionElectronEta->Fill(e->Eta());
897     const MCParticle *mcElectron = SimWeMatch(e);
898     if (mcElectron) {
899     const Double_t chargeAssign = e->Charge()*mcElectron->Charge();
900     hAllConversionElectronChargeAssign->Fill(chargeAssign);
901     if (chargeAssign==-1.0) {
902     hAllConversionElectronPtWrongCharge->Fill(e->Pt());
903     hAllConversionElectronEtaWrongCharge->Fill(e->Eta());
904     }
905     }
906     else
907     hAllConversionElectronChargeAssign->Fill(0.0);
908     }
909    
910     for (UInt_t i=0; i<removedElectrons->GetEntries(); ++i) {
911     const Electron *e = removedElectrons->At(i);
912     hRemovedElectronPt->Fill(e->Pt());
913     hRemovedElectronEta->Fill(e->Eta());
914     const MCParticle *mcElectron = SimWeMatch(e);
915     if (mcElectron) {
916     const Double_t chargeAssign = e->Charge()*mcElectron->Charge();
917     hRemovedElectronChargeAssign->Fill(chargeAssign);
918     if (chargeAssign==-1.0) {
919     hRemovedElectronPtWrongCharge->Fill(e->Pt());
920     hRemovedElectronEtaWrongCharge->Fill(e->Eta());
921     }
922     }
923     else
924     hRemovedElectronChargeAssign->Fill(0.0);
925     }
926    
927    
928     }
929    
930     //__________________________________________________________________________________________________
931     void ConversionRemoval::SlaveTerminate()
932     {
933     // Run finishing code on the computer (slave) that did the analysis. For this module, we dont do
934     // anything here.
935     }
936    
937     //__________________________________________________________________________________________________
938     void ConversionRemoval::Terminate()
939     {
940    
941     fTimer.Stop();
942     printf("Total Analysis Time = %f\n",fTimer.CpuTime());
943    
944    
945     TCanvas* c1 = new TCanvas();
946     hConversionRadius->Draw();
947    
948     TCanvas* c2 = new TCanvas();
949     hConversionRPhi->Draw("col");
950     //c2->SetLogz();
951    
952     // Run finishing code on the client computer. For this module, we dont do anything here.
953     }
954    
955     BitMask16 ConversionRemoval::FailedCuts(const DecayParticle* c) {
956    
957    
958     //if (p->GetVertex()->Prob() < 0.005)
959     // return false;
960     UInt_t nFailed = 0;
961    
962     BitMask16 failed;
963    
964     if ( c->NDaughters() != 2)
965     failed.SetBit(eNDaughters);
966    
967     if ( c->Pt() < fPtMin )
968     failed.SetBit(ePt);
969    
970     if ( !PassRho(c->Position().Rho()) )
971     failed.SetBit(eRho);
972    
973     if ( TMath::Abs(c->Eta()) > fEtaMax )
974     failed.SetBit(eEta);
975    
976     if ( c->Lxy() < fLxyMin || c->Lz() < fLzMin )
977     failed.SetBit(eL);
978    
979     if ( TMath::Abs(c->Dxy()) > fAbsDxyMax )
980     failed.SetBit(eDxy);
981    
982     if ( TMath::Abs(c->Charge()) != 0 )
983     failed.SetBit(eCharge);
984    
985     // if (GetEventHeader()->BunchCrossing()!=51 && GetEventHeader()->BunchCrossing()!=2724)
986     // failed.SetBit(eBx);
987    
988     // if (fTracks->GetEntries()>150)
989     // failed.SetBit(eBx);
990    
991     // Double_t absPhi = TMath::Abs(c->Phi());
992     // if (!( absPhi<(TMath::Pi()/4.0) || absPhi>(3.0*TMath::Pi()/4.0)))
993     // failed.SetBit(eBx);
994     //
995     if (c->NSharedHits() > fMaxNSharedHits || c->NSharedHits() < fMinNSharedHits)
996     failed.SetBit(eSharedHits);
997    
998     const mithep::Vertex *pv = fPrimaryVertexes->At(0);
999     if (fRequireGoodPv && (pv->NTracksFit()<2 || pv->Prob()<1e-6 || pv->Z()<-12.5 || pv->Z()>12.5) )
1000     failed.SetBit(eBx);
1001    
1002     if ( fEvtSel->ClusVtxQual() < fMinClusterVtxQual )
1003     failed.SetBit(eClusVtx);
1004    
1005     Bool_t failedElectrons=false;
1006     for (UInt_t i=0; i<c->NDaughters(); ++i) {
1007     const DaughterData* d = c->DaughterDat(i);
1008     const Track *trk = dynamic_cast<const ChargedParticle*>
1009     (c->Daughter(i))->Trk();
1010     Bool_t trackQuality = ( !trk->IsGsf() || !fTrackQualityFirstOnly );
1011     BitMask16 failedElectronCuts = FailedElectronCuts(d, trackQuality);
1012     if (failedElectronCuts.NBitsSet())
1013     failedElectrons=true;
1014     }
1015     if (failedElectrons)
1016     failed.SetBit(eDaughters);
1017    
1018     if ( c->Prob() < fProbMin )
1019     failed.SetBit(eProb);
1020    
1021     return failed;
1022     // LoadBranch(fMvfConvUnconstrainedName);
1023     // const DecayParticle *unconstrained = MatchingConversion(c, fMvfConversionsUnconstrained);
1024     //
1025     // if (!unconstrained)
1026     // nFailed++;
1027     //
1028     // if ( TwoPionMass(unconstrained) > 0.4 )
1029     // nFailed++;
1030     //hConvDCotTheta->Fill(dCotTheta);
1031    
1032     }
1033    
1034     Bool_t ConversionRemoval::PassConvCuts(const Conversion* p) {
1035     if (p->NDaughters() != 2)
1036     return false;
1037    
1038     Double_t convRadius = p->DecayVertex().Position().Rho();
1039     if (convRadius < 2.0)
1040     //if (convRadius < 2.0 || convRadius > 20.0)
1041     //if (convRadius < 20.0)
1042     return false;
1043    
1044     const Electron* pElectron1 = (Electron*)p->Daughter(0);
1045     const Electron* pElectron2 = (Electron*)p->Daughter(1);
1046    
1047    
1048     //Double_t deltaPhi = TMath::ACos((pElectron1->Px()*pElectron2->Px() + pElectron1->Py()*pElectron2->Py() + pElectron1->Pz()*pElectron2->Pz())/(pElectron1->Mom().P()*pElectron2->Mom().P()));
1049    
1050     //if (deltaPhi>0.5)
1051     // return false;
1052     // if (fabs(p->DCotTheta())>0.2)
1053     if (fabs(p->DCotTheta())>0.75)
1054     return false;
1055    
1056     if (p->Charge()!=0)
1057     return false;
1058    
1059    
1060     /* for (Int_t i=0; i<p->NDaughters(); i++) {
1061     const Electron* e = p->Daughter(i);
1062     if (!PassElectronCuts(e))
1063     return false;
1064     } */
1065     //if (p->Mass()<0.6)
1066     // return false;
1067    
1068     //if (p->GetVertex().Prob() < 0.2)// || p->GetVertex().Prob() > 0.9)
1069     // return false;
1070    
1071     return true;
1072     }
1073    
1074     BitMask16 ConversionRemoval::FailedElectronCuts(const DaughterData* d, Bool_t trackQuality) {
1075     //if (p->Pt() < 5.0)
1076     // return false;
1077    
1078     BitMask16 failed;
1079    
1080     if (d->Pt() < fElectronPtMin)
1081     failed.SetBit(eEPt);
1082    
1083     if (TMath::Abs(d->Eta()) > fElectronEtaMax)
1084     failed.SetBit(eEEta);
1085    
1086     const StableData *s = dynamic_cast<const StableData*>(d);
1087    
1088     if (!s)
1089     Fatal("FailedElectronCuts", "DaughterData not a StableData");
1090    
1091     const ChargedParticle* c = dynamic_cast<const ChargedParticle*>(s->Original());
1092    
1093     if (!c)
1094     Fatal("FailedElectronCuts", "Daughter not a ChargedParticle");
1095    
1096     const Track* t = c->Trk();
1097    
1098     if (!t)
1099     Fatal("FailedElectronCuts", "Daughter has no track");
1100    
1101     if (s->NMissedHits() > fMissedHitsMax)
1102     failed.SetBit(eENMissingHits);
1103    
1104     if (s->NWrongHits() > fWrongHitsMax)
1105     failed.SetBit(eENWrongHits);
1106    
1107     if (trackQuality && t->NHits()<fNHitsMin)
1108     failed.SetBit(eENHits);
1109    
1110     if (trackQuality && t->NStereoHits()<fNStereoHitsMin)
1111     failed.SetBit(eENStereoHits);
1112    
1113     if (trackQuality && t->NPixelHits()<fNPixelHitsMin)
1114     failed.SetBit(eENPixelHits);
1115    
1116     if (trackQuality && t->Prob()<fTrackProbMin)
1117     failed.SetBit(eEProb);
1118    
1119     //if (trackQuality && fExcludePXB1 && t->Hit(Track::PXB1))
1120     if (trackQuality && fExcludePXB1 && (t->Hit(Track::PXB1)||t->Hit(Track::PXF1)))
1121     failed.SetBit(eEPxb1);
1122    
1123     const mithep::Vertex *pv = fPrimaryVertexes->At(0);
1124    
1125     if (trackQuality && (TMath::Abs(t->Z0()-pv->Z()) > fMaxTrackDzPv) )
1126     failed.SetBit(eDz);
1127    
1128     return failed;
1129     }
1130    
1131     Bool_t ConversionRemoval::PassTrackCuts(const Track* t) {
1132    
1133     // if ( t->Prob()<fTrackProbMin && t->NHits()<fNHitsMin )
1134    
1135     // if (t->NStereoHits() < 2)
1136     // return false;
1137    
1138     return false;
1139    
1140     }
1141    
1142     BitMask16 ConversionRemoval::FailedSimCuts(const MCParticle* p) {
1143    
1144     BitMask16 failed;
1145    
1146     if (p->PdgId()!=22)
1147     failed.SetBit(eSimPdg);
1148     if (TMath::Abs(p->Eta())>fEtaMax)
1149     failed.SetBit(eSimEta);
1150     //if (p->Pt()<5.0 || p->Pt()>25.0)
1151     //if (p->Pt()<25.0)
1152     if (p->Pt()<fPtMin)
1153     failed.SetBit(eSimPt);
1154    
1155     Double_t simRad = p->DecayVertex().Rho();
1156     //if (simRad<2.0 || simRad>128.0)
1157     //if (simRad<2.0 || simRad>20.0)
1158     //if (simRad<20.0 || simRad>128.0)
1159     if ( !PassRho(simRad) )
1160     failed.SetBit(eSimRho);
1161    
1162     Int_t nEPlus = 0;
1163     Int_t nEMinus = 0;
1164     Bool_t failedElectronPt=false;
1165     Bool_t failedElectronEta=false;
1166     for (UInt_t j=0; j<p->NDaughters(); j++) {
1167     const MCParticle* pDaughter = p->Daughter(j);
1168     if (pDaughter->PdgId()==11)
1169     nEPlus++;
1170     if (pDaughter->PdgId()==-11)
1171     nEMinus++;
1172     if (TMath::Abs(pDaughter->PdgId())==11) {
1173     if (pDaughter->Pt() < fElectronPtMin)
1174     failedElectronPt = true;
1175     if (TMath::Abs(pDaughter->Eta()) > fElectronEtaMax)
1176     failedElectronEta=true;
1177     }
1178     }
1179     if (failedElectronPt)
1180     failed.SetBit(eSimElectronPt);
1181     if (failedElectronEta)
1182     failed.SetBit(eSimElectronEta);
1183    
1184     if (nEPlus!=1 || nEMinus!=1)
1185     failed.SetBit(eSimDaughters);
1186    
1187     //get rid of all conversions which either don't produce a clean electron, or which
1188     //were produced from a real primary electron
1189     //if (fRequireCleanElectron && ( !ElectronMatch(p) || GenElectronMatch(p) ) )
1190     if (fRequireCleanElectron && !ElectronMatch(p))
1191     failed.SetBit(eCleanElectron);
1192    
1193     return failed;
1194     }
1195    
1196     const Electron* ConversionRemoval::ElectronMatch(const MCParticle *p) {
1197     // if (p->HasMother(22))
1198     // return 0;
1199     const Electron *eMatch = 0;
1200     if (fHitBasedMatching) {
1201     for (UInt_t i=0; i<fCleanElectrons->GetEntries(); ++i) {
1202     const Electron *e = fCleanElectrons->At(i);
1203     const MCParticle *ep = e->Trk()->MCPart();
1204     if ( ep && ep->DistinctMother()==p)
1205     return e;
1206     }
1207     }
1208     else {
1209     Double_t minDeltaR = 0.3;
1210     for (UInt_t i=0; i<fCleanElectrons->GetEntries(); ++i) {
1211     const Electron *e = fCleanElectrons->At(i);
1212     Double_t deltaR = MathUtils::DeltaR(*e,*p);
1213     if (deltaR < minDeltaR) {
1214     minDeltaR = deltaR;
1215     eMatch = e;
1216     }
1217     }
1218     }
1219    
1220     return eMatch;
1221    
1222     }
1223    
1224     const MCParticle* ConversionRemoval::GenElectronMatch(const MCParticle *p) {
1225     const MCParticle *mother = p;
1226     while (p) {
1227     if ( p->AbsPdgId()==11 && p->IsGenerated() )
1228     return p;
1229     else
1230     p = p->Mother();
1231     }
1232     return 0;
1233     }
1234    
1235     const MCParticle* ConversionRemoval::SimMatch(const DecayParticle* p) {
1236     if ( p->NDaughters()!=2 )
1237     return 0;
1238    
1239     const ChargedParticle *electron1 = dynamic_cast<const ChargedParticle*>(p->Daughter(0));
1240     const ChargedParticle *electron2 = dynamic_cast<const ChargedParticle*>(p->Daughter(1));
1241    
1242     if (!electron1 || !electron2)
1243     return 0;
1244    
1245     const MCParticle *simElectron1 = 0;
1246     const MCParticle *simElectron2 = 0;
1247     if (fHitBasedMatching) {
1248     simElectron1 = electron1->Trk()->MCPart();
1249     simElectron2 = electron2->Trk()->MCPart();
1250     }
1251     else {
1252     LoadBranch(fMCPartName);
1253     for (UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
1254     const MCParticle *mcp = fMCParticles->At(i);
1255     if (mcp->PdgId()==22 && mcp->DecayVertex().Rho()<80.0 && MathUtils::DeltaR(*mcp,*p) < 0.3)
1256     return mcp;
1257     }
1258     return 0;
1259     }
1260    
1261     if (simElectron1) {
1262     hTrackSimMatchType->Fill(simElectron1->PdgId());
1263     if (simElectron1->HasMother())
1264     hParentSimMatchType->Fill(simElectron1->Mother()->PdgId());
1265     }
1266    
1267     if (simElectron2) {
1268     hTrackSimMatchType->Fill(simElectron2->PdgId());
1269     if (simElectron2->HasMother())
1270     hParentSimMatchType->Fill(simElectron2->Mother()->PdgId());
1271     }
1272    
1273    
1274     if (!simElectron1) {
1275     const Track *t = electron1->Trk();
1276     hUnMatchedTrackChi2->Fill(t->Chi2()/((Double_t)t->Ndof()));
1277     hUnMatchedTrackProb->Fill(t->Prob());
1278     hUnMatchedTrackNHits->Fill(t->NHits());
1279     hUnMatchedTrackNHitsProb->Fill(t->NHits(),t->RChi2());
1280     hUnMatchedTrackD0->Fill(t->D0());
1281     }
1282    
1283     if (!simElectron2) {
1284     const Track *t = electron2->Trk();
1285     hUnMatchedTrackChi2->Fill(t->Chi2()/((Double_t)t->Ndof()));
1286     hUnMatchedTrackProb->Fill(t->Prob());
1287     hUnMatchedTrackNHits->Fill(t->NHits());
1288     hUnMatchedTrackNHitsProb->Fill(t->NHits(),t->RChi2());
1289     hUnMatchedTrackD0->Fill(t->D0());
1290     }
1291    
1292     if (!simElectron1 || !simElectron2) {
1293     //printf("unmatched electron\n");
1294     return 0;
1295     }
1296    
1297    
1298     if ( TMath::Abs(simElectron1->PdgId())!=11 || TMath::Abs(simElectron2->PdgId())!=11 ) {
1299     //printf("not electrons\n");
1300     return 0;
1301     }
1302    
1303     const MCParticle *simPhoton = simElectron1->DistinctMother();
1304    
1305     if (!simPhoton) {
1306     // printf("no photon\n");
1307     // hParentSimMatchType->Fill(0);
1308     return 0;
1309     }
1310    
1311     if (simElectron2->DistinctMother()!=simPhoton) {
1312     //printf("different mothers\n");
1313     // hParentSimMatchType->Fill(0);
1314     return 0;
1315     }
1316    
1317     if (simPhoton->PdgId()!=22) {
1318     //printf("not a photon\n");
1319     return 0;
1320     }
1321    
1322     // printf("found common mother with pdg=%i, daughter pdgs: %i, %i\n", simPhoton->PdgId(), simElectron1->PdgId(),simElectron2->PdgId());
1323    
1324     // hParentSimMatchType->Fill(simPhoton->PdgId());
1325    
1326     return simPhoton;
1327    
1328    
1329     }
1330    
1331     const MCParticle* ConversionRemoval::SimMatch(const Track* t) {
1332    
1333     const MCParticle *simElectron1 = 0;
1334     //const MCParticle *simElectron2 = 0;
1335     if (fHitBasedMatching) {
1336     simElectron1 = t->MCPart();
1337     }
1338     else {
1339     LoadBranch(fMCPartName);
1340     //Double_t minDeltaR = 999.9;
1341     for (UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
1342     const MCParticle *p = fMCParticles->At(i);
1343     if (p->PdgId()==22 && p->DecayVertex().Rho()<80.0 && MathUtils::DeltaR(*p,*t) < 0.3)
1344     return p;
1345     }
1346     }
1347    
1348     if (!simElectron1) {
1349     //printf("unmatched electron\n");
1350     return 0;
1351     }
1352    
1353    
1354     if ( TMath::Abs(simElectron1->PdgId())!=11 ) {
1355     //printf("not electrons\n");
1356     return 0;
1357     }
1358    
1359     const MCParticle *simPhoton = simElectron1->DistinctMother();
1360    
1361     if (!simPhoton) {
1362     // printf("no photon\n");
1363     // hParentSimMatchType->Fill(0);
1364     return 0;
1365     }
1366    
1367     if (simPhoton->PdgId()!=22) {
1368     //printf("not a photon\n");
1369     return 0;
1370     }
1371    
1372     // printf("found common mother with pdg=%i, daughter pdgs: %i, %i\n", simPhoton->PdgId(), simElectron1->PdgId(),simElectron2->PdgId());
1373    
1374     // hParentSimMatchType->Fill(simPhoton->PdgId());
1375    
1376     return simPhoton;
1377    
1378    
1379     }
1380    
1381     UInt_t ConversionRemoval::NTracks(const TrackCol *col)
1382     {
1383     UInt_t ntracks=0;
1384     for (UInt_t i=0; i<col->GetEntries(); ++i) {
1385     const Track *t = col->At(i);
1386     if ( PassTrackCuts(t) )
1387     ntracks++;
1388     }
1389    
1390     return ntracks;
1391     }
1392    
1393     // Double_t ConversionRemoval::TrackPtIsolation(const DecayParticle *p, Double_t r)
1394     // {
1395     // TObjArray conversionTracks;
1396     // for (UInt_t i=0; i<p->NDaughters(); ++i) {
1397     // const ChargedParticle* d = dynamic_cast<const ChargedParticle*>(p->Daughter(i));
1398     // if (d) {
1399     // const Track *t = d->Trk();
1400     // if (t)
1401     // conversionTracks.Add((TObject*)t);
1402     // }
1403     // }
1404     //
1405     //
1406     // LoadBranch(fTrackName);
1407     // Double_t sumPt=0.0;
1408     // for (UInt_t i=0; i<fTracks->GetEntries(); ++i) {
1409     // const Track *t = fTracks->At(i);
1410     // if (conversionTracks.IndexOf(t)==-1) {
1411     // Double_t deltaR = MathUtils::DeltaR(p->Phi(),p->Eta(),t->Phi(),t->Eta());
1412     // if (deltaR<r)
1413     // sumPt = sumPt + 1.0;//sumPt += t->Pt();
1414     // }
1415     // }
1416     //
1417     // return sumPt;
1418     //
1419     // }
1420    
1421     Bool_t ConversionRemoval::PassPhotonCuts(const Photon *p)
1422     {
1423     if (p->IsConverted())
1424     return false;
1425    
1426     return true;
1427     }
1428    
1429     Double_t ConversionRemoval::DCotTheta(const DecayParticle *c)
1430     {
1431     if (c->NDaughters()!=2)
1432     return 0.0;
1433    
1434     Double_t theta1 = c->DaughterDat(0)->Theta();
1435     Double_t theta2 = c->DaughterDat(1)->Theta();
1436    
1437     Double_t dCotTheta = 1./TMath::Tan(theta1) - 1./TMath::Tan(theta2);
1438     //Double_t dCotTheta = c->DaughterDat(0)->Pt() - c->DaughterDat(1)->Pt();
1439    
1440     if (c->DaughterDat(0)->Charge()==1)
1441     return dCotTheta;
1442     else
1443     return (-dCotTheta);
1444     }
1445    
1446     Double_t ConversionRemoval::DPhi(const DecayParticle *c)
1447     {
1448     if (c->NDaughters()!=2)
1449     return 0.0;
1450    
1451     ThreeVectorC mom1 = ((const StableData*)c->DaughterDat(0))->ThreeMom();
1452     ThreeVectorC mom2 = ((const StableData*)c->DaughterDat(1))->ThreeMom();
1453    
1454     Double_t dPhi = TMath::ACos(mom1.Dot(mom2)/(mom1.R()*mom2.R()));
1455    
1456     return dPhi;
1457     }
1458    
1459     Double_t ConversionRemoval::TwoPionMass(const DecayParticle *c)
1460     {
1461     if (c->NDaughters()!=2)
1462     return 0.0;
1463    
1464     StableParticle *pi1 = new StableParticle(211, (Track*)((ChargedParticle*)c->Daughter(0))->Trk());
1465     StableParticle *pi2 = new StableParticle(211, (Track*)((ChargedParticle*)c->Daughter(1))->Trk());
1466    
1467     StableData *pi1d = new StableData(pi1, ((StableData*)c->DaughterDat(0))->ThreeMom());
1468     StableData *pi2d = new StableData(pi2, ((StableData*)c->DaughterDat(1))->ThreeMom());
1469    
1470     CompositeParticle *meson = new CompositeParticle();
1471     meson->AddDaughter(pi1d);
1472     meson->AddDaughter(pi2d);
1473    
1474     Double_t mesonMass = meson->Mass();
1475    
1476     delete meson;
1477     delete pi1d;
1478     delete pi2d;
1479     delete pi1;
1480     delete pi2;
1481    
1482     return mesonMass;
1483     }
1484    
1485     const DecayParticle *ConversionRemoval::MatchingConversion(const DecayParticle *c, const DecayParticleCol *col) const
1486     {
1487     for (UInt_t i=0; i<col->GetEntries(); ++i) {
1488     const DecayParticle *p = col->At(i);
1489     if ( p->HasSameDaughters(c) )
1490     return c;
1491     }
1492    
1493     return 0;
1494     }
1495    
1496     const Electron *ConversionRemoval::MatchingElectron(const ChargedParticle *c, const ElectronCol *col) const
1497     {
1498     for (UInt_t i=0; i<col->GetEntries(); ++i) {
1499     const Electron *e = col->At(i);
1500    
1501     if ( c->Trk() == e->Trk() )
1502     return e;
1503     }
1504    
1505     return 0;
1506     }
1507    
1508     const Electron *ConversionRemoval::MatchingElectron(const Electron *ein, const ElectronCol *col) const
1509     {
1510     for (UInt_t i=0; i<col->GetEntries(); ++i) {
1511     const Electron *e = col->At(i);
1512    
1513     if ( e->SCluster() == ein->SCluster() )
1514     return e;
1515     }
1516    
1517     return 0;
1518     }
1519    
1520     void ConversionRemoval::AddRhoRange(Double_t lower, Double_t upper)
1521     {
1522     fRhoLbs.push_back(lower);
1523     fRhoUbs.push_back(upper);
1524     }
1525    
1526     Bool_t ConversionRemoval::PassRho(Double_t rho)
1527     {
1528     for (UInt_t i=0; i<fRhoLbs.size(); ++i) {
1529     if ( rho>fRhoLbs.at(i) && rho<fRhoUbs.at(i) )
1530     return true;
1531     }
1532    
1533     return false;
1534     }
1535    
1536     const MCParticle *ConversionRemoval::SimConversionMatch(const Electron *e) {
1537    
1538     //LoadBranch(fMCPartName);
1539    
1540     if (fHitBasedMatching) {
1541     const MCParticle *p = e->Trk()->MCPart();
1542     if (p && p->DistinctMother() && !FailedSimCuts(p->DistinctMother()).NBitsSet())
1543     return p->DistinctMother();
1544    
1545     }
1546     else {
1547     for (UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
1548     const MCParticle *p = fMCParticles->At(i);
1549     //if (MathUtils::DeltaPhi(*e,*p) < 0.3 && !FailedSimCuts(p).NBitsSet())
1550     if ( MathUtils::DeltaPhi(*e,*p) < 0.3 && p->AbsPdgId()==11 && p->DistinctMother() && !FailedSimCuts(p->DistinctMother()).NBitsSet())
1551     return p->DistinctMother();
1552     }
1553     }
1554    
1555     return 0;
1556    
1557     }
1558    
1559    
1560     const MCParticle *ConversionRemoval::SimWeMatch(const Electron *e) {
1561    
1562     if (fHitBasedMatching) {
1563     const MCParticle *p = e->Trk()->MCPart();
1564     if (p && p->AbsPdgId()==11 && p->DistinctMother() && (p->DistinctMother()->AbsPdgId()==24 || p->DistinctMother()->AbsPdgId()==23) )
1565     return p;
1566     }
1567     else {
1568     for (UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
1569     const MCParticle *p = fMCParticles->At(i);
1570     if (MathUtils::DeltaPhi(*e,*p) < 0.3 && p->AbsPdgId()==11 && p->DistinctMother() && (p->DistinctMother()->AbsPdgId()==24 || p->DistinctMother()->AbsPdgId()==23) )
1571     return p;
1572     }
1573     }
1574    
1575     return 0;
1576     }
1577    
1578     const Electron *ConversionRemoval::ElectronMatch(const DecayParticle *d, const ElectronCol *c) {
1579    
1580     if (d->NDaughters()<2)
1581     return 0;
1582    
1583     const ChargedParticle *cp = dynamic_cast<const ChargedParticle*>(d->Daughter(1));
1584     if (!cp)
1585     return 0;
1586    
1587     const Track *t = cp->Trk();
1588     if (!t)
1589     return 0;
1590    
1591     for (UInt_t i=0; i<c->GetEntries(); ++i) {
1592     const Electron *e = c->At(i);
1593     if (e->Trk()==t)
1594     return e;
1595     }
1596    
1597     return 0;
1598    
1599     }
1600