ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/ElectronCleaningMod.cc
Revision: 1.4
Committed: Tue Oct 14 05:12:48 2008 UTC (16 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
State: FILE REMOVED
Log Message:
Moved to MitPhysics/Mods

File Contents

# Content
1 // $Id: ElectronCleaningMod.cc,v 1.3 2008/10/09 10:38:44 ceballos Exp $
2
3 #include "MitAna/TreeMod/interface/ElectronCleaningMod.h"
4 #include <TH1D.h>
5 #include <TH2D.h>
6 #include "MitAna/DataTree/interface/Names.h"
7 #include "MitAna/DataCont/interface/ObjArray.h"
8 #include "MitAna/Utils/interface/IsolationTools.h"
9 #include "MitCommon/MathTools/interface/MathUtils.h"
10
11 using namespace mithep;
12
13 ClassImp(mithep::ElectronCleaningMod)
14
15 //--------------------------------------------------------------------------------------------------
16 ElectronCleaningMod::ElectronCleaningMod(const char *name, const char *title) :
17 BaseMod(name,title),
18 fPrintDebug(false),
19 fGoodElectronsName(Names::gkGoodElectronsName),
20 fCleanMuonsName(Names::gkCleanMuonsName),
21 fCleanElectronsName(Names::gkCleanElectronsName),
22 fMuons(0),
23 fElectrons(0),
24 fNEventsProcessed(0)
25 {
26 // Constructor.
27 }
28
29 //--------------------------------------------------------------------------------------------------
30 void ElectronCleaningMod::Begin()
31 {
32 // Run startup code on the client machine. For this module, we dont do
33 // anything here.
34 }
35
36 //--------------------------------------------------------------------------------------------------
37 void ElectronCleaningMod::Process()
38 {
39 // Process entries of the tree. For this module, we just load the branches and
40 //output debug info or not
41
42 fNEventsProcessed++;
43
44 if (fNEventsProcessed % 1000 == 0 || fPrintDebug) {
45 time_t systime;
46 systime = time(NULL);
47
48 cerr << endl << "ElectronCleaningMod : Process Event " << fNEventsProcessed << " Time: " << ctime(&systime) << endl;
49 }
50 //Get Clean Muons
51 ObjArray<Muon> *CleanMuons = dynamic_cast<ObjArray<Muon>* >
52 (FindObjThisEvt(fCleanMuonsName.Data()));
53 //Get Good ID Electrons
54 ObjArray<Electron> *GoodElectrons = dynamic_cast<ObjArray<Electron>* >
55 (FindObjThisEvt(fGoodElectronsName.Data()));
56
57 vector<Electron*> CleanElectronsVector;
58 //Go through all electrons and remove electron overlaps with muons and duplicates
59 for (UInt_t i=0; i<GoodElectrons->GetEntries(); ++i) {
60 Electron *e = GoodElectrons->At(i);
61
62 //Check whether it overlaps with a good muon. If the muon and electron both have
63 //proper tracker tracks then compare the tracks. otherwise check dR
64 bool isMuonOverlap = false;
65 for (UInt_t j=0; j<CleanMuons->GetEntries();j++) {
66 if (CleanMuons->At(j)->TrackerTrk() && e->TrackerTrk()) {
67 isMuonOverlap = (CleanMuons->At(j)->TrackerTrk() == e->TrackerTrk());
68 if (isMuonOverlap)
69 break;
70 } else {
71 double deltaR = MathUtils::DeltaR(CleanMuons->At(j)->Mom(), e->Mom());
72 if (deltaR < 0.1) {
73 isMuonOverlap = true;
74 break;
75 }
76 }
77 }
78
79 //Check whether it overlaps with another electron candidate
80 //Here I check whether we have two electron candidates with the same super cluster
81 //or two electron candidates with the same track. At the end we also check deltaR
82 //to be sure. If there is a duplicate we swap the old one with the new one if the new
83 //one has E/P closer to 1.0
84 bool isElectronOverlap = false;
85 for (UInt_t j=0; j<CleanElectronsVector.size(); j++) {
86 if (e->SCluster() == CleanElectronsVector[j]->SCluster() ||
87 e->Trk() == CleanElectronsVector[j]->Trk())
88 isElectronOverlap = true;
89
90 double deltaR = MathUtils::DeltaR(CleanElectronsVector[j]->Mom(), e->Mom());
91 if (deltaR < 0.1)
92 isElectronOverlap = true;
93
94 if (isElectronOverlap) {
95 if (abs(CleanElectronsVector[j]->ESuperClusterOverP() - 1) >
96 abs(e->ESuperClusterOverP() - 1)) {
97 CleanElectronsVector[j] = e;
98 }
99 break;
100 }
101 }
102 //If no overlaps then add to clean electrons
103 if ( !isMuonOverlap && !isElectronOverlap ) {
104 CleanElectronsVector.push_back(GoodElectrons->At(i));
105 }
106 }
107
108 //fill the electron ObjArray with the contents of the vector
109 //this is necessary because I want to swap out the duplicates, can't be done with ObjArray...
110 ObjArray<Electron> *CleanElectrons = new ObjArray<Electron>;
111 for (UInt_t j=0; j<CleanElectronsVector.size(); j++)
112 CleanElectrons->Add(CleanElectronsVector[j]);
113
114 //Final Summary Debug Output
115 if ( fPrintDebug ) {
116 cerr << "Event Dump: " << fNEventsProcessed << endl;
117
118 //print out event content to text
119 cerr << "Clean Electrons" << endl;
120 for (UInt_t i = 0; i < CleanElectrons->GetEntries(); i++) {
121 cerr << i << " " << CleanElectrons->At(i)->Pt() << " " << CleanElectrons->At(i)->Eta()
122 << " " << CleanElectrons->At(i)->Phi() << " "
123 << CleanElectrons->At(i)->ESuperClusterOverP() << endl;
124 }
125 }
126
127 //Save Objects for Other Modules to use
128 AddObjThisEvt(CleanElectrons, fCleanElectronsName.Data());
129 }
130
131
132 //--------------------------------------------------------------------------------------------------
133 void ElectronCleaningMod::SlaveBegin()
134 {
135 // Run startup code on the computer (slave) doing the actual analysis. Here,
136 // we typically initialize histograms and other analysis objects and request
137 // branches. For this module, we request a branch of the MitTree.
138
139 }
140
141 //--------------------------------------------------------------------------------------------------
142 void ElectronCleaningMod::SlaveTerminate()
143 {
144 // Run finishing code on the computer (slave) that did the analysis. For this
145 // module, we dont do anything here.
146
147 }
148
149 //--------------------------------------------------------------------------------------------------
150 void ElectronCleaningMod::Terminate()
151 {
152 // Run finishing code on the client computer. For this module, we dont do
153 // anything here.
154 }