ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.106
Committed: Sun Oct 2 10:03:21 2011 UTC (13 years, 7 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.105: +1 -3 lines
Log Message:
upgrade

File Contents

# User Rev Content
1 ceballos 1.106 // $Id: ElectronIDMod.cc,v 1.105 2011/09/25 18:14:03 sixie Exp $
2 loizides 1.1
3     #include "MitPhysics/Mods/interface/ElectronIDMod.h"
4 loizides 1.26 #include "MitAna/DataTree/interface/StableData.h"
5 ceballos 1.76 #include "MitAna/DataTree/interface/ElectronFwd.h"
6     #include "MitAna/DataTree/interface/MuonFwd.h"
7 loizides 1.26 #include "MitAna/DataTree/interface/VertexCol.h"
8 bendavid 1.62 #include "MitAna/DataTree/interface/TriggerObjectCol.h"
9 loizides 1.26 #include "MitAna/DataTree/interface/DecayParticleCol.h"
10 loizides 1.5 #include "MitPhysics/Init/interface/ModNames.h"
11 sixie 1.102 #include "TMVA/Tools.h"
12     #include "TMVA/Reader.h"
13 loizides 1.1
14     using namespace mithep;
15    
16     ClassImp(mithep::ElectronIDMod)
17    
18     //--------------------------------------------------------------------------------------------------
19 loizides 1.5 ElectronIDMod::ElectronIDMod(const char *name, const char *title) :
20 loizides 1.1 BaseMod(name,title),
21 loizides 1.5 fElectronBranchName(Names::gkElectronBrn),
22 ceballos 1.12 fConversionBranchName(Names::gkMvfConversionBrn),
23 loizides 1.5 fGoodElectronsName(ModNames::gkGoodElectronsName),
24 ceballos 1.78 fNonIsolatedMuonsName("random"),
25     fNonIsolatedElectronsName("random"),
26 ceballos 1.68 fVertexName(ModNames::gkGoodVertexesName),
27 bendavid 1.75 fBeamSpotName(Names::gkBeamSpotBrn),
28 ceballos 1.76 fTrackName(Names::gkTrackBrn),
29     fPFCandidatesName(Names::gkPFCandidatesBrn),
30 ceballos 1.31 fElectronIDType("CustomTight"),
31 sixie 1.87 fElectronIsoType("PFIso"),
32 bendavid 1.62 fTrigObjectsName("HLTModTrigObjs"),
33 loizides 1.1 fElectronPtMin(10),
34 bendavid 1.67 fElectronEtMin(0.0),
35 ceballos 1.64 fElectronEtaMax(2.5),
36 ceballos 1.95 fIDLikelihoodCut(-999.0),
37 loizides 1.1 fTrackIsolationCut(5.0),
38     fCaloIsolationCut(5.0),
39 loizides 1.5 fEcalJuraIsoCut(5.0),
40     fHcalIsolationCut(5.0),
41 fabstoec 1.97 fCombIsolationCut(0.1),
42 sixie 1.99 fCombRelativeIsolationCut(0.10),
43 fabstoec 1.97 fPFIsolationCut(-1.0),
44 ceballos 1.60 fApplyConvFilterType1(kTRUE),
45     fApplyConvFilterType2(kFALSE),
46 bendavid 1.82 fNWrongHitsMax(0),
47 ceballos 1.60 fNExpectedHitsInnerCut(999),
48 ceballos 1.98 fInvertNExpectedHitsInnerCut(kFALSE),
49 ceballos 1.59 fCombinedIdCut(kFALSE),
50 sixie 1.58 fApplySpikeRemoval(kTRUE),
51 ceballos 1.18 fApplyD0Cut(kTRUE),
52 ceballos 1.81 fApplyDZCut(kTRUE),
53 ceballos 1.45 fChargeFilter(kTRUE),
54 ceballos 1.60 fD0Cut(0.020),
55 ceballos 1.89 fDZCut(0.10),
56 ceballos 1.81 fWhichVertex(-1),
57 bendavid 1.62 fApplyTriggerMatching(kFALSE),
58 bendavid 1.67 fApplyEcalSeeded(kFALSE),
59     fApplyCombinedIso(kTRUE),
60     fApplyEcalFiducial(kFALSE),
61 ceballos 1.76 fElectronsFromBranch(kTRUE),
62 sixie 1.56 fElIdType(ElectronTools::kIdUndef),
63     fElIsoType(ElectronTools::kIsoUndef),
64 loizides 1.14 fElectrons(0),
65     fConversions(0),
66 bendavid 1.75 fVertices(0),
67 ceballos 1.76 fBeamSpot(0),
68     fTracks(0),
69     fPFCandidates(0),
70 ceballos 1.101 fIntRadius(0.0),
71 ceballos 1.78 fNonIsolatedMuons(0),
72     fNonIsolatedElectrons(0),
73 ceballos 1.80 fLH(0),
74     fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn),
75 sixie 1.102 fPileupEnergyDensity(0),
76     fElectronIDMVA(0),
77     fElectronMVAWeights_Subdet0Pt10To20(""),
78     fElectronMVAWeights_Subdet1Pt10To20(""),
79     fElectronMVAWeights_Subdet2Pt10To20(""),
80     fElectronMVAWeights_Subdet0Pt20ToInf(""),
81     fElectronMVAWeights_Subdet1Pt20ToInf(""),
82     fElectronMVAWeights_Subdet2Pt20ToInf("")
83    
84 loizides 1.1 {
85     // Constructor.
86     }
87    
88     //--------------------------------------------------------------------------------------------------
89 sixie 1.102 Bool_t ElectronIDMod::PassLikelihoodID(const Electron *ele) const
90 ceballos 1.77 {
91 sixie 1.102
92     Double_t LikelihoodValue = ElectronTools::Likelihood(fLH, ele);
93 ceballos 1.96
94 ceballos 1.95 double likCut = fIDLikelihoodCut;
95     if(likCut > -900){
96     if(ele->Pt() > 20){
97     if(ele->SCluster()->AbsEta() < 1.479){
98 ceballos 1.101 if(ele->NumberOfClusters() - 1 == 0) likCut = 3.5;
99     else likCut = 4.0;
100 ceballos 1.95 }
101     else {
102 ceballos 1.101 if(ele->NumberOfClusters() - 1 == 0) likCut = 4.0;
103     else likCut = 4.0;
104 ceballos 1.95 }
105     }
106     else {
107     if(ele->SCluster()->AbsEta() < 1.479){
108 ceballos 1.101 if(ele->NumberOfClusters() - 1 == 0) likCut = 4.0;
109     else likCut = 4.5;
110 ceballos 1.95 }
111     else {
112 ceballos 1.101 if(ele->NumberOfClusters() - 1 == 0) likCut = 4.0;
113     else likCut = 4.0;
114 ceballos 1.95 }
115     }
116     }
117 sixie 1.102 if (LikelihoodValue > likCut) return kTRUE;
118 ceballos 1.77 return kFALSE;
119     }
120    
121     //--------------------------------------------------------------------------------------------------
122 sixie 1.102 Bool_t ElectronIDMod::PassMVAID(const Electron *el, ElectronTools::EElIdType idType,
123     const Vertex *vertex) const
124     {
125     Double_t MVAValue = fElectronIDMVA->MVAValue(el, vertex);
126    
127     Int_t subdet = 0;
128     if (el->SCluster()->AbsEta() < 1.0) subdet = 0;
129     else if (el->SCluster()->AbsEta() < 1.479) subdet = 1;
130     else subdet = 2;
131     Int_t ptBin = 0;
132     if (el->Pt() > 20.0) ptBin = 1;
133     Int_t MVABin = -1;
134     if (subdet == 0 && ptBin == 0) MVABin = 0;
135     if (subdet == 1 && ptBin == 0) MVABin = 1;
136     if (subdet == 2 && ptBin == 0) MVABin = 2;
137     if (subdet == 0 && ptBin == 1) MVABin = 3;
138     if (subdet == 1 && ptBin == 1) MVABin = 4;
139     if (subdet == 2 && ptBin == 1) MVABin = 5;
140    
141     Double_t MVACut = -9999;
142 sixie 1.105 if (MVABin == 0) MVACut = 0.362;
143     if (MVABin == 1) MVACut = 0.467;
144     if (MVABin == 2) MVACut = 0.320;
145     if (MVABin == 3) MVACut = 0.968;
146 sixie 1.103 if (MVABin == 4) MVACut = 0.961;
147 sixie 1.105 if (MVABin == 5) MVACut = 0.929;
148 sixie 1.102
149     if (MVAValue > MVACut) return kTRUE;
150     return kFALSE;
151     }
152    
153     //--------------------------------------------------------------------------------------------------
154     Bool_t ElectronIDMod::PassIDCut(const Electron *ele, ElectronTools::EElIdType idType,
155     const Vertex *vertex) const
156 sixie 1.42 {
157    
158     Bool_t idcut = kFALSE;
159     switch (idType) {
160 sixie 1.56 case ElectronTools::kTight:
161 sixie 1.42 idcut = ele->PassTightID();
162     break;
163 sixie 1.56 case ElectronTools::kLoose:
164 sixie 1.42 idcut = ele->PassLooseID();
165     break;
166 sixie 1.56 case ElectronTools::kLikelihood:
167 ceballos 1.101 idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointFakeableId) &&
168 sixie 1.102 PassLikelihoodID(ele);
169 sixie 1.42 break;
170 sixie 1.56 case ElectronTools::kNoId:
171 sixie 1.42 idcut = kTRUE;
172     break;
173 sixie 1.56 case ElectronTools::kCustomIdLoose:
174     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kCustomIdLoose);
175 sixie 1.42 break;
176 sixie 1.56 case ElectronTools::kCustomIdTight:
177     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kCustomIdTight);
178 sixie 1.42 break;
179 ceballos 1.86 case ElectronTools::kVBTFWorkingPointFakeableId:
180     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointFakeableId);
181     break;
182 sixie 1.56 case ElectronTools::kVBTFWorkingPoint95Id:
183     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint95Id);
184 ceballos 1.54 break;
185 sixie 1.56 case ElectronTools::kVBTFWorkingPoint90Id:
186     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint90Id);
187 ceballos 1.54 break;
188 ceballos 1.60 case ElectronTools::kVBTFWorkingPoint85Id:
189     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint85Id);
190     break;
191 sixie 1.56 case ElectronTools::kVBTFWorkingPoint80Id:
192     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint80Id);
193     break;
194 ceballos 1.83 case ElectronTools::kVBTFWorkingPointLowPtId:
195     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointLowPtId);
196 ceballos 1.81 break;
197 sixie 1.56 case ElectronTools::kVBTFWorkingPoint70Id:
198     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint70Id);
199 ceballos 1.54 break;
200 sixie 1.102 case ElectronTools::kMVA_BDTG_V3:
201     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointFakeableId) &&
202     PassMVAID(ele, ElectronTools::kMVA_BDTG_V3, vertex);
203     break;
204 sixie 1.42 default:
205     break;
206     }
207    
208     return idcut;
209     }
210    
211     //--------------------------------------------------------------------------------------------------
212 ceballos 1.76 Bool_t ElectronIDMod::PassIsolationCut(const Electron *ele, ElectronTools::EElIsoType isoType,
213 ceballos 1.80 const TrackCol *tracks, const Vertex *vertex,
214     const Double_t rho) const
215 sixie 1.42 {
216    
217     Bool_t isocut = kFALSE;
218     switch (isoType) {
219 sixie 1.56 case ElectronTools::kTrackCalo:
220 sixie 1.42 isocut = (ele->TrackIsolationDr03() < fTrackIsolationCut) &&
221     (ele->CaloIsolation() < fCaloIsolationCut);
222     break;
223 sixie 1.56 case ElectronTools::kTrackJura:
224 ceballos 1.85 isocut = (ele->TrackIsolationDr03() < ele->Pt()*fTrackIsolationCut) &&
225     (ele->EcalRecHitIsoDr03() < ele->Pt()*fEcalJuraIsoCut) &&
226     (ele->HcalTowerSumEtDr03() < ele->Pt()*fHcalIsolationCut);
227 sixie 1.42 break;
228 sixie 1.56 case ElectronTools::kTrackJuraCombined:
229 ceballos 1.60 isocut = (ele->TrackIsolationDr03() + ele->EcalRecHitIsoDr03()
230 ceballos 1.49 - 1.5 < fCombIsolationCut);
231     break;
232 sixie 1.56 case ElectronTools::kTrackJuraSliding:
233 sixie 1.42 {
234 ceballos 1.80 Double_t totalIso = ele->TrackIsolationDr03() + TMath::Max(ele->EcalRecHitIsoDr03() + ele->HcalTowerSumEtDr03() - rho * TMath::Pi() * 0.3 * 0.3, 0.0);
235     if(ele->SCluster()->AbsEta() < 1.479) totalIso = ele->TrackIsolationDr03() + TMath::Max(TMath::Max(ele->EcalRecHitIsoDr03() - 1.0, 0.0) + ele->HcalTowerSumEtDr03() - rho * TMath::Pi() * 0.3 * 0.3, 0.0);
236 ceballos 1.79 if (totalIso < (ele->Pt()*fCombIsolationCut) )
237     isocut = kTRUE;
238     }
239     break;
240 ceballos 1.80 case ElectronTools::kTrackJuraSlidingNoCorrection:
241 ceballos 1.79 {
242 ceballos 1.80 Double_t totalIso = ele->TrackIsolationDr03() + (ele->EcalRecHitIsoDr03() + ele->HcalTowerSumEtDr03());
243     if(ele->SCluster()->AbsEta() < 1.479) totalIso = ele->TrackIsolationDr03() + (TMath::Max(ele->EcalRecHitIsoDr03() - 1.0, 0.0) + ele->HcalTowerSumEtDr03());
244 ceballos 1.76 if (totalIso < (ele->Pt()*fCombIsolationCut) )
245     isocut = kTRUE;
246     }
247     break;
248 sixie 1.99 case ElectronTools::kCombinedRelativeConeAreaCorrected:
249     {
250     Double_t totalIso = ele->TrackIsolationDr03() + ele->EcalRecHitIsoDr03() + ele->HcalTowerSumEtDr03() - rho * TMath::Pi() * 0.3 * 0.3;
251     if (totalIso < (ele->Pt()*fCombRelativeIsolationCut) )
252     isocut = kTRUE;
253     }
254     break;
255 ceballos 1.76 case ElectronTools::kPFIso:
256     {
257 sixie 1.87 Double_t pfIsoCutValue = 9999;
258 fabstoec 1.97 if(fPFIsolationCut > 0){
259     pfIsoCutValue = fPFIsolationCut;
260 ceballos 1.88 } else {
261 ceballos 1.91 if (ele->SCluster()->AbsEta() < 1.479) {
262 ceballos 1.88 if (ele->Pt() > 20) {
263 ceballos 1.92 pfIsoCutValue = 0.13;
264 ceballos 1.88 } else {
265 ceballos 1.92 pfIsoCutValue = 0.13;
266 ceballos 1.88 }
267 sixie 1.87 } else {
268 ceballos 1.91 if (ele->Pt() > 20) {
269     pfIsoCutValue = 0.09;
270     } else {
271     pfIsoCutValue = 0.09;
272     }
273     }
274 sixie 1.87 }
275 ceballos 1.101 Double_t totalIso = IsolationTools::PFElectronIsolation(ele, fPFCandidates, vertex, 0.1, 1.0, 0.4, fIntRadius);
276 sixie 1.87 if (totalIso < (ele->Pt()*pfIsoCutValue) )
277 ceballos 1.89 isocut = kTRUE;
278 ceballos 1.76 }
279     break;
280     case ElectronTools::kPFIsoNoL:
281     {
282     Double_t beta = IsolationTools::BetaE(tracks, ele, vertex, 0.0, 0.2, 0.3, 0.02);
283 ceballos 1.79 if(beta == 0) beta = 1.0;
284 sixie 1.87 Double_t totalIso = IsolationTools::PFElectronIsolation(ele, fPFCandidates, vertex, fNonIsolatedMuons, fNonIsolatedElectrons, 0.1, 1.0, 0.4, 0.0, 3, beta);
285 fabstoec 1.97 if (totalIso < (ele->Pt()*fPFIsolationCut) )
286 sixie 1.42 isocut = kTRUE;
287     }
288     break;
289 sixie 1.56 case ElectronTools::kVBTFWorkingPoint95Iso:
290 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint95Iso, fApplyCombinedIso);
291 sixie 1.56 break;
292     case ElectronTools::kVBTFWorkingPoint90Iso:
293 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint90Iso, fApplyCombinedIso);
294 sixie 1.51 break;
295 ceballos 1.60 case ElectronTools::kVBTFWorkingPoint85Iso:
296 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint85Iso, fApplyCombinedIso);
297 ceballos 1.60 break;
298 sixie 1.56 case ElectronTools::kVBTFWorkingPoint80Iso:
299 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint80Iso, fApplyCombinedIso);
300 sixie 1.51 break;
301 sixie 1.56 case ElectronTools::kVBTFWorkingPoint70Iso:
302 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint70Iso, fApplyCombinedIso);
303 sixie 1.51 break;
304 sixie 1.56 case ElectronTools::kNoIso:
305 sixie 1.42 isocut = kTRUE;
306     break;
307 sixie 1.56 case ElectronTools::kCustomIso:
308 sixie 1.42 default:
309     break;
310     }
311    
312     return isocut;
313     }
314    
315    
316     //--------------------------------------------------------------------------------------------------
317 loizides 1.1 void ElectronIDMod::Process()
318     {
319     // Process entries of the tree.
320    
321 ceballos 1.76 if(fElIsoType != ElectronTools::kPFIsoNoL) {
322     LoadEventObject(fElectronBranchName, fElectrons);
323     }
324     else {
325     fElectrons = GetObjThisEvt<ElectronOArr>(fElectronBranchName);
326 ceballos 1.78 fNonIsolatedMuons = GetObjThisEvt<MuonCol>(fNonIsolatedMuonsName);
327     fNonIsolatedElectrons = GetObjThisEvt<ElectronCol>(fNonIsolatedElectronsName);
328 ceballos 1.76 }
329 bendavid 1.75 LoadEventObject(fBeamSpotName, fBeamSpot);
330 ceballos 1.76 LoadEventObject(fTrackName, fTracks);
331     LoadEventObject(fPFCandidatesName, fPFCandidates);
332 sixie 1.100 if(fElIsoType == ElectronTools::kTrackJuraSliding ||
333     fElIsoType == ElectronTools::kCombinedRelativeConeAreaCorrected) {
334 ceballos 1.80 LoadEventObject(fPileupEnergyDensityName, fPileupEnergyDensity);
335     }
336 ceballos 1.76 fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
337 loizides 1.1
338 bendavid 1.62 //get trigger object collection if trigger matching is enabled
339     const TriggerObjectCol *trigObjs = 0;
340     if (fApplyTriggerMatching) {
341     trigObjs = GetHLTObjects(fTrigObjectsName);
342     }
343    
344 loizides 1.6 ElectronOArr *GoodElectrons = new ElectronOArr;
345     GoodElectrons->SetName(fGoodElectronsName);
346 loizides 1.1
347 ceballos 1.18 for (UInt_t i=0; i<fElectrons->GetEntries(); ++i) {
348 loizides 1.5 const Electron *e = fElectrons->At(i);
349 loizides 1.1
350 ceballos 1.66 if (e->SCluster() == 0)
351     continue;
352    
353 ceballos 1.65 if (e->Pt() < fElectronPtMin)
354 loizides 1.5 continue;
355 loizides 1.1
356 dkralph 1.73 if (e->SCluster()->Et() < fElectronEtMin)
357 bendavid 1.67 continue;
358    
359 ceballos 1.65 if (e->AbsEta() > fElectronEtaMax)
360 ceballos 1.64 continue;
361    
362 bendavid 1.67 if (fApplyEcalFiducial && ( (e->SCluster()->AbsEta()>1.4442 && e->SCluster()->AbsEta()<1.5666) || e->SCluster()->AbsEta()>2.5 )) {
363     continue;
364     }
365    
366     if (fApplyEcalSeeded && !e->IsEcalDriven()) {
367     continue;
368     }
369    
370 bendavid 1.62 //apply trigger matching
371     Bool_t matchTrigger = fApplyTriggerMatching && ElectronTools::PassTriggerMatching(e,trigObjs);
372     if (fApplyTriggerMatching && !matchTrigger)
373     continue;
374    
375 sixie 1.55 //apply ECAL spike removal
376 sixie 1.56 Bool_t spikecut = ElectronTools::PassSpikeRemovalFilter(e);
377 sixie 1.57 if (fApplySpikeRemoval && !spikecut)
378 sixie 1.55 continue;
379    
380 sixie 1.42 //apply Isolation Cut
381 ceballos 1.80 Double_t Rho = 0.0;
382 sixie 1.100 if( fElIsoType == ElectronTools::kTrackJuraSliding
383     || fElIsoType == ElectronTools::kCombinedRelativeConeAreaCorrected ) {
384     Rho = fPileupEnergyDensity->At(0)->Rho();
385 ceballos 1.80 }
386     Bool_t isocut = PassIsolationCut(e, fElIsoType, fTracks, fVertices->At(0), Rho);
387 sixie 1.42 if (!isocut)
388 loizides 1.5 continue;
389    
390 ceballos 1.60 // apply conversion filters
391     Bool_t passConvVetoType1 = kFALSE;
392     if (fApplyConvFilterType1) {
393 sixie 1.42 LoadEventObject(fConversionBranchName, fConversions);
394 ceballos 1.60 passConvVetoType1 = ElectronTools::PassConversionFilter(e, fConversions,
395 bendavid 1.82 fBeamSpot->At(0), 0, 1e-6, 2.0, kTRUE, kFALSE);
396 ceballos 1.12 }
397 ceballos 1.60 else {
398     passConvVetoType1 = kTRUE;
399     }
400    
401     if (passConvVetoType1 == kFALSE) continue;
402    
403     Bool_t passConvVetoType2 = kFALSE;
404     if (fApplyConvFilterType2) {
405     passConvVetoType2 = TMath::Abs(e->ConvPartnerDCotTheta()) >= 0.02 ||
406     TMath::Abs(e->ConvPartnerDist()) >= 0.02;
407     }
408     else {
409     passConvVetoType2 = kTRUE;
410     }
411 sixie 1.42
412 ceballos 1.60 if (passConvVetoType2 == kFALSE) continue;
413 ceballos 1.72
414 ceballos 1.60 // apply NExpectedHitsInner Cut
415 ceballos 1.98 if(fInvertNExpectedHitsInnerCut == kFALSE && fNExpectedHitsInnerCut < 999 &&
416 ceballos 1.69 e->CorrectedNExpectedHitsInner() > fNExpectedHitsInnerCut) continue;
417 ceballos 1.60
418 ceballos 1.98 // apply NExpectedHitsInner inverted Cut
419     if(fInvertNExpectedHitsInnerCut == kTRUE && fNExpectedHitsInnerCut < 999 &&
420     e->CorrectedNExpectedHitsInner() <= fNExpectedHitsInnerCut) continue;
421    
422 sixie 1.42 // apply d0 cut
423 ceballos 1.15 if (fApplyD0Cut) {
424 ceballos 1.81 Bool_t passD0cut = kTRUE;
425     if(fWhichVertex >= -1) passD0cut = ElectronTools::PassD0Cut(e, fVertices, fD0Cut, fWhichVertex);
426     else passD0cut = ElectronTools::PassD0Cut(e, fBeamSpot, fD0Cut);
427 sixie 1.42 if (!passD0cut)
428 ceballos 1.24 continue;
429 ceballos 1.12 }
430    
431 ceballos 1.81 // apply dz cut
432     if (fApplyDZCut) {
433 ceballos 1.83 Bool_t passDZcut = ElectronTools::PassDZCut(e, fVertices, fDZCut, fWhichVertex);
434 ceballos 1.81 if (!passDZcut)
435     continue;
436     }
437    
438 sixie 1.102 //apply id cut
439     Bool_t idcut = PassIDCut(e, fElIdType, fVertices->At(0));
440     if (!idcut)
441     continue;
442    
443 ceballos 1.59 // apply charge filter
444 sixie 1.42 if(fChargeFilter == kTRUE) {
445 sixie 1.56 Bool_t passChargeFilter = ElectronTools::PassChargeFilter(e);
446 sixie 1.42 if (!passChargeFilter) continue;
447 ceballos 1.45 }
448    
449 ceballos 1.63 // apply full combined id, using Tight cuts
450 ceballos 1.59 if(fCombinedIdCut == kTRUE) {
451 ceballos 1.68 fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
452 ceballos 1.59 LoadEventObject(fConversionBranchName, fConversions);
453 ceballos 1.63 Int_t result = ElectronTools::PassTightId(e, *&fVertices, fConversions, 2);
454 ceballos 1.59 if(result != 15) continue;
455     }
456    
457 loizides 1.5 // add good electron
458 ceballos 1.12 GoodElectrons->Add(e);
459 loizides 1.5 }
460 loizides 1.1
461 loizides 1.9 // sort according to pt
462     GoodElectrons->Sort();
463    
464 loizides 1.5 // add to event for other modules to use
465 loizides 1.6 AddObjThisEvt(GoodElectrons);
466 loizides 1.1 }
467    
468     //--------------------------------------------------------------------------------------------------
469     void ElectronIDMod::SlaveBegin()
470     {
471     // Run startup code on the computer (slave) doing the actual analysis. Here,
472 loizides 1.5 // we just request the electron collection branch.
473 loizides 1.1
474 ceballos 1.76 // In this case we cannot have a branch
475     if (fElectronIsoType.CompareTo("PFIsoNoL") != 0 ) {
476     ReqEventObject(fElectronBranchName, fElectrons,fElectronsFromBranch);
477     }
478     ReqEventObject(fBeamSpotName, fBeamSpot, kTRUE);
479     ReqEventObject(fTrackName, fTracks, kTRUE);
480     ReqEventObject(fPFCandidatesName, fPFCandidates, kTRUE);
481 sixie 1.100 if (fElectronIsoType.CompareTo("TrackJuraSliding") == 0
482     || fElectronIsoType.CompareTo("CombinedRelativeConeAreaCorrected") == 0 ) {
483 ceballos 1.80 ReqEventObject(fPileupEnergyDensityName, fPileupEnergyDensity, kTRUE);
484     }
485 loizides 1.17
486 ceballos 1.59 if(fCombinedIdCut == kTRUE) {
487 ceballos 1.60 fElectronIDType = "NoId";
488     fElectronIsoType = "NoIso";
489     fApplyConvFilterType1 = kFALSE;
490     fApplyConvFilterType2 = kFALSE;
491     fApplyD0Cut = kFALSE;
492 ceballos 1.81 fApplyDZCut = kFALSE;
493 ceballos 1.59 }
494    
495 ceballos 1.60 if (fApplyConvFilterType1 || fCombinedIdCut == kTRUE)
496 loizides 1.23 ReqEventObject(fConversionBranchName, fConversions, kTRUE);
497 loizides 1.17
498 sixie 1.42 Setup();
499 sixie 1.102
500 sixie 1.42 }
501    
502     //--------------------------------------------------------------------------------------------------
503     void ElectronIDMod::Setup()
504     {
505     // Set all options properly before execution.
506    
507 loizides 1.5 if (fElectronIDType.CompareTo("Tight") == 0)
508 sixie 1.56 fElIdType = ElectronTools::kTight;
509 loizides 1.5 else if (fElectronIDType.CompareTo("Loose") == 0)
510 sixie 1.56 fElIdType = ElectronTools::kLoose;
511 sixie 1.93 else if (fElectronIDType.CompareTo("Likelihood") == 0) {
512     if (!fLH) { cout << "Error: Likelihood not initialized.\n"; assert(0); }
513 sixie 1.56 fElIdType = ElectronTools::kLikelihood;
514 sixie 1.93 } else if (fElectronIDType.CompareTo("NoId") == 0)
515 sixie 1.56 fElIdType = ElectronTools::kNoId;
516 sixie 1.42 else if (fElectronIDType.CompareTo("ZeeId") == 0)
517 sixie 1.56 fElIdType = ElectronTools::kZeeId;
518 sixie 1.51 else if (fElectronIDType.CompareTo("CustomLoose") == 0)
519 sixie 1.56 fElIdType = ElectronTools::kCustomIdLoose;
520 sixie 1.51 else if (fElectronIDType.CompareTo("CustomTight") == 0)
521 sixie 1.56 fElIdType = ElectronTools::kCustomIdTight;
522 ceballos 1.86 else if (fElectronIDType.CompareTo("VBTFWorkingPointFakeableId") == 0)
523     fElIdType = ElectronTools::kVBTFWorkingPointFakeableId;
524 sixie 1.55 else if (fElectronIDType.CompareTo("VBTFWorkingPoint95Id") == 0)
525 sixie 1.56 fElIdType = ElectronTools::kVBTFWorkingPoint95Id;
526 sixie 1.51 else if (fElectronIDType.CompareTo("VBTFWorkingPoint90Id") == 0)
527 sixie 1.56 fElIdType = ElectronTools::kVBTFWorkingPoint90Id;
528 sixie 1.51 else if (fElectronIDType.CompareTo("VBTFWorkingPoint80Id") == 0)
529 sixie 1.56 fElIdType = ElectronTools::kVBTFWorkingPoint80Id;
530 ceballos 1.83 else if (fElectronIDType.CompareTo("VBTFWorkingPointLowPtId") == 0)
531     fElIdType = ElectronTools::kVBTFWorkingPointLowPtId;
532 ceballos 1.60 else if (fElectronIDType.CompareTo("VBTFWorkingPoint85Id") == 0)
533     fElIdType = ElectronTools::kVBTFWorkingPoint85Id;
534 sixie 1.51 else if (fElectronIDType.CompareTo("VBTFWorkingPoint70Id") == 0)
535 sixie 1.56 fElIdType = ElectronTools::kVBTFWorkingPoint70Id;
536 sixie 1.102 else if (fElectronIDType.CompareTo("MVA_BDTG_V3") == 0) {
537     fElIdType = ElectronTools::kMVA_BDTG_V3;
538     if (!fLH) { cout << "Error: Likelihood not initialized.\n"; assert(0);}
539     } else {
540 loizides 1.5 SendError(kAbortAnalysis, "SlaveBegin",
541     "The specified electron identification %s is not defined.",
542     fElectronIDType.Data());
543     return;
544     }
545 sixie 1.51
546 loizides 1.5 if (fElectronIsoType.CompareTo("TrackCalo") == 0 )
547 sixie 1.56 fElIsoType = ElectronTools::kTrackCalo;
548 loizides 1.5 else if (fElectronIsoType.CompareTo("TrackJura") == 0)
549 sixie 1.56 fElIsoType = ElectronTools::kTrackJura;
550 ceballos 1.49 else if(fElectronIsoType.CompareTo("TrackJuraCombined") == 0)
551 sixie 1.56 fElIsoType = ElectronTools::kTrackJuraCombined;
552 loizides 1.5 else if(fElectronIsoType.CompareTo("TrackJuraSliding") == 0)
553 sixie 1.56 fElIsoType = ElectronTools::kTrackJuraSliding;
554 ceballos 1.80 else if(fElectronIsoType.CompareTo("TrackJuraSlidingNoCorrection") == 0)
555     fElIsoType = ElectronTools::kTrackJuraSlidingNoCorrection;
556 sixie 1.99 else if(fElectronIsoType.CompareTo("CombinedRelativeConeAreaCorrected") == 0)
557     fElIsoType = ElectronTools::kCombinedRelativeConeAreaCorrected;
558 ceballos 1.76 else if (fElectronIsoType.CompareTo("PFIso") == 0 )
559     fElIsoType = ElectronTools::kPFIso;
560     else if (fElectronIsoType.CompareTo("PFIsoNoL") == 0 )
561     fElIsoType = ElectronTools::kPFIsoNoL;
562 loizides 1.5 else if (fElectronIsoType.CompareTo("NoIso") == 0 )
563 sixie 1.56 fElIsoType = ElectronTools::kNoIso;
564 sixie 1.42 else if (fElectronIsoType.CompareTo("ZeeIso") == 0 )
565 sixie 1.56 fElIsoType = ElectronTools::kZeeIso;
566 sixie 1.55 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint95Iso") == 0 )
567 sixie 1.56 fElIsoType = ElectronTools::kVBTFWorkingPoint95Iso;
568 sixie 1.51 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint90Iso") == 0 )
569 sixie 1.56 fElIsoType = ElectronTools::kVBTFWorkingPoint90Iso;
570 ceballos 1.60 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint85Iso") == 0 )
571     fElIsoType = ElectronTools::kVBTFWorkingPoint85Iso;
572 sixie 1.51 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint80Iso") == 0 )
573 sixie 1.56 fElIsoType = ElectronTools::kVBTFWorkingPoint80Iso;
574 sixie 1.51 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint70Iso") == 0 )
575 sixie 1.56 fElIsoType = ElectronTools::kVBTFWorkingPoint70Iso;
576 loizides 1.5 else if (fElectronIsoType.CompareTo("Custom") == 0 ) {
577 sixie 1.56 fElIsoType = ElectronTools::kCustomIso;
578 loizides 1.5 SendError(kWarning, "SlaveBegin",
579     "Custom electron isolation is not yet implemented.");
580     } else {
581     SendError(kAbortAnalysis, "SlaveBegin",
582     "The specified electron isolation %s is not defined.",
583     fElectronIsoType.Data());
584     return;
585     }
586 sixie 1.42
587 loizides 1.30
588 sixie 1.102 //If we use MVA ID, need to load MVA weights
589     if (fElIdType == ElectronTools::kMVA_BDTG_V3) {
590     fElectronIDMVA = new ElectronIDMVA();
591     fElectronIDMVA->Initialize("BDTG method",
592     fElectronMVAWeights_Subdet0Pt10To20,
593     fElectronMVAWeights_Subdet1Pt10To20,
594     fElectronMVAWeights_Subdet2Pt10To20,
595     fElectronMVAWeights_Subdet0Pt20ToInf,
596     fElectronMVAWeights_Subdet1Pt20ToInf,
597     fElectronMVAWeights_Subdet2Pt20ToInf,
598     fLH);
599     }
600    
601 loizides 1.30 }
602 ceballos 1.77
603     //--------------------------------------------------------------------------------------------------
604     void ElectronIDMod::Terminate()
605     {
606     // Run finishing code on the computer (slave) that did the analysis
607     }