ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.41
Committed: Wed Oct 21 13:45:44 2009 UTC (15 years, 6 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.40: +1 -2 lines
Log Message:
new electron ID

File Contents

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