ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.107
Committed: Mon Oct 3 19:57:58 2011 UTC (13 years, 7 months ago) by sixie
Content type: text/plain
Branch: MAIN
Changes since 1.106: +41 -16 lines
Log Message:
update to new BDTG version and working point

File Contents

# User Rev Content
1 sixie 1.107 // $Id: ElectronIDMod.cc,v 1.106 2011/10/02 10:03:21 ceballos 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.107 if (idType == ElectronTools::kMVA_BDTG_V1) {
143     if (MVABin == 0) MVACut = 0.115;
144     if (MVABin == 1) MVACut = 0.463;
145     if (MVABin == 2) MVACut = 0.497;
146     if (MVABin == 3) MVACut = 0.945;
147     if (MVABin == 4) MVACut = 0.949;
148     if (MVABin == 5) MVACut = 0.890;
149     } else if (idType == ElectronTools::kMVA_BDTG_V2) {
150     if (MVABin == 0) MVACut = 0.125;
151     if (MVABin == 1) MVACut = 0.516;
152     if (MVABin == 2) MVACut = 0.535;
153     if (MVABin == 3) MVACut = 0.949;
154     if (MVABin == 4) MVACut = 0.952;
155     if (MVABin == 5) MVACut = 0.892;
156     }
157    
158 sixie 1.102 if (MVAValue > MVACut) return kTRUE;
159     return kFALSE;
160     }
161    
162     //--------------------------------------------------------------------------------------------------
163     Bool_t ElectronIDMod::PassIDCut(const Electron *ele, ElectronTools::EElIdType idType,
164     const Vertex *vertex) const
165 sixie 1.42 {
166    
167     Bool_t idcut = kFALSE;
168     switch (idType) {
169 sixie 1.56 case ElectronTools::kTight:
170 sixie 1.42 idcut = ele->PassTightID();
171     break;
172 sixie 1.56 case ElectronTools::kLoose:
173 sixie 1.42 idcut = ele->PassLooseID();
174     break;
175 sixie 1.56 case ElectronTools::kLikelihood:
176 ceballos 1.101 idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointFakeableId) &&
177 sixie 1.102 PassLikelihoodID(ele);
178 sixie 1.42 break;
179 sixie 1.56 case ElectronTools::kNoId:
180 sixie 1.42 idcut = kTRUE;
181     break;
182 sixie 1.56 case ElectronTools::kCustomIdLoose:
183     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kCustomIdLoose);
184 sixie 1.42 break;
185 sixie 1.56 case ElectronTools::kCustomIdTight:
186     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kCustomIdTight);
187 sixie 1.42 break;
188 ceballos 1.86 case ElectronTools::kVBTFWorkingPointFakeableId:
189     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointFakeableId);
190     break;
191 sixie 1.56 case ElectronTools::kVBTFWorkingPoint95Id:
192     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint95Id);
193 ceballos 1.54 break;
194 sixie 1.56 case ElectronTools::kVBTFWorkingPoint90Id:
195     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint90Id);
196 ceballos 1.54 break;
197 ceballos 1.60 case ElectronTools::kVBTFWorkingPoint85Id:
198     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint85Id);
199     break;
200 sixie 1.56 case ElectronTools::kVBTFWorkingPoint80Id:
201     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint80Id);
202     break;
203 ceballos 1.83 case ElectronTools::kVBTFWorkingPointLowPtId:
204     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointLowPtId);
205 ceballos 1.81 break;
206 sixie 1.56 case ElectronTools::kVBTFWorkingPoint70Id:
207     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPoint70Id);
208 ceballos 1.54 break;
209 sixie 1.107 case ElectronTools::kMVA_BDTG_V1:
210     idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointFakeableId) &&
211     PassMVAID(ele, ElectronTools::kMVA_BDTG_V1, vertex);
212     break;
213     case ElectronTools::kMVA_BDTG_V2:
214 sixie 1.102 idcut = ElectronTools::PassCustomID(ele, ElectronTools::kVBTFWorkingPointFakeableId) &&
215 sixie 1.107 PassMVAID(ele, ElectronTools::kMVA_BDTG_V2, vertex);
216 sixie 1.102 break;
217 sixie 1.42 default:
218     break;
219     }
220    
221     return idcut;
222     }
223    
224     //--------------------------------------------------------------------------------------------------
225 ceballos 1.76 Bool_t ElectronIDMod::PassIsolationCut(const Electron *ele, ElectronTools::EElIsoType isoType,
226 ceballos 1.80 const TrackCol *tracks, const Vertex *vertex,
227     const Double_t rho) const
228 sixie 1.42 {
229    
230     Bool_t isocut = kFALSE;
231     switch (isoType) {
232 sixie 1.56 case ElectronTools::kTrackCalo:
233 sixie 1.42 isocut = (ele->TrackIsolationDr03() < fTrackIsolationCut) &&
234     (ele->CaloIsolation() < fCaloIsolationCut);
235     break;
236 sixie 1.56 case ElectronTools::kTrackJura:
237 ceballos 1.85 isocut = (ele->TrackIsolationDr03() < ele->Pt()*fTrackIsolationCut) &&
238     (ele->EcalRecHitIsoDr03() < ele->Pt()*fEcalJuraIsoCut) &&
239     (ele->HcalTowerSumEtDr03() < ele->Pt()*fHcalIsolationCut);
240 sixie 1.42 break;
241 sixie 1.56 case ElectronTools::kTrackJuraCombined:
242 ceballos 1.60 isocut = (ele->TrackIsolationDr03() + ele->EcalRecHitIsoDr03()
243 ceballos 1.49 - 1.5 < fCombIsolationCut);
244     break;
245 sixie 1.56 case ElectronTools::kTrackJuraSliding:
246 sixie 1.42 {
247 ceballos 1.80 Double_t totalIso = ele->TrackIsolationDr03() + TMath::Max(ele->EcalRecHitIsoDr03() + ele->HcalTowerSumEtDr03() - rho * TMath::Pi() * 0.3 * 0.3, 0.0);
248     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);
249 ceballos 1.79 if (totalIso < (ele->Pt()*fCombIsolationCut) )
250     isocut = kTRUE;
251     }
252     break;
253 ceballos 1.80 case ElectronTools::kTrackJuraSlidingNoCorrection:
254 ceballos 1.79 {
255 ceballos 1.80 Double_t totalIso = ele->TrackIsolationDr03() + (ele->EcalRecHitIsoDr03() + ele->HcalTowerSumEtDr03());
256     if(ele->SCluster()->AbsEta() < 1.479) totalIso = ele->TrackIsolationDr03() + (TMath::Max(ele->EcalRecHitIsoDr03() - 1.0, 0.0) + ele->HcalTowerSumEtDr03());
257 ceballos 1.76 if (totalIso < (ele->Pt()*fCombIsolationCut) )
258     isocut = kTRUE;
259     }
260     break;
261 sixie 1.99 case ElectronTools::kCombinedRelativeConeAreaCorrected:
262     {
263     Double_t totalIso = ele->TrackIsolationDr03() + ele->EcalRecHitIsoDr03() + ele->HcalTowerSumEtDr03() - rho * TMath::Pi() * 0.3 * 0.3;
264     if (totalIso < (ele->Pt()*fCombRelativeIsolationCut) )
265     isocut = kTRUE;
266     }
267     break;
268 ceballos 1.76 case ElectronTools::kPFIso:
269     {
270 sixie 1.87 Double_t pfIsoCutValue = 9999;
271 fabstoec 1.97 if(fPFIsolationCut > 0){
272     pfIsoCutValue = fPFIsolationCut;
273 ceballos 1.88 } else {
274 ceballos 1.91 if (ele->SCluster()->AbsEta() < 1.479) {
275 ceballos 1.88 if (ele->Pt() > 20) {
276 ceballos 1.92 pfIsoCutValue = 0.13;
277 ceballos 1.88 } else {
278 ceballos 1.92 pfIsoCutValue = 0.13;
279 ceballos 1.88 }
280 sixie 1.87 } else {
281 ceballos 1.91 if (ele->Pt() > 20) {
282     pfIsoCutValue = 0.09;
283     } else {
284     pfIsoCutValue = 0.09;
285     }
286     }
287 sixie 1.87 }
288 ceballos 1.101 Double_t totalIso = IsolationTools::PFElectronIsolation(ele, fPFCandidates, vertex, 0.1, 1.0, 0.4, fIntRadius);
289 sixie 1.87 if (totalIso < (ele->Pt()*pfIsoCutValue) )
290 ceballos 1.89 isocut = kTRUE;
291 ceballos 1.76 }
292     break;
293     case ElectronTools::kPFIsoNoL:
294     {
295     Double_t beta = IsolationTools::BetaE(tracks, ele, vertex, 0.0, 0.2, 0.3, 0.02);
296 ceballos 1.79 if(beta == 0) beta = 1.0;
297 sixie 1.87 Double_t totalIso = IsolationTools::PFElectronIsolation(ele, fPFCandidates, vertex, fNonIsolatedMuons, fNonIsolatedElectrons, 0.1, 1.0, 0.4, 0.0, 3, beta);
298 fabstoec 1.97 if (totalIso < (ele->Pt()*fPFIsolationCut) )
299 sixie 1.42 isocut = kTRUE;
300     }
301     break;
302 sixie 1.56 case ElectronTools::kVBTFWorkingPoint95Iso:
303 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint95Iso, fApplyCombinedIso);
304 sixie 1.56 break;
305     case ElectronTools::kVBTFWorkingPoint90Iso:
306 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint90Iso, fApplyCombinedIso);
307 sixie 1.51 break;
308 ceballos 1.60 case ElectronTools::kVBTFWorkingPoint85Iso:
309 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint85Iso, fApplyCombinedIso);
310 ceballos 1.60 break;
311 sixie 1.56 case ElectronTools::kVBTFWorkingPoint80Iso:
312 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint80Iso, fApplyCombinedIso);
313 sixie 1.51 break;
314 sixie 1.56 case ElectronTools::kVBTFWorkingPoint70Iso:
315 bendavid 1.67 isocut = ElectronTools::PassCustomIso(ele, ElectronTools::kVBTFWorkingPoint70Iso, fApplyCombinedIso);
316 sixie 1.51 break;
317 sixie 1.56 case ElectronTools::kNoIso:
318 sixie 1.42 isocut = kTRUE;
319     break;
320 sixie 1.56 case ElectronTools::kCustomIso:
321 sixie 1.42 default:
322     break;
323     }
324    
325     return isocut;
326     }
327    
328    
329     //--------------------------------------------------------------------------------------------------
330 loizides 1.1 void ElectronIDMod::Process()
331     {
332     // Process entries of the tree.
333    
334 ceballos 1.76 if(fElIsoType != ElectronTools::kPFIsoNoL) {
335     LoadEventObject(fElectronBranchName, fElectrons);
336     }
337     else {
338     fElectrons = GetObjThisEvt<ElectronOArr>(fElectronBranchName);
339 ceballos 1.78 fNonIsolatedMuons = GetObjThisEvt<MuonCol>(fNonIsolatedMuonsName);
340     fNonIsolatedElectrons = GetObjThisEvt<ElectronCol>(fNonIsolatedElectronsName);
341 ceballos 1.76 }
342 bendavid 1.75 LoadEventObject(fBeamSpotName, fBeamSpot);
343 ceballos 1.76 LoadEventObject(fTrackName, fTracks);
344     LoadEventObject(fPFCandidatesName, fPFCandidates);
345 sixie 1.100 if(fElIsoType == ElectronTools::kTrackJuraSliding ||
346     fElIsoType == ElectronTools::kCombinedRelativeConeAreaCorrected) {
347 ceballos 1.80 LoadEventObject(fPileupEnergyDensityName, fPileupEnergyDensity);
348     }
349 ceballos 1.76 fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
350 loizides 1.1
351 bendavid 1.62 //get trigger object collection if trigger matching is enabled
352     const TriggerObjectCol *trigObjs = 0;
353     if (fApplyTriggerMatching) {
354     trigObjs = GetHLTObjects(fTrigObjectsName);
355     }
356    
357 loizides 1.6 ElectronOArr *GoodElectrons = new ElectronOArr;
358     GoodElectrons->SetName(fGoodElectronsName);
359 loizides 1.1
360 ceballos 1.18 for (UInt_t i=0; i<fElectrons->GetEntries(); ++i) {
361 loizides 1.5 const Electron *e = fElectrons->At(i);
362 loizides 1.1
363 ceballos 1.66 if (e->SCluster() == 0)
364     continue;
365    
366 ceballos 1.65 if (e->Pt() < fElectronPtMin)
367 loizides 1.5 continue;
368 loizides 1.1
369 dkralph 1.73 if (e->SCluster()->Et() < fElectronEtMin)
370 bendavid 1.67 continue;
371    
372 ceballos 1.65 if (e->AbsEta() > fElectronEtaMax)
373 ceballos 1.64 continue;
374    
375 bendavid 1.67 if (fApplyEcalFiducial && ( (e->SCluster()->AbsEta()>1.4442 && e->SCluster()->AbsEta()<1.5666) || e->SCluster()->AbsEta()>2.5 )) {
376     continue;
377     }
378    
379     if (fApplyEcalSeeded && !e->IsEcalDriven()) {
380     continue;
381     }
382    
383 bendavid 1.62 //apply trigger matching
384     Bool_t matchTrigger = fApplyTriggerMatching && ElectronTools::PassTriggerMatching(e,trigObjs);
385     if (fApplyTriggerMatching && !matchTrigger)
386     continue;
387    
388 sixie 1.55 //apply ECAL spike removal
389 sixie 1.56 Bool_t spikecut = ElectronTools::PassSpikeRemovalFilter(e);
390 sixie 1.57 if (fApplySpikeRemoval && !spikecut)
391 sixie 1.55 continue;
392    
393 sixie 1.42 //apply Isolation Cut
394 ceballos 1.80 Double_t Rho = 0.0;
395 sixie 1.100 if( fElIsoType == ElectronTools::kTrackJuraSliding
396     || fElIsoType == ElectronTools::kCombinedRelativeConeAreaCorrected ) {
397     Rho = fPileupEnergyDensity->At(0)->Rho();
398 ceballos 1.80 }
399     Bool_t isocut = PassIsolationCut(e, fElIsoType, fTracks, fVertices->At(0), Rho);
400 sixie 1.42 if (!isocut)
401 loizides 1.5 continue;
402    
403 ceballos 1.60 // apply conversion filters
404     Bool_t passConvVetoType1 = kFALSE;
405     if (fApplyConvFilterType1) {
406 sixie 1.42 LoadEventObject(fConversionBranchName, fConversions);
407 ceballos 1.60 passConvVetoType1 = ElectronTools::PassConversionFilter(e, fConversions,
408 bendavid 1.82 fBeamSpot->At(0), 0, 1e-6, 2.0, kTRUE, kFALSE);
409 ceballos 1.12 }
410 ceballos 1.60 else {
411     passConvVetoType1 = kTRUE;
412     }
413    
414     if (passConvVetoType1 == kFALSE) continue;
415    
416     Bool_t passConvVetoType2 = kFALSE;
417     if (fApplyConvFilterType2) {
418     passConvVetoType2 = TMath::Abs(e->ConvPartnerDCotTheta()) >= 0.02 ||
419     TMath::Abs(e->ConvPartnerDist()) >= 0.02;
420     }
421     else {
422     passConvVetoType2 = kTRUE;
423     }
424 sixie 1.42
425 ceballos 1.60 if (passConvVetoType2 == kFALSE) continue;
426 ceballos 1.72
427 ceballos 1.60 // apply NExpectedHitsInner Cut
428 ceballos 1.98 if(fInvertNExpectedHitsInnerCut == kFALSE && fNExpectedHitsInnerCut < 999 &&
429 ceballos 1.69 e->CorrectedNExpectedHitsInner() > fNExpectedHitsInnerCut) continue;
430 ceballos 1.60
431 ceballos 1.98 // apply NExpectedHitsInner inverted Cut
432     if(fInvertNExpectedHitsInnerCut == kTRUE && fNExpectedHitsInnerCut < 999 &&
433     e->CorrectedNExpectedHitsInner() <= fNExpectedHitsInnerCut) continue;
434    
435 sixie 1.42 // apply d0 cut
436 ceballos 1.15 if (fApplyD0Cut) {
437 ceballos 1.81 Bool_t passD0cut = kTRUE;
438     if(fWhichVertex >= -1) passD0cut = ElectronTools::PassD0Cut(e, fVertices, fD0Cut, fWhichVertex);
439     else passD0cut = ElectronTools::PassD0Cut(e, fBeamSpot, fD0Cut);
440 sixie 1.42 if (!passD0cut)
441 ceballos 1.24 continue;
442 ceballos 1.12 }
443    
444 ceballos 1.81 // apply dz cut
445     if (fApplyDZCut) {
446 ceballos 1.83 Bool_t passDZcut = ElectronTools::PassDZCut(e, fVertices, fDZCut, fWhichVertex);
447 ceballos 1.81 if (!passDZcut)
448     continue;
449     }
450    
451 sixie 1.102 //apply id cut
452     Bool_t idcut = PassIDCut(e, fElIdType, fVertices->At(0));
453     if (!idcut)
454     continue;
455    
456 ceballos 1.59 // apply charge filter
457 sixie 1.42 if(fChargeFilter == kTRUE) {
458 sixie 1.56 Bool_t passChargeFilter = ElectronTools::PassChargeFilter(e);
459 sixie 1.42 if (!passChargeFilter) continue;
460 ceballos 1.45 }
461    
462 ceballos 1.63 // apply full combined id, using Tight cuts
463 ceballos 1.59 if(fCombinedIdCut == kTRUE) {
464 ceballos 1.68 fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
465 ceballos 1.59 LoadEventObject(fConversionBranchName, fConversions);
466 ceballos 1.63 Int_t result = ElectronTools::PassTightId(e, *&fVertices, fConversions, 2);
467 ceballos 1.59 if(result != 15) continue;
468     }
469    
470 loizides 1.5 // add good electron
471 ceballos 1.12 GoodElectrons->Add(e);
472 loizides 1.5 }
473 loizides 1.1
474 loizides 1.9 // sort according to pt
475     GoodElectrons->Sort();
476    
477 loizides 1.5 // add to event for other modules to use
478 loizides 1.6 AddObjThisEvt(GoodElectrons);
479 loizides 1.1 }
480    
481     //--------------------------------------------------------------------------------------------------
482     void ElectronIDMod::SlaveBegin()
483     {
484     // Run startup code on the computer (slave) doing the actual analysis. Here,
485 loizides 1.5 // we just request the electron collection branch.
486 loizides 1.1
487 ceballos 1.76 // In this case we cannot have a branch
488     if (fElectronIsoType.CompareTo("PFIsoNoL") != 0 ) {
489     ReqEventObject(fElectronBranchName, fElectrons,fElectronsFromBranch);
490     }
491     ReqEventObject(fBeamSpotName, fBeamSpot, kTRUE);
492     ReqEventObject(fTrackName, fTracks, kTRUE);
493     ReqEventObject(fPFCandidatesName, fPFCandidates, kTRUE);
494 sixie 1.100 if (fElectronIsoType.CompareTo("TrackJuraSliding") == 0
495     || fElectronIsoType.CompareTo("CombinedRelativeConeAreaCorrected") == 0 ) {
496 ceballos 1.80 ReqEventObject(fPileupEnergyDensityName, fPileupEnergyDensity, kTRUE);
497     }
498 loizides 1.17
499 ceballos 1.59 if(fCombinedIdCut == kTRUE) {
500 ceballos 1.60 fElectronIDType = "NoId";
501     fElectronIsoType = "NoIso";
502     fApplyConvFilterType1 = kFALSE;
503     fApplyConvFilterType2 = kFALSE;
504     fApplyD0Cut = kFALSE;
505 ceballos 1.81 fApplyDZCut = kFALSE;
506 ceballos 1.59 }
507    
508 ceballos 1.60 if (fApplyConvFilterType1 || fCombinedIdCut == kTRUE)
509 loizides 1.23 ReqEventObject(fConversionBranchName, fConversions, kTRUE);
510 loizides 1.17
511 sixie 1.42 Setup();
512 sixie 1.102
513 sixie 1.42 }
514    
515     //--------------------------------------------------------------------------------------------------
516     void ElectronIDMod::Setup()
517     {
518     // Set all options properly before execution.
519    
520 loizides 1.5 if (fElectronIDType.CompareTo("Tight") == 0)
521 sixie 1.56 fElIdType = ElectronTools::kTight;
522 loizides 1.5 else if (fElectronIDType.CompareTo("Loose") == 0)
523 sixie 1.56 fElIdType = ElectronTools::kLoose;
524 sixie 1.93 else if (fElectronIDType.CompareTo("Likelihood") == 0) {
525     if (!fLH) { cout << "Error: Likelihood not initialized.\n"; assert(0); }
526 sixie 1.56 fElIdType = ElectronTools::kLikelihood;
527 sixie 1.93 } else if (fElectronIDType.CompareTo("NoId") == 0)
528 sixie 1.56 fElIdType = ElectronTools::kNoId;
529 sixie 1.42 else if (fElectronIDType.CompareTo("ZeeId") == 0)
530 sixie 1.56 fElIdType = ElectronTools::kZeeId;
531 sixie 1.51 else if (fElectronIDType.CompareTo("CustomLoose") == 0)
532 sixie 1.56 fElIdType = ElectronTools::kCustomIdLoose;
533 sixie 1.51 else if (fElectronIDType.CompareTo("CustomTight") == 0)
534 sixie 1.56 fElIdType = ElectronTools::kCustomIdTight;
535 ceballos 1.86 else if (fElectronIDType.CompareTo("VBTFWorkingPointFakeableId") == 0)
536     fElIdType = ElectronTools::kVBTFWorkingPointFakeableId;
537 sixie 1.55 else if (fElectronIDType.CompareTo("VBTFWorkingPoint95Id") == 0)
538 sixie 1.56 fElIdType = ElectronTools::kVBTFWorkingPoint95Id;
539 sixie 1.51 else if (fElectronIDType.CompareTo("VBTFWorkingPoint90Id") == 0)
540 sixie 1.56 fElIdType = ElectronTools::kVBTFWorkingPoint90Id;
541 sixie 1.51 else if (fElectronIDType.CompareTo("VBTFWorkingPoint80Id") == 0)
542 sixie 1.56 fElIdType = ElectronTools::kVBTFWorkingPoint80Id;
543 ceballos 1.83 else if (fElectronIDType.CompareTo("VBTFWorkingPointLowPtId") == 0)
544     fElIdType = ElectronTools::kVBTFWorkingPointLowPtId;
545 ceballos 1.60 else if (fElectronIDType.CompareTo("VBTFWorkingPoint85Id") == 0)
546     fElIdType = ElectronTools::kVBTFWorkingPoint85Id;
547 sixie 1.51 else if (fElectronIDType.CompareTo("VBTFWorkingPoint70Id") == 0)
548 sixie 1.56 fElIdType = ElectronTools::kVBTFWorkingPoint70Id;
549 sixie 1.107 else if (fElectronIDType.CompareTo("MVA_BDTG_V1") == 0)
550     fElIdType = ElectronTools::kMVA_BDTG_V1;
551     else if (fElectronIDType.CompareTo("MVA_BDTG_V2") == 0)
552     fElIdType = ElectronTools::kMVA_BDTG_V2;
553     else {
554 loizides 1.5 SendError(kAbortAnalysis, "SlaveBegin",
555     "The specified electron identification %s is not defined.",
556     fElectronIDType.Data());
557     return;
558     }
559 sixie 1.51
560 loizides 1.5 if (fElectronIsoType.CompareTo("TrackCalo") == 0 )
561 sixie 1.56 fElIsoType = ElectronTools::kTrackCalo;
562 loizides 1.5 else if (fElectronIsoType.CompareTo("TrackJura") == 0)
563 sixie 1.56 fElIsoType = ElectronTools::kTrackJura;
564 ceballos 1.49 else if(fElectronIsoType.CompareTo("TrackJuraCombined") == 0)
565 sixie 1.56 fElIsoType = ElectronTools::kTrackJuraCombined;
566 loizides 1.5 else if(fElectronIsoType.CompareTo("TrackJuraSliding") == 0)
567 sixie 1.56 fElIsoType = ElectronTools::kTrackJuraSliding;
568 ceballos 1.80 else if(fElectronIsoType.CompareTo("TrackJuraSlidingNoCorrection") == 0)
569     fElIsoType = ElectronTools::kTrackJuraSlidingNoCorrection;
570 sixie 1.99 else if(fElectronIsoType.CompareTo("CombinedRelativeConeAreaCorrected") == 0)
571     fElIsoType = ElectronTools::kCombinedRelativeConeAreaCorrected;
572 ceballos 1.76 else if (fElectronIsoType.CompareTo("PFIso") == 0 )
573     fElIsoType = ElectronTools::kPFIso;
574     else if (fElectronIsoType.CompareTo("PFIsoNoL") == 0 )
575     fElIsoType = ElectronTools::kPFIsoNoL;
576 loizides 1.5 else if (fElectronIsoType.CompareTo("NoIso") == 0 )
577 sixie 1.56 fElIsoType = ElectronTools::kNoIso;
578 sixie 1.42 else if (fElectronIsoType.CompareTo("ZeeIso") == 0 )
579 sixie 1.56 fElIsoType = ElectronTools::kZeeIso;
580 sixie 1.55 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint95Iso") == 0 )
581 sixie 1.56 fElIsoType = ElectronTools::kVBTFWorkingPoint95Iso;
582 sixie 1.51 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint90Iso") == 0 )
583 sixie 1.56 fElIsoType = ElectronTools::kVBTFWorkingPoint90Iso;
584 ceballos 1.60 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint85Iso") == 0 )
585     fElIsoType = ElectronTools::kVBTFWorkingPoint85Iso;
586 sixie 1.51 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint80Iso") == 0 )
587 sixie 1.56 fElIsoType = ElectronTools::kVBTFWorkingPoint80Iso;
588 sixie 1.51 else if (fElectronIsoType.CompareTo("VBTFWorkingPoint70Iso") == 0 )
589 sixie 1.56 fElIsoType = ElectronTools::kVBTFWorkingPoint70Iso;
590 loizides 1.5 else if (fElectronIsoType.CompareTo("Custom") == 0 ) {
591 sixie 1.56 fElIsoType = ElectronTools::kCustomIso;
592 loizides 1.5 SendError(kWarning, "SlaveBegin",
593     "Custom electron isolation is not yet implemented.");
594     } else {
595     SendError(kAbortAnalysis, "SlaveBegin",
596     "The specified electron isolation %s is not defined.",
597     fElectronIsoType.Data());
598     return;
599     }
600 sixie 1.42
601 loizides 1.30
602 sixie 1.102 //If we use MVA ID, need to load MVA weights
603 sixie 1.107 if (fElIdType == ElectronTools::kMVA_BDTG_V1) {
604     fElectronIDMVA = new ElectronIDMVA();
605     fElectronIDMVA->Initialize("BDTG method",
606     fElectronMVAWeights_Subdet0Pt10To20,
607     fElectronMVAWeights_Subdet1Pt10To20,
608     fElectronMVAWeights_Subdet2Pt10To20,
609     fElectronMVAWeights_Subdet0Pt20ToInf,
610     fElectronMVAWeights_Subdet1Pt20ToInf,
611     fElectronMVAWeights_Subdet2Pt20ToInf,
612     ElectronIDMVA::kV1);
613     }
614     if (fElIdType == ElectronTools::kMVA_BDTG_V2) {
615 sixie 1.102 fElectronIDMVA = new ElectronIDMVA();
616     fElectronIDMVA->Initialize("BDTG method",
617     fElectronMVAWeights_Subdet0Pt10To20,
618     fElectronMVAWeights_Subdet1Pt10To20,
619     fElectronMVAWeights_Subdet2Pt10To20,
620     fElectronMVAWeights_Subdet0Pt20ToInf,
621     fElectronMVAWeights_Subdet1Pt20ToInf,
622     fElectronMVAWeights_Subdet2Pt20ToInf,
623 sixie 1.107 ElectronIDMVA::kV2);
624 sixie 1.102 }
625    
626 loizides 1.30 }
627 ceballos 1.77
628     //--------------------------------------------------------------------------------------------------
629     void ElectronIDMod::Terminate()
630     {
631     // Run finishing code on the computer (slave) that did the analysis
632     }