-
Notifications
You must be signed in to change notification settings - Fork 2
/
DTTnPSegmentEff.C
510 lines (373 loc) · 14.7 KB
/
DTTnPSegmentEff.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
#include "DTTnPSegmentEff.h"
DTTnPSegmentEff::DTTnPSegmentEff(const std::string & configFile) : DTTnPBaseAnalysis(configFile)
{
}
void DTTnPSegmentEff::Loop()
{
TFile outputFile(m_sampleConfig.outputFileName,"recreate");
outputFile.cd();
book();
if (fChain == 0) return;
Long64_t nentries = (m_sampleConfig.nEvents > 0 &&
fChain->GetEntries() > m_sampleConfig.nEvents) ?
m_sampleConfig.nEvents : fChain->GetEntries();
std::cout << "[DTTnPSegmentEff::Loop] going to process "
<< nentries << " entries\n" << std::flush;
Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++)
{
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEvent(jentry); nbytes += nb;
if(jentry % 10000 == 0)
std::cout << "[DTTnPSegmentEff::Loop] processed : "
<< jentry << " entries\r" << std::flush;
bool hasGoodRun = false;
for (const auto & run : m_sampleConfig.runs)
{
if (run == 0 ||
run == runnumber)
{
hasGoodRun = true;
break;
}
}
if(!hasGoodRun)
continue;
auto tnpPairs = tnpSelection();
for(const auto & pair : tnpPairs)
{
fill(pair.second);
}
}
harvesting();
std::cout << std::endl;
endJob();
outputFile.Write();
outputFile.Close();
}
void DTTnPSegmentEff::book()
{
DTTnPBaseAnalysis::book();
Double_t ptBins[22] = {0., 5., 10., 15., 20., 25., 30., 35., 40., 50., 60.,
70., 90., 110., 130., 150., 200., 250., 300., 400., 500., 750};
m_plots["nOtherMatchedChVsEta"] = new TH2F("nOtherMatchedChVsEta",
"# of matched stations other than the one under investigation",
96,-1.2,1.2,5,-0.5,4.5);
m_effs["effSecVsWhAllOne"] = new TEfficiency("effSecVsWhAllOne",
"segment efficiency sector vs wheel;sector;wheel",
24,0.5,12.5,10,-2.5,2.5);
m_effs["effSecVsWhAllTwo"] = new TEfficiency("effSecVsWhAllTwo",
"segment efficiency sector vs wheel;wheel/station;sector;",
20,1.0,21.0,12,1.0,13.0);
m_plots["effChambAll"] = new TH1F("effChambAll",
"segment efficiency chamber summary;efficiency;# chambers",
75,0.9,1.05);
for (Int_t iCh = 1; iCh < 5; ++iCh)
{
std::stringstream iChTag;
iChTag << "MB" << iCh;
std::string hName = "probePt" + iChTag.str();
m_plots[hName] = new TH1F(hName.c_str(),
"probe p_{T};p_{T} [GeV];#entries/GeV",
200,0.,200.);
hName = "probeEta" + iChTag.str();
m_plots[hName] = new TH1F(hName.c_str(),
"probe #eta;#eta;#entries/0.05",
56,-1.2,1.2);
hName = "probePhi" + iChTag.str();
m_plots[hName] = new TH1F(hName.c_str(),
"probe #phi;#phi;#entries/(pi*90)",
180,-TMath::Pi(),TMath::Pi());
hName = "probeDrVsPt" + iChTag.str();
m_plots[hName] = new TH2F(hName.c_str(),
"dR vs p_{T};p_{T} [GeV];dR",
200,0.,200.,50,0.,0.5);
hName = "probeDxVsPt" + iChTag.str();
m_plots[hName] = new TH2F(hName.c_str(),
"dX vs p_{T};p_{T} [GeV];dX",
200,0.,200.,50,0.,50);
hName = "probeDyVsPt" + iChTag.str();
m_plots[hName] = new TH2F(hName.c_str(),
"dY vs p_{T};p_{T} [GeV];dY",
200,0.,200.,50,0.,50);
hName = "effAccVsEta" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency x acceptance vs #eta;muon #eta;Efficiency",
48,-1.2,1.2);
hName = "effAccVsPhiPlus" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency x acceptance vs #phi for mu^{+};muon #phi;Efficiency",
96,-TMath::Pi(),TMath::Pi());
hName = "effAccVsPhiMinus" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency x acceptance vs #phi for mu^{-};muon #phi;Efficiency",
96,-TMath::Pi(),TMath::Pi());
hName = "effAccPhiVsEtaPlus" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency x acceptance #phi vs #eta for mu^{+};muon #phi;muon #eta",
96,-TMath::Pi(),TMath::Pi(),96,-1.4,1.4);
hName = "effAccPhiVsEtaMinus" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency x acceptance #phi vs #eta for mu^{+};muon #phi;muon #eta",
96,-TMath::Pi(),TMath::Pi(),96,-1.4,1.4);
hName = "effAccVsPt" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency x acceptance vs p_{T};muon p_{T};Efficiency",
21, ptBins);
hName = "effVsPt" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency vs p_{T};muon p_{T};Efficiency",
21, ptBins);
hName = "effVsLumi" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency vs inst. lumi.;inst. lumi.;Efficiency",
50,0.,20000.);
hName = "effVsRun" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency vs run number;run number;Efficiency",
1000, 315252., 325175);
hName = "effVsVtx" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency vs # of reco. vtx.;# of reco. vtx.;Efficiency",
100,0.,100.);
hName = "effVsNHitsPhi" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency vs # phi hits.; # phi hits;Efficiency",
8,0.5,8.5);
hName = "effSecVsWh" + iChTag.str();
m_effs[hName] = new TEfficiency(hName.c_str(),
"segment efficiency sector vs wheel;sector;wheel",
14,1.,15.,5,-2.,3.);
hName = "effChamb" + iChTag.str();
m_plots[hName.c_str()] = new TH1F(hName.c_str(),
"segment efficiency chamber summary;efficiency;# chambers",
50,0.9,1.);
}
}
void DTTnPSegmentEff::harvesting()
{
std::vector<std::string> effNames = { "effSecVsWhMB1", "effSecVsWhMB2", "effSecVsWhMB3", "effSecVsWhMB4" };
std::vector<std::string> plotNames = { "effChambMB1", "effChambMB2", "effChambMB3", "effChambMB4" };
std::vector<std::string>::const_iterator effNamesIt = effNames.begin();
std::vector<std::string>::const_iterator plotNamesIt = plotNames.begin();
std::vector<std::string>::const_iterator effNamesEnd = effNames.end();
std::vector<std::string>::const_iterator plotNamesEnd = plotNames.end();
for (; effNamesIt != effNamesEnd && plotNamesIt != plotNamesEnd; ++effNamesIt, ++plotNamesIt)
{
Int_t nBinsX = m_effs[(*effNamesIt)]->GetTotalHistogram()->GetNbinsX();
Int_t nBinsY = m_effs[(*effNamesIt)]->GetTotalHistogram()->GetNbinsY();
for (Int_t binX = 1; binX <= nBinsX; ++binX)
{
if (binX > 12 && effNamesIt->find("MB4") == std::string::npos)
break;
for (Int_t binY = 1; binY <= nBinsY; ++binY)
{
Int_t bin = m_effs[(*effNamesIt)]->GetGlobalBin(binX,binY);
m_plots[(*plotNamesIt)]->Fill(m_effs[(*effNamesIt)]->GetEfficiency(bin));
m_plots["effChambAll"]->Fill(m_effs[(*effNamesIt)]->GetEfficiency(bin));
}
}
}
}
void DTTnPSegmentEff::fill(const Int_t iMu)
{
TLorentzVector probeVec;
probeVec.SetXYZM(Mu_px->at(iMu),
Mu_py->at(iMu),
Mu_pz->at(iMu),
0.106);
for (Int_t iCh = 1; iCh < 5; ++iCh)
{
std::stringstream iChTag;
iChTag << "MB" << iCh;
Int_t nMatchInOtherCh = DTTnPBaseAnalysis::nMatchedCh(iMu,iCh);
m_plots["nOtherMatchedChVsEta"]->Fill(Mu_eta->at(iMu),nMatchInOtherCh);
if ( nMatchInOtherCh >= m_tnpConfig.probe_minNMatchedSeg ||
Mu_numberOfRPCLayers_rpc->at(iMu) >= m_tnpConfig.probe_minNRPCLayers )
{
std::pair<Int_t,Int_t> iPassingProbe = getPassingProbe(iMu,iCh);
Int_t iPassingSeg = iPassingProbe.first;
Int_t iPassingMatch = iPassingProbe.second;
std::string hName = "effAccVsEta" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,Mu_eta->at(iMu));
if (Mu_charge->at(iMu) == 1)
{
hName = "effAccPhiVsEtaPlus" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,Mu_phi->at(iMu),Mu_eta->at(iMu));
}
if (Mu_charge->at(iMu) == -1)
{
hName = "effAccPhiVsEtaMinus" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,Mu_phi->at(iMu),Mu_eta->at(iMu));
}
if (std::abs(probeVec.Eta()) < m_tnpConfig.probe_maxAbsEta[iCh - 1])
{
hName = "probePt" + iChTag.str();
m_plots[hName]->Fill(probeVec.Pt());
hName = "probeEta" + iChTag.str();
m_plots[hName]->Fill(probeVec.Eta());
hName = "probePhi" + iChTag.str();
m_plots[hName]->Fill(probeVec.Phi());
if (iPassingSeg > -1)
{
Float_t xMu = getXY<Float_t>(Mu_matches_x,iMu,iPassingMatch);
Float_t yMu = getXY<Float_t>(Mu_matches_y,iMu,iPassingMatch);
Float_t xSeg = dtsegm4D_x_pos_loc->at(iPassingSeg);
Float_t ySeg = dtsegm4D_y_pos_loc->at(iPassingSeg);
Float_t dX = std::abs(xSeg-xMu);
Float_t dY = std::abs(ySeg-yMu);
Float_t dR = sqrt(dX*dX + dY*dY);
hName = "probeDrVsPt" + iChTag.str();
m_plots[hName.c_str()]->Fill(probeVec.Pt(),dR);
hName = "probeDxVsPt" + iChTag.str();
m_plots[hName.c_str()]->Fill(probeVec.Pt(),dX);
hName = "probeDyVsPt" + iChTag.str();
m_plots[hName.c_str()]->Fill(probeVec.Pt(),dY);
}
if (Mu_charge->at(iMu) == 1)
{
hName = "effAccVsPhiPlus" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,Mu_phi->at(iMu));
}
if (Mu_charge->at(iMu) == -1)
{
hName = "effAccVsPhiMinus" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,Mu_phi->at(iMu));
}
hName = "effAccVsPt" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,probeVec.Pt());
for (Int_t iMatch = 0; iMatch < Mu_nMatches->at(iMu); ++iMatch)
{
Int_t whMu = getXY<Int_t>(Mu_matches_Wh,iMu,iMatch);
Int_t secMu = getXY<Int_t>(Mu_matches_Sec,iMu,iMatch);
Int_t stMu = getXY<Int_t>(Mu_matches_St,iMu,iMatch);
Float_t xMu = getXY<Float_t>(Mu_matches_x,iMu,iMatch);
Float_t yMu = getXY<Float_t>(Mu_matches_y,iMu,iMatch);
Float_t xBorderMu = getXY<Float_t>(Mu_matches_edgeX,iMu,iMatch);
Float_t yBorderMu = getXY<Float_t>(Mu_matches_edgeY,iMu,iMatch);
if (stMu == iCh &&
xBorderMu < m_tnpConfig.probe_maxBorderDx &&
yBorderMu < m_tnpConfig.probe_maxBorderDy )
{
iPassingSeg = getPassingProbeInCh(iMu,stMu,secMu,whMu,xMu,yMu);
hName = "effVsPt" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,probeVec.Pt());
hName = "effSecVsWh" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,secMu + 0.5,whMu + 0.5);
Float_t secBinOne = secMu == 13 ? 4 : secMu==14 ? 10 : secMu;
secBinOne += (stMu % 2 == 1) ? -0.1 : 0.1;
Float_t whBinOne = whMu + ((stMu -1) / 2 == 0 ? -0.1 : 0.1);
hName = "effSecVsWhAllOne";
m_effs[hName]->Fill(iPassingSeg >= 0,secBinOne,whBinOne);
Float_t secBinTwo = secMu == 13 ? 4 : secMu==14 ? 10 : secMu;
secBinTwo += 0.1;
Float_t whBinTwo = whMu + 3.1 + ((stMu - 1) * 5);
hName = "effSecVsWhAllTwo";
m_effs[hName]->Fill(iPassingSeg >= 0,whBinTwo,secBinTwo);
hName = "effVsLumi" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,lumiperblock);
hName = "effVsVtx" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,PV_Nvtx);
hName = "effVsRun" + iChTag.str();
m_effs[hName]->Fill(iPassingSeg >= 0,runnumber);
hName = "effVsNHitsPhi" + iChTag.str();
Int_t nPhiHits = iPassingSeg >= 0 ? dtsegm4D_phinhits->at(iPassingSeg) : 0;
for (Int_t phiHits = 1; phiHits < 9; ++phiHits)
m_effs[hName]->Fill(nPhiHits >= phiHits, phiHits);
}
}
}
}
}
}
void DTTnPSegmentEff::endJob()
{
for (Int_t iCh = 1; iCh < 5; ++iCh)
{
std::stringstream iChTag;
iChTag << "MB" << iCh;
for (Int_t iWh = 1; iWh < 6; ++iWh)
{
for (Int_t iSec = 1; iSec < 15; ++iSec)
{
if (iSec > 12 && iCh !=4)
continue;
std::string hName = "effChamb" + iChTag.str();
std::string effName = "effSecVsWh" + iChTag.str();
m_plots[hName.c_str()]->Fill(m_effs[effName.c_str()]->GetEfficiency(m_effs[effName.c_str()]->GetGlobalBin(iSec,iWh)));
}
}
}
}
std::pair<Int_t,Int_t> DTTnPSegmentEff::getPassingProbe(const Int_t iMu,
const Int_t iCh)
{
Int_t iBestMatch = -1;
Int_t iBestSeg = -1;
Float_t bestSegDr = 999.;
for (Int_t iMatch = 0; iMatch < Mu_nMatches->at(iMu); ++ iMatch)
{
Int_t whMu = getXY<Int_t>(Mu_matches_Wh,iMu,iMatch);
Int_t secMu = getXY<Int_t>(Mu_matches_Sec,iMu,iMatch);
Int_t stMu = getXY<Int_t>(Mu_matches_St,iMu,iMatch);
Float_t xMu = getXY<Float_t>(Mu_matches_x,iMu,iMatch);
Float_t yMu = getXY<Float_t>(Mu_matches_y,iMu,iMatch);
if (stMu == iCh)
{
Int_t iSeg = getPassingProbeInCh(iMu,stMu,secMu,
whMu,xMu,yMu);
if (iSeg < 0)
continue;
Float_t xSeg = dtsegm4D_x_pos_loc->at(iSeg);
Float_t ySeg = dtsegm4D_y_pos_loc->at(iSeg);
Float_t dX = std::abs(xSeg-xMu);
Float_t dY = std::abs(ySeg-yMu);
Float_t dR = sqrt(dX*dX + dY*dY);
if(dR < bestSegDr)
{
iBestMatch = iMatch;
iBestSeg = iSeg;
bestSegDr = dR;
}
}
}
return std::pair<Int_t,Int_t>(iBestSeg,iBestMatch);
}
Int_t DTTnPSegmentEff::getPassingProbeInCh(const Int_t iMu,
const Int_t stMu,
const Int_t secMu,
const Int_t whMu,
const Int_t xMu,
const Int_t yMu)
{
Int_t iBestSeg = -1;
Float_t bestSegDr = 999.;
Float_t bestSegDx = 999.;
Float_t bestSegDy = 999.;
for (Int_t iSeg = 0; iSeg < Ndtsegments; ++ iSeg)
{
Int_t whSeg = dtsegm4D_wheel->at(iSeg);
Int_t secSeg = dtsegm4D_sector->at(iSeg);
Int_t stSeg = dtsegm4D_station->at(iSeg);
Float_t xSeg = dtsegm4D_x_pos_loc->at(iSeg);
Float_t ySeg = dtsegm4D_y_pos_loc->at(iSeg);
Float_t dX = std::abs(xSeg-xMu);
Float_t dY = std::abs(ySeg-yMu);
Float_t dR = sqrt(dX*dX + dY*dY);
if(whMu == whSeg &&
secMu == secSeg &&
stMu == stSeg &&
dR < bestSegDr &&
dR < m_tnpConfig.passing_probe_maxTkSegDr &&
dX < m_tnpConfig.passing_probe_maxTkSegDx &&
dY < m_tnpConfig.passing_probe_maxTkSegDy )
{
iBestSeg = iSeg;
bestSegDr = dR;
bestSegDx = dX;
bestSegDy = dY;
}
}
return iBestSeg;
}