1 |
|
// $Id$ |
2 |
|
|
3 |
|
#include "MitPhysics/Mods/interface/MuonIDMod.h" |
4 |
– |
#include "MitAna/DataTree/interface/Names.h" |
5 |
– |
#include "MitAna/DataCont/interface/ObjArray.h" |
6 |
– |
#include "MitPhysics/Utils/interface/IsolationTools.h" |
4 |
|
#include "MitCommon/MathTools/interface/MathUtils.h" |
5 |
+ |
#include "MitPhysics/Init/interface/ModNames.h" |
6 |
|
|
7 |
|
using namespace mithep; |
8 |
|
|
11 |
|
//-------------------------------------------------------------------------------------------------- |
12 |
|
MuonIDMod::MuonIDMod(const char *name, const char *title) : |
13 |
|
BaseMod(name,title), |
14 |
< |
fPrintDebug(false), |
15 |
< |
fMuonName(Names::gkMuonBrn), |
16 |
< |
fCleanMuonsName(Names::gkCleanMuonsName), |
17 |
< |
fMuons(0), |
14 |
> |
fMuonBranchName(Names::gkMuonBrn), |
15 |
> |
fCleanMuonsName(ModNames::gkCleanMuonsName), |
16 |
> |
fVertexName("PrimaryVertexesBeamSpot"), |
17 |
> |
fMuonIDType("Loose"), |
18 |
> |
fMuonIsoType("TrackCaloSliding"), |
19 |
> |
fMuonClassType("Global"), |
20 |
|
fTrackIsolationCut(3.0), |
21 |
|
fCaloIsolationCut(3.0), |
22 |
< |
fCombIsolationCut(-1.0), |
23 |
< |
fTMOneStationLooseCut(true), |
24 |
< |
fTMOneStationTightCut (false), |
25 |
< |
fTM2DCompatibilityLooseCut(true), |
26 |
< |
fTM2DCompatibilityTightCut(false), |
27 |
< |
fMuonSlidingIso(true), |
22 |
> |
fCombIsolationCut(5.0), |
23 |
|
fMuonPtMin(10), |
24 |
< |
fNEventsProcessed(0) |
24 |
> |
fApplyD0Cut(kTRUE), |
25 |
> |
fD0Cut(0.025), |
26 |
> |
fReverseIsoCut(kFALSE), |
27 |
> |
fReverseD0Cut(kFALSE), |
28 |
> |
fMuIDType(kIdUndef), |
29 |
> |
fMuIsoType(kIsoUndef), |
30 |
> |
fMuClassType(kClassUndef), |
31 |
> |
fMuons(0), |
32 |
> |
fVertices(0), |
33 |
> |
fMuonTools(0) |
34 |
|
{ |
35 |
|
// Constructor. |
36 |
|
} |
37 |
|
|
38 |
|
//-------------------------------------------------------------------------------------------------- |
35 |
– |
void MuonIDMod::Begin() |
36 |
– |
{ |
37 |
– |
// Run startup code on the client machine. For this module, we dont do |
38 |
– |
// anything here. |
39 |
– |
} |
40 |
– |
|
41 |
– |
//-------------------------------------------------------------------------------------------------- |
39 |
|
void MuonIDMod::Process() |
40 |
|
{ |
41 |
|
// Process entries of the tree. |
42 |
|
|
43 |
< |
fNEventsProcessed++; |
44 |
< |
|
45 |
< |
if (fNEventsProcessed % 1000000 == 0 || fPrintDebug) { |
46 |
< |
time_t systime; |
47 |
< |
systime = time(NULL); |
48 |
< |
|
52 |
< |
cerr << endl << "MuonIDMod : Process Event " << fNEventsProcessed << " Time: " << ctime(&systime) << endl; |
53 |
< |
} |
54 |
< |
|
55 |
< |
//Get Muons |
56 |
< |
LoadBranch(fMuonName); |
57 |
< |
ObjArray<Muon> *CleanMuons = new ObjArray<Muon>; |
43 |
> |
LoadEventObject(fMuonBranchName, fMuons); |
44 |
> |
LoadEventObject(fVertexName, fVertices); |
45 |
> |
|
46 |
> |
MuonOArr *CleanMuons = new MuonOArr; |
47 |
> |
CleanMuons->SetName(fCleanMuonsName); |
48 |
> |
|
49 |
|
for (UInt_t i=0; i<fMuons->GetEntries(); ++i) { |
50 |
< |
Muon *mu = fMuons->At(i); |
51 |
< |
|
52 |
< |
Double_t MuonClass = -1; |
53 |
< |
if (mu->GlobalTrk()) |
54 |
< |
MuonClass = 0; |
55 |
< |
else if (mu->StandaloneTrk()) |
56 |
< |
MuonClass = 1; |
57 |
< |
else if (mu->TrackerTrk()) |
58 |
< |
MuonClass = 2; |
59 |
< |
|
60 |
< |
bool allCuts = false; |
61 |
< |
|
62 |
< |
// We always want global muons |
63 |
< |
if(MuonClass == 0) allCuts = true; |
64 |
< |
|
65 |
< |
// Isolation requirements |
66 |
< |
if(fMuonSlidingIso == true){ // Fix version |
67 |
< |
double totalIso = 1.0 * mu->IsoR03SumPt() + |
68 |
< |
1.0 * mu->IsoR03EmEt() + |
69 |
< |
1.0 * mu->IsoR03HadEt(); |
70 |
< |
bool theIso = false; |
71 |
< |
if((totalIso < (mu->Pt()-10.0)*5.0/15.0) || |
72 |
< |
(totalIso < 5.0 && mu->Pt() > 25)) theIso = true; |
73 |
< |
if(theIso == false) allCuts = false; |
50 |
> |
const Muon *mu = fMuons->At(i); |
51 |
> |
|
52 |
> |
Bool_t pass = kFALSE; |
53 |
> |
Double_t pt = 0; // make sure pt is taken from the correct track! |
54 |
> |
switch (fMuClassType) { |
55 |
> |
case kAll: |
56 |
> |
pass = kTRUE; |
57 |
> |
if (mu->HasTrk()) |
58 |
> |
pt = mu->Pt(); |
59 |
> |
break; |
60 |
> |
case kGlobal: |
61 |
> |
pass = mu->HasGlobalTrk(); |
62 |
> |
if (pass) |
63 |
> |
pt = mu->GlobalTrk()->Pt(); |
64 |
> |
break; |
65 |
> |
case kSta: |
66 |
> |
pass = mu->HasStandaloneTrk(); |
67 |
> |
if (pass) |
68 |
> |
pt = mu->StandaloneTrk()->Pt(); |
69 |
> |
break; |
70 |
> |
case kTrackerOnly: |
71 |
> |
pass = mu->HasTrackerTrk(); |
72 |
> |
if (pass) |
73 |
> |
pt = mu->TrackerTrk()->Pt(); |
74 |
> |
break; |
75 |
> |
default: |
76 |
> |
break; |
77 |
|
} |
78 |
< |
else if(fCombIsolationCut < 0.0){ // Different tracker and Cal iso |
79 |
< |
if(mu->IsoR03SumPt() >= fTrackIsolationCut) allCuts = false; |
80 |
< |
if(mu->IsoR03EmEt() + |
81 |
< |
mu->IsoR03HadEt() >= fCaloIsolationCut) allCuts = false; |
78 |
> |
|
79 |
> |
if (!pass) |
80 |
> |
continue; |
81 |
> |
|
82 |
> |
if (pt <= fMuonPtMin) |
83 |
> |
continue; |
84 |
> |
|
85 |
> |
Bool_t idpass = kFALSE; |
86 |
> |
switch (fMuIDType) { |
87 |
> |
case kLoose: |
88 |
> |
idpass = fMuonTools->IsGood(mu, MuonTools::kTMOneStationLoose) && |
89 |
> |
fMuonTools->IsGood(mu, MuonTools::kTM2DCompatibilityLoose); |
90 |
> |
break; |
91 |
> |
case kTight: |
92 |
> |
idpass = fMuonTools->IsGood(mu, MuonTools::kTMOneStationTight) && |
93 |
> |
fMuonTools->IsGood(mu, MuonTools::kTM2DCompatibilityTight); |
94 |
> |
break; |
95 |
> |
case kNoId: |
96 |
> |
idpass = kTRUE; |
97 |
> |
break; |
98 |
> |
default: |
99 |
> |
break; |
100 |
|
} |
101 |
< |
else { // Combined iso |
102 |
< |
if(1.0 * mu->IsoR03SumPt() + |
103 |
< |
1.0 * mu->IsoR03EmEt() + |
104 |
< |
1.0 * mu->IsoR03HadEt() >= fCombIsolationCut) allCuts = false; |
101 |
> |
|
102 |
> |
if (!idpass) |
103 |
> |
continue; |
104 |
> |
|
105 |
> |
Bool_t isocut = kFALSE; |
106 |
> |
switch (fMuIsoType) { |
107 |
> |
case kTrackCalo: |
108 |
> |
isocut = (mu->IsoR03SumPt() < fTrackIsolationCut) && |
109 |
> |
(mu->IsoR03EmEt() + mu->IsoR03HadEt() < fCaloIsolationCut); |
110 |
> |
break; |
111 |
> |
case kTrackCaloCombined: |
112 |
> |
isocut = (1.0 * mu->IsoR03SumPt() + 1.0 * mu->IsoR03EmEt() + |
113 |
> |
1.0 * mu->IsoR03HadEt() < fCombIsolationCut); |
114 |
> |
break; |
115 |
> |
case kTrackCaloSliding: |
116 |
> |
{ |
117 |
> |
Double_t totalIso = 1.0 * mu->IsoR03SumPt() + |
118 |
> |
1.0 * mu->IsoR03EmEt() + |
119 |
> |
1.0 * mu->IsoR03HadEt(); |
120 |
> |
if ((totalIso < (pt-10.0)*5.0/15.0 && pt <= 25) || |
121 |
> |
(totalIso < 5.0 && mu->Pt() > 25) || |
122 |
> |
totalIso <= 0) |
123 |
> |
isocut = kTRUE; |
124 |
> |
|
125 |
> |
if (fReverseIsoCut == kTRUE && |
126 |
> |
isocut == kFALSE && totalIso < 10) |
127 |
> |
isocut = kTRUE; |
128 |
> |
else if(fReverseIsoCut == kTRUE) |
129 |
> |
isocut = kFALSE; |
130 |
> |
} |
131 |
> |
break; |
132 |
> |
case kNoIso: |
133 |
> |
isocut = kTRUE; |
134 |
> |
break; |
135 |
> |
case kCustomIso: |
136 |
> |
default: |
137 |
> |
break; |
138 |
|
} |
139 |
|
|
140 |
< |
// Muon chambers and calo compatibility requirements |
141 |
< |
if(fTMOneStationLooseCut == true && |
142 |
< |
myMuonTools.isGood(mu, MuonTools::TMOneStationLoose) == false) |
143 |
< |
allCuts = false; |
144 |
< |
|
145 |
< |
if(fTMOneStationTightCut == true && |
146 |
< |
myMuonTools.isGood(mu, MuonTools::TMOneStationTight) == false) |
147 |
< |
allCuts = false; |
148 |
< |
|
149 |
< |
if(fTM2DCompatibilityLooseCut == true && |
150 |
< |
myMuonTools.isGood(mu, MuonTools::TM2DCompatibilityLoose) == false) |
151 |
< |
allCuts = false; |
152 |
< |
|
153 |
< |
if(fTM2DCompatibilityTightCut == true && |
154 |
< |
myMuonTools.isGood(mu, MuonTools::TM2DCompatibilityTight) == false) |
155 |
< |
allCuts = false; |
156 |
< |
|
157 |
< |
// Min Pt requirement |
158 |
< |
if(mu->Pt() <= fMuonPtMin) allCuts = false; |
159 |
< |
|
160 |
< |
if(allCuts) { |
161 |
< |
CleanMuons->Add(mu); |
140 |
> |
if (isocut == kFALSE) |
141 |
> |
continue; |
142 |
> |
|
143 |
> |
if (fApplyD0Cut) { |
144 |
> |
Bool_t d0cut = kFALSE; |
145 |
> |
const Track *mt = mu->BestTrk(); |
146 |
> |
if (!mt) |
147 |
> |
continue; |
148 |
> |
Double_t d0_real = 1e30; |
149 |
> |
for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) { |
150 |
> |
Double_t pD0 = mt->D0Corrected(*fVertices->At(i0)); |
151 |
> |
if(TMath::Abs(pD0) < TMath::Abs(d0_real)) |
152 |
> |
d0_real = TMath::Abs(pD0); |
153 |
> |
} |
154 |
> |
if(d0_real < fD0Cut) d0cut = kTRUE; |
155 |
> |
|
156 |
> |
if (fReverseD0Cut == kTRUE && |
157 |
> |
d0cut == kFALSE && d0_real < 0.05) |
158 |
> |
d0cut = kTRUE; |
159 |
> |
else if(fReverseD0Cut == kTRUE) |
160 |
> |
d0cut = kFALSE; |
161 |
> |
|
162 |
> |
if (d0cut == kFALSE) |
163 |
> |
continue; |
164 |
|
} |
165 |
+ |
|
166 |
+ |
// add good muon |
167 |
+ |
CleanMuons->Add(mu); |
168 |
|
} |
169 |
|
|
170 |
< |
//Final Summary Debug Output |
171 |
< |
if ( fPrintDebug ) { |
122 |
< |
cerr << "Event Dump: " << fNEventsProcessed << endl; |
123 |
< |
cerr << "Muons" << endl; |
124 |
< |
for (UInt_t i = 0; i < CleanMuons->GetEntries(); i++) { |
125 |
< |
cerr << i << " " << CleanMuons->At(i)->Pt() << " " << CleanMuons->At(i)->Eta() |
126 |
< |
<< " " << CleanMuons->At(i)->Phi() << endl; |
127 |
< |
} |
128 |
< |
} |
129 |
< |
|
130 |
< |
//Save Objects for Other Modules to use |
131 |
< |
AddObjThisEvt(CleanMuons, fCleanMuonsName.Data()); |
132 |
< |
} |
170 |
> |
// sort according to pt |
171 |
> |
CleanMuons->Sort(); |
172 |
|
|
173 |
+ |
// add objects for other modules to use |
174 |
+ |
AddObjThisEvt(CleanMuons); |
175 |
+ |
} |
176 |
|
|
177 |
|
//-------------------------------------------------------------------------------------------------- |
178 |
|
void MuonIDMod::SlaveBegin() |
179 |
|
{ |
180 |
|
// Run startup code on the computer (slave) doing the actual analysis. Here, |
181 |
< |
// we typically initialize histograms and other analysis objects and request |
140 |
< |
// branches. For this module, we request a branch of the MitTree. |
181 |
> |
// we just request the muon collection branch. |
182 |
|
|
183 |
< |
ReqBranch(fMuonName, fMuons); |
143 |
< |
} |
183 |
> |
ReqEventObject(fMuonBranchName, fMuons, kTRUE); |
184 |
|
|
185 |
< |
//-------------------------------------------------------------------------------------------------- |
186 |
< |
void MuonIDMod::SlaveTerminate() |
147 |
< |
{ |
148 |
< |
// Run finishing code on the computer (slave) that did the analysis. For this |
149 |
< |
// module, we dont do anything here. |
185 |
> |
if (fApplyD0Cut) |
186 |
> |
ReqEventObject(fVertexName, fVertices, kTRUE); |
187 |
|
|
188 |
< |
} |
188 |
> |
fMuonTools = new MuonTools; |
189 |
|
|
190 |
< |
//-------------------------------------------------------------------------------------------------- |
191 |
< |
void MuonIDMod::Terminate() |
192 |
< |
{ |
193 |
< |
// Run finishing code on the client computer. For this module, we dont do |
194 |
< |
// anything here. |
190 |
> |
if (fMuonIDType.CompareTo("Tight") == 0) |
191 |
> |
fMuIDType = kTight; |
192 |
> |
else if (fMuonIDType.CompareTo("Loose") == 0) |
193 |
> |
fMuIDType = kLoose; |
194 |
> |
else if (fMuonIDType.CompareTo("NoId") == 0) |
195 |
> |
fMuIDType = kNoId; |
196 |
> |
else if (fMuonIDType.CompareTo("Custom") == 0) { |
197 |
> |
fMuIDType = kCustomId; |
198 |
> |
SendError(kWarning, "SlaveBegin", |
199 |
> |
"Custom muon identification is not yet implemented."); |
200 |
> |
} else { |
201 |
> |
SendError(kAbortAnalysis, "SlaveBegin", |
202 |
> |
"The specified muon identification %s is not defined.", |
203 |
> |
fMuonIDType.Data()); |
204 |
> |
return; |
205 |
> |
} |
206 |
> |
|
207 |
> |
if (fMuonIsoType.CompareTo("TrackCalo") == 0) |
208 |
> |
fMuIsoType = kTrackCalo; |
209 |
> |
else if (fMuonIsoType.CompareTo("TrackCaloCombined") == 0) |
210 |
> |
fMuIsoType = kTrackCaloCombined; |
211 |
> |
else if (fMuonIsoType.CompareTo("TrackCaloSliding") == 0) |
212 |
> |
fMuIsoType = kTrackCaloSliding; |
213 |
> |
else if (fMuonIsoType.CompareTo("NoIso") == 0) |
214 |
> |
fMuIsoType = kNoIso; |
215 |
> |
else if (fMuonIsoType.CompareTo("Custom") == 0) { |
216 |
> |
fMuIsoType = kCustomIso; |
217 |
> |
SendError(kWarning, "SlaveBegin", |
218 |
> |
"Custom muon isolation is not yet implemented."); |
219 |
> |
} else { |
220 |
> |
SendError(kAbortAnalysis, "SlaveBegin", |
221 |
> |
"The specified muon isolation %s is not defined.", |
222 |
> |
fMuonIsoType.Data()); |
223 |
> |
return; |
224 |
> |
} |
225 |
> |
|
226 |
> |
if (fMuonClassType.CompareTo("All") == 0) |
227 |
> |
fMuClassType = kAll; |
228 |
> |
else if (fMuonClassType.CompareTo("Global") == 0) |
229 |
> |
fMuClassType = kGlobal; |
230 |
> |
else if (fMuonClassType.CompareTo("Standalone") == 0) |
231 |
> |
fMuClassType = kSta; |
232 |
> |
else if (fMuonClassType.CompareTo("TrackerOnly") == 0) |
233 |
> |
fMuClassType = kTrackerOnly; |
234 |
> |
else { |
235 |
> |
SendError(kAbortAnalysis, "SlaveBegin", |
236 |
> |
"The specified muon class %s is not defined.", |
237 |
> |
fMuonClassType.Data()); |
238 |
> |
return; |
239 |
> |
} |
240 |
|
} |