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

File Contents

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