ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/FakeMods/src/GenFakeableObjsMod.cc
Revision: 1.6
Committed: Tue Nov 3 08:40:37 2009 UTC (15 years, 6 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.5: +86 -164 lines
Log Message:
a few fixes

File Contents

# User Rev Content
1 ceballos 1.6 // $Id: GenFakeableObjsMod.cc,v 1.5 2009/08/11 09:16:01 loizides 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.6 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.6 Bool_t passConversionFilter = electronID->PassConversionFilter(tmpEle, fConversions);
317 loizides 1.1
318     //****************************************************************************************
319     // D0 Cut
320 loizides 1.5 //****************************************************************************************
321 ceballos 1.6 Bool_t passD0Cut = electronID->PassD0Cut(tmpEle,fVertices);
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     Bool_t passConversionFilter = electronID->PassConversionFilter(tmpEle, fConversions);
432 loizides 1.1
433     //****************************************************************************************
434     // D0 Cut
435 loizides 1.5 //****************************************************************************************
436 ceballos 1.6 Bool_t passD0Cut = electronID->PassD0Cut(tmpEle,fVertices);
437    
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     }
454     }
455     } else if (fElFOType == kElFOLoose) {
456     for (UInt_t i=0; i<DuplicateRemovedElectrons->GetEntries(); i++) {
457     const Electron *denominator = DuplicateRemovedElectrons->At(i);
458 loizides 1.5 Double_t denominatorIso =
459     denominator->TrackIsolationDr03() +
460     denominator->EcalRecHitIsoDr04() - 1.5;
461 ceballos 1.6
462 loizides 1.1 //Veto denominators matching to real electrons
463     Bool_t IsGenLepton = false;
464     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
465     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
466     GenLeptonsAndTaus->At(l)->Phi(),
467     GenLeptonsAndTaus->At(l)->Eta()) < 0.1) {
468     IsGenLepton = true;
469     }
470     }
471    
472     //Veto denominators matching to clean leptons
473     Bool_t IsCleanLepton = false;
474     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
475     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
476     CleanLeptons->At(l)->Phi(),
477     CleanLeptons->At(l)->Eta()) < 0.1) {
478     IsCleanLepton = true;
479     }
480     }
481    
482     //Veto on Trigger jet
483     Bool_t IsTriggerJet = false;
484     if (fVetoTriggerJet) {
485     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
486 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
487     denominator->Eta(),
488     triggerObjects->At(l)->Phi(),
489     triggerObjects->At(l)->Eta());
490 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
491     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
492     && deltaR < 0.3
493     ) {
494     IsTriggerJet = true;
495     break;
496     }
497     }
498     }
499    
500 ceballos 1.6 const Electron *tmpEle = denominator;
501     //****************************************************************************************
502     // Isolation Cut
503     //****************************************************************************************
504     Double_t combIso =
505     denominator->TrackIsolationDr03() + denominator->EcalRecHitIsoDr04() - 1.5;
506    
507     Bool_t passIsolationCut = (combIso <= fCombIsolationCut || fCombIsolationCut < 0) &&
508     (denominator->TrackIsolationDr04() <= fTrackIsolationCut || fTrackIsolationCut < 0) &&
509     (denominator->EcalRecHitIsoDr04() <= fEcalIsolationCut || fEcalIsolationCut < 0) &&
510     (denominator->HcalTowerSumEtDr04() <= fHcalIsolationCut || fHcalIsolationCut < 0) ;
511    
512 loizides 1.1 //****************************************************************************************
513     // conversion filter
514 loizides 1.5 //****************************************************************************************
515 ceballos 1.6 Bool_t passConversionFilter = electronID->PassConversionFilter(tmpEle, fConversions);
516 loizides 1.1
517     //****************************************************************************************
518     // D0 Cut
519 loizides 1.5 //****************************************************************************************
520 ceballos 1.6 Bool_t passD0Cut = electronID->PassD0Cut(tmpEle,fVertices);
521    
522     //****************************************************************************************
523     // Make denominator object cuts
524     //****************************************************************************************
525     if( denominator->Pt() > 10.0
526     && passIsolationCut
527     && (passConversionFilter || !fApplyConvFilter)
528     && (passD0Cut || !fApplyD0Cut)
529 loizides 1.1 && denominator->PassLooseID()
530 ceballos 1.6 && !(fVetoCleanLeptons && IsCleanLepton)
531 loizides 1.1 && !(fVetoGenLeptons && IsGenLepton)
532     && !(fVetoTriggerJet && IsTriggerJet)
533 ceballos 1.6 ) {
534 phedex 1.2 Electron *tmpElectron = ElFakeableObjs->AddNew();
535 loizides 1.1 tmpElectron->SetPtEtaPhi(denominator->Pt(), denominator->Eta(),denominator->Phi());
536     tmpElectron->SetGsfTrk(denominator->GsfTrk());
537     tmpElectron->SetSuperCluster(denominator->SCluster());
538     }
539     }
540     }
541    
542     //***********************************************************************************************
543     //Fakeable Objects for Muon Fakes
544     //***********************************************************************************************
545     if (fMuFOType == kMuFOIsoTrack) {
546     for (UInt_t i=0; i<fTracks->GetEntries(); i++) {
547     const Track *track = fTracks->At(i);
548     Double_t trackIsolation = IsolationTools::TrackIsolation(track, 0.4, 0.015, 1.0,
549     0.2, fTracks);
550     //Determine if muon fakeable object matches a gen lepton
551     Bool_t IsGenLepton = false;
552     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
553     if (MathUtils::DeltaR(track->Phi(), track->Eta(),
554     GenLeptonsAndTaus->At(l)->Phi(),
555     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
556     IsGenLepton = true;
557     }
558     }
559    
560     //Veto denominators matching to clean leptons
561     Bool_t IsCleanLepton = false;
562     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
563     if (MathUtils::DeltaR(track->Phi(), track->Eta(),
564     CleanLeptons->At(l)->Phi(),
565     CleanLeptons->At(l)->Eta()) < 0.1) {
566     IsCleanLepton = true;
567     }
568     }
569    
570     //Veto on Trigger jet
571     Bool_t IsTriggerJet = false;
572     if (fVetoTriggerJet) {
573     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
574     Double_t deltaR = MathUtils::DeltaR(track->Phi(), track->Eta(),
575     triggerObjects->At(l)->Phi(),
576     triggerObjects->At(l)->Eta());
577     if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
578     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
579     && deltaR < 0.3
580     ) {
581     IsTriggerJet = true;
582     break;
583     }
584     }
585     }
586    
587     //****************************************************************************************
588     // D0 Cut
589     //****************************************************************************************
590     double d0Min = 99999;
591     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
592     double pD0 = track->D0Corrected(*fVertices->At(i0));
593     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
594     }
595    
596    
597     //define denominator cuts
598     if (track->Pt() > 10.0 && trackIsolation < 10.0
599     && d0Min < 0.025
600     && !(fVetoGenLeptons && IsGenLepton)
601     && !(fVetoCleanLeptons && IsCleanLepton)
602     && !(fVetoTriggerJet && IsTriggerJet)
603     ) {
604     //add to fakeable objects
605 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
606 loizides 1.1 tmpMuon->SetTrackerTrk(track);
607     }
608     }
609     } else if (fMuFOType == kMuFOGlobal) {
610     for (UInt_t i=0; i<fMuons->GetEntries(); i++) {
611     const Muon *denominator = fMuons->At(i);
612     Double_t totalIsolation = denominator->IsoR03SumPt() + denominator->IsoR03EmEt() +
613     denominator->IsoR03HadEt();
614    
615     //Determine if muon fakeable object matches a gen lepton
616     Bool_t IsGenLepton = false;
617     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
618     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
619     GenLeptonsAndTaus->At(l)->Phi(),
620     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
621     IsGenLepton = true;
622     }
623     }
624    
625     //Veto denominators matching to clean leptons
626     Bool_t IsCleanLepton = false;
627     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
628     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
629     CleanLeptons->At(l)->Phi(),
630     CleanLeptons->At(l)->Eta()) < 0.1) {
631     IsCleanLepton = true;
632     }
633     }
634    
635     //Veto on Trigger jet
636     Bool_t IsTriggerJet = false;
637     if (fVetoTriggerJet) {
638     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
639 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
640     denominator->Eta(),
641     triggerObjects->At(l)->Phi(),
642     triggerObjects->At(l)->Eta());
643 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
644     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
645     && deltaR < 0.3
646     ) {
647     IsTriggerJet = true;
648     break;
649     }
650     }
651     }
652    
653     //****************************************************************************************
654     // D0 Cut
655 loizides 1.5 //****************************************************************************************
656 loizides 1.1 double d0Min = 99999;
657     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
658     double pD0 = denominator->Trk()->D0Corrected(*fVertices->At(i0));
659     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
660     }
661    
662     if (denominator->Pt() > 10.0 && totalIsolation < 10.0 && denominator->HasGlobalTrk()
663     && d0Min < 0.025
664     && !(fVetoGenLeptons && IsGenLepton)
665     && !(fVetoCleanLeptons && IsCleanLepton)
666     && !(fVetoTriggerJet && IsTriggerJet)
667     ) {
668 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
669 loizides 1.1 tmpMuon->SetGlobalTrk(denominator->GlobalTrk());
670     tmpMuon->SetTrackerTrk(denominator->TrackerTrk());
671     }
672     }
673     } else if (fMuFOType == kMuFOTrackerMuon) {
674     for (UInt_t i=0; i<fMuons->GetEntries(); i++) {
675     const Muon *denominator = fMuons->At(i);
676 loizides 1.5 Double_t totalIsolation =
677     denominator->IsoR03SumPt() +
678     denominator->IsoR03EmEt() +
679     denominator->IsoR03HadEt();
680 loizides 1.1
681     //Determine if muon fakeable object matches a gen lepton
682     Bool_t IsGenLepton = false;
683     for (UInt_t l=0; l<GenLeptonsAndTaus->GetEntries(); l++) {
684     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
685     GenLeptonsAndTaus->At(l)->Phi(),
686     GenLeptonsAndTaus->At(l)->Eta()) < 0.3) {
687     IsGenLepton = true;
688     }
689     }
690    
691     //Veto denominators matching to clean leptons
692     Bool_t IsCleanLepton = false;
693     for (UInt_t l=0; l<CleanLeptons->GetEntries(); l++) {
694     if (MathUtils::DeltaR(denominator->Phi(), denominator->Eta(),
695     CleanLeptons->At(l)->Phi(),
696     CleanLeptons->At(l)->Eta()) < 0.1) {
697     IsCleanLepton = true;
698     }
699     }
700    
701     //Veto on Trigger jet
702     Bool_t IsTriggerJet = false;
703     if (fVetoTriggerJet) {
704     for (UInt_t l=0; l<triggerObjects->GetEntries(); l++) {
705 loizides 1.5 Double_t deltaR = MathUtils::DeltaR(denominator->Phi(),
706     denominator->Eta(),
707     triggerObjects->At(l)->Phi(),
708     triggerObjects->At(l)->Eta());
709 loizides 1.1 if (triggerObjects->At(l)->TrigName() == fTriggerName.Data()
710     && triggerObjects->At(l)->Type() == TriggerObject::TriggerJet
711     && deltaR < 0.3
712     ) {
713     IsTriggerJet = true;
714     break;
715     }
716     }
717     }
718    
719     //****************************************************************************************
720     // D0 Cut
721 loizides 1.5 //****************************************************************************************
722 loizides 1.1 double d0Min = 99999;
723     for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
724     double pD0 = denominator->Trk()->D0Corrected(*fVertices->At(i0));
725     if(TMath::Abs(pD0) < TMath::Abs(d0Min)) d0Min = TMath::Abs(pD0);
726     }
727    
728     if (denominator->Pt() > 10.0 && totalIsolation < 10.0 && denominator->HasTrackerTrk()
729     && d0Min < 0.025
730     && !(fVetoGenLeptons && IsGenLepton)
731     && !(fVetoCleanLeptons && IsCleanLepton)
732     && !(fVetoTriggerJet && IsTriggerJet)
733     ) {
734 phedex 1.2 Muon* tmpMuon = MuFakeableObjs->AddNew();
735 loizides 1.1 tmpMuon->SetTrackerTrk(denominator->TrackerTrk());
736     }
737     }
738     }
739    
740     //***********************************************************************************************
741     //Export the fakeable object collections for other modules to use
742     //***********************************************************************************************
743 phedex 1.2 ElFakeableObjs->SetName(fElFakeableObjsName);
744     AddObjThisEvt(ElFakeableObjs);
745     MuFakeableObjs->SetName(fMuFakeableObjsName);
746     AddObjThisEvt(MuFakeableObjs);
747 loizides 1.1
748     delete GenLeptonsAndTaus;
749     delete SuperClusters;
750     delete DuplicateRemovedElectrons;
751     }