ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.103
Committed: Sun Sep 25 15:00:18 2011 UTC (13 years, 7 months ago) by sixie
Content type: text/plain
Branch: MAIN
Changes since 1.102: +6 -6 lines
Log Message:
update the ELectron ID MVA working point

File Contents

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