ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_HLTMuonHistogramDivision.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
6//Methods to Divide HLTMuon Histograms to calculate efficiency and occupancy after merging.
7//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch)
8//Date: Aug 2009
10
12
13#include <iostream>
14#include <iomanip>
15#include <algorithm>
16#include <fstream>
17#include <cmath>
18#include <cstdlib>
19#include <sstream>
20#include <vector>
21#include <utility>
22#include <map>
23#include <string>
24
25#include "TH1F.h"
26#include "TH2F.h"
27#include "TFile.h"
28#include "TClass.h"
29#include "TKey.h"
30#include "TMath.h"
31#include "TF1.h"
32#include "TTree.h"
33#include "TBranch.h"
34#include "TGraph.h"
35#include "TString.h"
36#include "TGraphAsymmErrors.h"
37
38
39namespace dqutils {
40 // static const bool fdbg = false;
41 static const bool fdbg = true;
42
43 void MonitoringFile::HLTMuonHistogramDivision(const std::string& inFilename, TString& run_dir) {
44 bool HI_pp_key = false;//true::HI false::pp
45
46 if (fdbg) std::cout << " Start to Divide HLTMuon Histograms for Efficiency and Rate Ratio" << std::endl;
47 PostProcessorFileWrapper mf(inFilename, "HLT Histogram Division");
48 if (!mf.IsOpen()) {
49 std::cerr << "HLTMuonPostProcess(): "
50 << "Input file not opened \n";
51 return;
52 }
53 if (mf.GetSize() < 1000.) {
54 std::cerr << "HLTMuonPostProcess(): "
55 << "Input file empty \n";
56 return;
57 }
58 // get run directory name
59 //Seemingly unnecessary lines are necessary
60 TIter nextcd0(gDirectory->GetListOfKeys());
61 TKey* key0 = (TKey*) nextcd0();
62 if (key0 == 0) return;
63
64 TDirectory* dir0 = dynamic_cast<TDirectory*> (key0->ReadObj());
65 if (dir0 == 0) return;
66
67 dir0->cd();
68
69 auto getHPointer ATLAS_THREAD_SAFE = [&mf] ATLAS_NOT_THREAD_SAFE(const TString &hname)->TH1F * {
70 TH1F* pH {};
71 mf.get(hname, pH);
72 if (!pH and fdbg) {
73 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << hname << std::endl;
74 }
75 return pH;
76 };
77 auto getHistogramPair = [&getHPointer] (const TString &numeratorName, const TString &denominatorName)->std::pair<TH1F *, TH1F *> {
78 TH1F* pH2 {};
79 TH1F* pH1 = getHPointer(numeratorName);
80 if (pH1){
81 pH2 = getHPointer(denominatorName);
82 }
83 return std::pair{pH1, pH2};
84 };
85
86 auto getH2Pointer ATLAS_THREAD_SAFE = [&mf] ATLAS_NOT_THREAD_SAFE(const TString &hname)->TH2F * {
87 TH2F* pH {};
88 mf.get(hname, pH);
89 if (!pH and fdbg) {
90 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << hname << std::endl;
91 }
92 return pH;
93 };
94
95
97
98 // 110728: removing the iteration of searching run directory according to the new MDT code
99 // 150621: reenable ...
100 TIter next_run(mf.GetListOfKeys());
101 TKey* key_run(0);
102 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) { //== the while commented out at the end
103 if (!key_run->IsFolder()) continue;
104 run_dir = key_run->GetName();
105 if (!run_dir.Contains("run")) {
106 continue;
107 }
108 break;
109 }
110 if (!run_dir.Contains("run")) {
111 std::cerr << "HLTMuon: unable to find run directory ..." << std::endl;
112 return;
113 }
114 {
115 if (fdbg) {
116 std::cout << "HLTMuon: run directory is " << run_dir << std::endl;
117 }
118 std::string run_dir2 = run_dir.Data();
119
120 //===HLTMuon
121
122 TH1F* hHI_PP_Flag(0);
123 TString hi_pp_flag = run_dir + "/HLT/MuonMon/Common/HI_PP_Flag";
124 hHI_PP_Flag = getHPointer(hi_pp_flag);
125 if (hHI_PP_Flag) {
126 HI_pp_key = hHI_PP_Flag->GetBinContent(1) > 0;
127 }
128
129 TString muon_dir = run_dir + "/HLT/MuonMon/";
130
131 TString cm_dir = muon_dir + "Common/";
132 TString mf_dir = muon_dir + "L2MuonSA/";
133 TString mc_dir = muon_dir + "muComb/";
134 TString mi_dir = muon_dir + "muIso/";
135 TString tm_dir = muon_dir + "TileMu/";
136 TString ef_dir = muon_dir + "MuonEF/";
137 // YY added
138 TString ztp_dir = muon_dir + "MuZTP/";
139
140 TString eff_dir = muon_dir + "Efficiency/";
141 TString nd_dir = muon_dir + "Efficiency/NumDenom/";
142 TString rate_dir = muon_dir + "Rate/";
143 TString rr_dir = muon_dir + "Rate/Ratio/";
144
145 TString seff;
146 TString seffg; // YY added
147 TString snum;
148 TString sden;
149 TString stmp;
150 TString stmpg;
151
152 TH1F* h1tmp(0);
153 TH1F* h1eff(0);
154 TH1F* h1sumeff(0); // new YY
155 TH1F* h1effsum(nullptr);
156 TGraphAsymmErrors* h1tmpg;
157
158 //==Efficiency
159 // L2MuonSA efficiency
160 TDirectory* dir = mf.GetDirectory(eff_dir);
161 if (!dir) {
162 std::cerr << "HLTMuonHistogramDivision: directory " << eff_dir << " not found" << std::endl;
163 return;
164 }
165
166 std::vector<TString> effnames;
167 effnames.push_back("L2MuonSA_effi_toRecMuonCB_pt");
168 effnames.push_back("L2MuonSA_effi_toRecMuonCB_pt_barrel");
169 effnames.push_back("L2MuonSA_effi_toRecMuonCB_pt_endcap");
170 effnames.push_back("L2MuonSA_effi_toRecMuonCB_eta");
171 effnames.push_back("L2MuonSA_effi_toRecMuonCB_phi");
172
173 for (std::vector<TString>::iterator it = effnames.begin(); it != effnames.end(); ++it) {
174 seff = eff_dir + (*it);
175 snum = mf_dir + (*it) + "_numer";
176 sden = mf_dir + (*it) + "_denom";
177 stmp = (*it);
178 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
179 if (not h1num) continue;
180 //
181 h1tmp = (TH1F*) h1den->Clone();
182 h1tmp->SetName(stmp);
183 std::string stcar = h1tmp->GetTitle();
184 stcar.replace(stcar.end() - 5, stcar.end(), "");
185 h1tmp->SetTitle(stcar.c_str());
186 h1tmp->GetYaxis()->SetTitle("Efficiency");
187 h1tmp->Reset();
188 h1tmp->Divide(h1num, h1den, 1., 1., "B");
189 dir->cd();
190 h1tmp->Write();
191 }//effnames
192 mf.Write();
193
194 // muComb efficiency
195 effnames.clear();
196 effnames.push_back("muComb_effi_toOffl_pt");
197 effnames.push_back("muComb_effi_toOffl_pt_barrel");
198 effnames.push_back("muComb_effi_toOffl_pt_endcap");
199 effnames.push_back("muComb_effi_toOffl_eta");
200 effnames.push_back("muComb_effi_toOffl_phi");
201
202 for (std::vector<TString>::iterator it = effnames.begin(); it != effnames.end(); ++it) {
203 seff = eff_dir + (*it);
204 snum = mc_dir + (*it) + "_numer";
205 sden = mc_dir + (*it) + "_denom";
206 stmp = (*it);
207 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
208 if (!h1num) continue;
209 //
210 h1tmp = (TH1F*) h1den->Clone();
211 h1tmp->SetName(stmp);
212 std::string stcar = h1tmp->GetTitle();
213 stcar.replace(stcar.end() - 5, stcar.end(), "");
214 h1tmp->SetTitle(stcar.c_str());
215 h1tmp->GetYaxis()->SetTitle("Efficiency");
216 h1tmp->Reset();
217 h1tmp->Divide(h1num, h1den, 1., 1., "B");
218 dir->cd();
219 h1tmp->Write();
220 }//effnames
221 mf.Write();
222
223 // muIso efficiency
224 effnames.clear();
225 effnames.push_back("muIso_effi_toOffl_pt");
226
227 for (std::vector<TString>::iterator it = effnames.begin(); it != effnames.end(); ++it) {
228 seff = eff_dir + (*it);
229 snum = mi_dir + (*it) + "_numer";
230 sden = mi_dir + (*it) + "_denom";
231 stmp = (*it);
232 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
233 if (!h1num) continue;
234 //
235 h1tmp = (TH1F*) h1den->Clone();
236 h1tmp->SetName(stmp);
237 std::string stcar = h1tmp->GetTitle();
238 stcar.replace(stcar.end() - 5, stcar.end(), "");
239 h1tmp->SetTitle(stcar.c_str());
240 h1tmp->GetYaxis()->SetTitle("Efficiency");
241 h1tmp->Reset();
242 h1tmp->Divide(h1num, h1den, 1., 1., "B");
243 dir->cd();
244 h1tmp->Write();
245 }//effnames
246 mf.Write();
247
248 // TileMu efficiency
249 effnames.clear();
250 std::vector<TString> numnames;
251 std::vector<TString> dennames;
252 effnames.push_back("TileMu_RecCBMuon_EffEta");
253 numnames.push_back("Rec_Eta_Num");
254 dennames.push_back("Rec_Eta");
255 effnames.push_back("TileMu_RecCBMuon_EffPhi");
256 numnames.push_back("Rec_Phi_Num");
257 dennames.push_back("Rec_Phi");
258 effnames.push_back("TileTrackMu_RecCBMuon_EffEta");
259 numnames.push_back("TileTrackMu_Eta");
260 dennames.push_back("Rec_Eta");
261 effnames.push_back("TileTrackMu_RecCBMuon_EffPhi");
262 numnames.push_back("TileTrackMu_Phi");
263 dennames.push_back("Rec_Phi");
264 effnames.push_back("TileTrackMu_RecCBMuon_EffPt");
265 numnames.push_back("TileTrackMu_Pt");
266 dennames.push_back("Rec_Pt");
267
268 for (unsigned int i = 0; i < effnames.size(); i++) {
269 seff = eff_dir + effnames.at(i);
270 snum = tm_dir + numnames.at(i);
271 sden = tm_dir + dennames.at(i);
272 stmp = effnames.at(i);
273 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
274 if (!h1num) continue;
275
276 h1tmp = (TH1F*) h1den->Clone();
277 h1tmp->SetName(stmp);
278 std::istringstream iss(stmp.Data());
279 std::string token;
280 int ili = 0;
281 while (std::getline(iss, token, '_')) {
282 stmp = token + "Feature wrt Offline)";
283 ili++;
284 if (ili > 0) break;
285 }
286
287 std::string stcar = h1tmp->GetTitle();
288 if (stcar.find("Pt") != std::string::npos) {
289 stmp = "Efficiency on p_{T} (" + stmp;
290 h1tmp->GetXaxis()->SetTitle("p_{T}");
291 }
292 if (stcar.find("Eta") != std::string::npos) stmp = "Efficiency on #eta (" + stmp;
293 if (stcar.find("Phi") != std::string::npos) stmp = "Efficiency on #phi (" + stmp;
294 h1tmp->SetTitle(stmp);
295 h1tmp->GetYaxis()->SetTitle("Efficiency");
296 h1tmp->Reset();
297 h1tmp->Divide(h1num, h1den, 1., 1., "B");
298 dir->cd();
299 h1tmp->Write();
300 }//effnames
301 mf.Write();
302
303 // MuonEF efficiency
304 effnames.clear();
305 numnames.clear();
306 dennames.clear();
307 effnames.push_back("EFMS_effi_toOffl_pt");
308 effnames.push_back("EFMS_effi_toOffl_eta");
309 effnames.push_back("EFMS_effi_toOffl_phi");
310 effnames.push_back("EFSA_effi_toOffl_pt");
311 effnames.push_back("EFCB_effi_toOffl_pt");
312
313 for (std::vector<TString>::iterator it = effnames.begin(); it != effnames.end(); ++it) {
314 seff = eff_dir + (*it);
315 snum = ef_dir + (*it) + "_numer";
316 sden = ef_dir + (*it) + "_denom";
317 stmp = (*it);
318 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
319 if (!h1num) continue;
320
321 h1tmp = (TH1F*) h1den->Clone();
322 h1tmp->SetName(stmp);
323 std::string stcar = h1tmp->GetTitle();
324 stcar.replace(stcar.end() - 5, stcar.end(), "");
325 h1tmp->SetTitle(stcar.c_str());
326 h1tmp->GetYaxis()->SetTitle("Efficiency");
327 h1tmp->Reset();
328 h1tmp->Divide(h1num, h1den, 1., 1., "B");
329 dir->cd();
330 h1tmp->Write();
331 }//effnames
332 mf.Write();
333
334 //==Turn on
335 std::vector<TString> chainsMSonly;
336 std::vector<TString> chainsStandard;
337 std::vector<TString> chainsMG;
338 std::vector<TString> chainsMI;
339 std::vector<TString> chainsGeneric;
340 std::vector<TString> chainsEFiso;
341 std::vector<TString> chainsEFFS;
342
343 // Generic (EFsuper etc.)
344
345 chainsGeneric.push_back("muChain1"); // MAM
346 chainsGeneric.push_back("muChain2"); // MAM
347
348 // Generic (Isolated muons)
349 chainsEFiso.push_back("muChainEFiso1"); // MAM
350 chainsEFiso.push_back("muChainEFiso2"); // MAM
351
352 // MSonly
353
354 chainsMSonly.push_back("muChainMSonly1"); // MAM
355 chainsMSonly.push_back("muChainMSonly2"); // MAM
356
357 // EFFS triggers (L. Yuan)
358 chainsEFFS.push_back("muChainEFFS"); // MAM
359
360 enum indexINDEP {
361 INDORTH, INDEGAMMA, INDMET, INDJET, INDTAU, INDMBIAS
362 };
363 TString trigger[INDMBIAS + 1];
364
365 trigger[INDORTH] = "Orthog";//EGamma + Tau + Jet + MET
366 trigger[INDEGAMMA] = "EGamma";
367 trigger[INDMET] = "MET";
368 trigger[INDJET] = "Jet";
369
370 //int maxindep = 0; // YY 20.01.2012
371
372 // YY added:
373 TString ESchainName = "_ES";
374
375 TString bestr[2] = {
376 "_Barrel", "_Endcap"
377 };
378
379 // made it as enum: 20.1.2012
380 std::string triggerES[7] = {
381 "_ESstd", "_EStag", "_ESid", "_ESindep", "_ESHIL1", "_ESHIid", "_ESHIindep"
382 };
383 enum indexES {
384 ESSTD, ESTAG, ESID, ESINDEP, ESHIL1, ESHIID, ESHIINDEP
385 };
386
387 int maxESbr = ESINDEP;
388
389 bool CB_mon_ESbr[ESHIINDEP + 1];
390 bool MS_mon_ESbr[ESHIINDEP + 1];
391
392 CB_mon_ESbr[ESSTD] = 0;
393 CB_mon_ESbr[ESTAG] = 0;
394 CB_mon_ESbr[ESID] = 1;
395 CB_mon_ESbr[ESINDEP] = 0;
396 CB_mon_ESbr[ESHIL1] = 0;
397 CB_mon_ESbr[ESHIID] = 0;
398 CB_mon_ESbr[ESHIINDEP] = 0;
399
400 MS_mon_ESbr[ESSTD] = 0;
401 MS_mon_ESbr[ESTAG] = 1;
402 MS_mon_ESbr[ESID] = 0;
403 MS_mon_ESbr[ESINDEP] = 0;
404 MS_mon_ESbr[ESHIL1] = 0;
405 MS_mon_ESbr[ESHIID] = 0;
406 MS_mon_ESbr[ESHIINDEP] = 0;
407
408 std::vector<std::string> vectkwd;
409
410 vectkwd.push_back(triggerES[ESTAG]);
411 vectkwd.push_back(triggerES[ESID]);
412 vectkwd.push_back("_Jet");
413 vectkwd.push_back("_all");
414
415 TString hptName = "_hpt";
416 TString MSchainName = "_MSb";
417
418 // YY: pt range.
419 int iSTDL;
420 int iSTDH;
421 if (HI_pp_key) {
422 iSTDL = 45; // 12 GeV
423 //iSTDL = 54; // 15 GeV
424 iSTDH = 75; // 25 GeV
425 } else {
426 iSTDL = 105; // 60 GeV
427 //iSTDL = 91; // 40 GeV
428 iSTDH = 120; // 100 GeV
429 //iSTDH = 120; // 100 GeV
430 }
431 int iMSL = 105; // 60 GeV
432 int iMSH = 120; // 100 GeV
433
434 if (HI_pp_key) {
435 iMSL = 54;//15GeV
436 iMSH = 75;//25GeV
437 }
438 // YY added:
439 enum ieffAlgo {
440 iL2MuonSA = 0, // StdAlgo
441 iMuComb = 1, // StdAlgo
442 iEFCB = 2, // StdAlgo
443 iMuGirl = 3, // StdAlgo
444
445 iEFSA = 1 // MSAlgo
446 };
447
448 // Standard Chains
449 //TString alg[5] = {"_L2MuonSA", "_MuComb", "_MuonEFMS", "_MuonEFSA", "_MuonEFCB"};
450 //TString wrtalg[5] = {"_L1", "_L2MuonSA", "_MuComb", "_MuComb", "_MuComb"};
451
452 // ******************************************************//
453 // start the code add by Yuan //
454 //TString FS_pre_trigger = "mu18it_tight";
455 TString FS_pre_trigger = "EFFSpre";
456 for (unsigned int i = 0; i < chainsEFFS.size(); i++) {
457 TString chainName = chainsEFFS.at(i);
458
459 TString hists_str[9] = {
460 chainName + "_tagEFFSpre" + "_Turn_On_Curve_wrt_probe_MuidCB",
461 chainName + "_tagEFFSpre" + "_Turn_On_Curve_wrt_probe_MuidCB_Barrel",
462 chainName + "_tagEFFSpre" + "_Turn_On_Curve_wrt_probe_MuidCB_Endcap",
463 chainName + "_tagEFFSpre_mu0_15" + "_Turn_On_Curve_wrt_probe_MuidCB",
464 chainName + "_tagEFFSpre_mu15_20" + "_Turn_On_Curve_wrt_probe_MuidCB",
465 chainName + "_tagEFFSpre_mu20" + "_Turn_On_Curve_wrt_probe_MuidCB",
466 chainName + "_Turn_On_Curve_wrt_subleading_MuidCB",
467 FS_pre_trigger + "_dimuonTP" + "_Turn_On_Curve_wrt_probe_MuidCB",
468 FS_pre_trigger + "_dimuonTP" + "_Turn_On_Curve_wrt_L1_probe_MuidCB",
469 };
470
471 bool for_mydebug = false;
472 auto getHPointerQuietly ATLAS_THREAD_SAFE =
473 [&mf, for_mydebug] ATLAS_NOT_THREAD_SAFE(const TString &hname)->TH1F * {
474 TH1F* pH {};
475 mf.get(hname, pH);
476 if (!pH and for_mydebug) {
477 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << hname << std::endl;
478 }
479 return pH;
480 };
481 auto getHistogramPairQuietly = [&getHPointerQuietly] (const TString &numeratorName, const TString &denominatorName)->std::pair<TH1F *, TH1F *> {
482 TH1F* pH2 {};
483 TH1F* pH1 = getHPointerQuietly(numeratorName);
484 if (pH1){
485 pH2 = getHPointerQuietly(denominatorName);
486 }
487 return std::pair{pH1, pH2};
488 };
489
490
491 for (int iROI = 0; iROI < 9; iROI++) {
492 sden = nd_dir + hists_str[iROI] + "_Denominator";
493 snum = nd_dir + hists_str[iROI] + "_Numerator";
494 seff = eff_dir + hists_str[iROI];
495 seffg = seff + "_Fit";
496
497 stmp = hists_str[iROI];
498 stmpg = hists_str[iROI] + "_Fit";
499 const auto & [h1num, h1den] = getHistogramPairQuietly(snum, sden);
500 if (!h1num) continue;
501
502 h1tmp = (TH1F*) h1den->Clone();
503 h1tmp->SetName(stmp);
504 h1tmp->SetTitle(stmp);
505 h1tmp->GetYaxis()->SetTitle("Efficiency");
506 h1tmp->Reset();
507 h1tmp->Divide(h1num, h1den, 1., 1., "B");
508 dir->cd();
509 h1tmp->Write();
510 h1tmpg = new TGraphAsymmErrors();
511 h1tmpg->SetMarkerStyle(20);
512 h1tmpg->SetMinimum(0.0);
513 h1tmpg->SetMaximum(1.05);
514 h1tmpg->BayesDivide(h1num, h1den);
515 h1tmpg->GetYaxis()->SetTitle("Efficiency");
516 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
517 h1tmpg->SetName(stmpg);
518 h1tmpg->Write();
519 delete h1tmpg;
520 } // end the loop on individual turn-on curves
521
522 TString L1_TP_str = FS_pre_trigger + "_dimuonTP_L1" + "_Turn_On_Curve_wrt_probe_MuidCB";
523 sden = nd_dir + FS_pre_trigger + "_dimuonTP" + "_Turn_On_Curve_wrt_probe_MuidCB" + "_Denominator";
524 snum = nd_dir + FS_pre_trigger + "_dimuonTP" + "_Turn_On_Curve_wrt_L1_probe_MuidCB" + "_Denominator";
525 seff = eff_dir + L1_TP_str;
526 seffg = seff + "_Fit";
527 stmp = L1_TP_str;
528 stmpg = L1_TP_str + "_Fit";
529 const auto & [h1num, h1den] = getHistogramPairQuietly(snum, sden);
530 if (!h1num) continue;
531
532 h1tmp = (TH1F*) h1den->Clone();
533 h1tmp->SetName(stmp);
534 h1tmp->SetTitle(stmp);
535 h1tmp->GetYaxis()->SetTitle("Efficiency");
536 h1tmp->Reset();
537 h1tmp->Divide(h1num, h1den, 1., 1., "B");
538 dir->cd();
539 h1tmp->Write();
540 h1tmpg = new TGraphAsymmErrors();
541 h1tmpg->SetMarkerStyle(20);
542 h1tmpg->SetMinimum(0.0);
543 h1tmpg->SetMaximum(1.05);
544 h1tmpg->BayesDivide(h1num, h1den);
545 h1tmpg->GetYaxis()->SetTitle("Efficiency");
546 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
547 dir->cd();
548 h1tmpg->SetName(stmpg);
549 h1tmpg->Write();
550 delete h1tmpg;
551
552 //**** summargy plot **********//
553
554 TString histNumB = nd_dir + chainName + "_tagEFFSpre_Turn_On_Curve_wrt_probe_MuidCB_Barrel_Numerator";
555 TString histDenB = nd_dir + chainName + "_tagEFFSpre_Turn_On_Curve_wrt_probe_MuidCB_Barrel_Denominator";
556 TString histNumE = nd_dir + chainName + "_tagEFFSpre_Turn_On_Curve_wrt_probe_MuidCB_Endcap_Numerator";
557 TString histDenE = nd_dir + chainName + "_tagEFFSpre_Turn_On_Curve_wrt_probe_MuidCB_Endcap_Denominator";
558 TString histL1sum = eff_dir + chainName + "_EFplateau_wrtOffline";
559 const auto & [h1numb, h1denb] = getHistogramPairQuietly(histNumB, histDenB);
560 if (!h1numb) continue;
561
562 const auto & [h1nume, h1dene] = getHistogramPairQuietly(histNumE, histDenE);
563 if (!h1nume) continue;
564
565 TH1F* h1sumL = getHPointerQuietly(histL1sum);
566 if (!h1sumL) continue;
567 //
568 int iSTDL = 75;//25GeV
569 int iSTDH = 120;
570 if (HI_pp_key) {//HI run 4-25GeV
571 iSTDL = 17;
572 iSTDH = 75;
573 }
574 double sumeff {}, sumerr {};
575 double sumn = h1numb->Integral(iSTDL, iSTDH); // 60-100 GeV
576 double sumd = h1denb->Integral(iSTDL, iSTDH);
577 if (sumd != 0.) {
578 sumeff = (double) sumn / (double) sumd;
579 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
580 }
581
582 h1sumL->SetBinContent(1, sumeff);
583 h1sumL->SetBinError(1, sumerr);
584
585 sumn = h1nume->Integral(iSTDL, iSTDH);
586 sumd = h1dene->Integral(iSTDL, iSTDH);
587 if (sumd == 0.) {
588 sumeff = 0.;
589 sumerr = 0.;
590 } else {
591 sumeff = (double) sumn / (double) sumd;
592 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
593 }
594 h1sumL->GetYaxis()->SetTitle("Efficiency");
595 h1sumL->SetBinContent(2, sumeff);
596 h1sumL->SetBinError(2, sumerr);
597 h1sumL->SetMinimum(0.0);
598 h1sumL->SetMaximum(1.05);
599
600 dir->cd();
601 h1sumL->Write("", TObject::kOverwrite);
602
603 TString histNum_mu0_15 = nd_dir + chainName + "_tagEFFSpre_mu0_15_Turn_On_Curve_wrt_probe_MuidCB_Numerator";
604 TString histDen_mu0_15 = nd_dir + chainName + "_tagEFFSpre_mu0_15_Turn_On_Curve_wrt_probe_MuidCB_Denominator";
605 TString histNum_mu15_20 = nd_dir + chainName + "_tagEFFSpre_mu15_20_Turn_On_Curve_wrt_probe_MuidCB_Numerator";
606 TString histDen_mu15_20 = nd_dir + chainName + "_tagEFFSpre_mu15_20_Turn_On_Curve_wrt_probe_MuidCB_Denominator";
607 TString histNum_mu20 = nd_dir + chainName + "_tagEFFSpre_mu20_Turn_On_Curve_wrt_probe_MuidCB_Numerator";
608 TString histDen_mu20 = nd_dir + chainName + "_tagEFFSpre_mu20_Turn_On_Curve_wrt_probe_MuidCB_Denominator";
609 TString histEFsum_mu = eff_dir + chainName + "_EFplateau_wrtOffline_mu_dependence";
610
611 TH1F* h1num_mu0_15 = getHPointerQuietly(histNum_mu0_15);
612 if (!h1num_mu0_15) continue;
613
614 TH1F* h1num_mu15_20 = getHPointerQuietly(histNum_mu15_20);
615 if (!h1num_mu15_20) continue;
616
617 TH1F* h1num_mu20 = getHPointerQuietly(histNum_mu20);
618 if (!h1num_mu20) continue;
619
620 TH1F* h1den_mu0_15 = getHPointerQuietly(histDen_mu0_15);
621 if (!h1den_mu0_15) continue;
622
623 TH1F* h1den_mu15_20 = getHPointerQuietly(histDen_mu15_20);
624 if (!h1den_mu15_20) continue;
625
626 TH1F* h1den_mu20 = getHPointerQuietly(histDen_mu20);
627 if (!h1den_mu20) continue;
628
629 TH1F* h1sum_mu = getHPointerQuietly(histEFsum_mu);
630 if (!h1sum_mu) continue;
631
632 sumn = h1num_mu0_15->Integral(iSTDL, iSTDH); // 25-100 GeV
633 sumd = h1den_mu0_15->Integral(iSTDL, iSTDH);
634 if (sumd == 0.) {
635 sumeff = 0.;
636 sumerr = 0.;
637 } else {
638 sumeff = (double) sumn / (double) sumd;
639 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
640 }
641
642 h1sum_mu->SetBinContent(1, sumeff);
643 h1sum_mu->SetBinError(1, sumerr);
644
645 sumn = h1num_mu15_20->Integral(iSTDL, iSTDH);
646 sumd = h1den_mu15_20->Integral(iSTDL, iSTDH);
647 if (sumd == 0.) {
648 sumeff = 0.;
649 sumerr = 0.;
650 } else {
651 sumeff = (double) sumn / (double) sumd;
652 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
653 }
654 h1sum_mu->SetBinContent(2, sumeff);
655 h1sum_mu->SetBinError(2, sumerr);
656
657 sumn = h1num_mu20->Integral(iSTDL, iSTDH);
658 sumd = h1den_mu20->Integral(iSTDL, iSTDH);
659 if (sumd == 0.) {
660 sumeff = 0.;
661 sumerr = 0.;
662 } else {
663 sumeff = (double) sumn / (double) sumd;
664 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
665 }
666 h1sum_mu->GetYaxis()->SetTitle("Efficiency");
667 h1sum_mu->SetBinContent(3, sumeff);
668 h1sum_mu->SetBinError(3, sumerr);
669 h1sum_mu->SetMaximum(1.05);
670 h1sum_mu->SetMinimum(0.0);
671 dir->cd();
672 h1sum_mu->Write("", TObject::kOverwrite);
673 mf.Write();
674 }
675 // end of the code add by Yuan //
676 // ******************************************************//
677 TString alg2[3] = {
678 "_L2MuonSA", "_MuonEFMS", "_MuonEFSA"
679 };
680 TString wrtalg2[3] = {
681 "_L1", "_L2MuonSA", "_L2MuonSA"
682 };
683
684 // ******************************************************//
685 // ****************** MSonly Chains ********************//
686 // ******************************************************//
687 for (unsigned int i = 0; i < chainsMSonly.size(); i++) {
688 TString chainName = chainsMSonly.at(i);
689
690#if 0
691 for (int trg = 0; trg < maxindep; trg++) {
692 sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered_Denominator";
693
694 for (int alg = 0; alg < 3; alg++) {
695 snum = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered_Numerator";
696 seff = eff_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered";
697 seffg = seff + "_Fit"; // YY added 20.04.10
698 stmp = chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered";
699 stmpg = chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered" + "_Fit";
700 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
701 if (!h1num) continue;
702
703 h1tmp = (TH1F*) h1den->Clone();
704 h1tmp->SetName(stmp);
705 h1tmp->SetTitle(stmp);
706 h1tmp->GetYaxis()->SetTitle("Efficiency");
707 h1tmp->Reset();
708 h1tmp->Divide(h1num, h1den, 1., 1., "B");
709 dir->cd();
710 h1tmp->Write();
711 h1tmpg = new TGraphAsymmErrors();
712 h1tmpg->SetName(stmpg);
713 h1tmpg->SetMarkerStyle(20);
714 h1tmpg->SetMinimum(0.0);
715 h1tmpg->SetMaximum(1.05);
716 h1tmpg->BayesDivide(h1num, h1den);
717 h1tmpg->GetYaxis()->SetTitle("Efficiency");
718 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
719 dir->cd();
720 h1tmpg->Write();
721 delete h1tmpg;
722
723 // summary for jet trigger
724 if (0 == alg || 2 == alg) {
725 if (3 == trg) { // jet
726 double sumeff {}, sumerr {};
727 double sumn = h1num->Integral(iMSL, iMSH);
728 double sumd = h1den->Integral(iMSL, iMSH);
729 if (sumd != 0.) {
730 sumeff = (double) sumn / (double) sumd;
731 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
732 }
733 int iholx = -1;
734 if (0 == alg) {
735 iholx = static_cast<int>(iL2MuonSA);
736 } else if (2 == alg) {
737 iholx = static_cast<int>(iEFSA);
738 }
739
740 if (iholx >= 0) {
741 TString s = eff_dir + chainName + "_highpt_effsummary_by" + vectkwd.at(2);
742 h1sumeff = getHPointer(s);
743 if (!h1sumeff) continue;
744
745 h1sumeff->SetBinContent(iholx + 1, sumeff);
746 h1sumeff->SetBinError(iholx + 1, sumerr);
747 h1sumeff->GetYaxis()->SetTitleOffset(1.3);
748 h1sumeff->SetMinimum(0.0);
749 h1sumeff->SetMaximum(1.05);
750 // saving
751 dir->cd();
752 h1sumeff->Write("", TObject::kOverwrite);
753 }
754 }
755 }
756 }//alg
757 }//trg
758#endif
759 mf.Write();
760
761 for (int alg = 0; alg < 3; alg++) {
762 //wrt MuidSA
763 sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA_Denominator";
764 snum = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_Numerator";
765 seff = eff_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA";
766 seffg = seff + "_Fit"; // YY added 20.04.10
767 stmp = chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA";
768 stmpg = chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
769 const auto & [pNum, pDen] = getHistogramPair(snum, sden);
770 if (!pNum) continue;
771
772 h1tmp = (TH1F*) pDen->Clone();
773 h1tmp->SetName(stmp);
774 h1tmp->SetTitle(stmp);
775 h1tmp->GetYaxis()->SetTitle("Efficiency");
776 h1tmp->Reset();
777 h1tmp->Divide(pNum, pDen, 1., 1., "B");
778 dir->cd();
779 h1tmp->Write();
780 h1tmpg = new TGraphAsymmErrors();
781 h1tmpg->SetName(stmpg);
782 h1tmpg->SetMarkerStyle(20);
783 h1tmpg->SetMinimum(0.0);
784 h1tmpg->SetMaximum(1.05);
785 h1tmpg->BayesDivide(pNum, pDen);
786 h1tmpg->GetYaxis()->SetTitle("Efficiency");
787 h1tmpg->GetXaxis()->SetTitle(pDen->GetXaxis()->GetTitle());
788 dir->cd();
789 h1tmpg->Write();
790 delete h1tmpg;
791
792 if (0 == alg || 2 == alg) { // no condition on ES bits = all events
793 double sumeff {}, sumerr {};
794 double sumn = pNum->Integral(iMSL, iMSH);
795 double sumd = pDen->Integral(iMSL, iMSH);
796 if (sumd != 0.) {
797 sumeff = (double) sumn / (double) sumd;
798 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
799 }
800 int iholx = -1;
801 if (0 == alg) {
802 iholx = static_cast<int>(iL2MuonSA);
803 } else if (2 == alg) {
804 iholx = static_cast<int>(iEFSA);
805 }
806
807 if (iholx >= 0) {
808 TString s = eff_dir + chainName + "_highpt_effsummary_by" + vectkwd.at(3);
809 h1sumeff = getHPointer(s);
810 if (!h1sumeff) continue;
811 h1sumeff->GetYaxis()->SetTitleOffset(1.3);
812 h1sumeff->SetBinContent(iholx + 1, sumeff);
813 h1sumeff->SetBinError(iholx + 1, sumerr);
814 h1sumeff->SetMinimum(0.0);
815 h1sumeff->SetMaximum(1.05);
816 // saving
817 dir->cd();
818 h1sumeff->Write("", TObject::kOverwrite);
819 }
820 }
821 //wrt MuidSA
822
823 // for ES ----------------------------------------------------------------
824 for (int ies = 0; ies <= maxESbr; ies++) {
825 if (!MS_mon_ESbr[ies]) continue;
826 // for ES, L1 ------------------------------------------------------------
827 if (0 == alg) {
828 sden = nd_dir + chainName + triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA_Denominator";
829 snum = nd_dir + chainName + triggerES[ies] + "_L2MuonSA" + "_Turn_On_Curve_wrt" + "_L1" + "_Denominator";
830 seff = eff_dir + chainName + triggerES[ies] + "_L1" + "_Turn_On_Curve_wrt_MuidSA";
831 seffg = seff + "_Fit";
832 stmp = chainName + triggerES[alg] + "_L1" + "_Turn_On_Curve_wrt_MuidSA";
833 stmpg = chainName + triggerES[alg] + "_L1" + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
834 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
835 if (!h1num) continue;
836
837 h1tmp = (TH1F*) h1den->Clone();
838 h1tmp->SetName(stmp);
839 h1tmp->SetTitle(stmp);
840 h1tmp->GetYaxis()->SetTitle("Efficiency");
841 h1tmp->Reset();
842 h1tmp->Divide(h1num, h1den, 1., 1., "B");
843 dir->cd();
844 h1tmp->Write();
845 h1tmpg = new TGraphAsymmErrors();
846 h1tmpg->SetName(stmpg);
847 h1tmpg->SetMarkerStyle(20);
848 h1tmpg->SetMinimum(0.0);
849 h1tmpg->SetMaximum(1.05);
850 h1tmpg->BayesDivide(h1num, h1den);
851 h1tmpg->GetYaxis()->SetTitle("Efficiency");
852 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
853 dir->cd();
854 h1tmpg->Write();
855 delete h1tmpg;
856
857
858 for (int be = 0; be < 2; be++) {
859 sden = nd_dir + chainName + triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA" + bestr[be] + "_Denominator";
860 snum = nd_dir + chainName + triggerES[ies] + "_L2MuonSA" + "_Turn_On_Curve_wrt" + "_L1" + bestr[be] +
861 "_Denominator";
862 seff = eff_dir + chainName + triggerES[ies] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidSA";
863 seffg = seff + "_Fit";
864 stmp = chainName + triggerES[ies] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidSA";
865 stmpg = chainName + triggerES[ies] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
866 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
867 if (!h1num) continue;
868
869 h1tmp = (TH1F*) h1den->Clone();
870 h1tmp->SetName(stmp);
871 h1tmp->SetTitle(stmp);
872 h1tmp->GetYaxis()->SetTitle("Efficiency");
873 h1tmp->Reset();
874 h1tmp->Divide(h1num, h1den, 1., 1., "B");
875 dir->cd();
876 h1tmp->Write();
877 h1tmpg = new TGraphAsymmErrors();
878 h1tmpg->SetName(stmpg);
879 h1tmpg->SetMarkerStyle(20);
880 h1tmpg->SetMinimum(0.0);
881 h1tmpg->SetMaximum(1.05);
882 h1tmpg->BayesDivide(h1num, h1den);
883 h1tmpg->GetYaxis()->SetTitle("Efficiency");
884 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
885 dir->cd();
886 h1tmpg->Write();
887 delete h1tmpg;
888 }
889 }
890
891 // for ES, L1 end ------------------------------------------------------------
892 sden = nd_dir + chainName + triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA_Denominator";
893 snum = nd_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_Numerator";
894 seff = eff_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA";
895 seffg = seff + "_Fit"; // YY added 20.04.10
896 stmp = chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA";
897 stmpg = chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
898 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
899 if (!h1num) continue;
900
901 h1tmp = (TH1F*) h1den->Clone();
902 h1tmp->SetName(stmp);
903 h1tmp->SetTitle(stmp);
904 h1tmp->GetYaxis()->SetTitle("Efficiency");
905 h1tmp->Reset();
906 h1tmp->Divide(h1num, h1den, 1., 1., "B");
907 dir->cd();
908 h1tmp->Write();
909 h1tmpg = new TGraphAsymmErrors();
910 h1tmpg->SetName(stmpg);
911 h1tmpg->SetMarkerStyle(20);
912 h1tmpg->SetMinimum(0.0);
913 h1tmpg->SetMaximum(1.05);
914 h1tmpg->BayesDivide(h1num, h1den);
915 h1tmpg->GetYaxis()->SetTitle("Efficiency");
916 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
917 dir->cd();
918 h1tmpg->Write();
919 delete h1tmpg;
920
921 if (0 == alg || 2 == alg) {
922 if (ESTAG == ies || ESINDEP == ies) {
923 double sumeff, sumerr;
924 double sumn = h1num->Integral(iMSL, iMSH);
925 double sumd = h1den->Integral(iMSL, iMSH);
926 if (sumd == 0.) {
927 sumeff = 0.;
928 sumerr = 0.;
929 } else {
930 sumeff = (double) sumn / (double) sumd;
931 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
932 }
933 int iholx = -1;
934 if (0 == alg) {
935 iholx = static_cast<int>(iL2MuonSA);
936 } else if (2 == alg) {
937 iholx = static_cast<int>(iEFSA);
938 }
939
940 if (iholx >= 0) {
941 TString s = eff_dir + chainName + "_highpt_effsummary_by" + triggerES[ies];
942 h1sumeff = getHPointer(s);
943 if (!h1sumeff) continue;
944 h1sumeff->GetYaxis()->SetTitleOffset(1.3);
945 h1sumeff->SetBinContent(iholx + 1, sumeff);
946 h1sumeff->SetBinError(iholx + 1, sumerr);
947 h1sumeff->SetMinimum(0.0);
948 h1sumeff->SetMaximum(1.05);
949 // saving
950 dir->cd();
951 h1sumeff->Write("", TObject::kOverwrite);
952 }
953 }
954 }
955 }
956 // for ES: end ----------------------------------------------------------------
957
958 if (0 == alg || 2 == alg) {
959 for (int be = 0; be < 2; be++) {
960 //wrt MuidSA
961 sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA" + bestr[be] + "_Denominator";
962 snum = nd_dir + chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
963 seff = eff_dir + chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidSA";
964 seffg = seff + "_Fit"; // YY added 20.04.10
965 stmp = chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidSA";
966 stmpg = chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
967 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
968 if (!h1num) continue;
969
970 h1tmp = (TH1F*) h1den->Clone();
971 h1tmp->SetName(stmp);
972 h1tmp->SetTitle(stmp);
973 h1tmp->GetYaxis()->SetTitle("Efficiency");
974 h1tmp->Reset();
975 h1tmp->Divide(h1num, h1den, 1., 1., "B");
976 dir->cd();
977 h1tmp->Write();
978 h1tmpg = new TGraphAsymmErrors();
979 h1tmpg->SetName(stmpg);
980 h1tmpg->SetMarkerStyle(20);
981 h1tmpg->SetMinimum(0.0);
982 h1tmpg->SetMaximum(1.05);
983 h1tmpg->BayesDivide(h1num, h1den);
984 h1tmpg->GetYaxis()->SetTitle("Efficiency");
985 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
986 dir->cd();
987 h1tmpg->Write();
988 delete h1tmpg;
989 }
990 }
991
992 //wrt upstream
993 sden = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + "_Denominator";
994 snum = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_Numerator";
995 seff = eff_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg];
996 seffg = seff + "_Fit"; // YY added 20.04.10
997 stmp = chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg];
998 stmpg = chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + "_Fit";
999 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1000 if (!h1num) continue;
1001
1002 h1tmp = (TH1F*) h1den->Clone();
1003 h1tmp->SetName(stmp);
1004 h1tmp->SetTitle(stmp);
1005 h1tmp->GetYaxis()->SetTitle("Efficiency");
1006 h1tmp->Reset();
1007 h1tmp->Divide(h1num, h1den, 1., 1., "B");
1008 dir->cd();
1009 h1tmp->Write();
1010 h1tmpg = new TGraphAsymmErrors();
1011 h1tmpg->SetName(stmpg);
1012 h1tmpg->SetMarkerStyle(20);
1013 h1tmpg->SetMinimum(0.0);
1014 h1tmpg->SetMaximum(1.05);
1015 h1tmpg->BayesDivide(h1num, h1den);
1016 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1017 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1018 dir->cd();
1019 h1tmpg->Write();
1020 delete h1tmpg;
1021
1022
1023 //wrt upstream
1024 // for ES --------------------------------------------------------------------
1025 for (int ies = 0; ies <= maxESbr; ies++) {
1026 if (!MS_mon_ESbr[ies]) continue;
1027 sden = nd_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] +
1028 "_Denominator";
1029 snum = nd_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_Numerator";
1030 seff = eff_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg];
1031 seffg = seff + "_Fit"; // YY added 20.04.10
1032 stmp = chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg];
1033 stmpg = chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + "_Fit";
1034 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1035 if (!h1num) continue;
1036
1037 h1tmp = (TH1F*) h1den->Clone();
1038 h1tmp->SetName(stmp);
1039 h1tmp->SetTitle(stmp);
1040 h1tmp->GetYaxis()->SetTitle("Efficiency");
1041 h1tmp->Reset();
1042 h1tmp->Divide(h1num, h1den, 1., 1., "B");
1043 dir->cd();
1044 h1tmp->Write();
1045 h1tmpg = new TGraphAsymmErrors();
1046 h1tmpg->SetName(stmpg);
1047 h1tmpg->SetMarkerStyle(20);
1048 h1tmpg->SetMinimum(0.0);
1049 h1tmpg->SetMaximum(1.05);
1050 h1tmpg->BayesDivide(h1num, h1den);
1051 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1052 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1053 dir->cd();
1054 h1tmpg->Write();
1055 delete h1tmpg;
1056 }
1057 // for ES: end --------------------------------------------------------------------
1058
1059 if (0 == alg || 2 == alg) {
1060 for (int be = 0; be < 2; be++) {
1061 //wrt upstream
1062 sden = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + bestr[be] + "_Denominator";
1063 snum = nd_dir + chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1064 seff = eff_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + bestr[be];
1065 seffg = seff + "_Fit"; // YY added 20.04.10
1066 stmp = chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + bestr[be];
1067 stmpg = chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + bestr[be] + "_Fit";
1068 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1069 if (!h1num) continue;
1070
1071 h1tmp = (TH1F*) h1den->Clone();
1072 h1tmp->SetName(stmp);
1073 h1tmp->SetTitle(stmp);
1074 h1tmp->GetYaxis()->SetTitle("Efficiency");
1075 h1tmp->Reset();
1076 h1tmp->Divide(h1num, h1den, 1., 1., "B");
1077 dir->cd();
1078 h1tmp->Write();
1079 h1tmpg = new TGraphAsymmErrors();
1080 h1tmpg->SetName(stmpg);
1081 h1tmpg->SetMarkerStyle(20);
1082 h1tmpg->SetMinimum(0.0);
1083 h1tmpg->SetMaximum(1.05);
1084 h1tmpg->BayesDivide(h1num, h1den);
1085 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1086 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1087 dir->cd();
1088 h1tmpg->Write();
1089 delete h1tmpg;
1090 }
1091 }
1092 }//alg
1093 mf.Write();
1094 }//i
1095
1096 //==Rate
1097 dir = mf.GetDirectory(rr_dir);
1098 if (!dir) {
1099 if (fdbg) {
1100 std::cerr << "HLTMuonHistogramDivision: directory " << rr_dir << " not found" << std::endl;
1101 }
1102 return;
1103 }
1104
1105 // EF rate / offline rate
1106 std::string type[3] = {
1107 "MS_", "SA_", "CB_"
1108 };
1109 std::string off[3] = {
1110 "Moore_MS_", "Moore_SA_", "Muid_"
1111 };
1112 std::string cut[2] = {
1113 "4", "10"
1114 };
1115
1116 for (int itype = 0; itype < 3; itype++) {
1117 for (int icut = 0; icut < 2; icut++) {
1118 seff = rr_dir + "EF_" + type[itype] + "Over_" + off[itype] + cut[icut] + "GeV_Cut";
1119 snum = rate_dir + "Number_Of_EF_" + type[itype] + "Muons_" + cut[icut] + "GeV_Cut";
1120 sden = rate_dir + "Number_Of_" + off[itype] + "Muons_" + cut[icut] + "GeV_Cut";
1121 stmp = "EF_" + type[itype] + "Over_" + off[itype] + cut[icut] + "GeV_Cut";
1122 stmpg = "EF_" + type[itype] + "Over_" + off[itype] + cut[icut] + "GeV_Cut" + "_Fit";
1123 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1124 if (!h1num) continue;
1125
1126 h1tmp = (TH1F*) h1den->Clone();
1127 h1tmp->SetName(stmp);
1128 h1tmp->SetTitle(stmp);
1129 h1tmp->GetYaxis()->SetTitle("Efficiency");
1130 h1tmp->Reset();
1131 h1tmp->Divide(h1num, h1den, 1., 1., "B");
1132 dir->cd();
1133 h1tmp->Write();
1134 }//icut
1135 }//itype
1136 mf.Write();
1137
1138 // Triggers / Event
1139 std::vector<TString> chains;
1140 std::vector<TString> chains2;
1141
1142 {
1143 std::map<std::string, std::string> ztpmap;
1144
1145 ztpmap["muChain1"] = "L1_MU15";
1146 ztpmap["muChain2"] = "L1_MU15";
1147 ztpmap["muChainEFiso1"] = "L1_MU15";
1148 ztpmap["muChainEFiso2"] = "L1_MU15";
1149 ztpmap["muChainMSonly1"] = "L1_MU15";
1150 ztpmap["muChainMSonly2"] = "L1_MU15";
1151
1152 std::map<std::string, int> ztp_isomap;
1153 ztp_isomap["muChain1"] = 0;
1154 ztp_isomap["muChain2"] = 0;
1155 ztp_isomap["muChainEFiso1"] = 1;
1156 ztp_isomap["muChainEFiso2"] = 1;
1157 ztp_isomap["muChainMSonly1"] = 0;
1158 ztp_isomap["muChainMSonly2"] = 0;
1159
1160 for (std::map<std::string, std::string>::iterator itmap = ztpmap.begin(); itmap != ztpmap.end(); ++itmap) {
1161 TString histdirmuztp = run_dir + "/HLT/MuonMon/MuZTP/" + itmap->first;
1162 TDirectory* ztpdir = mf.GetDirectory(histdirmuztp);
1163 bool isefisochain = ztp_isomap[itmap->first] > 0;
1164
1165 //efficiency histograms
1166 std::vector<std::string> var;
1167 var.push_back("_Pt_");
1168 var.push_back("_Pt_EC_");
1169 var.push_back("_Pt_B_");
1170 var.push_back("_Pt_4bins_");
1171 var.push_back("_Pt_B_4bins_");
1172 var.push_back("_Eta_");
1173 var.push_back("_Phi_");
1174 var.push_back("_Phi_EC_");
1175 var.push_back("_Phi_B_");
1176 for (unsigned int k = 0; k < var.size(); k++) {
1177 std::vector<std::string> level;
1178 level.push_back("L1");
1179 level.push_back("L2");
1180 level.push_back("EF");
1181 if (isefisochain) level.push_back("EFIso");
1182 for (unsigned int j = 0; j < level.size(); j++) {
1183 //ABSOLUTE
1184 seffg = histdirmuztp + "/muZTP_eff_" + level[j] + var[k] + itmap->first;
1185 snum = histdirmuztp + "/muZTP" + var[k] + level[j] + "fired_" + itmap->first;
1186 sden = histdirmuztp + "/muZTP" + var[k] + itmap->first;
1187 stmp = "muZTP_eff_" + level[j] + var[k] + itmap->first;
1188 stmpg = "muZTP_eff_" + level[j] + var[k] + itmap->first;
1189 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1190 if (!h1num) continue;
1191
1192 h1tmpg = new TGraphAsymmErrors();
1193 h1tmpg->SetName(stmpg);
1194 h1tmpg->SetMarkerStyle(20);
1195 h1tmpg->SetMinimum(0.0);
1196 h1tmpg->SetMaximum(1.05);
1197 h1tmpg->BayesDivide(h1num, h1den);
1198 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1199 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1200 ztpdir->cd();
1201 h1tmpg->Write();
1202 delete h1tmpg;
1203 mf.Write();
1204
1205 seffg = histdirmuztp + "/muZTP_eff_" + level[j] + "_Eta_1bin_" + itmap->first;
1206 snum = histdirmuztp + "/muZTP_Eta_1bin_" + level[j] + "fired_" + itmap->first;
1207 sden = histdirmuztp + "/muZTP_Eta_1bin_" + itmap->first;
1208 stmpg = "muZTP_eff_" + level[j] + "_Eta_1bin_" + itmap->first;
1209 const auto & [h1num2, h1den2] = getHistogramPair(snum, sden);
1210 if (!h1num2) continue;
1211
1212 h1tmpg = new TGraphAsymmErrors();
1213 h1tmpg->SetName(stmpg);
1214 h1tmpg->SetMarkerStyle(20);
1215 h1tmpg->SetMinimum(0.0);
1216 h1tmpg->SetMaximum(1.05);
1217 h1tmpg->BayesDivide(h1num2, h1den2);
1218 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1219 h1tmpg->GetXaxis()->SetTitle(h1den2->GetXaxis()->GetTitle());
1220 ztpdir->cd();
1221 h1tmpg->Write();
1222 delete h1tmpg;
1223 mf.Write();
1224
1225 seffg = histdirmuztp + "/muZTP_eff_" + level[j] + "_Eta_2bins_" + itmap->first;
1226 snum = histdirmuztp + "/muZTP_Eta_2bins_" + level[j] + "fired_" + itmap->first;
1227 sden = histdirmuztp + "/muZTP_Eta_2bins_" + itmap->first;
1228 stmpg = "muZTP_eff_" + level[j] + "_Eta_2bins_" + itmap->first;
1229 const auto & [h1num3, h1den3] = getHistogramPair(snum, sden);
1230
1231 //h1num = getHPointer(snum);
1232 if (!h1num3) continue;
1233 //h1den = getHPointer(sden);
1234 //if (!h1den) continue;
1235
1236 h1tmpg = new TGraphAsymmErrors();
1237 h1tmpg->SetName(stmp);
1238 h1tmpg->SetMarkerStyle(20);
1239 h1tmpg->SetMinimum(0.0);
1240 h1tmpg->SetMaximum(1.05);
1241 h1tmpg->BayesDivide(h1num3, h1den3);
1242 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1243 h1tmpg->GetXaxis()->SetTitle(h1den3->GetXaxis()->GetTitle());
1244 ztpdir->cd();
1245 h1tmpg->Write();
1246 delete h1tmpg;
1247 mf.Write();
1248
1249 seffg = histdirmuztp + "/muZTP_eff_" + level[j] + "_Eta_1bin_cut_" + itmap->first;
1250 snum = histdirmuztp + "/muZTP_Eta_1bin_cut_" + level[j] + "fired_" + itmap->first;
1251 sden = histdirmuztp + "/muZTP_Eta_1bin_cut_" + itmap->first;
1252 stmpg = "muZTP_eff_" + level[j] + "_Eta_1bin_cut_" + itmap->first;
1253 const auto & [h1num4, h1den4] = getHistogramPair(snum, sden);
1254 if (!h1num4) continue;
1255
1256 h1tmpg = new TGraphAsymmErrors();
1257 h1tmpg->SetName(stmpg);
1258 h1tmpg->SetMarkerStyle(20);
1259 h1tmpg->SetMinimum(0.0);
1260 h1tmpg->SetMaximum(1.05);
1261 h1tmpg->BayesDivide(h1num4, h1den4);
1262 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1263 h1tmpg->GetXaxis()->SetTitle(h1den4->GetXaxis()->GetTitle());
1264 ztpdir->cd();
1265 h1tmpg->Write();
1266 delete h1tmpg;
1267 mf.Write();
1268
1269 seffg = histdirmuztp + "/muZTP_eff_" + level[j] + "_Eta_2bins_cut_" + itmap->first;
1270 snum = histdirmuztp + "/muZTP_Eta_2bins_cut_" + level[j] + "fired_" + itmap->first;
1271 sden = histdirmuztp + "/muZTP_Eta_2bins_cut_" + itmap->first;
1272 stmpg = "muZTP_eff_" + level[j] + "_Eta_2bins_cut_" + itmap->first;
1273 const auto & [h1num5, h1den5] = getHistogramPair(snum, sden);
1274 if (!h1num5) continue;
1275
1276 h1tmpg = new TGraphAsymmErrors();
1277 h1tmpg->SetName(stmpg);
1278 h1tmpg->SetMarkerStyle(20);
1279 h1tmpg->SetMinimum(0.0);
1280 h1tmpg->SetMaximum(1.05);
1281 h1tmpg->BayesDivide(h1num5, h1den5);
1282 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1283 h1tmpg->GetXaxis()->SetTitle(h1den5->GetXaxis()->GetTitle());
1284 ztpdir->cd();
1285 h1tmpg->Write();
1286 delete h1tmpg;
1287 mf.Write();
1288
1289 //2D ETA_PHI
1290 seff = histdirmuztp + "/muZTP_eff_EtaPhi_" + level[j] + "_" + itmap->first;
1291 snum = histdirmuztp + "/muZTP_EtaPhi_" + level[j] + "_" + itmap->first;
1292 sden = histdirmuztp + "/muZTP_EtaPhi_all_" + itmap->first;
1293 stmp = "muZTP_eff_EtaPhi_" + level[j] + "_" + itmap->first;
1294
1295 TH2F* h2num(0);
1296 TH2F* h2den(0);
1297 TH2F* h2tmp(0);
1298
1299 h2num = getH2Pointer(snum);
1300 if (!h2num) continue;
1301 h2den = getH2Pointer(sden);
1302 if (!h2den) continue;
1303
1304 h2tmp = (TH2F*) h1den->Clone();
1305 h2tmp->SetName(stmp);
1306 h2tmp->SetTitle(stmp);
1307 h2tmp->GetYaxis()->SetTitle("Efficiency");
1308 h2tmp->Reset();
1309 h2tmp->Divide(h1num, h1den, 1., 1., "B");
1310 dir->cd();
1311 h2tmp->Write();
1312 mf.Write();
1313 }//level
1314
1315 //RELATIVE
1316 seffg = histdirmuztp + "/muZTP_eff_EFwrtL2" + var[k] + itmap->first;
1317 snum = histdirmuztp + "/muZTP" + var[k] + "EFL2fired_" + itmap->first;
1318 sden = histdirmuztp + "/muZTP" + var[k] + "L2fired_" + itmap->first;
1319 stmpg = "muZTP_eff_EFwrtL2" + var[k] + itmap->first;
1320 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1321 if (!h1num) continue;
1322
1323 h1tmpg = new TGraphAsymmErrors();
1324 h1tmpg->SetName(stmpg);
1325 h1tmpg->SetMarkerStyle(20);
1326 h1tmpg->SetMinimum(0.0);
1327 h1tmpg->SetMaximum(1.05);
1328 h1tmpg->BayesDivide(h1num, h1den);
1329 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1330 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1331 ztpdir->cd();
1332 h1tmpg->Write();
1333 delete h1tmpg;
1334 mf.Write();
1335
1336 seffg = histdirmuztp + "/muZTP_eff_EFwrtL1" + var[k] + itmap->first;
1337 snum = histdirmuztp + "/muZTP" + var[k] + "EFfired_" + itmap->first;
1338 sden = histdirmuztp + "/muZTP" + var[k] + "L1fired_" + itmap->first;
1339 stmpg = "muZTP_eff_EFwrtL1" + var[k] + itmap->first;
1340 const auto & [h1num2, h1den2] = getHistogramPair(snum, sden);
1341 if (!h1num2) continue;
1342
1343 h1tmpg = new TGraphAsymmErrors();
1344 h1tmpg->SetName(stmpg);
1345 h1tmpg->SetMarkerStyle(20);
1346 h1tmpg->SetMinimum(0.0);
1347 h1tmpg->SetMaximum(1.05);
1348 h1tmpg->BayesDivide(h1num2, h1den2);
1349 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1350 h1tmpg->GetXaxis()->SetTitle(h1den2->GetXaxis()->GetTitle());
1351 ztpdir->cd();
1352 h1tmpg->Write();
1353 delete h1tmpg;
1354 mf.Write();
1355
1356 seffg = histdirmuztp + "/muZTP_eff_L2wrtL1" + var[k] + itmap->first;
1357 snum = histdirmuztp + "/muZTP" + var[k] + "L2fired_" + itmap->first;
1358 sden = histdirmuztp + "/muZTP" + var[k] + "L1fired_" + itmap->first;
1359 stmpg = "muZTP_eff_L2wrtL1" + var[k] + itmap->first;
1360 const auto & [h1num3, h1den3] = getHistogramPair(snum, sden);
1361 if (!h1num3) continue;
1362
1363 h1tmpg = new TGraphAsymmErrors();
1364 h1tmpg->SetName(stmpg);
1365 h1tmpg->SetMarkerStyle(20);
1366 h1tmpg->SetMinimum(0.0);
1367 h1tmpg->SetMaximum(1.05);
1368 h1tmpg->BayesDivide(h1num3, h1den3);
1369 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1370 h1tmpg->GetXaxis()->SetTitle(h1den3->GetXaxis()->GetTitle());
1371 ztpdir->cd();
1372 h1tmpg->Write();
1373 delete h1tmpg;
1374 mf.Write();
1375
1376 if (isefisochain) {
1377 seffg = histdirmuztp + "/muZTP_eff_EFIsowrtEF" + var[k] + itmap->first;
1378 snum = histdirmuztp + "/muZTP" + var[k] + "EFIsofired_" + itmap->first;
1379 sden = histdirmuztp + "/muZTP" + var[k] + "EFfired_" + itmap->first;
1380 stmpg = "muZTP_eff_EFIsowrtEF" + var[k] + itmap->first;
1381 const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1382 if (!h1num) continue;
1383
1384 h1tmpg = new TGraphAsymmErrors();
1385 h1tmpg->SetName(stmpg);
1386 h1tmpg->SetMarkerStyle(20);
1387 h1tmpg->SetMinimum(0.0);
1388 h1tmpg->SetMaximum(1.05);
1389 h1tmpg->BayesDivide(h1num, h1den);
1390 h1tmpg->GetYaxis()->SetTitle("Efficiency");
1391 h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1392 ztpdir->cd();
1393 h1tmpg->Write();
1394 delete h1tmpg;
1395 mf.Write();
1396 }
1397 }//var
1398 }
1399 // mf.Write();
1400 } // procMuZTP
1401
1402
1403 {
1404 TDirectory* efdir = mf.GetDirectory(eff_dir);
1405 if (!efdir) {
1406 if (fdbg) {
1407 std::cerr << "HLTMuonHistogramDivision: directory " << eff_dir << " not found" << std::endl;
1408 }
1409 return;
1410 }
1411
1412 // MAM
1413 const int MAXARR = 6;
1414 std::string charr[MAXARR] = {
1415 "muChain1", "muChain2", "muChainEFiso1", "muChainEFiso2", "muChainMSonly1", "muChainMSonly2"
1416 };
1417 std::string monarr[MAXARR] = {
1418 "_EFmuon", "_EFmuon", "_EFmuon", "_EFmuon", "_MuonEFSA", "_MuonEFSA"
1419 };
1420 std::string monL2arr[MAXARR] = {
1421 "_L2MuonSA", "_L2MuonSA", "_L2MuonSA", "_L2MuonSA", "_L2MuonSA", "_L2MuonSA"
1422 };
1423 bool isBarrelMon[MAXARR] = {
1424 false, false, false, false, true, true
1425 }; // enable MSonly
1426 bool isMSbMon[MAXARR] = {
1427 true, true, false, false, false, false
1428 }; // Skip isol and MSonly
1429 bool monL1[MAXARR] = {
1430 true, true, true, true, false, false
1431 }; // Skip MSonly
1432 bool isefIsolation[MAXARR] = {
1433 false, false, true, true, false, false
1434 }; // EF isolation add by Yuan
1435
1436 // I need to prepare maps ... mu20_MG -> MuGirlEF etc.
1437 for (int ialg = 0; ialg < MAXARR; ialg++) {
1438 std::string chainName = charr[ialg];
1439 std::string MoniAlg = monarr[ialg];
1440 std::string MoniL2Alg = monL2arr[ialg];
1441
1442 /* 1. Picking up ztp graph */
1443 TString hdirztp = muon_dir + "MuZTP/" + chainName + "/";
1444 TString histZtpNum, histZtpDen;
1445 if (!isBarrelMon[ialg]) {
1446 histZtpNum = hdirztp + "muZTP_Pt_4bins_EFfired_" + chainName;
1447 histZtpDen = hdirztp + "muZTP_Pt_4bins_L1fired_" + chainName;
1448 } else {
1449 histZtpNum = hdirztp + "muZTP_Pt_B_4bins_EFfired_" + chainName;
1450 histZtpDen = hdirztp + "muZTP_Pt_B_4bins_L1fired_" + chainName;
1451 }
1452 if (isefIsolation[ialg]) histZtpNum = hdirztp + "muZTP_Pt_4bins_EFIsofired_" + chainName; // add by Yuan
1453 TString histZtpEff = eff_dir + chainName + "_highpt3bins_effwrtL1";
1454 const auto & [h1num, h1den] = getHistogramPair(histZtpNum, histZtpDen);
1455 if (!h1num) continue;
1456 h1eff = getHPointer(histZtpEff);
1457 if (!h1eff) continue;
1458
1459 /* 2. Filling summary histogram from ZTP values */
1460 for (int ibin = 2; ibin <= 3; ibin++) {
1461 // at the moment it is not correct if we run the algorithm # 4: mu40_MSonly_barrel .
1462 double sumeff {}, sumerr {};
1463 double sumn = h1num->Integral(ibin, ibin);
1464 if (isBarrelMon[ialg] || isMSbMon[ialg]) sumn = h1num->Integral(ibin + 1, ibin + 1);
1465 double sumd = h1den->Integral(ibin, ibin);
1466 if (isBarrelMon[ialg] || isMSbMon[ialg]) sumd = h1den->Integral(ibin + 1, ibin + 1);
1467 if (sumd != 0.) {
1468 sumeff = (double) sumn / (double) sumd;
1469 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1470 }
1471 h1eff->GetYaxis()->SetTitle("Efficiency");
1472 h1eff->SetBinContent(ibin - 1, sumeff);
1473 h1eff->SetBinError(ibin - 1, sumerr);
1474 h1eff->SetMinimum(0.0);
1475 h1eff->SetMaximum(1.05);
1476 }
1477
1478
1479
1480 efdir->cd();
1481 h1eff->Write("", TObject::kOverwrite);
1482
1483 if (monL1[ialg]) { // MUST skip muGirl, muIso and MSonly as histograms are not defined!!!
1484 TString hdirztp = muon_dir + "MuZTP/" + chainName + "/";
1485 TString histZtpNumB = hdirztp + "muZTP_Pt_B_L1fired_" + chainName;
1486 TString histZtpDenB = hdirztp + "muZTP_Pt_B_" + chainName;
1487 TString histZtpNumE = hdirztp + "muZTP_Pt_EC_L1fired_" + chainName;
1488 TString histZtpDenE = hdirztp + "muZTP_Pt_EC_" + chainName;
1489 TString histZtpL1sum = eff_dir + chainName + "_highptL1plateau_wrtOffline";
1490
1491 TH1F* h1numb = getHPointer(histZtpNumB);
1492 if (!h1numb) continue;
1493 TH1F* h1nume = getHPointer(histZtpNumE);
1494 if (!h1nume) continue;
1495 TH1F* h1denb = getHPointer(histZtpDenB);
1496 if (!h1denb) continue;
1497 TH1F* h1dene = getHPointer(histZtpDenE);
1498 if (!h1dene) continue;
1499 TH1F* h1sumL = getHPointer(histZtpL1sum);
1500 if (!h1sumL) continue;
1501
1502 double sumeff, sumerr;
1503 double sumn = h1numb->Integral(13, 25); // 12-25 GeV
1504 if (HI_pp_key) sumn = h1numb->Integral(13, 20); // 60-100 GeV
1505 double sumd = h1denb->Integral(13, 25);
1506 if (HI_pp_key) sumd = h1denb->Integral(13, 20);
1507 if (sumd == 0.) {
1508 sumeff = 0.;
1509 sumerr = 0.;
1510 } else {
1511 sumeff = (double) sumn / (double) sumd;
1512 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1513 }
1514 h1sumL->SetBinContent(1, sumeff);
1515 h1sumL->SetBinError(1, sumerr);
1516
1517 sumn = h1nume->Integral(13, 25);
1518 if (HI_pp_key) sumn = h1numb->Integral(13, 20); // 60-100 GeV
1519 sumd = h1dene->Integral(13, 25);
1520 if (HI_pp_key) sumd = h1denb->Integral(13, 20);
1521 if (sumd == 0.) {
1522 sumeff = 0.;
1523 sumerr = 0.;
1524 } else {
1525 sumeff = (double) sumn / (double) sumd;
1526 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1527 }
1528 h1sumL->GetYaxis()->SetTitle("Efficiency");
1529 h1sumL->SetBinContent(2, sumeff);
1530 h1sumL->SetBinError(2, sumerr);
1531 h1sumL->SetMinimum(0.0);
1532 h1sumL->SetMaximum(1.05);
1533 efdir->cd();
1534 h1sumL->Write("", TObject::kOverwrite);
1535 }
1536 }
1537 mf.Write();
1538 } //procChainDQA_HighPt
1539 //===End HLTMuonw
1540
1541 // ******************************************************//
1542 // ********************* generic ***********************//
1543 // ******************************************************//
1544 TString monalg[3] = {
1545 "_L2MuonSA", "_MuComb", "_EFmuon"
1546 };
1547 TString wrtalg[3] = {
1548 "_L1", "_L2MuonSA", "_MuComb"
1549 };
1550 TString numer, denom, effi;
1551 TString histdireff = eff_dir;
1552
1553 TDirectory* efdir = mf.GetDirectory(eff_dir);
1554 if (!efdir) {
1555 if (fdbg) {
1556 std::cerr << "HLTMuonHistogramDivision: directory " << eff_dir << " not found" << std::endl;
1557 }
1558 return;
1559 }
1560
1561 // processing Iso histograms in the same manner
1562 chainsGeneric.insert(chainsGeneric.end(), chainsEFiso.begin(), chainsEFiso.end());
1563
1564 for (unsigned int i = 0; i < chainsGeneric.size(); i++) {
1565 TString chainName = chainsGeneric.at(i);
1566 if (fdbg) {
1567 std::cout << "proc generic " << chainName << std::endl;
1568 }
1569
1570 //wrt CB muon && Upstream trigger
1571 for (int alg = 0; alg < 3; alg++) {
1572 denom = chainName + "_Turn_On_Curve_wrt_MuidCB_Denominator";
1573 numer = chainName + monalg[alg] + "_Turn_On_Curve_Numerator";
1574 effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB";
1575 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1576
1577 denom = chainName + MSchainName + "_Turn_On_Curve_wrt_MuidCB_Denominator";
1578 numer = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_Numerator";
1579 effi = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB";
1580 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1581
1582 // Summary all - removed
1583
1584 denom = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator";
1585 numer = chainName + monalg[alg] + "_Turn_On_Curve_Numerator";
1586 effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg];
1587 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1588
1589
1590 denom = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator";
1591 numer = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_Numerator";
1592 effi = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg];
1593 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1594
1595 // for ES ------------------------------------------------------------------------------------
1596 for (int i = 0; i <= maxESbr; i++) {
1597 if (!CB_mon_ESbr[i]) continue;
1598 if (0 == alg) {
1599 // L1 efficiency: new for 2011 HI runs and afterward
1600 // only division once since it is "the zero-th" algorithm
1601 denom = chainName + triggerES[i] + "_Turn_On_Curve_wrt_MuidCB_Denominator";
1602 numer = chainName + triggerES[i] + "_L2MuonSA" + "_Turn_On_Curve_wrt" + "_L1" + "_Denominator";
1603 effi = chainName + triggerES[i] + "_L1" + "_Turn_On_Curve_wrt_MuidCB";
1604 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1605
1606 // Need to implement barrel and endcap ...
1607 for (int be = 0; be < 2; be++) {
1608 denom = chainName + triggerES[i] + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator";
1609 numer = chainName + triggerES[i] + "_L2MuonSA" + "_Turn_On_Curve_wrt" + "_L1" + bestr[be] +
1610 "_Denominator";
1611 effi = chainName + triggerES[i] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidCB";
1612 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1613 const auto & [h1num, h1den] = getHistogramPair(nd_dir + numer, nd_dir + denom);
1614 if (!h1num) continue;
1615
1616 if (ESINDEP == i) {
1617 // integrating over and fill in a summary histogram
1618 double sumeff {}, sumerr {};
1619 double sumn = h1num->Integral(iSTDL, iSTDH); // 60-100 GeV
1620 double sumd = h1den->Integral(iSTDL, iSTDH);
1621
1622 if (sumd != 0.) {
1623 sumeff = (double) sumn / (double) sumd;
1624 sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1625 }
1626
1627 TString s = histdireff + chainName + "_L1plateau_wrtOffline_by_ESindep";
1628 TH1F* h1effL1 = getHPointer(s);
1629 if (!h1effL1) continue;
1630 h1effL1->SetBinContent(be + 1, sumeff);
1631 h1effL1->SetBinError(be + 1, sumerr);
1632 h1eff->SetMinimum(0.0);
1633 h1eff->SetMaximum(1.05);
1634 efdir->cd();
1635 h1effL1->Write("", TObject::kOverwrite);
1636 }
1637 }
1638 }
1639
1640 denom = chainName + triggerES[i] + "_Turn_On_Curve_wrt_MuidCB_Denominator";
1641 numer = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_Numerator";
1642 effi = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB";
1643 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1644 const auto & [h1num, h1den] = getHistogramPair(nd_dir + numer, nd_dir + denom);
1645
1646 // Summary ESid and ESindep
1647
1648 if (!h1num) continue;
1649 if (0 == alg || 1 == alg || 2 == alg) {
1650 double sumd {}, sumn {}, sumeff {}, sumerr {};
1651 sumn = h1num->Integral(iSTDL, iSTDH);
1652 sumd = h1den->Integral(iSTDL, iSTDH);
1653
1654 if (sumd != 0.) {
1655 sumeff = (double) sumn / (double) sumd;
1656 sumerr = std::sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1657 }
1658 int iholx = -1;
1659 if (0 == alg) {
1660 iholx = static_cast<int>(iL2MuonSA);
1661 } else if (1 == alg) {
1662 iholx = static_cast<int>(iMuComb);
1663 } else if (2 == alg) {
1664 iholx = static_cast<int>(iEFCB);
1665 }
1666
1667 TString s = histdireff + chainName + "_highpt_effsummary_by" + triggerES[i];
1668 h1effsum = getHPointer(s);
1669 if (!h1effsum) continue;
1670 //
1671 h1effsum->GetYaxis()->SetTitleOffset(1.3);
1672 h1effsum->SetBinContent(iholx + 1, sumeff);
1673 h1effsum->SetBinError(iholx + 1, sumerr);
1674 h1effsum->SetMinimum(0.0);
1675 h1effsum->SetMaximum(1.05);
1676 efdir->cd();
1677 h1effsum->Write("", TObject::kOverwrite);
1678 }
1679
1680 denom = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator";
1681 numer = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_Numerator";
1682 effi = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg];
1683 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1684 }
1685 // for ES : END ------------------------------------------------------------------------------
1686
1687 // Barrel/Endcap
1688 if (0 == alg || 1 == alg || 2 == alg) {
1689 for (int be = 0; be < 2; be++) {
1690 denom = chainName + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator";
1691 numer = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1692 effi = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidCB";
1693 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1694 }
1695
1696 for (int be = 0; be < 2; be++) {
1697 denom = chainName + MSchainName + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator";
1698 numer = chainName + MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1699 effi = chainName + MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidCB";
1700 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1701 }
1702
1703 for (int be = 0; be < 2; be++) {
1704 denom = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be] + "_Denominator";
1705 numer = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1706 effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be];
1707 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1708 }
1709
1710
1711 for (int be = 0; be < 2; be++) {
1712 denom = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be] +
1713 "_Denominator";
1714 numer = chainName + MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1715 effi = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be];
1716 HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1717 }
1718 }
1719 }
1720 }
1721 }//while (now just open bracket: 110728
1722 }//MonitoringFile::HLTMuonHistogramDivision
1723
1725 TString sdir, TString snum, TString sden, TString seff, TString seffg) {
1726 auto getHPointer ATLAS_THREAD_SAFE = [&mf] ATLAS_NOT_THREAD_SAFE(const TString &hname)->TH1F * {
1727 TH1F* pH {};
1728 mf.get(hname, pH);
1729 if (!pH and fdbg) {
1730 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << hname << std::endl;
1731 }
1732 return pH;
1733 };
1734 TH1F* h1tmpf(0);
1735 TH1F* h1num(0);
1736 TH1F* h1den(0);
1737 TGraphAsymmErrors* h1tmpfg = new TGraphAsymmErrors();
1738
1739 ;
1740 TString stmp = seff + seffg;
1741
1742 h1num = getHPointer(sdir + "NumDenom/" + snum);
1743 if (!h1num) return;
1744
1745 h1den = getHPointer(sdir + "NumDenom/" + sden);
1746 if (!h1den) return;
1747
1748 TDirectory* dir = mf.GetDirectory(sdir);
1749
1750 h1tmpf = (TH1F*) h1den->Clone();
1751 h1tmpf->SetName(stmp);
1752 h1tmpf->SetTitle(stmp);
1753 h1tmpf->GetYaxis()->SetTitle("Efficiency");
1754 h1tmpf->Reset();
1755 h1tmpf->Divide(h1num, h1den, 1., 1., "B");
1756 h1tmpf->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1757 h1tmpf->SetMinimum(0.0);
1758 h1tmpfg->SetMaximum(1.05);
1759 h1tmpf->SetName(stmp);
1760 dir->cd();
1761 h1tmpf->Write();
1762 h1tmpfg->SetMarkerStyle(20);
1763 h1tmpfg->SetMinimum(0.0);
1764 h1tmpfg->SetMaximum(1.05);
1765 h1tmpfg->BayesDivide(h1num, h1den);
1766 h1tmpfg->GetYaxis()->SetTitle("Efficiency");
1767 h1tmpfg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1768 dir->cd();
1769 h1tmpfg->SetName(stmp);
1770 h1tmpfg->Write();
1771 delete h1tmpfg;
1772 }
1773}//namespace
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
#define ATLAS_THREAD_SAFE
static void HLTMuonHistogramDivision(const std::string &inFilename, TString &run_dir)
static void HLTMuonHDiv(PostProcessorFileWrapper &mf, TString sdir, TString snum, TString sden, TString seff, TString seffg)