ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.49
Committed: Sun Dec 6 14:59:28 2009 UTC (15 years, 5 months ago) by ceballos
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_013, Mit_013pre1, Mit_012i, Mit_012g, Mit_012f, Mit_012e
Changes since 1.48: +8 -1 lines
Log Message:
small updates

File Contents

# User Rev Content
1 ceballos 1.49 // $Id: ElectronIDMod.cc,v 1.48 2009/11/08 13:52:29 sixie Exp $
2 loizides 1.1
3     #include "MitPhysics/Mods/interface/ElectronIDMod.h"
4 loizides 1.26 #include "MitAna/DataTree/interface/StableData.h"
5     #include "MitAna/DataTree/interface/ElectronCol.h"
6     #include "MitAna/DataTree/interface/VertexCol.h"
7     #include "MitAna/DataTree/interface/DecayParticleCol.h"
8 loizides 1.5 #include "MitPhysics/Init/interface/ModNames.h"
9 loizides 1.1
10     using namespace mithep;
11    
12     ClassImp(mithep::ElectronIDMod)
13    
14     //--------------------------------------------------------------------------------------------------
15 loizides 1.5 ElectronIDMod::ElectronIDMod(const char *name, const char *title) :
16 loizides 1.1 BaseMod(name,title),
17 loizides 1.5 fElectronBranchName(Names::gkElectronBrn),
18 ceballos 1.12 fConversionBranchName(Names::gkMvfConversionBrn),
19 loizides 1.5 fGoodElectronsName(ModNames::gkGoodElectronsName),
20 ceballos 1.12 fVertexName(string("PrimaryVertexesBeamSpot").c_str()),
21 ceballos 1.31 fElectronIDType("CustomTight"),
22 ceballos 1.8 fElectronIsoType("TrackJuraSliding"),
23 loizides 1.1 fElectronPtMin(10),
24     fIDLikelihoodCut(0.9),
25     fTrackIsolationCut(5.0),
26     fCaloIsolationCut(5.0),
27 loizides 1.5 fEcalJuraIsoCut(5.0),
28     fHcalIsolationCut(5.0),
29 ceballos 1.49 fCombIsolationCut(5.0),
30 loizides 1.14 fApplyConvFilter(kTRUE),
31 bendavid 1.38 fWrongHitsRequirement(kTRUE),
32 ceballos 1.18 fApplyD0Cut(kTRUE),
33 ceballos 1.45 fChargeFilter(kTRUE),
34 loizides 1.14 fD0Cut(0.025),
35 loizides 1.25 fReverseIsoCut(kFALSE),
36     fReverseD0Cut(kFALSE),
37 loizides 1.5 fElIdType(kIdUndef),
38 ceballos 1.12 fElIsoType(kIsoUndef),
39 loizides 1.14 fElectrons(0),
40     fConversions(0),
41 loizides 1.25 fVertices(0)
42 loizides 1.1 {
43     // Constructor.
44     }
45    
46     //--------------------------------------------------------------------------------------------------
47 loizides 1.30 Bool_t ElectronIDMod::PassCustomID(const Electron *ele) const
48     {
49 loizides 1.32 // Based on RecoEgamma/ElectronIdentification/src/CutBasedElectronID.cc.
50 loizides 1.30
51     Double_t eOverP = ele->ESuperClusterOverP();
52     Double_t fBrem = ele->FBrem();
53    
54     if ((eOverP < fCuts[5][0]) && (fBrem < fCuts[5][1]))
55     return kFALSE;
56    
57     if (eOverP < fCuts[5][2]*(1-fBrem))
58     return kFALSE;
59    
60     Int_t cat = 2;
61     if ((ele->IsEB() && fBrem<0.06) || (ele->IsEE() && fBrem<0.1))
62     cat=1;
63     else if (eOverP < 1.2 && eOverP > 0.8)
64     cat=0;
65    
66     Double_t eSeedOverPin = ele->ESeedClusterOverPIn();
67     Double_t hOverE = ele->HadronicOverEm();
68     Double_t sigmaee = ele->CoviEtaiEta();
69     Double_t deltaPhiIn = TMath::Abs(ele->DeltaPhiSuperClusterTrackAtVtx());
70     Double_t deltaEtaIn = TMath::Abs(ele->DeltaEtaSuperClusterTrackAtVtx());
71    
72     Int_t eb = 1;
73     if (ele->IsEB())
74     eb = 0;
75    
76     if (hOverE>fCuts[0][cat+4*eb])
77     return kFALSE;
78    
79     if (sigmaee>fCuts[1][cat+4*eb])
80     return kFALSE;
81    
82 ceballos 1.40 if (deltaPhiIn>fCuts[2][cat+4*eb])
83     return kFALSE;
84 loizides 1.30
85     if(deltaEtaIn>fCuts[3][cat+4*eb])
86     return kFALSE;
87    
88     if(eSeedOverPin<fCuts[4][cat+4*eb])
89     return kFALSE;
90    
91     return kTRUE;
92     }
93    
94     //--------------------------------------------------------------------------------------------------
95 sixie 1.42 Bool_t ElectronIDMod::PassIDCut(const Electron *ele, EElIdType idType) const
96     {
97    
98     Bool_t idcut = kFALSE;
99     switch (idType) {
100     case kTight:
101     idcut = ele->PassTightID();
102     break;
103     case kLoose:
104     idcut = ele->PassLooseID();
105     break;
106     case kLikelihood:
107     idcut = (ele->IDLikelihood() > fIDLikelihoodCut);
108     break;
109     case kNoId:
110     idcut = kTRUE;
111     break;
112     case kCustomIdLoose:
113     idcut = ElectronIDMod::PassCustomID(ele);
114     break;
115     case kCustomIdTight:
116     idcut = ElectronIDMod::PassCustomID(ele);
117     break;
118     case kZeeId:
119     if (ele->IsEB()) {
120     idcut = (ele->CoviEtaiEta() < 0.01 && ele->DeltaEtaSuperClusterTrackAtVtx() < 0.0071);
121     } else {
122     idcut = (ele->CoviEtaiEta() < 0.028 && ele->DeltaEtaSuperClusterTrackAtVtx() < 0.0066);
123     }
124     break;
125     default:
126     break;
127     }
128    
129     return idcut;
130     }
131    
132    
133     //--------------------------------------------------------------------------------------------------
134     Bool_t ElectronIDMod::PassIsolationCut(const Electron *ele, EElIsoType isoType) const
135     {
136    
137     Bool_t isocut = kFALSE;
138     switch (isoType) {
139     case kTrackCalo:
140     isocut = (ele->TrackIsolationDr03() < fTrackIsolationCut) &&
141     (ele->CaloIsolation() < fCaloIsolationCut);
142     break;
143     case kTrackJura:
144     isocut = (ele->TrackIsolationDr03() < fTrackIsolationCut) &&
145     (ele->EcalRecHitIsoDr04() < fEcalJuraIsoCut) &&
146     (ele->HcalIsolation() < fHcalIsolationCut);
147     break;
148 ceballos 1.49 case kTrackJuraCombined:
149     isocut = (ele->TrackIsolationDr03() + ele->EcalRecHitIsoDr04()
150     - 1.5 < fCombIsolationCut);
151     break;
152 sixie 1.42 case kTrackJuraSliding:
153     {
154     Double_t totalIso = ele->TrackIsolationDr03() + ele->EcalRecHitIsoDr04() - 1.5;
155     if (totalIso < (ele->Pt()-10.0)*4.5/20.0 ||
156     totalIso <= 0)
157     isocut = kTRUE;
158    
159     if (fReverseIsoCut == kTRUE &&
160     isocut == kFALSE && totalIso < 10)
161     isocut = kTRUE;
162     else if(fReverseIsoCut == kTRUE)
163     isocut = kFALSE;
164     }
165     break;
166     case kNoIso:
167     isocut = kTRUE;
168     break;
169     case kZeeIso:
170     if (ele->IsEB()) {
171     isocut = (ele->TrackIsolationDr04() < 7.2 && ele->EcalRecHitIsoDr04() < 5.7 && ele->HcalTowerSumEtDr04() < 8.1);
172     } else {
173     isocut = (ele->TrackIsolationDr04() < 5.1 && ele->EcalRecHitIsoDr04() < 5.0 && ele->HcalTowerSumEtDr04() < 3.4);
174     }
175     break;
176     case kCustomIso:
177     default:
178     break;
179     }
180    
181     return isocut;
182     }
183    
184    
185     //--------------------------------------------------------------------------------------------------
186     Bool_t ElectronIDMod::PassConversionFilter(const Electron *ele, const DecayParticleCol *conversions) const
187     {
188     Bool_t isGoodConversion = kFALSE;
189    
190     for (UInt_t ifc=0; ifc<conversions->GetEntries(); ifc++) {
191    
192     Bool_t ConversionMatchFound = kFALSE;
193     for (UInt_t d=0; d<conversions->At(ifc)->NDaughters(); d++) {
194     const Track *trk = dynamic_cast<const ChargedParticle*>
195     (conversions->At(ifc)->Daughter(d))->Trk();
196     if (ele->GsfTrk() == trk) {
197     ConversionMatchFound = kTRUE;
198     break;
199     }
200     }
201    
202     // if match between the e-track and one of the conversion legs
203     if (ConversionMatchFound == kTRUE){
204     isGoodConversion = (conversions->At(ifc)->Prob() > 1e-6) &&
205     (conversions->At(ifc)->Lxy() > 0) &&
206     (conversions->At(ifc)->Lz() > 0) &&
207     (conversions->At(ifc)->Position().Rho() > 2.0);
208    
209     if (isGoodConversion == kTRUE) {
210     for (UInt_t d=0; d<conversions->At(ifc)->NDaughters(); d++) {
211     const Track *trk = dynamic_cast<const ChargedParticle*>
212     (conversions->At(ifc)->Daughter(d))->Trk();
213    
214     if (trk) {
215     // These requirements are not used for the GSF track
216     if (!(trk->NHits() >= 3 && trk->Prob() > 1e-6) && trk!=ele->GsfTrk())
217     isGoodConversion = kFALSE;
218    
219     const StableData *sd = dynamic_cast<const StableData*>
220     (conversions->At(ifc)->DaughterDat(d));
221     if (fWrongHitsRequirement && sd->NWrongHits() != 0)
222     isGoodConversion = kFALSE;
223    
224     } else {
225     isGoodConversion = kFALSE;
226     }
227     }
228     }
229     }
230    
231     if (isGoodConversion == kTRUE) break;
232    
233     } // loop over all conversions
234    
235 ceballos 1.46 return !isGoodConversion;
236 sixie 1.42 }
237    
238     //--------------------------------------------------------------------------------------------------
239     Bool_t ElectronIDMod::PassD0Cut(const Electron *ele, const VertexCol *vertices) const
240     {
241     Bool_t d0cut = kFALSE;
242     // d0 cut
243     Double_t d0_real = 99999;
244     for(UInt_t i0 = 0; i0 < vertices->GetEntries(); i0++) {
245     Double_t pD0 = ele->GsfTrk()->D0Corrected(*vertices->At(i0));
246     if(TMath::Abs(pD0) < TMath::Abs(d0_real)) d0_real = TMath::Abs(pD0);
247     }
248     if(d0_real < fD0Cut) d0cut = kTRUE;
249    
250     if (fReverseD0Cut == kTRUE &&
251     d0cut == kFALSE && d0_real < 0.05)
252     d0cut = kTRUE;
253     else if(fReverseD0Cut == kTRUE)
254     d0cut = kFALSE;
255    
256     return d0cut;
257     }
258    
259     //--------------------------------------------------------------------------------------------------
260     Bool_t ElectronIDMod::PassChargeFilter(const Electron *ele) const
261     {
262     Bool_t passChargeFilter = kTRUE;
263     if(ele->TrackerTrk() &&
264     ele->TrackerTrk()->Charge() != ele->Charge()) passChargeFilter = kFALSE;
265    
266     return passChargeFilter;
267     }
268    
269     //--------------------------------------------------------------------------------------------------
270 loizides 1.1 void ElectronIDMod::Process()
271     {
272     // Process entries of the tree.
273    
274 loizides 1.23 LoadEventObject(fElectronBranchName, fElectrons);
275 loizides 1.1
276 loizides 1.6 ElectronOArr *GoodElectrons = new ElectronOArr;
277     GoodElectrons->SetName(fGoodElectronsName);
278 loizides 1.1
279 ceballos 1.18 for (UInt_t i=0; i<fElectrons->GetEntries(); ++i) {
280 loizides 1.5 const Electron *e = fElectrons->At(i);
281 loizides 1.1
282 loizides 1.5 if (e->Pt() <= fElectronPtMin)
283     continue;
284 loizides 1.1
285 sixie 1.42 //apply id cut
286     Bool_t idcut = PassIDCut(e, fElIdType);
287 loizides 1.5 if (!idcut)
288     continue;
289    
290 sixie 1.42 //apply Isolation Cut
291     Bool_t isocut = PassIsolationCut(e, fElIsoType);
292     if (!isocut)
293 loizides 1.5 continue;
294    
295 loizides 1.14 // apply conversion filter
296 ceballos 1.47 Bool_t passConvVeto = kFALSE;
297 loizides 1.14 if (fApplyConvFilter) {
298 sixie 1.42 LoadEventObject(fConversionBranchName, fConversions);
299 ceballos 1.47 passConvVeto = PassConversionFilter(e, fConversions);
300 sixie 1.48 } else {
301     passConvVeto = kTRUE;
302 ceballos 1.12 }
303 ceballos 1.47 if (passConvVeto == kFALSE) continue;
304 sixie 1.42
305     // apply d0 cut
306 ceballos 1.15 if (fApplyD0Cut) {
307 sixie 1.42 LoadEventObject(fVertexName, fVertices);
308 ceballos 1.46 Bool_t passD0cut = PassD0Cut(e, fVertices);
309 sixie 1.42 if (!passD0cut)
310 ceballos 1.24 continue;
311 ceballos 1.12 }
312    
313 sixie 1.42 //apply charge filter
314     if(fChargeFilter == kTRUE) {
315     Bool_t passChargeFilter = PassChargeFilter(e);
316     if (!passChargeFilter) continue;
317 ceballos 1.45 }
318    
319 loizides 1.5 // add good electron
320 ceballos 1.12 GoodElectrons->Add(e);
321 loizides 1.5 }
322 loizides 1.1
323 loizides 1.9 // sort according to pt
324     GoodElectrons->Sort();
325    
326 loizides 1.5 // add to event for other modules to use
327 loizides 1.6 AddObjThisEvt(GoodElectrons);
328 loizides 1.1 }
329    
330     //--------------------------------------------------------------------------------------------------
331     void ElectronIDMod::SlaveBegin()
332     {
333     // Run startup code on the computer (slave) doing the actual analysis. Here,
334 loizides 1.5 // we just request the electron collection branch.
335 loizides 1.1
336 loizides 1.23 ReqEventObject(fElectronBranchName, fElectrons, kTRUE);
337 loizides 1.17
338 ceballos 1.16 if (fApplyConvFilter)
339 loizides 1.23 ReqEventObject(fConversionBranchName, fConversions, kTRUE);
340 loizides 1.17
341 ceballos 1.15 if (fApplyD0Cut)
342 loizides 1.23 ReqEventObject(fVertexName, fVertices, kTRUE);
343 loizides 1.1
344 sixie 1.42 Setup();
345     }
346    
347     //--------------------------------------------------------------------------------------------------
348     void ElectronIDMod::Setup()
349     {
350     // Set all options properly before execution.
351    
352 loizides 1.5 if (fElectronIDType.CompareTo("Tight") == 0)
353     fElIdType = kTight;
354     else if (fElectronIDType.CompareTo("Loose") == 0)
355     fElIdType = kLoose;
356     else if (fElectronIDType.CompareTo("Likelihood") == 0)
357     fElIdType = kLikelihood;
358 loizides 1.10 else if (fElectronIDType.CompareTo("NoId") == 0)
359     fElIdType = kNoId;
360 sixie 1.42 else if (fElectronIDType.CompareTo("ZeeId") == 0)
361     fElIdType = kZeeId;
362 loizides 1.30 else if (fElectronIDType.CompareTo("CustomLoose") == 0) {
363 peveraer 1.29 fElIdType = kCustomIdLoose;
364 loizides 1.30 } else if (fElectronIDType.CompareTo("CustomTight") == 0) {
365 peveraer 1.29 fElIdType = kCustomIdTight;
366 loizides 1.30 }
367 peveraer 1.29 else {
368 loizides 1.5 SendError(kAbortAnalysis, "SlaveBegin",
369     "The specified electron identification %s is not defined.",
370     fElectronIDType.Data());
371     return;
372     }
373    
374 loizides 1.30 SetCustomIDCuts(fElIdType);
375    
376 loizides 1.5 if (fElectronIsoType.CompareTo("TrackCalo") == 0 )
377     fElIsoType = kTrackCalo;
378     else if (fElectronIsoType.CompareTo("TrackJura") == 0)
379     fElIsoType = kTrackJura;
380 ceballos 1.49 else if(fElectronIsoType.CompareTo("TrackJuraCombined") == 0)
381     fElIsoType = kTrackJuraCombined;
382 loizides 1.5 else if(fElectronIsoType.CompareTo("TrackJuraSliding") == 0)
383     fElIsoType = kTrackJuraSliding;
384     else if (fElectronIsoType.CompareTo("NoIso") == 0 )
385     fElIsoType = kNoIso;
386 sixie 1.42 else if (fElectronIsoType.CompareTo("ZeeIso") == 0 )
387     fElIsoType = kZeeIso;
388 loizides 1.5 else if (fElectronIsoType.CompareTo("Custom") == 0 ) {
389     fElIsoType = kCustomIso;
390     SendError(kWarning, "SlaveBegin",
391     "Custom electron isolation is not yet implemented.");
392     } else {
393     SendError(kAbortAnalysis, "SlaveBegin",
394     "The specified electron isolation %s is not defined.",
395     fElectronIsoType.Data());
396     return;
397     }
398 sixie 1.42
399 loizides 1.1 }
400 loizides 1.30
401     //--------------------------------------------------------------------------------------------------
402     void ElectronIDMod::SetCustomIDCuts(EElIdType idt)
403     {
404 loizides 1.32 // Set cut values based on RecoEgamma/ElectronIdentification/python/electronIdCutBasedExt_cfi.py.
405     // The following changes are in sigmaetaeta for endcups and deltaetain.
406 loizides 1.30
407     Double_t tightcuts[6][8]={
408 ceballos 1.40 {0.086, 0.1, 0.052, 0.0, 0.050, 0.059, 0.061, 0.0}, //hovere
409 sixie 1.44 {0.011, 0.011, 0.011, 0.0, 0.033, 0.029, 0.030, 0.0}, //sigmaetaeta
410     {0.038, 0.024, 0.045, 0.0, 0.034, 0.017, 0.026, 0.0}, //deltaphiin
411     {0.0081, 0.0029, 0.0051, 0.0, 0.0070, 0.0062, 0.0088, 0.0}, //deltaetain
412 ceballos 1.40 {0.0, 0.9, 0.0, 0.0, 0.0, 0.78, 0.0, 0.0}, //eoverp
413     {0.8,0.2,0.9,0,0,0,0,0}}; //extra cuts fbrem and E_Over_P
414 loizides 1.30
415     Double_t loosecuts[6][8]={
416 loizides 1.39 {0.076, 0.033, 0.07, 0.0, 0.083,0.148, 0.033, 0.0}, //hovere
417     {0.0101, 0.0095, 0.0097, 0.0, 0.03, 0.03, 0.03, 0.0}, //sigmaetaeta
418     {0.053, 0.0189, 0.059, 0.099, 0.0278,0.0157, 0.042, 0.080}, //deltaphiin
419     {0.0078, 0.00259, 0.0062, 0.0, 0.0078,0.0061, 0.0061, 0.0}, //deltaetain
420     {0.3, 0.92, 0.211, 0.0, 0.42, 0.88, 0.68, 0.0}, //eoverp
421     {0.8,0.2,0,0,0,0,0,0}}; //extra cuts fbrem and E_Over_P
422 loizides 1.30
423 sixie 1.42
424 loizides 1.30 switch (idt) {
425     case kCustomIdTight:
426     memcpy(fCuts,tightcuts,sizeof(fCuts));
427     break;
428     case kCustomIdLoose:
429     memcpy(fCuts,loosecuts,sizeof(fCuts));
430     break;
431     default:
432     memset(fCuts,0,sizeof(fCuts));
433     break;
434     }
435     }