ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronCleaningMod.cc
Revision: 1.3
Committed: Thu Nov 27 16:30:27 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.2: +7 -8 lines
Log Message:
Cleaning up. Not finished yet.

File Contents

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