ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.39
Committed: Tue Sep 29 19:41:13 2009 UTC (15 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011a
Changes since 1.38: +13 -14 lines
Log Message:
Cosmetics

File Contents

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