ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/FakeMods/src/GenFakeableObjsMod.cc
Revision: 1.12
Committed: Tue Oct 26 10:26:28 2010 UTC (14 years, 6 months ago) by sixie
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016
Changes since 1.11: +13 -11 lines
Log Message:
change isolation cut for electron denominator

File Contents

# User Rev Content
1 sixie 1.12 // $Id: GenFakeableObjsMod.cc,v 1.11 2010/10/20 02:44:47 ceballos 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.10 electronID->SetApplyConversionFilterType1(fApplyConvFilter);
115 ceballos 1.9 electronID->SetWrongHitsRequirement(fWrongHitsRequirement);
116     electronID->SetApplyD0Cut(fApplyD0Cut);
117     electronID->SetChargeFilter(fChargeFilter);
118     electronID->SetD0Cut(fD0Cut);
119    
120 loizides 1.1 }
121    
122     //--------------------------------------------------------------------------------------------------
123     void GenFakeableObjsMod::Process()
124     {
125     // Process entries of the tree.
126     LoadBranch(fElectronBranchName);
127     LoadBranch(fMuonBranchName);
128     LoadBranch(fTrackBranchName);
129     LoadBranch(fGsfTrackBranchName);
130     LoadBranch(fBarrelSuperClusterBranchName);
131     LoadBranch(fEndcapSuperClusterBranchName);
132     LoadBranch(fConversionBranchName);
133    
134 ceballos 1.11 fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
135    
136 loizides 1.1 //Load Trigger Objects
137     const TriggerObjectCol *triggerObjects = GetHLTObjects(fTriggerObjectsName);
138     if (!triggerObjects && fVetoTriggerJet) {
139     cout << "Error: Could not load Trigger Object Collection with name "
140     << fTriggerObjectsName << endl;
141     }
142    
143     // get input clean object collections
144     mithep::ParticleOArr *CleanLeptons = dynamic_cast<mithep::ParticleOArr*>
145     (FindObjThisEvt(ModNames::gkMergedLeptonsName));
146     const ElectronCol *CleanElectrons = 0;
147     if (!fCleanElectronsName.IsNull())
148     CleanElectrons = GetObjThisEvt<ElectronCol>(fCleanElectronsName);
149     const MuonCol *CleanMuons = 0;
150     if (!fCleanMuonsName.IsNull())
151     CleanMuons = GetObjThisEvt<MuonCol>(fCleanMuonsName);
152     const JetCol *GoodJets = 0;
153     if (!fGoodJetsName.IsNull())
154     GoodJets = GetObjThisEvt<JetCol>(fGoodJetsName);
155    
156     //get input MC collections
157     const MCParticleCol *GenLeptons = 0;
158     if (!fMCLeptonsName.IsNull())
159     GenLeptons = GetObjThisEvt<MCParticleCol>(fMCLeptonsName);
160     const MCParticleCol *GenTaus = 0;
161     if (!fMCTausName.IsNull())
162     GenTaus = GetObjThisEvt<MCParticleCol>(fMCTausName);
163     ObjArray<MCParticle> *GenLeptonsAndTaus = new ObjArray<MCParticle>;
164     for (UInt_t i=0; i<GenLeptons->GetEntries(); i++)
165     GenLeptonsAndTaus->Add(GenLeptons->At(i));
166     for (UInt_t i=0; i<GenTaus->GetEntries(); i++)
167     GenLeptonsAndTaus->Add(GenTaus->At(i));
168    
169     //Combine Barrel and Endcap superclusters into the same ObjArray
170     ObjArray <SuperCluster> *SuperClusters = new ObjArray <SuperCluster>;
171     for (UInt_t i=0; i<fBarrelSuperClusters->GetEntries(); i++) {
172     SuperClusters->Add(fBarrelSuperClusters->At(i));
173     }
174     for (UInt_t i=0; i<fEndcapSuperClusters->GetEntries(); i++) {
175     SuperClusters->Add(fEndcapSuperClusters->At(i));
176     }
177    
178     //collections for duplicate removed electrons
179     ObjArray<Electron> *DuplicateRemovedElectrons = new ObjArray<Electron>;
180     std::vector<const Electron*> tmpDuplicateRemovedElectrons;
181    
182     // create final output collection
183 phedex 1.2 ElectronArr *ElFakeableObjs = new ElectronArr;
184     MuonArr *MuFakeableObjs = new MuonArr;
185 loizides 1.1
186    
187     //***********************************************************************************************
188     //First do duplicate electron removal
189     //***********************************************************************************************
190     for (UInt_t i=0; i<fElectrons->GetEntries(); ++i) {
191 ceballos 1.6
192    
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     Double_t deltaR = MathUtils::DeltaR(tmpDuplicateRemovedElectrons[j]->Mom(), e->Mom());
198     if (e->SCluster() == tmpDuplicateRemovedElectrons[j]->SCluster() ||
199 sixie 1.12 e->GsfTrk() == tmpDuplicateRemovedElectrons[j]->GsfTrk()) {
200 loizides 1.1 isElectronOverlap = kTRUE;
201     }
202    
203    
204     if (isElectronOverlap) {
205     if (TMath::Abs(tmpDuplicateRemovedElectrons[j]->ESuperClusterOverP() - 1) >
206     TMath::Abs(e->ESuperClusterOverP() - 1)) {
207     tmpDuplicateRemovedElectrons[j] = e;
208     }
209     break;
210     }
211     }
212    
213     if (!isElectronOverlap) {
214     tmpDuplicateRemovedElectrons.push_back(e);
215     }
216     }
217     for (UInt_t i=0; i<tmpDuplicateRemovedElectrons.size(); ++i) {
218     DuplicateRemovedElectrons->Add(tmpDuplicateRemovedElectrons[i]);
219     }
220    
221     //***********************************************************************************************
222     //Fakeable Objects for Electron Fakes
223     //Supercluster matched to nearest isolated track.
224     //***********************************************************************************************
225     if (fElFOType == kElFOGsfPlusSC) {
226    
227     std::vector<const Electron*> GsfTrackSCDenominators;
228    
229     //loop over all super clusters
230     for (UInt_t i=0; i<SuperClusters->GetEntries(); i++) {
231     const SuperCluster *cluster = SuperClusters->At(i);
232    
233     //find best matching track based on DR to the cluster
234     const Track *EOverPMatchedTrk = NULL;
235     double BestEOverP = 5000.0;
236     for (UInt_t j=0; j<fGsfTracks->GetEntries(); j++) {
237     const Track *trk = fGsfTracks->At(j);
238    
239     //Use best E/P matching within dR of 0.3
240     double dR = MathUtils::DeltaR(cluster->Phi(), cluster->Eta(), trk->Phi(), trk->Eta());
241     Double_t EOverP = cluster->Energy() / trk->P();
242     if( fabs(1-EOverP) < fabs(1-BestEOverP) && dR < 0.3 ) {
243     BestEOverP = EOverP;
244     EOverPMatchedTrk = trk;
245     }
246     }
247    
248     //****************************************************************************************
249     //Use Best E/P Matching and require the track is within 0.3 of the super cluster position
250     //****************************************************************************************
251     if( EOverPMatchedTrk ) {
252    
253     //calculate track isolation around the matched track
254     Double_t matchiso=0;
255     matchiso = IsolationTools::TrackIsolation(EOverPMatchedTrk, 0.3, 0.015, 1.0, 0.2,
256     fTracks);
257    
258     //Veto denominators matching to real electrons
259     Bool_t IsGenLepton = false;
260     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
261     if (MathUtils::DeltaR(EOverPMatchedTrk->Phi(), EOverPMatchedTrk->Eta(),
262     GenLeptonsAndTaus->At(l)->Phi(),
263     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
264     IsGenLepton = true;
265     }
266     }
267    
268     //Veto denominators matching to clean leptons
269     Bool_t IsCleanLepton = false;
270     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
271     if (MathUtils::DeltaR(EOverPMatchedTrk->Phi(), EOverPMatchedTrk->Eta(),
272     CleanLeptons->At(l)->Phi(),
273     CleanLeptons->At(l)->Eta()) < 0.1) {
274     IsCleanLepton = true;
275     }
276     }
277    
278     //Veto on Leading jet
279     Bool_t IsTriggerJet = false;
280     if (fVetoTriggerJet) {
281     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
282 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(EOverPMatchedTrk->Phi(),
283     EOverPMatchedTrk->Eta(),
284     triggerObjects->At(l)->Phi(),
285     triggerObjects->At(l)->Eta());
286 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
287     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
288     && deltaR < 0.3
289     ) {
290     IsTriggerJet = true;
291     break;
292     }
293     }
294     }
295    
296     //create new electron object for the denominator under consideration
297     Bool_t denominatorSaved = false;
298     Electron *denominator = new Electron();
299     Double_t p = TMath::Sqrt(cluster->Energy()*cluster->Energy()
300     - denominator->Mass()*denominator->Mass());
301     denominator->SetPtEtaPhi(TMath::Abs(p*TMath::Cos(EOverPMatchedTrk->Lambda())),
302     EOverPMatchedTrk->Eta(),EOverPMatchedTrk->Phi());
303     denominator->SetGsfTrk(EOverPMatchedTrk);
304     denominator->SetSuperCluster(cluster);
305    
306 ceballos 1.6 const Electron *tmpEle = denominator;
307     //****************************************************************************************
308     // Isolation Cut
309     //****************************************************************************************
310     Bool_t passIsolationCut = (matchiso <= fTrackIsolationCut);
311    
312 loizides 1.1 //****************************************************************************************
313     // conversion filter
314 loizides 1.5 //****************************************************************************************
315 ceballos 1.9 Bool_t passConversionFilter = ElectronTools::PassConversionFilter(tmpEle, fConversions, kTRUE);
316 loizides 1.1
317     //****************************************************************************************
318     // D0 Cut
319 loizides 1.5 //****************************************************************************************
320 ceballos 1.9 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE, kFALSE);
321 loizides 1.1
322     //****************************************************************************************
323     // Make denominator object cuts
324     //****************************************************************************************
325 ceballos 1.6 if( denominator->Pt() > 10.0
326     && passIsolationCut
327     && (passConversionFilter || !fApplyConvFilter)
328     && (passD0Cut || !fApplyD0Cut)
329 loizides 1.1 && !(fVetoCleanLeptons && IsCleanLepton)
330     && !(fVetoGenLeptons && IsGenLepton)
331     && !(fVetoTriggerJet && IsTriggerJet)
332     ) {
333    
334     //check whether we have duplicate denominators. If yes then choose best E/P one.
335     Bool_t foundDuplicate = false;
336     for (UInt_t d=0; d<GsfTrackSCDenominators.size();++d) {
337     if (GsfTrackSCDenominators[d]->GsfTrk() == denominator->GsfTrk()) {
338     if (fabs(denominator->SCluster()->Energy()/denominator->GsfTrk()->P() - 1)
339     < fabs(GsfTrackSCDenominators[d]->SCluster()->Energy()/
340     GsfTrackSCDenominators[d]->GsfTrk()->P() - 1)) {
341     //swap this one with previous one and delete the previous one
342     const Electron *denominatorToBeDeleted = GsfTrackSCDenominators[d];
343     GsfTrackSCDenominators[d] = denominator;
344     denominatorSaved = true;
345     foundDuplicate = true;
346     delete denominatorToBeDeleted;
347     break;
348     }
349     }
350     }
351     if (!foundDuplicate) {
352     GsfTrackSCDenominators.push_back(denominator);
353     denominatorSaved = true;
354     }
355     } //end if candidate passes denominator cuts
356     //delete denominator candidate object
357     if (!denominatorSaved) {
358     delete denominator;
359     }
360     }//end if track -> SC match was found
361     } //loop over SC
362    
363     //Save denominators permanently for export
364     for (UInt_t d=0; d<GsfTrackSCDenominators.size() ; ++d) {
365 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
366 loizides 1.1 tmpElectron->SetPtEtaPhi(GsfTrackSCDenominators[d]->Pt(),
367     GsfTrackSCDenominators[d]->Eta(),GsfTrackSCDenominators[d]->Phi());
368     tmpElectron->SetGsfTrk(GsfTrackSCDenominators[d]->GsfTrk());
369     tmpElectron->SetSuperCluster(GsfTrackSCDenominators[d]->SCluster());
370     delete GsfTrackSCDenominators[d];
371     }
372     } else if (fElFOType == kElFOReco) {
373 ceballos 1.6
374 loizides 1.1 for (UInt_t i=0; i<DuplicateRemovedElectrons->GetEntries(); i++) {
375     const Electron *denominator = DuplicateRemovedElectrons->At(i);
376    
377     //Veto denominators matching to real electrons
378     Bool_t IsGenLepton = false;
379     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
380     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
381     GenLeptonsAndTaus->At(l)->Phi(),
382     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
383     IsGenLepton = true;
384     }
385     }
386    
387     //Veto denominators matching to clean leptons
388     Bool_t IsCleanLepton = false;
389     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
390     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
391     CleanLeptons->At(l)->Phi(),
392     CleanLeptons->At(l)->Eta()) < 0.1) {
393     IsCleanLepton = true;
394     }
395     }
396    
397     //Veto on Trigger jet
398     Bool_t IsTriggerJet = false;
399     if (fVetoTriggerJet) {
400     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
401 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
402     denominator->Eta(),
403     triggerObjects->At(l)->Phi(),
404     triggerObjects->At(l)->Eta());
405 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
406     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
407     && deltaR < 0.3
408     ) {
409     IsTriggerJet = true;
410     break;
411     }
412     }
413     }
414    
415 ceballos 1.6 const Electron *tmpEle = denominator;
416     //****************************************************************************************
417     // Isolation Cut
418     //****************************************************************************************
419     Double_t combIso =
420 sixie 1.12 denominator->TrackIsolationDr03() + TMath::Max(denominator->EcalRecHitIsoDr03() - 1.0, 0.0) + denominator->HcalTowerSumEtDr03();
421     if (fabs(denominator->Eta()) > 1.5) {
422     combIso = denominator->TrackIsolationDr03() + denominator->EcalRecHitIsoDr03() + denominator->HcalTowerSumEtDr03();
423     }
424 ceballos 1.6
425 sixie 1.12 Bool_t passIsolationCut = (combIso / denominator->Pt() <= fCombIsolationCut || fCombIsolationCut < 0) &&
426     (denominator->TrackIsolationDr04()/ denominator->Pt() <= fTrackIsolationCut || fTrackIsolationCut < 0) &&
427     (denominator->EcalRecHitIsoDr04()/ denominator->Pt() <= fEcalIsolationCut || fEcalIsolationCut < 0) &&
428     (denominator->HcalTowerSumEtDr04()/ denominator->Pt() <= fHcalIsolationCut || fHcalIsolationCut < 0) ;
429 ceballos 1.6
430     //****************************************************************************************
431 loizides 1.1 // conversion filter
432 ceballos 1.6 //****************************************************************************************
433 sixie 1.12 Bool_t passConversionFilter = ElectronTools::PassConversionFilter(tmpEle, fConversions, kTRUE);
434 loizides 1.1
435     //****************************************************************************************
436     // D0 Cut
437 loizides 1.5 //****************************************************************************************
438 ceballos 1.9 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE, kFALSE);
439 ceballos 1.6
440 loizides 1.1 //****************************************************************************************
441 ceballos 1.6 // Make denominator object cuts
442 loizides 1.5 //****************************************************************************************
443 ceballos 1.6 if( denominator->Pt() > 10.0
444     && passIsolationCut
445     && (passConversionFilter || !fApplyConvFilter)
446     && (passD0Cut || !fApplyD0Cut)
447     && !(fVetoCleanLeptons && IsCleanLepton)
448 loizides 1.1 && !(fVetoGenLeptons && IsGenLepton)
449     && !(fVetoTriggerJet && IsTriggerJet)
450 ceballos 1.6 ) {
451 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
452 loizides 1.1 tmpElectron->SetPtEtaPhi(denominator->Pt(), denominator->Eta(),denominator->Phi());
453     tmpElectron->SetGsfTrk(denominator->GsfTrk());
454     tmpElectron->SetSuperCluster(denominator->SCluster());
455 sixie 1.7 }
456 loizides 1.1 }
457     } else if (fElFOType == kElFOLoose) {
458     for (UInt_t i=0; i<DuplicateRemovedElectrons->GetEntries(); i++) {
459     const Electron *denominator = DuplicateRemovedElectrons->At(i);
460 ceballos 1.6
461 loizides 1.1 //Veto denominators matching to real electrons
462     Bool_t IsGenLepton = false;
463     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
464     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
465     GenLeptonsAndTaus->At(l)->Phi(),
466     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
467     IsGenLepton = true;
468     }
469     }
470    
471     //Veto denominators matching to clean leptons
472     Bool_t IsCleanLepton = false;
473     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
474     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
475     CleanLeptons->At(l)->Phi(),
476     CleanLeptons->At(l)->Eta()) < 0.1) {
477     IsCleanLepton = true;
478     }
479     }
480    
481     //Veto on Trigger jet
482     Bool_t IsTriggerJet = false;
483     if (fVetoTriggerJet) {
484     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
485 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
486     denominator->Eta(),
487     triggerObjects->At(l)->Phi(),
488     triggerObjects->At(l)->Eta());
489 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
490     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
491     && deltaR < 0.3
492     ) {
493     IsTriggerJet = true;
494     break;
495     }
496     }
497     }
498    
499 ceballos 1.6 const Electron *tmpEle = denominator;
500     //****************************************************************************************
501     // Isolation Cut
502     //****************************************************************************************
503     Double_t combIso =
504     denominator->TrackIsolationDr03() + denominator->EcalRecHitIsoDr04() - 1.5;
505    
506     Bool_t passIsolationCut = (combIso <= fCombIsolationCut || fCombIsolationCut < 0) &&
507     (denominator->TrackIsolationDr04() <= fTrackIsolationCut || fTrackIsolationCut < 0) &&
508     (denominator->EcalRecHitIsoDr04() <= fEcalIsolationCut || fEcalIsolationCut < 0) &&
509     (denominator->HcalTowerSumEtDr04() <= fHcalIsolationCut || fHcalIsolationCut < 0) ;
510    
511 loizides 1.1 //****************************************************************************************
512     // conversion filter
513 loizides 1.5 //****************************************************************************************
514 ceballos 1.9 Bool_t passConversionFilter = ElectronTools::PassConversionFilter(tmpEle, fConversions, kTRUE);
515 loizides 1.1
516     //****************************************************************************************
517     // D0 Cut
518 loizides 1.5 //****************************************************************************************
519 ceballos 1.9 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE, kFALSE);
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     }