ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/ElectronCleaningMod.cc
Revision: 1.12
Committed: Sun Sep 25 18:52:01 2011 UTC (13 years, 7 months ago) by sixie
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a, Mit_028a, Mit_028, Mit_027, Mit_027a, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, HEAD
Changes since 1.11: +58 -49 lines
Log Message:
add null pointer protection

File Contents

# Content
1 // $Id: ElectronCleaningMod.cc,v 1.11 2011/03/27 17:05:55 ceballos Exp $
2
3 #include "MitPhysics/Mods/interface/ElectronCleaningMod.h"
4 #include "MitCommon/MathTools/interface/MathUtils.h"
5 #include "MitAna/DataTree/interface/ElectronCol.h"
6 #include "MitAna/DataTree/interface/MuonCol.h"
7 #include "MitAna/DataTree/interface/Track.h"
8 #include "MitPhysics/Init/interface/ModNames.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 fGoodElectronsName(ModNames::gkGoodElectronsName),
18 fCleanMuonsName(ModNames::gkCleanMuonsName),
19 fCleanElectronsName(ModNames::gkCleanElectronsName)
20 {
21 // Constructor.
22 }
23
24 //--------------------------------------------------------------------------------------------------
25 void ElectronCleaningMod::Process()
26 {
27 // Process entries of the tree.
28
29 // get input collection
30 const MuonCol *CleanMuons = GetObjThisEvt<MuonCol>(fCleanMuonsName);
31 const ElectronCol *GoodElectrons = GetObjThisEvt<ElectronCol>(fGoodElectronsName);
32
33 // Go through all electrons and remove electron overlaps with muons and duplicates.
34 std::vector<const Electron*> CleanElTemp;
35
36 if (GoodElectrons) {
37 for (UInt_t i=0; i<GoodElectrons->GetEntries(); ++i) {
38 const Electron *e = GoodElectrons->At(i);
39
40 FourVectorM mom(e->Mom());
41
42 // Check whether it overlaps with a good muon: If the muon and electron both have
43 // tracker tracks then compare the tracks, otherwise
44 Bool_t isMuonOverlap = kFALSE;
45 if (CleanMuons) {
46 UInt_t n = CleanMuons->GetEntries();
47 for (UInt_t j=0; j<n; ++j) {
48 Double_t deltaR = MathUtils::DeltaR(CleanMuons->At(j)->Mom(), mom);
49 if (deltaR < 0.1) {
50 isMuonOverlap = kTRUE;
51 break;
52 }
53 }
54 } else {
55 cout << "Warning: GoodMuons collection " << fCleanMuonsName << " was not found.\n";
56 }
57
58 if (isMuonOverlap)
59 continue;
60
61 // Check whether it overlaps with another electron candidate:
62 // Here I check whether we have two electron candidates with the same super cluster
63 // or two electron candidates with the same track. At the end we also check deltaR
64 // to be sure. If there is a duplicate we swap the old one with the new one if the new
65 // one has E/P closer to 1.0.
66 bool isElectronOverlap = kFALSE;
67 for (UInt_t j=0; j<CleanElTemp.size(); ++j) {
68
69 if (e->SCluster() == CleanElTemp[j]->SCluster() ||
70 e->Trk() == CleanElTemp[j]->Trk())
71 isElectronOverlap = kTRUE;
72
73 if (!isElectronOverlap) {
74 Double_t deltaR = MathUtils::DeltaR(CleanElTemp[j]->Mom(), mom);
75 if (deltaR < 0.1)
76 isElectronOverlap = kTRUE;
77 }
78
79 if (isElectronOverlap) {
80 if (TMath::Abs(CleanElTemp[j]->ESuperClusterOverP() - 1) >
81 TMath::Abs(e->ESuperClusterOverP() - 1)) {
82 CleanElTemp[j] = e;
83 }
84 break;
85 }
86 }
87
88 if (isElectronOverlap)
89 continue;
90
91 // if no overlaps then add to clean electrons
92 CleanElTemp.push_back(GoodElectrons->At(i));
93 }
94 } else {
95 cout << "Warning: GoodElectrons collection " << fGoodElectronsName << " was not found.\n";
96 }
97
98 // Fill the electron array with the contents of the vector:
99 ElectronOArr *CleanElectrons = new ElectronOArr;
100 CleanElectrons->SetName(fCleanElectronsName);
101
102 for (UInt_t j=0; j<CleanElTemp.size(); ++j)
103 CleanElectrons->Add(CleanElTemp[j]);
104 CleanElectrons->Sort();
105
106 // add to event for other modules to use
107 AddObjThisEvt(CleanElectrons);
108 }