ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/FakeMods/src/GenFakeableObjsMod.cc
Revision: 1.13
Committed: Fri Jan 21 11:25:28 2011 UTC (14 years, 3 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.12: +8 -8 lines
Log Message:
removing some old reverse cuts

File Contents

# User Rev Content
1 ceballos 1.13 // $Id: GenFakeableObjsMod.cc,v 1.12 2010/10/26 10:26:28 sixie Exp $
2 loizides 1.1
3     #include "MitPhysics/FakeMods/interface/GenFakeableObjsMod.h"
4 loizides 1.3 #include "MitCommon/MathTools/interface/MathUtils.h"
5 loizides 1.1 #include "MitAna/DataUtil/interface/Debug.h"
6 loizides 1.3 #include "MitAna/DataTree/interface/ElectronCol.h"
7     #include "MitAna/DataTree/interface/MuonCol.h"
8     #include "MitAna/DataTree/interface/SuperClusterCol.h"
9     #include "MitAna/DataTree/interface/TrackCol.h"
10     #include "MitAna/DataTree/interface/JetCol.h"
11     #include "MitAna/DataTree/interface/VertexCol.h"
12     #include "MitAna/DataTree/interface/DecayParticleCol.h"
13     #include "MitAna/DataTree/interface/StableData.h"
14 loizides 1.1 #include "MitPhysics/Init/interface/ModNames.h"
15     #include "MitPhysics/Utils/interface/IsolationTools.h"
16 ceballos 1.6 #include "MitPhysics/Mods/interface/ElectronIDMod.h"
17 loizides 1.1
18     using namespace mithep;
19    
20     ClassImp(mithep::GenFakeableObjsMod)
21    
22     //--------------------------------------------------------------------------------------------------
23     GenFakeableObjsMod::GenFakeableObjsMod(const char *name, const char *title) :
24     BaseMod(name,title),
25 ceballos 1.6
26     fApplyConvFilter(kTRUE),
27     fWrongHitsRequirement(kTRUE),
28     fApplyD0Cut(kTRUE),
29     fChargeFilter(kTRUE),
30 sixie 1.12 fD0Cut(0.02),
31     fCombIsolationCut(0.5),
32 ceballos 1.6 fTrackIsolationCut(-1.0),
33     fEcalIsolationCut(-1.0),
34     fHcalIsolationCut(-1.0),
35     fVetoTriggerJet(kFALSE),
36     fVetoGenLeptons(kTRUE),
37     fVetoCleanLeptons(kFALSE),
38 loizides 1.1 fElectronFOType("GsfPlusSC"),
39     fMuonFOType("IsoTrack"),
40     fTriggerName("NotSpecified"),
41     fTriggerObjectsName("NotSpecified"),
42     fElectronBranchName(Names::gkElectronBrn),
43     fMuonBranchName(Names::gkMuonBrn),
44     fTrackBranchName(Names::gkTrackBrn),
45     fGsfTrackBranchName(Names::gkGsfTrackBrn),
46     fBarrelSuperClusterBranchName(Names::gkBarrelSuperClusterBrn),
47     fEndcapSuperClusterBranchName(Names::gkEndcapSuperClusterBrn),
48 ceballos 1.11 fVertexName(ModNames::gkGoodVertexesName),
49 loizides 1.1 fConversionBranchName(Names::gkMvfConversionBrn),
50     fGoodJetsName(ModNames::gkGoodJetsName),
51     fCleanElectronsName(ModNames::gkCleanElectronsName),
52     fCleanMuonsName(ModNames::gkCleanMuonsName),
53     fMCLeptonsName(ModNames::gkMCLeptonsName),
54     fMCTausName(ModNames::gkMCTausName),
55 phedex 1.2 fElFakeableObjsName(ModNames::gkElFakeableObjsName),
56     fMuFakeableObjsName(ModNames::gkMuFakeableObjsName),
57 loizides 1.1 fElFOType(kElFOUndef),
58     fMuFOType(kMuFOUndef),
59     fBarrelSuperClusters(0),
60     fEndcapSuperClusters(0),
61     fTracks(0),
62     fGsfTracks(0),
63     fVertices(0),
64     fConversions(0)
65     {
66     // Constructor.
67     }
68    
69     //--------------------------------------------------------------------------------------------------
70     void GenFakeableObjsMod::SlaveBegin()
71     {
72     // Run startup code on the computer (slave) doing the actual analysis. Here,
73     // we typically initialize histograms and other analysis objects and request
74     // branches. For this module, we request a branch of the MitTree.
75    
76     //------------------------------------------------------------------------------------------------
77     // Request the branches (no significant time safed by not doing this)
78     //------------------------------------------------------------------------------------------------
79     ReqBranch(fElectronBranchName, fElectrons);
80     ReqBranch(fMuonBranchName, fMuons);
81     ReqBranch(fTrackBranchName, fTracks);
82     ReqBranch(fGsfTrackBranchName, fGsfTracks);
83     ReqBranch(fBarrelSuperClusterBranchName, fBarrelSuperClusters);
84     ReqBranch(fEndcapSuperClusterBranchName, fEndcapSuperClusters);
85     ReqBranch(fConversionBranchName, fConversions);
86    
87     if (fElectronFOType.CompareTo("GsfPlusSC") == 0)
88     fElFOType = kElFOGsfPlusSC;
89     else if (fElectronFOType.CompareTo("Reco") == 0)
90     fElFOType = kElFOReco;
91     else if (fElectronFOType.CompareTo("Loose") == 0)
92     fElFOType = kElFOLoose;
93     else {
94     SendError(kAbortAnalysis, "SlaveBegin",
95     "The specified electron fakeable object %s is not defined.",
96     fElectronFOType.Data());
97     return;
98     }
99    
100     if (fMuonFOType.CompareTo("IsoTrack") == 0)
101     fMuFOType = kMuFOIsoTrack;
102     else if (fMuonFOType.CompareTo("Global") == 0)
103     fMuFOType = kMuFOGlobal;
104     else if (fMuonFOType.CompareTo("TrackerMuon") == 0)
105     fMuFOType = kMuFOTrackerMuon;
106     else {
107     SendError(kAbortAnalysis, "SlaveBegin",
108     "The specified muon fakeable object %s is not defined.",
109     fMuonFOType.Data());
110     return;
111     }
112    
113 ceballos 1.9 electronID = new ElectronIDMod();
114 ceballos 1.13 electronID->SetApplyConversionFilterType1(kFALSE);
115     electronID->SetApplyConversionFilterType2(fApplyConvFilter);
116 ceballos 1.9 electronID->SetWrongHitsRequirement(fWrongHitsRequirement);
117     electronID->SetApplyD0Cut(fApplyD0Cut);
118     electronID->SetChargeFilter(fChargeFilter);
119     electronID->SetD0Cut(fD0Cut);
120    
121 loizides 1.1 }
122    
123     //--------------------------------------------------------------------------------------------------
124     void GenFakeableObjsMod::Process()
125     {
126     // Process entries of the tree.
127     LoadBranch(fElectronBranchName);
128     LoadBranch(fMuonBranchName);
129     LoadBranch(fTrackBranchName);
130     LoadBranch(fGsfTrackBranchName);
131     LoadBranch(fBarrelSuperClusterBranchName);
132     LoadBranch(fEndcapSuperClusterBranchName);
133     LoadBranch(fConversionBranchName);
134    
135 ceballos 1.11 fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
136    
137 loizides 1.1 //Load Trigger Objects
138     const TriggerObjectCol *triggerObjects = GetHLTObjects(fTriggerObjectsName);
139     if (!triggerObjects && fVetoTriggerJet) {
140     cout << "Error: Could not load Trigger Object Collection with name "
141     << fTriggerObjectsName << endl;
142     }
143    
144     // get input clean object collections
145     mithep::ParticleOArr *CleanLeptons = dynamic_cast<mithep::ParticleOArr*>
146     (FindObjThisEvt(ModNames::gkMergedLeptonsName));
147     const ElectronCol *CleanElectrons = 0;
148     if (!fCleanElectronsName.IsNull())
149     CleanElectrons = GetObjThisEvt<ElectronCol>(fCleanElectronsName);
150     const MuonCol *CleanMuons = 0;
151     if (!fCleanMuonsName.IsNull())
152     CleanMuons = GetObjThisEvt<MuonCol>(fCleanMuonsName);
153     const JetCol *GoodJets = 0;
154     if (!fGoodJetsName.IsNull())
155     GoodJets = GetObjThisEvt<JetCol>(fGoodJetsName);
156    
157     //get input MC collections
158     const MCParticleCol *GenLeptons = 0;
159     if (!fMCLeptonsName.IsNull())
160     GenLeptons = GetObjThisEvt<MCParticleCol>(fMCLeptonsName);
161     const MCParticleCol *GenTaus = 0;
162     if (!fMCTausName.IsNull())
163     GenTaus = GetObjThisEvt<MCParticleCol>(fMCTausName);
164     ObjArray<MCParticle> *GenLeptonsAndTaus = new ObjArray<MCParticle>;
165     for (UInt_t i=0; i<GenLeptons->GetEntries(); i++)
166     GenLeptonsAndTaus->Add(GenLeptons->At(i));
167     for (UInt_t i=0; i<GenTaus->GetEntries(); i++)
168     GenLeptonsAndTaus->Add(GenTaus->At(i));
169    
170     //Combine Barrel and Endcap superclusters into the same ObjArray
171     ObjArray <SuperCluster> *SuperClusters = new ObjArray <SuperCluster>;
172     for (UInt_t i=0; i<fBarrelSuperClusters->GetEntries(); i++) {
173     SuperClusters->Add(fBarrelSuperClusters->At(i));
174     }
175     for (UInt_t i=0; i<fEndcapSuperClusters->GetEntries(); i++) {
176     SuperClusters->Add(fEndcapSuperClusters->At(i));
177     }
178    
179     //collections for duplicate removed electrons
180     ObjArray<Electron> *DuplicateRemovedElectrons = new ObjArray<Electron>;
181     std::vector<const Electron*> tmpDuplicateRemovedElectrons;
182    
183     // create final output collection
184 phedex 1.2 ElectronArr *ElFakeableObjs = new ElectronArr;
185     MuonArr *MuFakeableObjs = new MuonArr;
186 loizides 1.1
187    
188     //***********************************************************************************************
189     //First do duplicate electron removal
190     //***********************************************************************************************
191     for (UInt_t i=0; i<fElectrons->GetEntries(); ++i) {
192 ceballos 1.6
193 loizides 1.1 const Electron *e = fElectrons->At(i);
194     Bool_t isElectronOverlap = kFALSE;
195    
196     for (UInt_t j=0; j<tmpDuplicateRemovedElectrons.size(); ++j) {
197     if (e->SCluster() == tmpDuplicateRemovedElectrons[j]->SCluster() ||
198 sixie 1.12 e->GsfTrk() == tmpDuplicateRemovedElectrons[j]->GsfTrk()) {
199 loizides 1.1 isElectronOverlap = kTRUE;
200     }
201    
202    
203     if (isElectronOverlap) {
204     if (TMath::Abs(tmpDuplicateRemovedElectrons[j]->ESuperClusterOverP() - 1) >
205     TMath::Abs(e->ESuperClusterOverP() - 1)) {
206     tmpDuplicateRemovedElectrons[j] = e;
207     }
208     break;
209     }
210     }
211    
212     if (!isElectronOverlap) {
213     tmpDuplicateRemovedElectrons.push_back(e);
214     }
215     }
216     for (UInt_t i=0; i<tmpDuplicateRemovedElectrons.size(); ++i) {
217     DuplicateRemovedElectrons->Add(tmpDuplicateRemovedElectrons[i]);
218     }
219    
220     //***********************************************************************************************
221     //Fakeable Objects for Electron Fakes
222     //Supercluster matched to nearest isolated track.
223     //***********************************************************************************************
224     if (fElFOType == kElFOGsfPlusSC) {
225    
226     std::vector<const Electron*> GsfTrackSCDenominators;
227    
228     //loop over all super clusters
229     for (UInt_t i=0; i<SuperClusters->GetEntries(); i++) {
230     const SuperCluster *cluster = SuperClusters->At(i);
231    
232     //find best matching track based on DR to the cluster
233     const Track *EOverPMatchedTrk = NULL;
234     double BestEOverP = 5000.0;
235     for (UInt_t j=0; j<fGsfTracks->GetEntries(); j++) {
236     const Track *trk = fGsfTracks->At(j);
237    
238     //Use best E/P matching within dR of 0.3
239     double dR = MathUtils::DeltaR(cluster->Phi(), cluster->Eta(), trk->Phi(), trk->Eta());
240     Double_t EOverP = cluster->Energy() / trk->P();
241     if( fabs(1-EOverP) < fabs(1-BestEOverP) && dR < 0.3 ) {
242     BestEOverP = EOverP;
243     EOverPMatchedTrk = trk;
244     }
245     }
246    
247     //****************************************************************************************
248     //Use Best E/P Matching and require the track is within 0.3 of the super cluster position
249     //****************************************************************************************
250     if( EOverPMatchedTrk ) {
251    
252     //calculate track isolation around the matched track
253     Double_t matchiso=0;
254     matchiso = IsolationTools::TrackIsolation(EOverPMatchedTrk, 0.3, 0.015, 1.0, 0.2,
255     fTracks);
256    
257     //Veto denominators matching to real electrons
258     Bool_t IsGenLepton = false;
259     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
260     if (MathUtils::DeltaR(EOverPMatchedTrk->Phi(), EOverPMatchedTrk->Eta(),
261     GenLeptonsAndTaus->At(l)->Phi(),
262     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
263     IsGenLepton = true;
264     }
265     }
266    
267     //Veto denominators matching to clean leptons
268     Bool_t IsCleanLepton = false;
269     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
270     if (MathUtils::DeltaR(EOverPMatchedTrk->Phi(), EOverPMatchedTrk->Eta(),
271     CleanLeptons->At(l)->Phi(),
272     CleanLeptons->At(l)->Eta()) < 0.1) {
273     IsCleanLepton = true;
274     }
275     }
276    
277     //Veto on Leading jet
278     Bool_t IsTriggerJet = false;
279     if (fVetoTriggerJet) {
280     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
281 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(EOverPMatchedTrk->Phi(),
282     EOverPMatchedTrk->Eta(),
283     triggerObjects->At(l)->Phi(),
284     triggerObjects->At(l)->Eta());
285 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
286     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
287     && deltaR < 0.3
288     ) {
289     IsTriggerJet = true;
290     break;
291     }
292     }
293     }
294    
295     //create new electron object for the denominator under consideration
296     Bool_t denominatorSaved = false;
297     Electron *denominator = new Electron();
298     Double_t p = TMath::Sqrt(cluster->Energy()*cluster->Energy()
299     - denominator->Mass()*denominator->Mass());
300     denominator->SetPtEtaPhi(TMath::Abs(p*TMath::Cos(EOverPMatchedTrk->Lambda())),
301     EOverPMatchedTrk->Eta(),EOverPMatchedTrk->Phi());
302     denominator->SetGsfTrk(EOverPMatchedTrk);
303     denominator->SetSuperCluster(cluster);
304    
305 ceballos 1.6 const Electron *tmpEle = denominator;
306     //****************************************************************************************
307     // Isolation Cut
308     //****************************************************************************************
309     Bool_t passIsolationCut = (matchiso <= fTrackIsolationCut);
310    
311 loizides 1.1 //****************************************************************************************
312     // conversion filter
313 loizides 1.5 //****************************************************************************************
314 ceballos 1.9 Bool_t passConversionFilter = ElectronTools::PassConversionFilter(tmpEle, fConversions, kTRUE);
315 loizides 1.1
316     //****************************************************************************************
317     // D0 Cut
318 loizides 1.5 //****************************************************************************************
319 ceballos 1.13 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE);
320 loizides 1.1
321     //****************************************************************************************
322     // Make denominator object cuts
323     //****************************************************************************************
324 ceballos 1.6 if( denominator->Pt() > 10.0
325     && passIsolationCut
326     && (passConversionFilter || !fApplyConvFilter)
327     && (passD0Cut || !fApplyD0Cut)
328 loizides 1.1 && !(fVetoCleanLeptons && IsCleanLepton)
329     && !(fVetoGenLeptons && IsGenLepton)
330     && !(fVetoTriggerJet && IsTriggerJet)
331     ) {
332    
333     //check whether we have duplicate denominators. If yes then choose best E/P one.
334     Bool_t foundDuplicate = false;
335     for (UInt_t d=0; d<GsfTrackSCDenominators.size();++d) {
336     if (GsfTrackSCDenominators[d]->GsfTrk() == denominator->GsfTrk()) {
337     if (fabs(denominator->SCluster()->Energy()/denominator->GsfTrk()->P() - 1)
338     < fabs(GsfTrackSCDenominators[d]->SCluster()->Energy()/
339     GsfTrackSCDenominators[d]->GsfTrk()->P() - 1)) {
340     //swap this one with previous one and delete the previous one
341     const Electron *denominatorToBeDeleted = GsfTrackSCDenominators[d];
342     GsfTrackSCDenominators[d] = denominator;
343     denominatorSaved = true;
344     foundDuplicate = true;
345     delete denominatorToBeDeleted;
346     break;
347     }
348     }
349     }
350     if (!foundDuplicate) {
351     GsfTrackSCDenominators.push_back(denominator);
352     denominatorSaved = true;
353     }
354     } //end if candidate passes denominator cuts
355     //delete denominator candidate object
356     if (!denominatorSaved) {
357     delete denominator;
358     }
359     }//end if track -> SC match was found
360     } //loop over SC
361    
362     //Save denominators permanently for export
363     for (UInt_t d=0; d<GsfTrackSCDenominators.size() ; ++d) {
364 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
365 loizides 1.1 tmpElectron->SetPtEtaPhi(GsfTrackSCDenominators[d]->Pt(),
366     GsfTrackSCDenominators[d]->Eta(),GsfTrackSCDenominators[d]->Phi());
367     tmpElectron->SetGsfTrk(GsfTrackSCDenominators[d]->GsfTrk());
368     tmpElectron->SetSuperCluster(GsfTrackSCDenominators[d]->SCluster());
369     delete GsfTrackSCDenominators[d];
370     }
371     } else if (fElFOType == kElFOReco) {
372 ceballos 1.6
373 loizides 1.1 for (UInt_t i=0; i<DuplicateRemovedElectrons->GetEntries(); i++) {
374     const Electron *denominator = DuplicateRemovedElectrons->At(i);
375    
376     //Veto denominators matching to real electrons
377     Bool_t IsGenLepton = false;
378     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
379     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
380     GenLeptonsAndTaus->At(l)->Phi(),
381     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
382     IsGenLepton = true;
383     }
384     }
385    
386     //Veto denominators matching to clean leptons
387     Bool_t IsCleanLepton = false;
388     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
389     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
390     CleanLeptons->At(l)->Phi(),
391     CleanLeptons->At(l)->Eta()) < 0.1) {
392     IsCleanLepton = true;
393     }
394     }
395    
396     //Veto on Trigger jet
397     Bool_t IsTriggerJet = false;
398     if (fVetoTriggerJet) {
399     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
400 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
401     denominator->Eta(),
402     triggerObjects->At(l)->Phi(),
403     triggerObjects->At(l)->Eta());
404 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
405     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
406     && deltaR < 0.3
407     ) {
408     IsTriggerJet = true;
409     break;
410     }
411     }
412     }
413    
414 ceballos 1.6 const Electron *tmpEle = denominator;
415     //****************************************************************************************
416     // Isolation Cut
417     //****************************************************************************************
418     Double_t combIso =
419 sixie 1.12 denominator->TrackIsolationDr03() + TMath::Max(denominator->EcalRecHitIsoDr03() - 1.0, 0.0) + denominator->HcalTowerSumEtDr03();
420     if (fabs(denominator->Eta()) > 1.5) {
421     combIso = denominator->TrackIsolationDr03() + denominator->EcalRecHitIsoDr03() + denominator->HcalTowerSumEtDr03();
422     }
423 ceballos 1.6
424 sixie 1.12 Bool_t passIsolationCut = (combIso / denominator->Pt() <= fCombIsolationCut || fCombIsolationCut < 0) &&
425     (denominator->TrackIsolationDr04()/ denominator->Pt() <= fTrackIsolationCut || fTrackIsolationCut < 0) &&
426     (denominator->EcalRecHitIsoDr04()/ denominator->Pt() <= fEcalIsolationCut || fEcalIsolationCut < 0) &&
427     (denominator->HcalTowerSumEtDr04()/ denominator->Pt() <= fHcalIsolationCut || fHcalIsolationCut < 0) ;
428 ceballos 1.6
429     //****************************************************************************************
430 loizides 1.1 // conversion filter
431 ceballos 1.6 //****************************************************************************************
432 sixie 1.12 Bool_t passConversionFilter = ElectronTools::PassConversionFilter(tmpEle, fConversions, kTRUE);
433 loizides 1.1
434     //****************************************************************************************
435     // D0 Cut
436 loizides 1.5 //****************************************************************************************
437 ceballos 1.13 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE);
438 ceballos 1.6
439 loizides 1.1 //****************************************************************************************
440 ceballos 1.6 // Make denominator object cuts
441 loizides 1.5 //****************************************************************************************
442 ceballos 1.6 if( denominator->Pt() > 10.0
443     && passIsolationCut
444     && (passConversionFilter || !fApplyConvFilter)
445     && (passD0Cut || !fApplyD0Cut)
446     && !(fVetoCleanLeptons && IsCleanLepton)
447 loizides 1.1 && !(fVetoGenLeptons && IsGenLepton)
448     && !(fVetoTriggerJet && IsTriggerJet)
449 ceballos 1.6 ) {
450 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
451 loizides 1.1 tmpElectron->SetPtEtaPhi(denominator->Pt(), denominator->Eta(),denominator->Phi());
452     tmpElectron->SetGsfTrk(denominator->GsfTrk());
453     tmpElectron->SetSuperCluster(denominator->SCluster());
454 sixie 1.7 }
455 loizides 1.1 }
456     } else if (fElFOType == kElFOLoose) {
457     for (UInt_t i=0; i<DuplicateRemovedElectrons->GetEntries(); i++) {
458     const Electron *denominator = DuplicateRemovedElectrons->At(i);
459 ceballos 1.6
460 loizides 1.1 //Veto denominators matching to real electrons
461     Bool_t IsGenLepton = false;
462     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
463     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
464     GenLeptonsAndTaus->At(l)->Phi(),
465     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
466     IsGenLepton = true;
467     }
468     }
469    
470     //Veto denominators matching to clean leptons
471     Bool_t IsCleanLepton = false;
472     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
473     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
474     CleanLeptons->At(l)->Phi(),
475     CleanLeptons->At(l)->Eta()) < 0.1) {
476     IsCleanLepton = true;
477     }
478     }
479    
480     //Veto on Trigger jet
481     Bool_t IsTriggerJet = false;
482     if (fVetoTriggerJet) {
483     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
484 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
485     denominator->Eta(),
486     triggerObjects->At(l)->Phi(),
487     triggerObjects->At(l)->Eta());
488 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
489     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
490     && deltaR < 0.3
491     ) {
492     IsTriggerJet = true;
493     break;
494     }
495     }
496     }
497    
498 ceballos 1.6 const Electron *tmpEle = denominator;
499     //****************************************************************************************
500     // Isolation Cut
501     //****************************************************************************************
502     Double_t combIso =
503     denominator->TrackIsolationDr03() + denominator->EcalRecHitIsoDr04() - 1.5;
504    
505     Bool_t passIsolationCut = (combIso <= fCombIsolationCut || fCombIsolationCut < 0) &&
506     (denominator->TrackIsolationDr04() <= fTrackIsolationCut || fTrackIsolationCut < 0) &&
507     (denominator->EcalRecHitIsoDr04() <= fEcalIsolationCut || fEcalIsolationCut < 0) &&
508     (denominator->HcalTowerSumEtDr04() <= fHcalIsolationCut || fHcalIsolationCut < 0) ;
509    
510 loizides 1.1 //****************************************************************************************
511     // conversion filter
512 loizides 1.5 //****************************************************************************************
513 ceballos 1.13 Bool_t passConversionFilter = TMath::Abs(denominator->ConvPartnerDCotTheta()) >= 0.02 ||
514     TMath::Abs(denominator->ConvPartnerDist()) >= 0.02;
515 loizides 1.1
516     //****************************************************************************************
517     // D0 Cut
518 loizides 1.5 //****************************************************************************************
519 ceballos 1.13 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE);
520 ceballos 1.6
521     //****************************************************************************************
522     // Make denominator object cuts
523     //****************************************************************************************
524     if( denominator->Pt() > 10.0
525     && passIsolationCut
526     && (passConversionFilter || !fApplyConvFilter)
527     && (passD0Cut || !fApplyD0Cut)
528 loizides 1.1 && denominator->PassLooseID()
529 ceballos 1.6 && !(fVetoCleanLeptons && IsCleanLepton)
530 loizides 1.1 && !(fVetoGenLeptons && IsGenLepton)
531     && !(fVetoTriggerJet && IsTriggerJet)
532 ceballos 1.6 ) {
533 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
534 loizides 1.1 tmpElectron->SetPtEtaPhi(denominator->Pt(), denominator->Eta(),denominator->Phi());
535     tmpElectron->SetGsfTrk(denominator->GsfTrk());
536     tmpElectron->SetSuperCluster(denominator->SCluster());
537     }
538     }
539     }
540    
541     //***********************************************************************************************
542     //Fakeable Objects for Muon Fakes
543     //***********************************************************************************************
544     if (fMuFOType == kMuFOIsoTrack) {
545     for (UInt_t i=0; i<fTracks->GetEntries(); i++) {
546     const Track *track = fTracks->At(i);
547     Double_t trackIsolation = IsolationTools::TrackIsolation(track, 0.4, 0.015, 1.0,
548     0.2, fTracks);
549     //Determine if muon fakeable object matches a gen lepton
550     Bool_t IsGenLepton = false;
551     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
552     if (MathUtils::DeltaR(track->Phi(), track->Eta(),
553     GenLeptonsAndTaus->At(l)->Phi(),
554     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
555     IsGenLepton = true;
556     }
557     }
558    
559     //Veto denominators matching to clean leptons
560     Bool_t IsCleanLepton = false;
561     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
562     if (MathUtils::DeltaR(track->Phi(), track->Eta(),
563     CleanLeptons->At(l)->Phi(),
564     CleanLeptons->At(l)->Eta()) < 0.1) {
565     IsCleanLepton = true;
566     }
567     }
568    
569     //Veto on Trigger jet
570     Bool_t IsTriggerJet = false;
571     if (fVetoTriggerJet) {
572     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
573     Double_t deltaR = MathUtils::DeltaR(track->Phi(), track->Eta(),
574     triggerObjects->At(l)->Phi(),
575     triggerObjects->At(l)->Eta());
576     if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
577     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
578     && deltaR < 0.3
579     ) {
580     IsTriggerJet = true;
581     break;
582     }
583     }
584     }
585    
586     //****************************************************************************************
587     // D0 Cut
588     //****************************************************************************************
589     double d0Min = 99999;
590     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
591     double pD0 = track->D0Corrected(*fVertices->At(i0));
592     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
593     }
594    
595    
596     //define denominator cuts
597     if (track->Pt() > 10.0 && trackIsolation < 10.0
598     && d0Min < 0.025
599     && !(fVetoGenLeptons && IsGenLepton)
600     && !(fVetoCleanLeptons && IsCleanLepton)
601     && !(fVetoTriggerJet && IsTriggerJet)
602     ) {
603     //add to fakeable objects
604 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
605 loizides 1.1 tmpMuon->SetTrackerTrk(track);
606     }
607     }
608     } else if (fMuFOType == kMuFOGlobal) {
609     for (UInt_t i=0; i<fMuons->GetEntries(); i++) {
610     const Muon *denominator = fMuons->At(i);
611     Double_t totalIsolation = denominator->IsoR03SumPt() + denominator->IsoR03EmEt() +
612     denominator->IsoR03HadEt();
613    
614     //Determine if muon fakeable object matches a gen lepton
615     Bool_t IsGenLepton = false;
616     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
617     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
618     GenLeptonsAndTaus->At(l)->Phi(),
619     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
620     IsGenLepton = true;
621     }
622     }
623    
624     //Veto denominators matching to clean leptons
625     Bool_t IsCleanLepton = false;
626     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
627     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
628     CleanLeptons->At(l)->Phi(),
629     CleanLeptons->At(l)->Eta()) < 0.1) {
630     IsCleanLepton = true;
631     }
632     }
633    
634     //Veto on Trigger jet
635     Bool_t IsTriggerJet = false;
636     if (fVetoTriggerJet) {
637     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
638 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
639     denominator->Eta(),
640     triggerObjects->At(l)->Phi(),
641     triggerObjects->At(l)->Eta());
642 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
643     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
644     && deltaR < 0.3
645     ) {
646     IsTriggerJet = true;
647     break;
648     }
649     }
650     }
651    
652     //****************************************************************************************
653     // D0 Cut
654 loizides 1.5 //****************************************************************************************
655 loizides 1.1 double d0Min = 99999;
656     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
657     double pD0 = denominator->Trk()->D0Corrected(*fVertices->At(i0));
658     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
659     }
660    
661     if (denominator->Pt() > 10.0 && totalIsolation < 10.0 && denominator->HasGlobalTrk()
662     && d0Min < 0.025
663     && !(fVetoGenLeptons && IsGenLepton)
664     && !(fVetoCleanLeptons && IsCleanLepton)
665     && !(fVetoTriggerJet && IsTriggerJet)
666     ) {
667 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
668 loizides 1.1 tmpMuon->SetGlobalTrk(denominator->GlobalTrk());
669     tmpMuon->SetTrackerTrk(denominator->TrackerTrk());
670     }
671     }
672     } else if (fMuFOType == kMuFOTrackerMuon) {
673     for (UInt_t i=0; i<fMuons->GetEntries(); i++) {
674     const Muon *denominator = fMuons->At(i);
675 loizides 1.5 Double_t totalIsolation =
676     denominator->IsoR03SumPt() +
677     denominator->IsoR03EmEt() +
678     denominator->IsoR03HadEt();
679 loizides 1.1
680     //Determine if muon fakeable object matches a gen lepton
681     Bool_t IsGenLepton = false;
682     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
683     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
684     GenLeptonsAndTaus->At(l)->Phi(),
685     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
686     IsGenLepton = true;
687     }
688     }
689    
690     //Veto denominators matching to clean leptons
691     Bool_t IsCleanLepton = false;
692     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
693     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
694     CleanLeptons->At(l)->Phi(),
695     CleanLeptons->At(l)->Eta()) < 0.1) {
696     IsCleanLepton = true;
697     }
698     }
699    
700     //Veto on Trigger jet
701     Bool_t IsTriggerJet = false;
702     if (fVetoTriggerJet) {
703     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
704 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
705     denominator->Eta(),
706     triggerObjects->At(l)->Phi(),
707     triggerObjects->At(l)->Eta());
708 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
709     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
710     && deltaR < 0.3
711     ) {
712     IsTriggerJet = true;
713     break;
714     }
715     }
716     }
717    
718     //****************************************************************************************
719     // D0 Cut
720 loizides 1.5 //****************************************************************************************
721 loizides 1.1 double d0Min = 99999;
722     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
723     double pD0 = denominator->Trk()->D0Corrected(*fVertices->At(i0));
724     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
725     }
726    
727     if (denominator->Pt() > 10.0 && totalIsolation < 10.0 && denominator->HasTrackerTrk()
728     && d0Min < 0.025
729     && !(fVetoGenLeptons && IsGenLepton)
730     && !(fVetoCleanLeptons && IsCleanLepton)
731     && !(fVetoTriggerJet && IsTriggerJet)
732     ) {
733 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
734 loizides 1.1 tmpMuon->SetTrackerTrk(denominator->TrackerTrk());
735     }
736     }
737     }
738    
739     //***********************************************************************************************
740     //Export the fakeable object collections for other modules to use
741     //***********************************************************************************************
742 phedex 1.2 ElFakeableObjs->SetName(fElFakeableObjsName);
743     AddObjThisEvt(ElFakeableObjs);
744     MuFakeableObjs->SetName(fMuFakeableObjsName);
745     AddObjThisEvt(MuFakeableObjs);
746 loizides 1.1
747     delete GenLeptonsAndTaus;
748     delete SuperClusters;
749     delete DuplicateRemovedElectrons;
750     }