1 |
// $Id: MuonIDMod.cc,v 1.29 2010/05/21 05:59:55 ceballos Exp $
|
2 |
|
3 |
#include "MitPhysics/Mods/interface/MuonIDMod.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 |
|
11 |
ClassImp(mithep::MuonIDMod)
|
12 |
|
13 |
//--------------------------------------------------------------------------------------------------
|
14 |
MuonIDMod::MuonIDMod(const char *name, const char *title) :
|
15 |
BaseMod(name,title),
|
16 |
fMuonBranchName(Names::gkMuonBrn),
|
17 |
fCleanMuonsName(ModNames::gkCleanMuonsName),
|
18 |
fVertexName("PrimaryVertexes"),
|
19 |
fMuonIDType("Minimal"),
|
20 |
fMuonIsoType("TrackCaloSliding"),
|
21 |
fMuonClassType("Global"),
|
22 |
fTrackIsolationCut(3.0),
|
23 |
fCaloIsolationCut(3.0),
|
24 |
fCombIsolationCut(5.0),
|
25 |
fMuonPtMin(10),
|
26 |
fApplyD0Cut(kTRUE),
|
27 |
fD0Cut(0.020),
|
28 |
fEtaCut(2.4),
|
29 |
fReverseIsoCut(kFALSE),
|
30 |
fReverseD0Cut(kFALSE),
|
31 |
fMuIDType(kIdUndef),
|
32 |
fMuIsoType(kIsoUndef),
|
33 |
fMuClassType(kClassUndef),
|
34 |
fMuons(0),
|
35 |
fVertices(0),
|
36 |
fMuonTools(0)
|
37 |
{
|
38 |
// Constructor.
|
39 |
}
|
40 |
|
41 |
//--------------------------------------------------------------------------------------------------
|
42 |
void MuonIDMod::Process()
|
43 |
{
|
44 |
// Process entries of the tree.
|
45 |
|
46 |
LoadEventObject(fMuonBranchName, fMuons);
|
47 |
if (fApplyD0Cut) {
|
48 |
LoadEventObject(fVertexName, fVertices);
|
49 |
}
|
50 |
|
51 |
MuonOArr *CleanMuons = new MuonOArr;
|
52 |
CleanMuons->SetName(fCleanMuonsName);
|
53 |
|
54 |
for (UInt_t i=0; i<fMuons->GetEntries(); ++i) {
|
55 |
const Muon *mu = fMuons->At(i);
|
56 |
|
57 |
Bool_t pass = kFALSE;
|
58 |
Double_t pt = 0; // make sure pt is taken from the correct track!
|
59 |
Double_t eta = 0; // make sure eta is taken from the correct track!
|
60 |
switch (fMuClassType) {
|
61 |
case kAll:
|
62 |
pass = kTRUE;
|
63 |
if (mu->HasTrk()) {
|
64 |
pt = mu->Pt();
|
65 |
eta = TMath::Abs(mu->Eta());
|
66 |
}
|
67 |
break;
|
68 |
case kGlobal:
|
69 |
pass = mu->HasGlobalTrk() && mu->IsTrackerMuon() &&
|
70 |
mu->Quality().Quality(MuonQuality::TrackerMuonArbitrated);
|
71 |
if (pass) {
|
72 |
pt = mu->TrackerTrk()->Pt();
|
73 |
eta = TMath::Abs(mu->TrackerTrk()->Eta());
|
74 |
}
|
75 |
break;
|
76 |
case kSta:
|
77 |
pass = mu->HasStandaloneTrk();
|
78 |
if (pass) {
|
79 |
pt = mu->StandaloneTrk()->Pt();
|
80 |
eta = TMath::Abs(mu->StandaloneTrk()->Eta());
|
81 |
}
|
82 |
break;
|
83 |
case kTrackerMuon:
|
84 |
pass = mu->HasTrackerTrk() && mu->IsTrackerMuon() &&
|
85 |
mu->Quality().Quality(MuonQuality::TrackerMuonArbitrated);
|
86 |
if (pass) {
|
87 |
pt = mu->TrackerTrk()->Pt();
|
88 |
eta = TMath::Abs(mu->TrackerTrk()->Eta());
|
89 |
}
|
90 |
break;
|
91 |
case kCaloMuon:
|
92 |
pass = mu->HasTrackerTrk() && mu->IsCaloMuon();
|
93 |
if (pass) {
|
94 |
pt = mu->TrackerTrk()->Pt();
|
95 |
eta = TMath::Abs(mu->TrackerTrk()->Eta());
|
96 |
}
|
97 |
break;
|
98 |
case kTrackerBased:
|
99 |
pass = mu->HasTrackerTrk();
|
100 |
if (pass) {
|
101 |
pt = mu->TrackerTrk()->Pt();
|
102 |
eta = TMath::Abs(mu->TrackerTrk()->Eta());
|
103 |
}
|
104 |
break;
|
105 |
default:
|
106 |
break;
|
107 |
}
|
108 |
|
109 |
if (!pass)
|
110 |
continue;
|
111 |
|
112 |
if (pt <= fMuonPtMin)
|
113 |
continue;
|
114 |
|
115 |
if (eta >= fEtaCut)
|
116 |
continue;
|
117 |
|
118 |
Bool_t idpass = kFALSE;
|
119 |
switch (fMuIDType) {
|
120 |
case kLoose:
|
121 |
idpass = mu->Quality().Quality(MuonQuality::TMOneStationLoose) &&
|
122 |
mu->Quality().Quality(MuonQuality::TM2DCompatibilityLoose) &&
|
123 |
mu->BestTrk()->NHits() > 10 &&
|
124 |
mu->BestTrk()->Chi2()/mu->BestTrk()->Ndof() < 10 &&
|
125 |
mu->NSegments() > 0 &&
|
126 |
mu->Quality().Quality(MuonQuality::GlobalMuonPromptTight);
|
127 |
break;
|
128 |
case kTight:
|
129 |
idpass = mu->Quality().Quality(MuonQuality::TMOneStationTight) &&
|
130 |
mu->Quality().Quality(MuonQuality::TM2DCompatibilityTight) &&
|
131 |
mu->BestTrk()->NHits() > 10 &&
|
132 |
mu->BestTrk()->Chi2()/mu->BestTrk()->Ndof() < 10 &&
|
133 |
mu->NSegments() > 0 &&
|
134 |
mu->Quality().Quality(MuonQuality::GlobalMuonPromptTight);
|
135 |
break;
|
136 |
case kMinimal:
|
137 |
idpass = mu->BestTrk()->NHits() > 10 &&
|
138 |
mu->BestTrk()->Chi2()/mu->BestTrk()->Ndof() < 10 &&
|
139 |
mu->NSegments() > 0 &&
|
140 |
mu->Quality().Quality(MuonQuality::GlobalMuonPromptTight);
|
141 |
break;
|
142 |
case kNoId:
|
143 |
idpass = kTRUE;
|
144 |
break;
|
145 |
default:
|
146 |
break;
|
147 |
}
|
148 |
|
149 |
if (!idpass)
|
150 |
continue;
|
151 |
|
152 |
Bool_t isocut = kFALSE;
|
153 |
switch (fMuIsoType) {
|
154 |
case kTrackCalo:
|
155 |
isocut = (mu->IsoR03SumPt() < fTrackIsolationCut) &&
|
156 |
(mu->IsoR03EmEt() + mu->IsoR03HadEt() < fCaloIsolationCut);
|
157 |
break;
|
158 |
case kTrackCaloCombined:
|
159 |
isocut = (1.0 * mu->IsoR03SumPt() + 1.0 * mu->IsoR03EmEt() +
|
160 |
1.0 * mu->IsoR03HadEt() < fCombIsolationCut);
|
161 |
break;
|
162 |
case kTrackCaloSliding:
|
163 |
{
|
164 |
Double_t totalIso = 1.0 * mu->IsoR03SumPt() +
|
165 |
1.0 * mu->IsoR03EmEt() +
|
166 |
1.0 * mu->IsoR03HadEt();
|
167 |
if (totalIso < (mu->Pt()*0.15) )
|
168 |
isocut = kTRUE;
|
169 |
|
170 |
if (fReverseIsoCut == kTRUE &&
|
171 |
isocut == kFALSE && totalIso < 10)
|
172 |
isocut = kTRUE;
|
173 |
else if(fReverseIsoCut == kTRUE)
|
174 |
isocut = kFALSE;
|
175 |
}
|
176 |
break;
|
177 |
case kNoIso:
|
178 |
isocut = kTRUE;
|
179 |
break;
|
180 |
case kCustomIso:
|
181 |
default:
|
182 |
break;
|
183 |
}
|
184 |
|
185 |
if (isocut == kFALSE)
|
186 |
continue;
|
187 |
|
188 |
if (fApplyD0Cut) {
|
189 |
Bool_t d0cut = kFALSE;
|
190 |
const Track *mt = mu->BestTrk();
|
191 |
if (!mt)
|
192 |
continue;
|
193 |
Double_t d0_real = 1e30;
|
194 |
for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
|
195 |
Double_t pD0 = mt->D0Corrected(*fVertices->At(i0));
|
196 |
if(TMath::Abs(pD0) < TMath::Abs(d0_real))
|
197 |
d0_real = TMath::Abs(pD0);
|
198 |
}
|
199 |
if(d0_real < fD0Cut) d0cut = kTRUE;
|
200 |
|
201 |
if (fReverseD0Cut == kTRUE &&
|
202 |
d0cut == kFALSE && d0_real < 0.05)
|
203 |
d0cut = kTRUE;
|
204 |
else if(fReverseD0Cut == kTRUE)
|
205 |
d0cut = kFALSE;
|
206 |
|
207 |
if (d0cut == kFALSE)
|
208 |
continue;
|
209 |
}
|
210 |
|
211 |
// add good muon
|
212 |
CleanMuons->Add(mu);
|
213 |
}
|
214 |
|
215 |
// sort according to pt
|
216 |
CleanMuons->Sort();
|
217 |
|
218 |
// add objects for other modules to use
|
219 |
AddObjThisEvt(CleanMuons);
|
220 |
}
|
221 |
|
222 |
//--------------------------------------------------------------------------------------------------
|
223 |
void MuonIDMod::SlaveBegin()
|
224 |
{
|
225 |
// Run startup code on the computer (slave) doing the actual analysis. Here,
|
226 |
// we just request the muon collection branch.
|
227 |
|
228 |
ReqEventObject(fMuonBranchName, fMuons, kTRUE);
|
229 |
|
230 |
if (fApplyD0Cut)
|
231 |
ReqEventObject(fVertexName, fVertices, kTRUE);
|
232 |
|
233 |
fMuonTools = new MuonTools;
|
234 |
|
235 |
if (fMuonIDType.CompareTo("Tight") == 0)
|
236 |
fMuIDType = kTight;
|
237 |
else if (fMuonIDType.CompareTo("Loose") == 0)
|
238 |
fMuIDType = kLoose;
|
239 |
else if (fMuonIDType.CompareTo("Minimal") == 0)
|
240 |
fMuIDType = kMinimal;
|
241 |
else if (fMuonIDType.CompareTo("NoId") == 0)
|
242 |
fMuIDType = kNoId;
|
243 |
else if (fMuonIDType.CompareTo("Custom") == 0) {
|
244 |
fMuIDType = kCustomId;
|
245 |
SendError(kWarning, "SlaveBegin",
|
246 |
"Custom muon identification is not yet implemented.");
|
247 |
} else {
|
248 |
SendError(kAbortAnalysis, "SlaveBegin",
|
249 |
"The specified muon identification %s is not defined.",
|
250 |
fMuonIDType.Data());
|
251 |
return;
|
252 |
}
|
253 |
|
254 |
if (fMuonIsoType.CompareTo("TrackCalo") == 0)
|
255 |
fMuIsoType = kTrackCalo;
|
256 |
else if (fMuonIsoType.CompareTo("TrackCaloCombined") == 0)
|
257 |
fMuIsoType = kTrackCaloCombined;
|
258 |
else if (fMuonIsoType.CompareTo("TrackCaloSliding") == 0)
|
259 |
fMuIsoType = kTrackCaloSliding;
|
260 |
else if (fMuonIsoType.CompareTo("NoIso") == 0)
|
261 |
fMuIsoType = kNoIso;
|
262 |
else if (fMuonIsoType.CompareTo("Custom") == 0) {
|
263 |
fMuIsoType = kCustomIso;
|
264 |
SendError(kWarning, "SlaveBegin",
|
265 |
"Custom muon isolation is not yet implemented.");
|
266 |
} else {
|
267 |
SendError(kAbortAnalysis, "SlaveBegin",
|
268 |
"The specified muon isolation %s is not defined.",
|
269 |
fMuonIsoType.Data());
|
270 |
return;
|
271 |
}
|
272 |
|
273 |
if (fMuonClassType.CompareTo("All") == 0)
|
274 |
fMuClassType = kAll;
|
275 |
else if (fMuonClassType.CompareTo("Global") == 0)
|
276 |
fMuClassType = kGlobal;
|
277 |
else if (fMuonClassType.CompareTo("Standalone") == 0)
|
278 |
fMuClassType = kSta;
|
279 |
else if (fMuonClassType.CompareTo("TrackerMuon") == 0)
|
280 |
fMuClassType = kTrackerMuon;
|
281 |
else if (fMuonClassType.CompareTo("CaloMuon") == 0)
|
282 |
fMuClassType = kCaloMuon;
|
283 |
else if (fMuonClassType.CompareTo("TrackerBased") == 0)
|
284 |
fMuClassType = kTrackerBased;
|
285 |
else {
|
286 |
SendError(kAbortAnalysis, "SlaveBegin",
|
287 |
"The specified muon class %s is not defined.",
|
288 |
fMuonClassType.Data());
|
289 |
return;
|
290 |
}
|
291 |
}
|