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 |
< |
fMuonIDType("Tight"), |
18 |
< |
fMuonIsoType("TrackCalo"), |
19 |
< |
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 |
< |
fNEventsProcessed(0) |
22 |
> |
fCombIsolationCut(5.0), |
23 |
> |
fMuonPtMin(10), |
24 |
> |
fD0Cut(0.025), |
25 |
> |
fMuIDType(kIdUndef), |
26 |
> |
fMuIsoType(kIsoUndef), |
27 |
> |
fMuClassType(kClassUndef), |
28 |
> |
fMuons(0), |
29 |
> |
fVertices(0), |
30 |
> |
fMuonTools(0), |
31 |
> |
fReverseIsoCut(kFALSE) |
32 |
|
{ |
33 |
|
// Constructor. |
34 |
|
} |
35 |
|
|
36 |
|
//-------------------------------------------------------------------------------------------------- |
30 |
– |
void MuonIDMod::Begin() |
31 |
– |
{ |
32 |
– |
// Run startup code on the client machine. For this module, we dont do |
33 |
– |
// anything here. |
34 |
– |
} |
35 |
– |
|
36 |
– |
//-------------------------------------------------------------------------------------------------- |
37 |
|
void MuonIDMod::Process() |
38 |
|
{ |
39 |
|
// Process entries of the tree. |
40 |
|
|
41 |
< |
fNEventsProcessed++; |
42 |
< |
|
43 |
< |
if (fNEventsProcessed % 1000 == 0 || fPrintDebug) { |
44 |
< |
time_t systime; |
45 |
< |
systime = time(NULL); |
46 |
< |
|
47 |
< |
cerr << endl << "MuonIDMod : Process Event " << fNEventsProcessed << " Time: " << ctime(&systime) << endl; |
48 |
< |
} |
49 |
< |
|
50 |
< |
//Get Muons |
51 |
< |
LoadBranch(fMuonName); |
52 |
< |
ObjArray<Muon> *CleanMuons = new ObjArray<Muon>; |
41 |
> |
LoadBranch(fMuonBranchName); |
42 |
> |
LoadBranch(fVertexName); |
43 |
> |
|
44 |
> |
MuonOArr *CleanMuons = new MuonOArr; |
45 |
> |
CleanMuons->SetName(fCleanMuonsName); |
46 |
> |
|
47 |
|
for (UInt_t i=0; i<fMuons->GetEntries(); ++i) { |
48 |
< |
Muon *mu = fMuons->At(i); |
49 |
< |
|
50 |
< |
Double_t MuonClass = -1; |
51 |
< |
if (mu->GlobalTrk()) |
52 |
< |
MuonClass = 0; |
53 |
< |
else if (mu->StandaloneTrk()) |
54 |
< |
MuonClass = 1; |
55 |
< |
else if (mu->TrackerTrk()) |
56 |
< |
MuonClass = 2; |
57 |
< |
|
58 |
< |
//These cuts are from the 1.6.X analysis. I'm waiting for Phil to finalize his Muon ID class |
59 |
< |
const int nCuts = 4; |
60 |
< |
double cutValue[nCuts] = {0.2, fTrackIsolationCut, fCaloIsolationCut, 1.5 }; |
61 |
< |
bool passCut[nCuts] = {false, false, false, false}; |
62 |
< |
double muonD0 = fabs(mu->BestTrk()->D0()); |
63 |
< |
if(muonD0 < cutValue[0] && MuonClass == 0 ) |
64 |
< |
passCut[0] = true; |
65 |
< |
if(mu->IsoR03SumPt() < cutValue[1]) passCut[1] = true; |
66 |
< |
if(mu->IsoR03EmEt() + |
67 |
< |
mu->IsoR03HadEt() < cutValue[2]) passCut[2] = true; |
68 |
< |
if(mu->Pt() > 10) |
69 |
< |
passCut[3] = true; |
70 |
< |
|
71 |
< |
// Final decision |
72 |
< |
bool allCuts = true; |
73 |
< |
for(int c=0; c<nCuts; c++) { |
74 |
< |
allCuts = allCuts & passCut[c]; |
75 |
< |
} |
76 |
< |
|
77 |
< |
if ( allCuts |
78 |
< |
&& abs(mu->Eta()) < 2.5 |
79 |
< |
) { |
80 |
< |
CleanMuons->Add(mu); |
48 |
> |
const Muon *mu = fMuons->At(i); |
49 |
> |
|
50 |
> |
Bool_t pass = kFALSE; |
51 |
> |
Double_t pt = 0; // make sure pt is taken from the correct track! |
52 |
> |
switch (fMuClassType) { |
53 |
> |
case kAll: |
54 |
> |
pass = kTRUE; |
55 |
> |
if (mu->HasTrk()) |
56 |
> |
pt = mu->Pt(); |
57 |
> |
break; |
58 |
> |
case kGlobal: |
59 |
> |
pass = mu->HasGlobalTrk(); |
60 |
> |
if (pass) |
61 |
> |
pt = mu->GlobalTrk()->Pt(); |
62 |
> |
break; |
63 |
> |
case kSta: |
64 |
> |
pass = mu->HasStandaloneTrk(); |
65 |
> |
if (pass) |
66 |
> |
pt = mu->StandaloneTrk()->Pt(); |
67 |
> |
break; |
68 |
> |
case kTrackerOnly: |
69 |
> |
pass = mu->HasTrackerTrk(); |
70 |
> |
if (pass) |
71 |
> |
pt = mu->TrackerTrk()->Pt(); |
72 |
> |
break; |
73 |
> |
default: |
74 |
> |
break; |
75 |
> |
} |
76 |
> |
|
77 |
> |
if (!pass) |
78 |
> |
continue; |
79 |
> |
|
80 |
> |
if (pt <= fMuonPtMin) |
81 |
> |
continue; |
82 |
> |
|
83 |
> |
Bool_t idpass = kFALSE; |
84 |
> |
switch (fMuIDType) { |
85 |
> |
case kLoose: |
86 |
> |
idpass = fMuonTools->IsGood(mu, MuonTools::kTMOneStationLoose) && |
87 |
> |
fMuonTools->IsGood(mu, MuonTools::kTM2DCompatibilityLoose); |
88 |
> |
break; |
89 |
> |
case kTight: |
90 |
> |
idpass = fMuonTools->IsGood(mu, MuonTools::kTMOneStationTight) && |
91 |
> |
fMuonTools->IsGood(mu, MuonTools::kTM2DCompatibilityTight); |
92 |
> |
break; |
93 |
> |
case kNoId: |
94 |
> |
idpass = kTRUE; |
95 |
> |
break; |
96 |
> |
default: |
97 |
> |
break; |
98 |
> |
} |
99 |
> |
|
100 |
> |
if (!idpass) |
101 |
> |
continue; |
102 |
> |
|
103 |
> |
Bool_t isopass = kFALSE; |
104 |
> |
switch (fMuIsoType) { |
105 |
> |
case kTrackCalo: |
106 |
> |
isopass = (mu->IsoR03SumPt() < fTrackIsolationCut) && |
107 |
> |
(mu->IsoR03EmEt() + mu->IsoR03HadEt() < fCaloIsolationCut); |
108 |
> |
break; |
109 |
> |
case kTrackCaloCombined: |
110 |
> |
isopass = (1.0 * mu->IsoR03SumPt() + 1.0 * mu->IsoR03EmEt() + |
111 |
> |
1.0 * mu->IsoR03HadEt() < fCombIsolationCut); |
112 |
> |
break; |
113 |
> |
case kTrackCaloSliding: |
114 |
> |
{ |
115 |
> |
Double_t totalIso = 1.0 * mu->IsoR03SumPt() + |
116 |
> |
1.0 * mu->IsoR03EmEt() + |
117 |
> |
1.0 * mu->IsoR03HadEt(); |
118 |
> |
if ((totalIso < (pt-10.0)*5.0/15.0 && pt <= 25) || |
119 |
> |
(totalIso < 5.0 && mu->Pt() > 25) || |
120 |
> |
totalIso <= 0) |
121 |
> |
isopass = kTRUE; |
122 |
> |
} |
123 |
> |
break; |
124 |
> |
case kNoIso: |
125 |
> |
isopass = kTRUE; |
126 |
> |
break; |
127 |
> |
case kCustomIso: |
128 |
> |
default: |
129 |
> |
break; |
130 |
|
} |
131 |
+ |
|
132 |
+ |
if ((isopass == kFALSE && fReverseIsoCut == kFALSE) || |
133 |
+ |
(isopass == kTRUE && fReverseIsoCut == kTRUE)) |
134 |
+ |
continue; |
135 |
+ |
|
136 |
+ |
// d0 cut only for global muons |
137 |
+ |
if (fMuClassType == kGlobal) { |
138 |
+ |
Double_t d0_real = 1e30; |
139 |
+ |
for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) { |
140 |
+ |
Double_t pD0 = mu->GlobalTrk()->D0Corrected(*fVertices->At(i0)); |
141 |
+ |
if(TMath::Abs(pD0) < TMath::Abs(d0_real)) |
142 |
+ |
d0_real = TMath::Abs(pD0); |
143 |
+ |
} |
144 |
+ |
if(d0_real >= fD0Cut) |
145 |
+ |
continue; |
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
// add good muon |
149 |
+ |
CleanMuons->Add(mu); |
150 |
|
} |
151 |
|
|
152 |
< |
//Final Summary Debug Output |
153 |
< |
if ( fPrintDebug ) { |
92 |
< |
cerr << "Event Dump: " << fNEventsProcessed << endl; |
93 |
< |
cerr << "Muons" << endl; |
94 |
< |
for (UInt_t i = 0; i < CleanMuons->GetEntries(); i++) { |
95 |
< |
cerr << i << " " << CleanMuons->At(i)->Pt() << " " << CleanMuons->At(i)->Eta() |
96 |
< |
<< " " << CleanMuons->At(i)->Phi() << endl; |
97 |
< |
} |
98 |
< |
} |
99 |
< |
|
100 |
< |
//Save Objects for Other Modules to use |
101 |
< |
AddObjThisEvt(CleanMuons, fCleanMuonsName.Data()); |
102 |
< |
} |
152 |
> |
// sort according to pt |
153 |
> |
CleanMuons->Sort(); |
154 |
|
|
155 |
+ |
// add objects for other modules to use |
156 |
+ |
AddObjThisEvt(CleanMuons); |
157 |
+ |
} |
158 |
|
|
159 |
|
//-------------------------------------------------------------------------------------------------- |
160 |
|
void MuonIDMod::SlaveBegin() |
161 |
|
{ |
162 |
|
// Run startup code on the computer (slave) doing the actual analysis. Here, |
163 |
< |
// we typically initialize histograms and other analysis objects and request |
110 |
< |
// branches. For this module, we request a branch of the MitTree. |
163 |
> |
// we just request the muon collection branch. |
164 |
|
|
165 |
< |
ReqBranch(fMuonName, fMuons); |
166 |
< |
} |
165 |
> |
ReqBranch(fMuonBranchName, fMuons); |
166 |
> |
ReqBranch(fVertexName, fVertices); |
167 |
|
|
168 |
< |
//-------------------------------------------------------------------------------------------------- |
116 |
< |
void MuonIDMod::SlaveTerminate() |
117 |
< |
{ |
118 |
< |
// Run finishing code on the computer (slave) that did the analysis. For this |
119 |
< |
// module, we dont do anything here. |
168 |
> |
fMuonTools = new MuonTools; |
169 |
|
|
170 |
< |
} |
170 |
> |
if (fMuonIDType.CompareTo("Tight") == 0) |
171 |
> |
fMuIDType = kTight; |
172 |
> |
else if (fMuonIDType.CompareTo("Loose") == 0) |
173 |
> |
fMuIDType = kLoose; |
174 |
> |
else if (fMuonIDType.CompareTo("NoId") == 0) |
175 |
> |
fMuIDType = kNoId; |
176 |
> |
else if (fMuonIDType.CompareTo("Custom") == 0) { |
177 |
> |
fMuIDType = kCustomId; |
178 |
> |
SendError(kWarning, "SlaveBegin", |
179 |
> |
"Custom muon identification is not yet implemented."); |
180 |
> |
} else { |
181 |
> |
SendError(kAbortAnalysis, "SlaveBegin", |
182 |
> |
"The specified muon identification %s is not defined.", |
183 |
> |
fMuonIDType.Data()); |
184 |
> |
return; |
185 |
> |
} |
186 |
|
|
187 |
< |
//-------------------------------------------------------------------------------------------------- |
188 |
< |
void MuonIDMod::Terminate() |
189 |
< |
{ |
190 |
< |
// Run finishing code on the client computer. For this module, we dont do |
191 |
< |
// anything here. |
187 |
> |
if (fMuonIsoType.CompareTo("TrackCalo") == 0) |
188 |
> |
fMuIsoType = kTrackCalo; |
189 |
> |
else if (fMuonIsoType.CompareTo("TrackCaloCombined") == 0) |
190 |
> |
fMuIsoType = kTrackCaloCombined; |
191 |
> |
else if (fMuonIsoType.CompareTo("TrackCaloSliding") == 0) |
192 |
> |
fMuIsoType = kTrackCaloSliding; |
193 |
> |
else if (fMuonIsoType.CompareTo("NoIso") == 0) |
194 |
> |
fMuIsoType = kNoIso; |
195 |
> |
else if (fMuonIsoType.CompareTo("Custom") == 0) { |
196 |
> |
fMuIsoType = kCustomIso; |
197 |
> |
SendError(kWarning, "SlaveBegin", |
198 |
> |
"Custom muon isolation is not yet implemented."); |
199 |
> |
} else { |
200 |
> |
SendError(kAbortAnalysis, "SlaveBegin", |
201 |
> |
"The specified muon isolation %s is not defined.", |
202 |
> |
fMuonIsoType.Data()); |
203 |
> |
return; |
204 |
> |
} |
205 |
> |
|
206 |
> |
if (fMuonClassType.CompareTo("All") == 0) |
207 |
> |
fMuClassType = kAll; |
208 |
> |
else if (fMuonClassType.CompareTo("Global") == 0) |
209 |
> |
fMuClassType = kGlobal; |
210 |
> |
else if (fMuonClassType.CompareTo("Standalone") == 0) |
211 |
> |
fMuClassType = kSta; |
212 |
> |
else if (fMuonClassType.CompareTo("TrackerOnly") == 0) |
213 |
> |
fMuClassType = kTrackerOnly; |
214 |
> |
else { |
215 |
> |
SendError(kAbortAnalysis, "SlaveBegin", |
216 |
> |
"The specified muon class %s is not defined.", |
217 |
> |
fMuonClassType.Data()); |
218 |
> |
return; |
219 |
> |
} |
220 |
|
} |