ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.33
Committed: Fri Aug 28 13:38:00 2009 UTC (15 years, 8 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.32: +6 -1 lines
Log Message:
adding last changes

File Contents

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