ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/FakeMods/src/GenFakeableObjsMod.cc
Revision: 1.5
Committed: Tue Aug 11 09:16:01 2009 UTC (15 years, 8 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011a, Mit_011, Mit_010a
Changes since 1.4: +36 -21 lines
Log Message:
Further cleanup

File Contents

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