ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/FakeMods/src/GenFakeableObjsMod.cc
Revision: 1.9
Committed: Wed May 12 19:05:26 2010 UTC (14 years, 11 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.8: +13 -10 lines
Log Message:
change in conversion naming

File Contents

# User Rev Content
1 sixie 1.8 // $Id: GenFakeableObjsMod.cc,v 1.7 2009/11/04 14:16:50 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     fD0Cut(0.025),
31     fCombIsolationCut(10.0),
32     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     fVertexBranchName(Names::gkPVBeamSpotBrn),
49     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     ReqBranch(fVertexBranchName, fVertices);
87    
88     if (fElectronFOType.CompareTo("GsfPlusSC") == 0)
89     fElFOType = kElFOGsfPlusSC;
90     else if (fElectronFOType.CompareTo("Reco") == 0)
91     fElFOType = kElFOReco;
92     else if (fElectronFOType.CompareTo("Loose") == 0)
93     fElFOType = kElFOLoose;
94     else {
95     SendError(kAbortAnalysis, "SlaveBegin",
96     "The specified electron fakeable object %s is not defined.",
97     fElectronFOType.Data());
98     return;
99     }
100    
101     if (fMuonFOType.CompareTo("IsoTrack") == 0)
102     fMuFOType = kMuFOIsoTrack;
103     else if (fMuonFOType.CompareTo("Global") == 0)
104     fMuFOType = kMuFOGlobal;
105     else if (fMuonFOType.CompareTo("TrackerMuon") == 0)
106     fMuFOType = kMuFOTrackerMuon;
107     else {
108     SendError(kAbortAnalysis, "SlaveBegin",
109     "The specified muon fakeable object %s is not defined.",
110     fMuonFOType.Data());
111     return;
112     }
113    
114 ceballos 1.9 electronID = new ElectronIDMod();
115     electronID->SetApplyConversionFilter(fApplyConvFilter);
116     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(fVertexBranchName);
134     LoadBranch(fConversionBranchName);
135    
136     //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     e->GsfTrk() == tmpDuplicateRemovedElectrons[j]->GsfTrk() ||
200     deltaR < 0.1) {
201     isElectronOverlap = kTRUE;
202     }
203    
204    
205     if (isElectronOverlap) {
206     if (TMath::Abs(tmpDuplicateRemovedElectrons[j]->ESuperClusterOverP() - 1) >
207     TMath::Abs(e->ESuperClusterOverP() - 1)) {
208     tmpDuplicateRemovedElectrons[j] = e;
209     }
210     break;
211     }
212     }
213    
214     if (!isElectronOverlap) {
215     tmpDuplicateRemovedElectrons.push_back(e);
216     }
217     }
218     for (UInt_t i=0; i<tmpDuplicateRemovedElectrons.size(); ++i) {
219     DuplicateRemovedElectrons->Add(tmpDuplicateRemovedElectrons[i]);
220     }
221    
222     //***********************************************************************************************
223     //Fakeable Objects for Electron Fakes
224     //Supercluster matched to nearest isolated track.
225     //***********************************************************************************************
226     if (fElFOType == kElFOGsfPlusSC) {
227    
228     std::vector<const Electron*> GsfTrackSCDenominators;
229    
230     //loop over all super clusters
231     for (UInt_t i=0; i<SuperClusters->GetEntries(); i++) {
232     const SuperCluster *cluster = SuperClusters->At(i);
233    
234     //find best matching track based on DR to the cluster
235     const Track *EOverPMatchedTrk = NULL;
236     double BestEOverP = 5000.0;
237     for (UInt_t j=0; j<fGsfTracks->GetEntries(); j++) {
238     const Track *trk = fGsfTracks->At(j);
239    
240     //Use best E/P matching within dR of 0.3
241     double dR = MathUtils::DeltaR(cluster->Phi(), cluster->Eta(), trk->Phi(), trk->Eta());
242     Double_t EOverP = cluster->Energy() / trk->P();
243     if( fabs(1-EOverP) < fabs(1-BestEOverP) && dR < 0.3 ) {
244     BestEOverP = EOverP;
245     EOverPMatchedTrk = trk;
246     }
247     }
248    
249     //****************************************************************************************
250     //Use Best E/P Matching and require the track is within 0.3 of the super cluster position
251     //****************************************************************************************
252     if( EOverPMatchedTrk ) {
253    
254     //calculate track isolation around the matched track
255     Double_t matchiso=0;
256     matchiso = IsolationTools::TrackIsolation(EOverPMatchedTrk, 0.3, 0.015, 1.0, 0.2,
257     fTracks);
258    
259     //Veto denominators matching to real electrons
260     Bool_t IsGenLepton = false;
261     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
262     if (MathUtils::DeltaR(EOverPMatchedTrk->Phi(), EOverPMatchedTrk->Eta(),
263     GenLeptonsAndTaus->At(l)->Phi(),
264     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
265     IsGenLepton = true;
266     }
267     }
268    
269     //Veto denominators matching to clean leptons
270     Bool_t IsCleanLepton = false;
271     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
272     if (MathUtils::DeltaR(EOverPMatchedTrk->Phi(), EOverPMatchedTrk->Eta(),
273     CleanLeptons->At(l)->Phi(),
274     CleanLeptons->At(l)->Eta()) < 0.1) {
275     IsCleanLepton = true;
276     }
277     }
278    
279     //Veto on Leading jet
280     Bool_t IsTriggerJet = false;
281     if (fVetoTriggerJet) {
282     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
283 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(EOverPMatchedTrk->Phi(),
284     EOverPMatchedTrk->Eta(),
285     triggerObjects->At(l)->Phi(),
286     triggerObjects->At(l)->Eta());
287 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
288     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
289     && deltaR < 0.3
290     ) {
291     IsTriggerJet = true;
292     break;
293     }
294     }
295     }
296    
297     //create new electron object for the denominator under consideration
298     Bool_t denominatorSaved = false;
299     Electron *denominator = new Electron();
300     Double_t p = TMath::Sqrt(cluster->Energy()*cluster->Energy()
301     - denominator->Mass()*denominator->Mass());
302     denominator->SetPtEtaPhi(TMath::Abs(p*TMath::Cos(EOverPMatchedTrk->Lambda())),
303     EOverPMatchedTrk->Eta(),EOverPMatchedTrk->Phi());
304     denominator->SetGsfTrk(EOverPMatchedTrk);
305     denominator->SetSuperCluster(cluster);
306    
307 ceballos 1.6 const Electron *tmpEle = denominator;
308     //****************************************************************************************
309     // Isolation Cut
310     //****************************************************************************************
311     Bool_t passIsolationCut = (matchiso <= fTrackIsolationCut);
312    
313 loizides 1.1 //****************************************************************************************
314     // conversion filter
315 loizides 1.5 //****************************************************************************************
316 ceballos 1.9 Bool_t passConversionFilter = ElectronTools::PassConversionFilter(tmpEle, fConversions, kTRUE);
317 loizides 1.1
318     //****************************************************************************************
319     // D0 Cut
320 loizides 1.5 //****************************************************************************************
321 ceballos 1.9 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE, kFALSE);
322 loizides 1.1
323     //****************************************************************************************
324     // Make denominator object cuts
325     //****************************************************************************************
326 ceballos 1.6 if( denominator->Pt() > 10.0
327     && passIsolationCut
328     && (passConversionFilter || !fApplyConvFilter)
329     && (passD0Cut || !fApplyD0Cut)
330 loizides 1.1 && !(fVetoCleanLeptons && IsCleanLepton)
331     && !(fVetoGenLeptons && IsGenLepton)
332     && !(fVetoTriggerJet && IsTriggerJet)
333     ) {
334    
335     //check whether we have duplicate denominators. If yes then choose best E/P one.
336     Bool_t foundDuplicate = false;
337     for (UInt_t d=0; d<GsfTrackSCDenominators.size();++d) {
338     if (GsfTrackSCDenominators[d]->GsfTrk() == denominator->GsfTrk()) {
339     if (fabs(denominator->SCluster()->Energy()/denominator->GsfTrk()->P() - 1)
340     < fabs(GsfTrackSCDenominators[d]->SCluster()->Energy()/
341     GsfTrackSCDenominators[d]->GsfTrk()->P() - 1)) {
342     //swap this one with previous one and delete the previous one
343     const Electron *denominatorToBeDeleted = GsfTrackSCDenominators[d];
344     GsfTrackSCDenominators[d] = denominator;
345     denominatorSaved = true;
346     foundDuplicate = true;
347     delete denominatorToBeDeleted;
348     break;
349     }
350     }
351     }
352     if (!foundDuplicate) {
353     GsfTrackSCDenominators.push_back(denominator);
354     denominatorSaved = true;
355     }
356     } //end if candidate passes denominator cuts
357     //delete denominator candidate object
358     if (!denominatorSaved) {
359     delete denominator;
360     }
361     }//end if track -> SC match was found
362     } //loop over SC
363    
364     //Save denominators permanently for export
365     for (UInt_t d=0; d<GsfTrackSCDenominators.size() ; ++d) {
366 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
367 loizides 1.1 tmpElectron->SetPtEtaPhi(GsfTrackSCDenominators[d]->Pt(),
368     GsfTrackSCDenominators[d]->Eta(),GsfTrackSCDenominators[d]->Phi());
369     tmpElectron->SetGsfTrk(GsfTrackSCDenominators[d]->GsfTrk());
370     tmpElectron->SetSuperCluster(GsfTrackSCDenominators[d]->SCluster());
371     delete GsfTrackSCDenominators[d];
372     }
373     } else if (fElFOType == kElFOReco) {
374 ceballos 1.6
375 loizides 1.1 for (UInt_t i=0; i<DuplicateRemovedElectrons->GetEntries(); i++) {
376     const Electron *denominator = DuplicateRemovedElectrons->At(i);
377    
378     //Veto denominators matching to real electrons
379     Bool_t IsGenLepton = false;
380     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
381     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
382     GenLeptonsAndTaus->At(l)->Phi(),
383     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
384     IsGenLepton = true;
385     }
386     }
387    
388     //Veto denominators matching to clean leptons
389     Bool_t IsCleanLepton = false;
390     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
391     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
392     CleanLeptons->At(l)->Phi(),
393     CleanLeptons->At(l)->Eta()) < 0.1) {
394     IsCleanLepton = true;
395     }
396     }
397    
398     //Veto on Trigger jet
399     Bool_t IsTriggerJet = false;
400     if (fVetoTriggerJet) {
401     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
402 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
403     denominator->Eta(),
404     triggerObjects->At(l)->Phi(),
405     triggerObjects->At(l)->Eta());
406 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
407     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
408     && deltaR < 0.3
409     ) {
410     IsTriggerJet = true;
411     break;
412     }
413     }
414     }
415    
416 ceballos 1.6 const Electron *tmpEle = denominator;
417     //****************************************************************************************
418     // Isolation Cut
419     //****************************************************************************************
420     Double_t combIso =
421     denominator->TrackIsolationDr03() + denominator->EcalRecHitIsoDr04() - 1.5;
422    
423     Bool_t passIsolationCut = (combIso <= fCombIsolationCut || fCombIsolationCut < 0) &&
424     (denominator->TrackIsolationDr04() <= fTrackIsolationCut || fTrackIsolationCut < 0) &&
425     (denominator->EcalRecHitIsoDr04() <= fEcalIsolationCut || fEcalIsolationCut < 0) &&
426     (denominator->HcalTowerSumEtDr04() <= fHcalIsolationCut || fHcalIsolationCut < 0) ;
427    
428     //****************************************************************************************
429 loizides 1.1 // conversion filter
430 ceballos 1.6 //****************************************************************************************
431 ceballos 1.9 Bool_t passConversionFilter = ElectronTools::PassConversionFilter(tmpEle, fConversions, kTRUE);
432 loizides 1.1
433     //****************************************************************************************
434     // D0 Cut
435 loizides 1.5 //****************************************************************************************
436 ceballos 1.9 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE, kFALSE);
437 ceballos 1.6
438 loizides 1.1 //****************************************************************************************
439 ceballos 1.6 // Make denominator object cuts
440 loizides 1.5 //****************************************************************************************
441 ceballos 1.6 if( denominator->Pt() > 10.0
442     && passIsolationCut
443     && (passConversionFilter || !fApplyConvFilter)
444     && (passD0Cut || !fApplyD0Cut)
445     && !(fVetoCleanLeptons && IsCleanLepton)
446 loizides 1.1 && !(fVetoGenLeptons && IsGenLepton)
447     && !(fVetoTriggerJet && IsTriggerJet)
448 ceballos 1.6 ) {
449 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
450 loizides 1.1 tmpElectron->SetPtEtaPhi(denominator->Pt(), denominator->Eta(),denominator->Phi());
451     tmpElectron->SetGsfTrk(denominator->GsfTrk());
452     tmpElectron->SetSuperCluster(denominator->SCluster());
453 sixie 1.7 }
454 loizides 1.1 }
455     } else if (fElFOType == kElFOLoose) {
456     for (UInt_t i=0; i<DuplicateRemovedElectrons->GetEntries(); i++) {
457     const Electron *denominator = DuplicateRemovedElectrons->At(i);
458 ceballos 1.6
459 loizides 1.1 //Veto denominators matching to real electrons
460     Bool_t IsGenLepton = false;
461     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
462     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
463     GenLeptonsAndTaus->At(l)->Phi(),
464     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
465     IsGenLepton = true;
466     }
467     }
468    
469     //Veto denominators matching to clean leptons
470     Bool_t IsCleanLepton = false;
471     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
472     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
473     CleanLeptons->At(l)->Phi(),
474     CleanLeptons->At(l)->Eta()) < 0.1) {
475     IsCleanLepton = true;
476     }
477     }
478    
479     //Veto on Trigger jet
480     Bool_t IsTriggerJet = false;
481     if (fVetoTriggerJet) {
482     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
483 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
484     denominator->Eta(),
485     triggerObjects->At(l)->Phi(),
486     triggerObjects->At(l)->Eta());
487 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
488     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
489     && deltaR < 0.3
490     ) {
491     IsTriggerJet = true;
492     break;
493     }
494     }
495     }
496    
497 ceballos 1.6 const Electron *tmpEle = denominator;
498     //****************************************************************************************
499     // Isolation Cut
500     //****************************************************************************************
501     Double_t combIso =
502     denominator->TrackIsolationDr03() + denominator->EcalRecHitIsoDr04() - 1.5;
503    
504     Bool_t passIsolationCut = (combIso <= fCombIsolationCut || fCombIsolationCut < 0) &&
505     (denominator->TrackIsolationDr04() <= fTrackIsolationCut || fTrackIsolationCut < 0) &&
506     (denominator->EcalRecHitIsoDr04() <= fEcalIsolationCut || fEcalIsolationCut < 0) &&
507     (denominator->HcalTowerSumEtDr04() <= fHcalIsolationCut || fHcalIsolationCut < 0) ;
508    
509 loizides 1.1 //****************************************************************************************
510     // conversion filter
511 loizides 1.5 //****************************************************************************************
512 ceballos 1.9 Bool_t passConversionFilter = ElectronTools::PassConversionFilter(tmpEle, fConversions, kTRUE);
513 loizides 1.1
514     //****************************************************************************************
515     // D0 Cut
516 loizides 1.5 //****************************************************************************************
517 ceballos 1.9 Bool_t passD0Cut = ElectronTools::PassD0Cut(tmpEle,fVertices, kTRUE, kFALSE);
518 ceballos 1.6
519     //****************************************************************************************
520     // Make denominator object cuts
521     //****************************************************************************************
522     if( denominator->Pt() > 10.0
523     && passIsolationCut
524     && (passConversionFilter || !fApplyConvFilter)
525     && (passD0Cut || !fApplyD0Cut)
526 loizides 1.1 && denominator->PassLooseID()
527 ceballos 1.6 && !(fVetoCleanLeptons && IsCleanLepton)
528 loizides 1.1 && !(fVetoGenLeptons && IsGenLepton)
529     && !(fVetoTriggerJet && IsTriggerJet)
530 ceballos 1.6 ) {
531 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
532 loizides 1.1 tmpElectron->SetPtEtaPhi(denominator->Pt(), denominator->Eta(),denominator->Phi());
533     tmpElectron->SetGsfTrk(denominator->GsfTrk());
534     tmpElectron->SetSuperCluster(denominator->SCluster());
535     }
536     }
537     }
538    
539     //***********************************************************************************************
540     //Fakeable Objects for Muon Fakes
541     //***********************************************************************************************
542     if (fMuFOType == kMuFOIsoTrack) {
543     for (UInt_t i=0; i<fTracks->GetEntries(); i++) {
544     const Track *track = fTracks->At(i);
545     Double_t trackIsolation = IsolationTools::TrackIsolation(track, 0.4, 0.015, 1.0,
546     0.2, fTracks);
547     //Determine if muon fakeable object matches a gen lepton
548     Bool_t IsGenLepton = false;
549     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
550     if (MathUtils::DeltaR(track->Phi(), track->Eta(),
551     GenLeptonsAndTaus->At(l)->Phi(),
552     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
553     IsGenLepton = true;
554     }
555     }
556    
557     //Veto denominators matching to clean leptons
558     Bool_t IsCleanLepton = false;
559     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
560     if (MathUtils::DeltaR(track->Phi(), track->Eta(),
561     CleanLeptons->At(l)->Phi(),
562     CleanLeptons->At(l)->Eta()) < 0.1) {
563     IsCleanLepton = true;
564     }
565     }
566    
567     //Veto on Trigger jet
568     Bool_t IsTriggerJet = false;
569     if (fVetoTriggerJet) {
570     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
571     Double_t deltaR = MathUtils::DeltaR(track->Phi(), track->Eta(),
572     triggerObjects->At(l)->Phi(),
573     triggerObjects->At(l)->Eta());
574     if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
575     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
576     && deltaR < 0.3
577     ) {
578     IsTriggerJet = true;
579     break;
580     }
581     }
582     }
583    
584     //****************************************************************************************
585     // D0 Cut
586     //****************************************************************************************
587     double d0Min = 99999;
588     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
589     double pD0 = track->D0Corrected(*fVertices->At(i0));
590     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
591     }
592    
593    
594     //define denominator cuts
595     if (track->Pt() > 10.0 && trackIsolation < 10.0
596     && d0Min < 0.025
597     && !(fVetoGenLeptons && IsGenLepton)
598     && !(fVetoCleanLeptons && IsCleanLepton)
599     && !(fVetoTriggerJet && IsTriggerJet)
600     ) {
601     //add to fakeable objects
602 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
603 loizides 1.1 tmpMuon->SetTrackerTrk(track);
604     }
605     }
606     } else if (fMuFOType == kMuFOGlobal) {
607     for (UInt_t i=0; i<fMuons->GetEntries(); i++) {
608     const Muon *denominator = fMuons->At(i);
609     Double_t totalIsolation = denominator->IsoR03SumPt() + denominator->IsoR03EmEt() +
610     denominator->IsoR03HadEt();
611    
612     //Determine if muon fakeable object matches a gen lepton
613     Bool_t IsGenLepton = false;
614     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
615     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
616     GenLeptonsAndTaus->At(l)->Phi(),
617     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
618     IsGenLepton = true;
619     }
620     }
621    
622     //Veto denominators matching to clean leptons
623     Bool_t IsCleanLepton = false;
624     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
625     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
626     CleanLeptons->At(l)->Phi(),
627     CleanLeptons->At(l)->Eta()) < 0.1) {
628     IsCleanLepton = true;
629     }
630     }
631    
632     //Veto on Trigger jet
633     Bool_t IsTriggerJet = false;
634     if (fVetoTriggerJet) {
635     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
636 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
637     denominator->Eta(),
638     triggerObjects->At(l)->Phi(),
639     triggerObjects->At(l)->Eta());
640 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
641     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
642     && deltaR < 0.3
643     ) {
644     IsTriggerJet = true;
645     break;
646     }
647     }
648     }
649    
650     //****************************************************************************************
651     // D0 Cut
652 loizides 1.5 //****************************************************************************************
653 loizides 1.1 double d0Min = 99999;
654     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
655     double pD0 = denominator->Trk()->D0Corrected(*fVertices->At(i0));
656     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
657     }
658    
659     if (denominator->Pt() > 10.0 && totalIsolation < 10.0 && denominator->HasGlobalTrk()
660     && d0Min < 0.025
661     && !(fVetoGenLeptons && IsGenLepton)
662     && !(fVetoCleanLeptons && IsCleanLepton)
663     && !(fVetoTriggerJet && IsTriggerJet)
664     ) {
665 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
666 loizides 1.1 tmpMuon->SetGlobalTrk(denominator->GlobalTrk());
667     tmpMuon->SetTrackerTrk(denominator->TrackerTrk());
668     }
669     }
670     } else if (fMuFOType == kMuFOTrackerMuon) {
671     for (UInt_t i=0; i<fMuons->GetEntries(); i++) {
672     const Muon *denominator = fMuons->At(i);
673 loizides 1.5 Double_t totalIsolation =
674     denominator->IsoR03SumPt() +
675     denominator->IsoR03EmEt() +
676     denominator->IsoR03HadEt();
677 loizides 1.1
678     //Determine if muon fakeable object matches a gen lepton
679     Bool_t IsGenLepton = false;
680     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
681     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
682     GenLeptonsAndTaus->At(l)->Phi(),
683     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
684     IsGenLepton = true;
685     }
686     }
687    
688     //Veto denominators matching to clean leptons
689     Bool_t IsCleanLepton = false;
690     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
691     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
692     CleanLeptons->At(l)->Phi(),
693     CleanLeptons->At(l)->Eta()) < 0.1) {
694     IsCleanLepton = true;
695     }
696     }
697    
698     //Veto on Trigger jet
699     Bool_t IsTriggerJet = false;
700     if (fVetoTriggerJet) {
701     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
702 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
703     denominator->Eta(),
704     triggerObjects->At(l)->Phi(),
705     triggerObjects->At(l)->Eta());
706 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
707     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
708     && deltaR < 0.3
709     ) {
710     IsTriggerJet = true;
711     break;
712     }
713     }
714     }
715    
716     //****************************************************************************************
717     // D0 Cut
718 loizides 1.5 //****************************************************************************************
719 loizides 1.1 double d0Min = 99999;
720     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
721     double pD0 = denominator->Trk()->D0Corrected(*fVertices->At(i0));
722     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
723     }
724    
725     if (denominator->Pt() > 10.0 && totalIsolation < 10.0 && denominator->HasTrackerTrk()
726     && d0Min < 0.025
727     && !(fVetoGenLeptons && IsGenLepton)
728     && !(fVetoCleanLeptons && IsCleanLepton)
729     && !(fVetoTriggerJet && IsTriggerJet)
730     ) {
731 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
732 loizides 1.1 tmpMuon->SetTrackerTrk(denominator->TrackerTrk());
733     }
734     }
735     }
736    
737     //***********************************************************************************************
738     //Export the fakeable object collections for other modules to use
739     //***********************************************************************************************
740 phedex 1.2 ElFakeableObjs->SetName(fElFakeableObjsName);
741     AddObjThisEvt(ElFakeableObjs);
742     MuFakeableObjs->SetName(fMuFakeableObjsName);
743     AddObjThisEvt(MuFakeableObjs);
744 loizides 1.1
745     delete GenLeptonsAndTaus;
746     delete SuperClusters;
747     delete DuplicateRemovedElectrons;
748     }