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

# User Rev Content
1 sixie 1.12 // $Id: ElectronCleaningMod.cc,v 1.11 2011/03/27 17:05:55 ceballos Exp $
2 loizides 1.1
3     #include "MitPhysics/Mods/interface/ElectronCleaningMod.h"
4 loizides 1.3 #include "MitCommon/MathTools/interface/MathUtils.h"
5 loizides 1.9 #include "MitAna/DataTree/interface/ElectronCol.h"
6     #include "MitAna/DataTree/interface/MuonCol.h"
7     #include "MitAna/DataTree/interface/Track.h"
8 loizides 1.3 #include "MitPhysics/Init/interface/ModNames.h"
9 loizides 1.1
10     using namespace mithep;
11    
12     ClassImp(mithep::ElectronCleaningMod)
13    
14     //--------------------------------------------------------------------------------------------------
15 loizides 1.4 ElectronCleaningMod::ElectronCleaningMod(const char *name, const char *title) :
16 loizides 1.1 BaseMod(name,title),
17 loizides 1.3 fGoodElectronsName(ModNames::gkGoodElectronsName),
18     fCleanMuonsName(ModNames::gkCleanMuonsName),
19 loizides 1.4 fCleanElectronsName(ModNames::gkCleanElectronsName)
20 loizides 1.1 {
21     // Constructor.
22     }
23    
24     //--------------------------------------------------------------------------------------------------
25     void ElectronCleaningMod::Process()
26     {
27 loizides 1.4 // Process entries of the tree.
28 loizides 1.1
29 loizides 1.4 // get input collection
30 loizides 1.7 const MuonCol *CleanMuons = GetObjThisEvt<MuonCol>(fCleanMuonsName);
31     const ElectronCol *GoodElectrons = GetObjThisEvt<ElectronCol>(fGoodElectronsName);
32 loizides 1.1
33 loizides 1.4 // Go through all electrons and remove electron overlaps with muons and duplicates.
34     std::vector<const Electron*> CleanElTemp;
35 loizides 1.1
36 sixie 1.12 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 loizides 1.4 }
57 sixie 1.12
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 loizides 1.1 }
87    
88 sixie 1.12 if (isElectronOverlap)
89     continue;
90 loizides 1.1
91 sixie 1.12 // 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 loizides 1.1
98 loizides 1.4 // Fill the electron array with the contents of the vector:
99     ElectronOArr *CleanElectrons = new ElectronOArr;
100     CleanElectrons->SetName(fCleanElectronsName);
101 loizides 1.1
102 loizides 1.4 for (UInt_t j=0; j<CleanElTemp.size(); ++j)
103     CleanElectrons->Add(CleanElTemp[j]);
104 loizides 1.6 CleanElectrons->Sort();
105 loizides 1.4
106     // add to event for other modules to use
107     AddObjThisEvt(CleanElectrons);
108 loizides 1.1 }