ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.32
Committed: Wed Aug 12 07:50:31 2009 UTC (15 years, 8 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011, Mit_010a
Changes since 1.31: +4 -3 lines
Log Message:
Improved comment

File Contents

# User Rev Content
1 loizides 1.32 // $Id: ElectronIDMod.cc,v 1.31 2009/08/11 15:16:17 ceballos 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 loizides 1.14 fApplyConvFilter(kTRUE),
30 ceballos 1.18 fApplyD0Cut(kTRUE),
31 loizides 1.14 fD0Cut(0.025),
32 loizides 1.25 fReverseIsoCut(kFALSE),
33     fReverseD0Cut(kFALSE),
34 loizides 1.5 fElIdType(kIdUndef),
35 ceballos 1.12 fElIsoType(kIsoUndef),
36 loizides 1.14 fElectrons(0),
37     fConversions(0),
38 loizides 1.25 fVertices(0)
39 loizides 1.1 {
40     // Constructor.
41     }
42    
43     //--------------------------------------------------------------------------------------------------
44 loizides 1.30 Bool_t ElectronIDMod::PassCustomID(const Electron *ele) const
45     {
46 loizides 1.32 // Based on RecoEgamma/ElectronIdentification/src/CutBasedElectronID.cc.
47 loizides 1.30
48     Double_t eOverP = ele->ESuperClusterOverP();
49     Double_t fBrem = ele->FBrem();
50    
51     if ((eOverP < fCuts[5][0]) && (fBrem < fCuts[5][1]))
52     return kFALSE;
53    
54     if (eOverP < fCuts[5][2]*(1-fBrem))
55     return kFALSE;
56    
57     Int_t cat = 2;
58     if ((ele->IsEB() && fBrem<0.06) || (ele->IsEE() && fBrem<0.1))
59     cat=1;
60     else if (eOverP < 1.2 && eOverP > 0.8)
61     cat=0;
62    
63     Double_t eSeedOverPin = ele->ESeedClusterOverPIn();
64     Double_t hOverE = ele->HadronicOverEm();
65     Double_t sigmaee = ele->CoviEtaiEta();
66     Double_t deltaPhiIn = TMath::Abs(ele->DeltaPhiSuperClusterTrackAtVtx());
67     Double_t deltaEtaIn = TMath::Abs(ele->DeltaEtaSuperClusterTrackAtVtx());
68    
69     Int_t eb = 1;
70     if (ele->IsEB())
71     eb = 0;
72    
73     if (hOverE>fCuts[0][cat+4*eb])
74     return kFALSE;
75    
76     if (sigmaee>fCuts[1][cat+4*eb])
77     return kFALSE;
78    
79     if (eOverP<1.5) {
80     if (deltaPhiIn>fCuts[2][cat+4*eb])
81     return kFALSE;
82     } else {
83     if(deltaPhiIn>fCuts[2][3+4*eb])
84     return kFALSE;
85     }
86    
87     if(deltaEtaIn>fCuts[3][cat+4*eb])
88     return kFALSE;
89    
90     if(eSeedOverPin<fCuts[4][cat+4*eb])
91     return kFALSE;
92    
93     return kTRUE;
94     }
95    
96     //--------------------------------------------------------------------------------------------------
97 loizides 1.1 void ElectronIDMod::Process()
98     {
99     // Process entries of the tree.
100    
101 loizides 1.23 LoadEventObject(fElectronBranchName, fElectrons);
102 loizides 1.1
103 loizides 1.6 ElectronOArr *GoodElectrons = new ElectronOArr;
104     GoodElectrons->SetName(fGoodElectronsName);
105 loizides 1.1
106 ceballos 1.18 for (UInt_t i=0; i<fElectrons->GetEntries(); ++i) {
107 loizides 1.5 const Electron *e = fElectrons->At(i);
108 loizides 1.1
109 loizides 1.5 if (e->Pt() <= fElectronPtMin)
110     continue;
111 loizides 1.1
112 loizides 1.5 Bool_t idcut = kFALSE;
113     switch (fElIdType) {
114     case kTight:
115     idcut = e->PassTightID();
116     break;
117     case kLoose:
118     idcut = e->PassLooseID();
119     break;
120     case kLikelihood:
121     idcut = (e->IDLikelihood() > fIDLikelihoodCut);
122     break;
123 loizides 1.11 case kNoId:
124     idcut = kTRUE;
125     break;
126 peveraer 1.29 case kCustomIdLoose:
127 loizides 1.30 idcut = ElectronIDMod::PassCustomID(e);
128 peveraer 1.29 break;
129     case kCustomIdTight:
130 loizides 1.30 idcut = ElectronIDMod::PassCustomID(e);
131     break;
132     default:
133 loizides 1.5 break;
134 loizides 1.1 }
135    
136 loizides 1.5 if (!idcut)
137     continue;
138    
139     Bool_t isocut = kFALSE;
140     switch (fElIsoType) {
141     case kTrackCalo:
142 bendavid 1.28 isocut = (e->TrackIsolationDr03() < fTrackIsolationCut) &&
143 loizides 1.5 (e->CaloIsolation() < fCaloIsolationCut);
144     break;
145     case kTrackJura:
146 bendavid 1.28 isocut = (e->TrackIsolationDr03() < fTrackIsolationCut) &&
147     (e->EcalRecHitIsoDr04() < fEcalJuraIsoCut) &&
148 loizides 1.5 (e->HcalIsolation() < fHcalIsolationCut);
149     break;
150     case kTrackJuraSliding:
151 ceballos 1.18 {
152 bendavid 1.28 Double_t totalIso = e->TrackIsolationDr03() + e->EcalRecHitIsoDr04() - 1.5;
153 ceballos 1.12 if ((totalIso < (e->Pt()-10.0)*5.0/15.0 && e->Pt() <= 25) ||
154     (totalIso < 5.0 && e->Pt() > 25) ||
155 ceballos 1.7 totalIso <= 0)
156 loizides 1.5 isocut = kTRUE;
157 ceballos 1.24
158     if (fReverseIsoCut == kTRUE &&
159     isocut == kFALSE && totalIso < 10)
160     isocut = kTRUE;
161     else if(fReverseIsoCut == kTRUE)
162     isocut = kFALSE;
163 loizides 1.5 }
164     break;
165     case kNoIso:
166     isocut = kTRUE;
167     break;
168     case kCustomIso:
169     default:
170     break;
171 loizides 1.1 }
172    
173 ceballos 1.24 if (isocut == kFALSE)
174 loizides 1.5 continue;
175    
176 loizides 1.14 // apply conversion filter
177 ceballos 1.12 Bool_t isGoodConversion = kFALSE;
178 loizides 1.14 if (fApplyConvFilter) {
179 ceballos 1.12 LoadBranch(fConversionBranchName);
180     for (UInt_t ifc=0; ifc<fConversions->GetEntries(); ifc++) {
181    
182     Bool_t ConversionMatchFound = kFALSE;
183     for (UInt_t d=0; d<fConversions->At(ifc)->NDaughters(); d++) {
184     const Track *trk = dynamic_cast<const ChargedParticle*>
185     (fConversions->At(ifc)->Daughter(d))->Trk();
186 ceballos 1.13 if (e->GsfTrk() == trk) {
187 ceballos 1.12 ConversionMatchFound = kTRUE;
188     break;
189     }
190     }
191    
192     // if match between the e-track and one of the conversion legs
193     if (ConversionMatchFound == kTRUE){
194 ceballos 1.19 isGoodConversion = (fConversions->At(ifc)->Prob() > 0.0005) &&
195 ceballos 1.12 (fConversions->At(ifc)->Lxy() > 0) &&
196     (fConversions->At(ifc)->Lz() > 0);
197    
198     if (isGoodConversion == kTRUE) {
199     for (UInt_t d=0; d<fConversions->At(ifc)->NDaughters(); d++) {
200     const Track *trk = dynamic_cast<const ChargedParticle*>
201     (fConversions->At(ifc)->Daughter(d))->Trk();
202    
203     if (trk) {
204 bendavid 1.27 // These requirements are not used for the GSF track
205     if (!(trk->NHits() > 8 && trk->Prob() > 0.005) && trk!=e->GsfTrk())
206 ceballos 1.12 isGoodConversion = kFALSE;
207    
208     const StableData *sd = dynamic_cast<const StableData*>
209     (fConversions->At(ifc)->DaughterDat(d));
210     if (sd->NWrongHits() != 0)
211     isGoodConversion = kFALSE;
212    
213     } else {
214     isGoodConversion = kFALSE;
215     }
216     }
217     }
218     }
219    
220     if (isGoodConversion == kTRUE) break;
221    
222     } // loop over all conversions
223    
224     }
225     if (isGoodConversion == kTRUE) continue;
226    
227 ceballos 1.15 if (fApplyD0Cut) {
228 ceballos 1.24 Bool_t d0cut = kFALSE;
229 ceballos 1.15 LoadBranch(fVertexName);
230     // d0 cut
231 loizides 1.30 Double_t d0_real = 99999;
232     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
233     Double_t pD0 = e->GsfTrk()->D0Corrected(*fVertices->At(i0));
234 ceballos 1.15 if(TMath::Abs(pD0) < TMath::Abs(d0_real)) d0_real = TMath::Abs(pD0);
235     }
236 ceballos 1.24 if(d0_real < fD0Cut) d0cut = kTRUE;
237    
238     if (fReverseD0Cut == kTRUE &&
239     d0cut == kFALSE && d0_real < 0.05)
240     d0cut = kTRUE;
241     else if(fReverseD0Cut == kTRUE)
242     d0cut = kFALSE;
243    
244     if (d0cut == kFALSE)
245     continue;
246 ceballos 1.12 }
247    
248 loizides 1.5 // add good electron
249 ceballos 1.12 GoodElectrons->Add(e);
250 loizides 1.5 }
251 loizides 1.1
252 loizides 1.9 // sort according to pt
253     GoodElectrons->Sort();
254    
255 loizides 1.5 // add to event for other modules to use
256 loizides 1.6 AddObjThisEvt(GoodElectrons);
257 loizides 1.1 }
258    
259     //--------------------------------------------------------------------------------------------------
260     void ElectronIDMod::SlaveBegin()
261     {
262     // Run startup code on the computer (slave) doing the actual analysis. Here,
263 loizides 1.5 // we just request the electron collection branch.
264 loizides 1.1
265 loizides 1.23 ReqEventObject(fElectronBranchName, fElectrons, kTRUE);
266 loizides 1.17
267 ceballos 1.16 if (fApplyConvFilter)
268 loizides 1.23 ReqEventObject(fConversionBranchName, fConversions, kTRUE);
269 loizides 1.17
270 ceballos 1.15 if (fApplyD0Cut)
271 loizides 1.23 ReqEventObject(fVertexName, fVertices, kTRUE);
272 loizides 1.1
273 loizides 1.5 if (fElectronIDType.CompareTo("Tight") == 0)
274     fElIdType = kTight;
275     else if (fElectronIDType.CompareTo("Loose") == 0)
276     fElIdType = kLoose;
277     else if (fElectronIDType.CompareTo("Likelihood") == 0)
278     fElIdType = kLikelihood;
279 loizides 1.10 else if (fElectronIDType.CompareTo("NoId") == 0)
280     fElIdType = kNoId;
281 loizides 1.30 else if (fElectronIDType.CompareTo("CustomLoose") == 0) {
282 peveraer 1.29 fElIdType = kCustomIdLoose;
283 loizides 1.30 } else if (fElectronIDType.CompareTo("CustomTight") == 0) {
284 peveraer 1.29 fElIdType = kCustomIdTight;
285 loizides 1.30 }
286 peveraer 1.29 else {
287 loizides 1.5 SendError(kAbortAnalysis, "SlaveBegin",
288     "The specified electron identification %s is not defined.",
289     fElectronIDType.Data());
290     return;
291     }
292    
293 loizides 1.30 SetCustomIDCuts(fElIdType);
294    
295 loizides 1.5 if (fElectronIsoType.CompareTo("TrackCalo") == 0 )
296     fElIsoType = kTrackCalo;
297     else if (fElectronIsoType.CompareTo("TrackJura") == 0)
298     fElIsoType = kTrackJura;
299     else if(fElectronIsoType.CompareTo("TrackJuraSliding") == 0)
300     fElIsoType = kTrackJuraSliding;
301     else if (fElectronIsoType.CompareTo("NoIso") == 0 )
302     fElIsoType = kNoIso;
303     else if (fElectronIsoType.CompareTo("Custom") == 0 ) {
304     fElIsoType = kCustomIso;
305     SendError(kWarning, "SlaveBegin",
306     "Custom electron isolation is not yet implemented.");
307     } else {
308     SendError(kAbortAnalysis, "SlaveBegin",
309     "The specified electron isolation %s is not defined.",
310     fElectronIsoType.Data());
311     return;
312     }
313 loizides 1.1 }
314 loizides 1.30
315     //--------------------------------------------------------------------------------------------------
316     void ElectronIDMod::SetCustomIDCuts(EElIdType idt)
317     {
318 loizides 1.32 // Set cut values based on RecoEgamma/ElectronIdentification/python/electronIdCutBasedExt_cfi.py.
319     // The following changes are in sigmaetaeta for endcups and deltaetain.
320 loizides 1.30
321     Double_t tightcuts[6][8]={
322 ceballos 1.31 {0.05, 0.042, 0.045, 0.0, 0.055, 0.037, 0.05, 0.0}, //hovere
323     {0.0125, 0.011, 0.01, 0.0, 0.0295, 0.0292, 0.0283, 0.0}, //sigmaetaeta
324     {0.032, 0.016, 0.0525, 0.09, 0.025, 0.035, 0.065, 0.092}, //deltaphiin
325     {0.0055, 0.003, 0.0075, 0.0, 0.0070, 0.0055, 0.0085, 0.0}, //deltaetain
326     {0.24, 0.94, 0.11, 0.0, 0.32, 0.83, 0.0, 0.0}, //eoverp
327     {0.8,0.2,0.9,0,0,0,0,0}}; //extra cuts fbrem and E_Over_P
328 loizides 1.30
329     Double_t loosecuts[6][8]={
330     {0.076, 0.033, 0.07, 0.0, 0.083,0.148, 0.033, 0.0}, //hovere
331     {0.0101, 0.0095, 0.0097, 0.0, 0.03, 0.03, 0.03, 0.0}, //sigmaetaeta
332     {0.053, 0.0189, 0.059, 0.099, 0.0278,0.0157, 0.042, 0.080}, //deltaphiin
333     {0.0078, 0.00259, 0.0062, 0.0, 0.0078,0.0061, 0.0061, 0.0}, //deltaetain
334     {0.3, 0.92, 0.211, 0.0, 0.42, 0.88, 0.68, 0.0}, //eoverp
335     {0.8,0.2,0,0,0,0,0,0}}; //extra cuts fbrem and E_Over_P
336    
337     switch (idt) {
338     case kCustomIdTight:
339     memcpy(fCuts,tightcuts,sizeof(fCuts));
340     break;
341     case kCustomIdLoose:
342     memcpy(fCuts,loosecuts,sizeof(fCuts));
343     break;
344     default:
345     memset(fCuts,0,sizeof(fCuts));
346     break;
347     }
348     }
349