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