ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronIDMod.cc
Revision: 1.105
Committed: Sun Sep 25 18:14:03 2011 UTC (13 years, 7 months ago) by sixie
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025pre2
Changes since 1.104: +6 -6 lines
Log Message:
update MVA to version trained using only even event numbers

File Contents

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