ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.35
Committed: Thu Sep 3 07:05:51 2009 UTC (15 years, 8 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.34: +4 -5 lines
Log Message:
tighter electron id

File Contents

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