ATLAS Offline Software
MonitoringFile_HLTMuonHistogramDivision.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
39 namespace 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  for (int trg = 0; trg < maxindep; trg++) {
691  sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered_Denominator";
692 
693  for (int alg = 0; alg < 3; alg++) {
694  snum = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered_Numerator";
695  seff = eff_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered";
696  seffg = seff + "_Fit"; // YY added 20.04.10
697  stmp = chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered";
698  stmpg = chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + trigger[trg] + "_Triggered" + "_Fit";
699  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
700  if (!h1num) continue;
701 
702  h1tmp = (TH1F*) h1den->Clone();
703  h1tmp->SetName(stmp);
704  h1tmp->SetTitle(stmp);
705  h1tmp->GetYaxis()->SetTitle("Efficiency");
706  h1tmp->Reset();
707  h1tmp->Divide(h1num, h1den, 1., 1., "B");
708  dir->cd();
709  h1tmp->Write();
710  h1tmpg = new TGraphAsymmErrors();
711  h1tmpg->SetName(stmpg);
712  h1tmpg->SetMarkerStyle(20);
713  h1tmpg->SetMinimum(0.0);
714  h1tmpg->SetMaximum(1.05);
715  h1tmpg->BayesDivide(h1num, h1den);
716  h1tmpg->GetYaxis()->SetTitle("Efficiency");
717  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
718  dir->cd();
719  h1tmpg->Write();
720  delete h1tmpg;
721 
722  // summary for jet trigger
723  if (0 == alg || 2 == alg) {
724  if (3 == trg) { // jet
725  double sumeff {}, sumerr {};
726  double sumn = h1num->Integral(iMSL, iMSH);
727  double sumd = h1den->Integral(iMSL, iMSH);
728  if (sumd != 0.) {
729  sumeff = (double) sumn / (double) sumd;
730  sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
731  }
732  int iholx = -1;
733  if (0 == alg) {
734  iholx = static_cast<int>(iL2MuonSA);
735  } else if (2 == alg) {
736  iholx = static_cast<int>(iEFSA);
737  }
738 
739  if (iholx >= 0) {
740  TString s = eff_dir + chainName + "_highpt_effsummary_by" + vectkwd.at(2);
741  h1sumeff = getHPointer(s);
742  if (!h1sumeff) continue;
743 
744  h1sumeff->SetBinContent(iholx + 1, sumeff);
745  h1sumeff->SetBinError(iholx + 1, sumerr);
746  h1sumeff->GetYaxis()->SetTitleOffset(1.3);
747  h1sumeff->SetMinimum(0.0);
748  h1sumeff->SetMaximum(1.05);
749  // saving
750  dir->cd();
751  h1sumeff->Write("", TObject::kOverwrite);
752  }
753  }
754  }
755  }//alg
756  }//trg
757  mf.Write();
758 
759  for (int alg = 0; alg < 3; alg++) {
760  //wrt MuidSA
761  sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA_Denominator";
762  snum = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_Numerator";
763  seff = eff_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA";
764  seffg = seff + "_Fit"; // YY added 20.04.10
765  stmp = chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA";
766  stmpg = chainName + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
767  const auto & [pNum, pDen] = getHistogramPair(snum, sden);
768  if (!pNum) continue;
769 
770  h1tmp = (TH1F*) pDen->Clone();
771  h1tmp->SetName(stmp);
772  h1tmp->SetTitle(stmp);
773  h1tmp->GetYaxis()->SetTitle("Efficiency");
774  h1tmp->Reset();
775  h1tmp->Divide(pNum, pDen, 1., 1., "B");
776  dir->cd();
777  h1tmp->Write();
778  h1tmpg = new TGraphAsymmErrors();
779  h1tmpg->SetName(stmpg);
780  h1tmpg->SetMarkerStyle(20);
781  h1tmpg->SetMinimum(0.0);
782  h1tmpg->SetMaximum(1.05);
783  h1tmpg->BayesDivide(pNum, pDen);
784  h1tmpg->GetYaxis()->SetTitle("Efficiency");
785  h1tmpg->GetXaxis()->SetTitle(pDen->GetXaxis()->GetTitle());
786  dir->cd();
787  h1tmpg->Write();
788  delete h1tmpg;
789 
790  if (0 == alg || 2 == alg) { // no condition on ES bits = all events
791  double sumeff {}, sumerr {};
792  double sumn = pNum->Integral(iMSL, iMSH);
793  double sumd = pDen->Integral(iMSL, iMSH);
794  if (sumd != 0.) {
795  sumeff = (double) sumn / (double) sumd;
796  sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
797  }
798  int iholx = -1;
799  if (0 == alg) {
800  iholx = static_cast<int>(iL2MuonSA);
801  } else if (2 == alg) {
802  iholx = static_cast<int>(iEFSA);
803  }
804 
805  if (iholx >= 0) {
806  TString s = eff_dir + chainName + "_highpt_effsummary_by" + vectkwd.at(3);
807  h1sumeff = getHPointer(s);
808  if (!h1sumeff) continue;
809  h1sumeff->GetYaxis()->SetTitleOffset(1.3);
810  h1sumeff->SetBinContent(iholx + 1, sumeff);
811  h1sumeff->SetBinError(iholx + 1, sumerr);
812  h1sumeff->SetMinimum(0.0);
813  h1sumeff->SetMaximum(1.05);
814  // saving
815  dir->cd();
816  h1sumeff->Write("", TObject::kOverwrite);
817  }
818  }
819  //wrt MuidSA
820 
821  // for ES ----------------------------------------------------------------
822  for (int ies = 0; ies <= maxESbr; ies++) {
823  if (!MS_mon_ESbr[ies]) continue;
824  // for ES, L1 ------------------------------------------------------------
825  if (0 == alg) {
826  sden = nd_dir + chainName + triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA_Denominator";
827  snum = nd_dir + chainName + triggerES[ies] + "_L2MuonSA" + "_Turn_On_Curve_wrt" + "_L1" + "_Denominator";
828  seff = eff_dir + chainName + triggerES[ies] + "_L1" + "_Turn_On_Curve_wrt_MuidSA";
829  seffg = seff + "_Fit";
830  stmp = chainName + triggerES[alg] + "_L1" + "_Turn_On_Curve_wrt_MuidSA";
831  stmpg = chainName + triggerES[alg] + "_L1" + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
832  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
833  if (!h1num) continue;
834 
835  h1tmp = (TH1F*) h1den->Clone();
836  h1tmp->SetName(stmp);
837  h1tmp->SetTitle(stmp);
838  h1tmp->GetYaxis()->SetTitle("Efficiency");
839  h1tmp->Reset();
840  h1tmp->Divide(h1num, h1den, 1., 1., "B");
841  dir->cd();
842  h1tmp->Write();
843  h1tmpg = new TGraphAsymmErrors();
844  h1tmpg->SetName(stmpg);
845  h1tmpg->SetMarkerStyle(20);
846  h1tmpg->SetMinimum(0.0);
847  h1tmpg->SetMaximum(1.05);
848  h1tmpg->BayesDivide(h1num, h1den);
849  h1tmpg->GetYaxis()->SetTitle("Efficiency");
850  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
851  dir->cd();
852  h1tmpg->Write();
853  delete h1tmpg;
854 
855 
856  for (int be = 0; be < 2; be++) {
857  sden = nd_dir + chainName + triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA" + bestr[be] + "_Denominator";
858  snum = nd_dir + chainName + triggerES[ies] + "_L2MuonSA" + "_Turn_On_Curve_wrt" + "_L1" + bestr[be] +
859  "_Denominator";
860  seff = eff_dir + chainName + triggerES[ies] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidSA";
861  seffg = seff + "_Fit";
862  stmp = chainName + triggerES[ies] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidSA";
863  stmpg = chainName + triggerES[ies] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
864  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
865  if (!h1num) continue;
866 
867  h1tmp = (TH1F*) h1den->Clone();
868  h1tmp->SetName(stmp);
869  h1tmp->SetTitle(stmp);
870  h1tmp->GetYaxis()->SetTitle("Efficiency");
871  h1tmp->Reset();
872  h1tmp->Divide(h1num, h1den, 1., 1., "B");
873  dir->cd();
874  h1tmp->Write();
875  h1tmpg = new TGraphAsymmErrors();
876  h1tmpg->SetName(stmpg);
877  h1tmpg->SetMarkerStyle(20);
878  h1tmpg->SetMinimum(0.0);
879  h1tmpg->SetMaximum(1.05);
880  h1tmpg->BayesDivide(h1num, h1den);
881  h1tmpg->GetYaxis()->SetTitle("Efficiency");
882  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
883  dir->cd();
884  h1tmpg->Write();
885  delete h1tmpg;
886  }
887  }
888 
889  // for ES, L1 end ------------------------------------------------------------
890  sden = nd_dir + chainName + triggerES[ies] + "_Turn_On_Curve_wrt_MuidSA_Denominator";
891  snum = nd_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_Numerator";
892  seff = eff_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA";
893  seffg = seff + "_Fit"; // YY added 20.04.10
894  stmp = chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA";
895  stmpg = chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
896  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
897  if (!h1num) continue;
898 
899  h1tmp = (TH1F*) h1den->Clone();
900  h1tmp->SetName(stmp);
901  h1tmp->SetTitle(stmp);
902  h1tmp->GetYaxis()->SetTitle("Efficiency");
903  h1tmp->Reset();
904  h1tmp->Divide(h1num, h1den, 1., 1., "B");
905  dir->cd();
906  h1tmp->Write();
907  h1tmpg = new TGraphAsymmErrors();
908  h1tmpg->SetName(stmpg);
909  h1tmpg->SetMarkerStyle(20);
910  h1tmpg->SetMinimum(0.0);
911  h1tmpg->SetMaximum(1.05);
912  h1tmpg->BayesDivide(h1num, h1den);
913  h1tmpg->GetYaxis()->SetTitle("Efficiency");
914  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
915  dir->cd();
916  h1tmpg->Write();
917  delete h1tmpg;
918 
919  if (0 == alg || 2 == alg) {
920  if (ESTAG == ies || ESINDEP == ies) {
921  double sumeff, sumerr;
922  double sumn = h1num->Integral(iMSL, iMSH);
923  double sumd = h1den->Integral(iMSL, iMSH);
924  if (sumd == 0.) {
925  sumeff = 0.;
926  sumerr = 0.;
927  } else {
928  sumeff = (double) sumn / (double) sumd;
929  sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
930  }
931  int iholx = -1;
932  if (0 == alg) {
933  iholx = static_cast<int>(iL2MuonSA);
934  } else if (2 == alg) {
935  iholx = static_cast<int>(iEFSA);
936  }
937 
938  if (iholx >= 0) {
939  TString s = eff_dir + chainName + "_highpt_effsummary_by" + triggerES[ies];
940  h1sumeff = getHPointer(s);
941  if (!h1sumeff) continue;
942  h1sumeff->GetYaxis()->SetTitleOffset(1.3);
943  h1sumeff->SetBinContent(iholx + 1, sumeff);
944  h1sumeff->SetBinError(iholx + 1, sumerr);
945  h1sumeff->SetMinimum(0.0);
946  h1sumeff->SetMaximum(1.05);
947  // saving
948  dir->cd();
949  h1sumeff->Write("", TObject::kOverwrite);
950  }
951  }
952  }
953  }
954  // for ES: end ----------------------------------------------------------------
955 
956  if (0 == alg || 2 == alg) {
957  for (int be = 0; be < 2; be++) {
958  //wrt MuidSA
959  sden = nd_dir + chainName + "_Turn_On_Curve_wrt_MuidSA" + bestr[be] + "_Denominator";
960  snum = nd_dir + chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
961  seff = eff_dir + chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidSA";
962  seffg = seff + "_Fit"; // YY added 20.04.10
963  stmp = chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidSA";
964  stmpg = chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidSA" + "_Fit";
965  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
966  if (!h1num) continue;
967 
968  h1tmp = (TH1F*) h1den->Clone();
969  h1tmp->SetName(stmp);
970  h1tmp->SetTitle(stmp);
971  h1tmp->GetYaxis()->SetTitle("Efficiency");
972  h1tmp->Reset();
973  h1tmp->Divide(h1num, h1den, 1., 1., "B");
974  dir->cd();
975  h1tmp->Write();
976  h1tmpg = new TGraphAsymmErrors();
977  h1tmpg->SetName(stmpg);
978  h1tmpg->SetMarkerStyle(20);
979  h1tmpg->SetMinimum(0.0);
980  h1tmpg->SetMaximum(1.05);
981  h1tmpg->BayesDivide(h1num, h1den);
982  h1tmpg->GetYaxis()->SetTitle("Efficiency");
983  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
984  dir->cd();
985  h1tmpg->Write();
986  delete h1tmpg;
987  }
988  }
989 
990  //wrt upstream
991  sden = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + "_Denominator";
992  snum = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_Numerator";
993  seff = eff_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg];
994  seffg = seff + "_Fit"; // YY added 20.04.10
995  stmp = chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg];
996  stmpg = chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + "_Fit";
997  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
998  if (!h1num) continue;
999 
1000  h1tmp = (TH1F*) h1den->Clone();
1001  h1tmp->SetName(stmp);
1002  h1tmp->SetTitle(stmp);
1003  h1tmp->GetYaxis()->SetTitle("Efficiency");
1004  h1tmp->Reset();
1005  h1tmp->Divide(h1num, h1den, 1., 1., "B");
1006  dir->cd();
1007  h1tmp->Write();
1008  h1tmpg = new TGraphAsymmErrors();
1009  h1tmpg->SetName(stmpg);
1010  h1tmpg->SetMarkerStyle(20);
1011  h1tmpg->SetMinimum(0.0);
1012  h1tmpg->SetMaximum(1.05);
1013  h1tmpg->BayesDivide(h1num, h1den);
1014  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1015  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1016  dir->cd();
1017  h1tmpg->Write();
1018  delete h1tmpg;
1019 
1020 
1021  //wrt upstream
1022  // for ES --------------------------------------------------------------------
1023  for (int ies = 0; ies <= maxESbr; ies++) {
1024  if (!MS_mon_ESbr[ies]) continue;
1025  sden = nd_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] +
1026  "_Denominator";
1027  snum = nd_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_Numerator";
1028  seff = eff_dir + chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg];
1029  seffg = seff + "_Fit"; // YY added 20.04.10
1030  stmp = chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg];
1031  stmpg = chainName + triggerES[ies] + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + "_Fit";
1032  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1033  if (!h1num) continue;
1034 
1035  h1tmp = (TH1F*) h1den->Clone();
1036  h1tmp->SetName(stmp);
1037  h1tmp->SetTitle(stmp);
1038  h1tmp->GetYaxis()->SetTitle("Efficiency");
1039  h1tmp->Reset();
1040  h1tmp->Divide(h1num, h1den, 1., 1., "B");
1041  dir->cd();
1042  h1tmp->Write();
1043  h1tmpg = new TGraphAsymmErrors();
1044  h1tmpg->SetName(stmpg);
1045  h1tmpg->SetMarkerStyle(20);
1046  h1tmpg->SetMinimum(0.0);
1047  h1tmpg->SetMaximum(1.05);
1048  h1tmpg->BayesDivide(h1num, h1den);
1049  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1050  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1051  dir->cd();
1052  h1tmpg->Write();
1053  delete h1tmpg;
1054  }
1055  // for ES: end --------------------------------------------------------------------
1056 
1057  if (0 == alg || 2 == alg) {
1058  for (int be = 0; be < 2; be++) {
1059  //wrt upstream
1060  sden = nd_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + bestr[be] + "_Denominator";
1061  snum = nd_dir + chainName + alg2[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1062  seff = eff_dir + chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + bestr[be];
1063  seffg = seff + "_Fit"; // YY added 20.04.10
1064  stmp = chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + bestr[be];
1065  stmpg = chainName + alg2[alg] + "_Turn_On_Curve_wrt" + wrtalg2[alg] + bestr[be] + "_Fit";
1066  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1067  if (!h1num) continue;
1068 
1069  h1tmp = (TH1F*) h1den->Clone();
1070  h1tmp->SetName(stmp);
1071  h1tmp->SetTitle(stmp);
1072  h1tmp->GetYaxis()->SetTitle("Efficiency");
1073  h1tmp->Reset();
1074  h1tmp->Divide(h1num, h1den, 1., 1., "B");
1075  dir->cd();
1076  h1tmp->Write();
1077  h1tmpg = new TGraphAsymmErrors();
1078  h1tmpg->SetName(stmpg);
1079  h1tmpg->SetMarkerStyle(20);
1080  h1tmpg->SetMinimum(0.0);
1081  h1tmpg->SetMaximum(1.05);
1082  h1tmpg->BayesDivide(h1num, h1den);
1083  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1084  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1085  dir->cd();
1086  h1tmpg->Write();
1087  delete h1tmpg;
1088  }
1089  }
1090  }//alg
1091  mf.Write();
1092  }//i
1093 
1094  //==Rate
1095  dir = mf.GetDirectory(rr_dir);
1096  if (!dir) {
1097  if (fdbg) {
1098  std::cerr << "HLTMuonHistogramDivision: directory " << rr_dir << " not found" << std::endl;
1099  }
1100  return;
1101  }
1102 
1103  // EF rate / offline rate
1104  std::string type[3] = {
1105  "MS_", "SA_", "CB_"
1106  };
1107  std::string off[3] = {
1108  "Moore_MS_", "Moore_SA_", "Muid_"
1109  };
1110  std::string cut[2] = {
1111  "4", "10"
1112  };
1113 
1114  for (int itype = 0; itype < 3; itype++) {
1115  for (int icut = 0; icut < 2; icut++) {
1116  seff = rr_dir + "EF_" + type[itype] + "Over_" + off[itype] + cut[icut] + "GeV_Cut";
1117  snum = rate_dir + "Number_Of_EF_" + type[itype] + "Muons_" + cut[icut] + "GeV_Cut";
1118  sden = rate_dir + "Number_Of_" + off[itype] + "Muons_" + cut[icut] + "GeV_Cut";
1119  stmp = "EF_" + type[itype] + "Over_" + off[itype] + cut[icut] + "GeV_Cut";
1120  stmpg = "EF_" + type[itype] + "Over_" + off[itype] + cut[icut] + "GeV_Cut" + "_Fit";
1121  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1122  if (!h1num) continue;
1123 
1124  h1tmp = (TH1F*) h1den->Clone();
1125  h1tmp->SetName(stmp);
1126  h1tmp->SetTitle(stmp);
1127  h1tmp->GetYaxis()->SetTitle("Efficiency");
1128  h1tmp->Reset();
1129  h1tmp->Divide(h1num, h1den, 1., 1., "B");
1130  dir->cd();
1131  h1tmp->Write();
1132  }//icut
1133  }//itype
1134  mf.Write();
1135 
1136  // Triggers / Event
1137  std::vector<TString> chains;
1138  std::vector<TString> chains2;
1139 
1140  {
1141  std::map<std::string, std::string> ztpmap;
1142 
1143  ztpmap["muChain1"] = "L1_MU15";
1144  ztpmap["muChain2"] = "L1_MU15";
1145  ztpmap["muChainEFiso1"] = "L1_MU15";
1146  ztpmap["muChainEFiso2"] = "L1_MU15";
1147  ztpmap["muChainMSonly1"] = "L1_MU15";
1148  ztpmap["muChainMSonly2"] = "L1_MU15";
1149 
1150  std::map<std::string, int> ztp_isomap;
1151  ztp_isomap["muChain1"] = 0;
1152  ztp_isomap["muChain2"] = 0;
1153  ztp_isomap["muChainEFiso1"] = 1;
1154  ztp_isomap["muChainEFiso2"] = 1;
1155  ztp_isomap["muChainMSonly1"] = 0;
1156  ztp_isomap["muChainMSonly2"] = 0;
1157 
1158  for (std::map<std::string, std::string>::iterator itmap = ztpmap.begin(); itmap != ztpmap.end(); ++itmap) {
1159  TString histdirmuztp = run_dir + "/HLT/MuonMon/MuZTP/" + itmap->first;
1160  TDirectory* ztpdir = mf.GetDirectory(histdirmuztp);
1161  bool isefisochain = ztp_isomap[itmap->first] > 0;
1162 
1163  //efficiency histograms
1164  std::vector<std::string> var;
1165  var.push_back("_Pt_");
1166  var.push_back("_Pt_EC_");
1167  var.push_back("_Pt_B_");
1168  var.push_back("_Pt_4bins_");
1169  var.push_back("_Pt_B_4bins_");
1170  var.push_back("_Eta_");
1171  var.push_back("_Phi_");
1172  var.push_back("_Phi_EC_");
1173  var.push_back("_Phi_B_");
1174  for (unsigned int k = 0; k < var.size(); k++) {
1175  std::vector<std::string> level;
1176  level.push_back("L1");
1177  level.push_back("L2");
1178  level.push_back("EF");
1179  if (isefisochain) level.push_back("EFIso");
1180  for (unsigned int j = 0; j < level.size(); j++) {
1181  //ABSOLUTE
1182  seffg = histdirmuztp + "/muZTP_eff_" + level[j] + var[k] + itmap->first;
1183  snum = histdirmuztp + "/muZTP" + var[k] + level[j] + "fired_" + itmap->first;
1184  sden = histdirmuztp + "/muZTP" + var[k] + itmap->first;
1185  stmp = "muZTP_eff_" + level[j] + var[k] + itmap->first;
1186  stmpg = "muZTP_eff_" + level[j] + var[k] + itmap->first;
1187  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1188  if (!h1num) continue;
1189 
1190  h1tmpg = new TGraphAsymmErrors();
1191  h1tmpg->SetName(stmpg);
1192  h1tmpg->SetMarkerStyle(20);
1193  h1tmpg->SetMinimum(0.0);
1194  h1tmpg->SetMaximum(1.05);
1195  h1tmpg->BayesDivide(h1num, h1den);
1196  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1197  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1198  ztpdir->cd();
1199  h1tmpg->Write();
1200  delete h1tmpg;
1201  mf.Write();
1202 
1203  seffg = histdirmuztp + "/muZTP_eff_" + level[j] + "_Eta_1bin_" + itmap->first;
1204  snum = histdirmuztp + "/muZTP_Eta_1bin_" + level[j] + "fired_" + itmap->first;
1205  sden = histdirmuztp + "/muZTP_Eta_1bin_" + itmap->first;
1206  stmpg = "muZTP_eff_" + level[j] + "_Eta_1bin_" + itmap->first;
1207  const auto & [h1num2, h1den2] = getHistogramPair(snum, sden);
1208  if (!h1num2) continue;
1209 
1210  h1tmpg = new TGraphAsymmErrors();
1211  h1tmpg->SetName(stmpg);
1212  h1tmpg->SetMarkerStyle(20);
1213  h1tmpg->SetMinimum(0.0);
1214  h1tmpg->SetMaximum(1.05);
1215  h1tmpg->BayesDivide(h1num2, h1den2);
1216  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1217  h1tmpg->GetXaxis()->SetTitle(h1den2->GetXaxis()->GetTitle());
1218  ztpdir->cd();
1219  h1tmpg->Write();
1220  delete h1tmpg;
1221  mf.Write();
1222 
1223  seffg = histdirmuztp + "/muZTP_eff_" + level[j] + "_Eta_2bins_" + itmap->first;
1224  snum = histdirmuztp + "/muZTP_Eta_2bins_" + level[j] + "fired_" + itmap->first;
1225  sden = histdirmuztp + "/muZTP_Eta_2bins_" + itmap->first;
1226  stmpg = "muZTP_eff_" + level[j] + "_Eta_2bins_" + itmap->first;
1227  const auto & [h1num3, h1den3] = getHistogramPair(snum, sden);
1228 
1229  //h1num = getHPointer(snum);
1230  if (!h1num3) continue;
1231  //h1den = getHPointer(sden);
1232  //if (!h1den) continue;
1233 
1234  h1tmpg = new TGraphAsymmErrors();
1235  h1tmpg->SetName(stmp);
1236  h1tmpg->SetMarkerStyle(20);
1237  h1tmpg->SetMinimum(0.0);
1238  h1tmpg->SetMaximum(1.05);
1239  h1tmpg->BayesDivide(h1num3, h1den3);
1240  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1241  h1tmpg->GetXaxis()->SetTitle(h1den3->GetXaxis()->GetTitle());
1242  ztpdir->cd();
1243  h1tmpg->Write();
1244  delete h1tmpg;
1245  mf.Write();
1246 
1247  seffg = histdirmuztp + "/muZTP_eff_" + level[j] + "_Eta_1bin_cut_" + itmap->first;
1248  snum = histdirmuztp + "/muZTP_Eta_1bin_cut_" + level[j] + "fired_" + itmap->first;
1249  sden = histdirmuztp + "/muZTP_Eta_1bin_cut_" + itmap->first;
1250  stmpg = "muZTP_eff_" + level[j] + "_Eta_1bin_cut_" + itmap->first;
1251  const auto & [h1num4, h1den4] = getHistogramPair(snum, sden);
1252  if (!h1num4) continue;
1253 
1254  h1tmpg = new TGraphAsymmErrors();
1255  h1tmpg->SetName(stmpg);
1256  h1tmpg->SetMarkerStyle(20);
1257  h1tmpg->SetMinimum(0.0);
1258  h1tmpg->SetMaximum(1.05);
1259  h1tmpg->BayesDivide(h1num4, h1den4);
1260  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1261  h1tmpg->GetXaxis()->SetTitle(h1den4->GetXaxis()->GetTitle());
1262  ztpdir->cd();
1263  h1tmpg->Write();
1264  delete h1tmpg;
1265  mf.Write();
1266 
1267  seffg = histdirmuztp + "/muZTP_eff_" + level[j] + "_Eta_2bins_cut_" + itmap->first;
1268  snum = histdirmuztp + "/muZTP_Eta_2bins_cut_" + level[j] + "fired_" + itmap->first;
1269  sden = histdirmuztp + "/muZTP_Eta_2bins_cut_" + itmap->first;
1270  stmpg = "muZTP_eff_" + level[j] + "_Eta_2bins_cut_" + itmap->first;
1271  const auto & [h1num5, h1den5] = getHistogramPair(snum, sden);
1272  if (!h1num5) continue;
1273 
1274  h1tmpg = new TGraphAsymmErrors();
1275  h1tmpg->SetName(stmpg);
1276  h1tmpg->SetMarkerStyle(20);
1277  h1tmpg->SetMinimum(0.0);
1278  h1tmpg->SetMaximum(1.05);
1279  h1tmpg->BayesDivide(h1num5, h1den5);
1280  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1281  h1tmpg->GetXaxis()->SetTitle(h1den5->GetXaxis()->GetTitle());
1282  ztpdir->cd();
1283  h1tmpg->Write();
1284  delete h1tmpg;
1285  mf.Write();
1286 
1287  //2D ETA_PHI
1288  seff = histdirmuztp + "/muZTP_eff_EtaPhi_" + level[j] + "_" + itmap->first;
1289  snum = histdirmuztp + "/muZTP_EtaPhi_" + level[j] + "_" + itmap->first;
1290  sden = histdirmuztp + "/muZTP_EtaPhi_all_" + itmap->first;
1291  stmp = "muZTP_eff_EtaPhi_" + level[j] + "_" + itmap->first;
1292 
1293  TH2F* h2num(0);
1294  TH2F* h2den(0);
1295  TH2F* h2tmp(0);
1296 
1297  h2num = getH2Pointer(snum);
1298  if (!h2num) continue;
1299  h2den = getH2Pointer(sden);
1300  if (!h2den) continue;
1301 
1302  h2tmp = (TH2F*) h1den->Clone();
1303  h2tmp->SetName(stmp);
1304  h2tmp->SetTitle(stmp);
1305  h2tmp->GetYaxis()->SetTitle("Efficiency");
1306  h2tmp->Reset();
1307  h2tmp->Divide(h1num, h1den, 1., 1., "B");
1308  dir->cd();
1309  h2tmp->Write();
1310  mf.Write();
1311  }//level
1312 
1313  //RELATIVE
1314  seffg = histdirmuztp + "/muZTP_eff_EFwrtL2" + var[k] + itmap->first;
1315  snum = histdirmuztp + "/muZTP" + var[k] + "EFL2fired_" + itmap->first;
1316  sden = histdirmuztp + "/muZTP" + var[k] + "L2fired_" + itmap->first;
1317  stmpg = "muZTP_eff_EFwrtL2" + var[k] + itmap->first;
1318  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1319  if (!h1num) continue;
1320 
1321  h1tmpg = new TGraphAsymmErrors();
1322  h1tmpg->SetName(stmpg);
1323  h1tmpg->SetMarkerStyle(20);
1324  h1tmpg->SetMinimum(0.0);
1325  h1tmpg->SetMaximum(1.05);
1326  h1tmpg->BayesDivide(h1num, h1den);
1327  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1328  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1329  ztpdir->cd();
1330  h1tmpg->Write();
1331  delete h1tmpg;
1332  mf.Write();
1333 
1334  seffg = histdirmuztp + "/muZTP_eff_EFwrtL1" + var[k] + itmap->first;
1335  snum = histdirmuztp + "/muZTP" + var[k] + "EFfired_" + itmap->first;
1336  sden = histdirmuztp + "/muZTP" + var[k] + "L1fired_" + itmap->first;
1337  stmpg = "muZTP_eff_EFwrtL1" + var[k] + itmap->first;
1338  const auto & [h1num2, h1den2] = getHistogramPair(snum, sden);
1339  if (!h1num2) continue;
1340 
1341  h1tmpg = new TGraphAsymmErrors();
1342  h1tmpg->SetName(stmpg);
1343  h1tmpg->SetMarkerStyle(20);
1344  h1tmpg->SetMinimum(0.0);
1345  h1tmpg->SetMaximum(1.05);
1346  h1tmpg->BayesDivide(h1num2, h1den2);
1347  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1348  h1tmpg->GetXaxis()->SetTitle(h1den2->GetXaxis()->GetTitle());
1349  ztpdir->cd();
1350  h1tmpg->Write();
1351  delete h1tmpg;
1352  mf.Write();
1353 
1354  seffg = histdirmuztp + "/muZTP_eff_L2wrtL1" + var[k] + itmap->first;
1355  snum = histdirmuztp + "/muZTP" + var[k] + "L2fired_" + itmap->first;
1356  sden = histdirmuztp + "/muZTP" + var[k] + "L1fired_" + itmap->first;
1357  stmpg = "muZTP_eff_L2wrtL1" + var[k] + itmap->first;
1358  const auto & [h1num3, h1den3] = getHistogramPair(snum, sden);
1359  if (!h1num3) continue;
1360 
1361  h1tmpg = new TGraphAsymmErrors();
1362  h1tmpg->SetName(stmpg);
1363  h1tmpg->SetMarkerStyle(20);
1364  h1tmpg->SetMinimum(0.0);
1365  h1tmpg->SetMaximum(1.05);
1366  h1tmpg->BayesDivide(h1num3, h1den3);
1367  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1368  h1tmpg->GetXaxis()->SetTitle(h1den3->GetXaxis()->GetTitle());
1369  ztpdir->cd();
1370  h1tmpg->Write();
1371  delete h1tmpg;
1372  mf.Write();
1373 
1374  if (isefisochain) {
1375  seffg = histdirmuztp + "/muZTP_eff_EFIsowrtEF" + var[k] + itmap->first;
1376  snum = histdirmuztp + "/muZTP" + var[k] + "EFIsofired_" + itmap->first;
1377  sden = histdirmuztp + "/muZTP" + var[k] + "EFfired_" + itmap->first;
1378  stmpg = "muZTP_eff_EFIsowrtEF" + var[k] + itmap->first;
1379  const auto & [h1num, h1den] = getHistogramPair(snum, sden);
1380  if (!h1num) continue;
1381 
1382  h1tmpg = new TGraphAsymmErrors();
1383  h1tmpg->SetName(stmpg);
1384  h1tmpg->SetMarkerStyle(20);
1385  h1tmpg->SetMinimum(0.0);
1386  h1tmpg->SetMaximum(1.05);
1387  h1tmpg->BayesDivide(h1num, h1den);
1388  h1tmpg->GetYaxis()->SetTitle("Efficiency");
1389  h1tmpg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1390  ztpdir->cd();
1391  h1tmpg->Write();
1392  delete h1tmpg;
1393  mf.Write();
1394  }
1395  }//var
1396  }
1397  // mf.Write();
1398  } // procMuZTP
1399 
1400 
1401  {
1402  TDirectory* efdir = mf.GetDirectory(eff_dir);
1403  if (!efdir) {
1404  if (fdbg) {
1405  std::cerr << "HLTMuonHistogramDivision: directory " << eff_dir << " not found" << std::endl;
1406  }
1407  return;
1408  }
1409 
1410  // MAM
1411  const int MAXARR = 6;
1412  std::string charr[MAXARR] = {
1413  "muChain1", "muChain2", "muChainEFiso1", "muChainEFiso2", "muChainMSonly1", "muChainMSonly2"
1414  };
1415  std::string monarr[MAXARR] = {
1416  "_EFmuon", "_EFmuon", "_EFmuon", "_EFmuon", "_MuonEFSA", "_MuonEFSA"
1417  };
1418  std::string monL2arr[MAXARR] = {
1419  "_L2MuonSA", "_L2MuonSA", "_L2MuonSA", "_L2MuonSA", "_L2MuonSA", "_L2MuonSA"
1420  };
1421  bool isBarrelMon[MAXARR] = {
1422  false, false, false, false, true, true
1423  }; // enable MSonly
1424  bool isMSbMon[MAXARR] = {
1425  true, true, false, false, false, false
1426  }; // Skip isol and MSonly
1427  bool monL1[MAXARR] = {
1428  true, true, true, true, false, false
1429  }; // Skip MSonly
1430  bool isefIsolation[MAXARR] = {
1431  false, false, true, true, false, false
1432  }; // EF isolation add by Yuan
1433 
1434  // I need to prepare maps ... mu20_MG -> MuGirlEF etc.
1435  for (int ialg = 0; ialg < MAXARR; ialg++) {
1436  std::string chainName = charr[ialg];
1437  std::string MoniAlg = monarr[ialg];
1438  std::string MoniL2Alg = monL2arr[ialg];
1439 
1440  /* 1. Picking up ztp graph */
1441  TString hdirztp = muon_dir + "MuZTP/" + chainName + "/";
1442  TString histZtpNum, histZtpDen;
1443  if (!isBarrelMon[ialg]) {
1444  histZtpNum = hdirztp + "muZTP_Pt_4bins_EFfired_" + chainName;
1445  histZtpDen = hdirztp + "muZTP_Pt_4bins_L1fired_" + chainName;
1446  } else {
1447  histZtpNum = hdirztp + "muZTP_Pt_B_4bins_EFfired_" + chainName;
1448  histZtpDen = hdirztp + "muZTP_Pt_B_4bins_L1fired_" + chainName;
1449  }
1450  if (isefIsolation[ialg]) histZtpNum = hdirztp + "muZTP_Pt_4bins_EFIsofired_" + chainName; // add by Yuan
1451  TString histZtpEff = eff_dir + chainName + "_highpt3bins_effwrtL1";
1452  const auto & [h1num, h1den] = getHistogramPair(histZtpNum, histZtpDen);
1453  if (!h1num) continue;
1454  h1eff = getHPointer(histZtpEff);
1455  if (!h1eff) continue;
1456 
1457  /* 2. Filling summary histogram from ZTP values */
1458  for (int ibin = 2; ibin <= 3; ibin++) {
1459  // at the moment it is not correct if we run the algorithm # 4: mu40_MSonly_barrel .
1460  double sumeff {}, sumerr {};
1461  double sumn = h1num->Integral(ibin, ibin);
1462  if (isBarrelMon[ialg] || isMSbMon[ialg]) sumn = h1num->Integral(ibin + 1, ibin + 1);
1463  double sumd = h1den->Integral(ibin, ibin);
1464  if (isBarrelMon[ialg] || isMSbMon[ialg]) sumd = h1den->Integral(ibin + 1, ibin + 1);
1465  if (sumd != 0.) {
1466  sumeff = (double) sumn / (double) sumd;
1467  sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1468  }
1469  h1eff->GetYaxis()->SetTitle("Efficiency");
1470  h1eff->SetBinContent(ibin - 1, sumeff);
1471  h1eff->SetBinError(ibin - 1, sumerr);
1472  h1eff->SetMinimum(0.0);
1473  h1eff->SetMaximum(1.05);
1474  }
1475 
1476 
1477 
1478  efdir->cd();
1479  h1eff->Write("", TObject::kOverwrite);
1480 
1481  if (monL1[ialg]) { // MUST skip muGirl, muIso and MSonly as histograms are not defined!!!
1482  TString hdirztp = muon_dir + "MuZTP/" + chainName + "/";
1483  TString histZtpNumB = hdirztp + "muZTP_Pt_B_L1fired_" + chainName;
1484  TString histZtpDenB = hdirztp + "muZTP_Pt_B_" + chainName;
1485  TString histZtpNumE = hdirztp + "muZTP_Pt_EC_L1fired_" + chainName;
1486  TString histZtpDenE = hdirztp + "muZTP_Pt_EC_" + chainName;
1487  TString histZtpL1sum = eff_dir + chainName + "_highptL1plateau_wrtOffline";
1488 
1489  TH1F* h1numb = getHPointer(histZtpNumB);
1490  if (!h1numb) continue;
1491  TH1F* h1nume = getHPointer(histZtpNumE);
1492  if (!h1nume) continue;
1493  TH1F* h1denb = getHPointer(histZtpDenB);
1494  if (!h1denb) continue;
1495  TH1F* h1dene = getHPointer(histZtpDenE);
1496  if (!h1dene) continue;
1497  TH1F* h1sumL = getHPointer(histZtpL1sum);
1498  if (!h1sumL) continue;
1499 
1500  double sumeff, sumerr;
1501  double sumn = h1numb->Integral(13, 25); // 12-25 GeV
1502  if (HI_pp_key) sumn = h1numb->Integral(13, 20); // 60-100 GeV
1503  double sumd = h1denb->Integral(13, 25);
1504  if (HI_pp_key) sumd = h1denb->Integral(13, 20);
1505  if (sumd == 0.) {
1506  sumeff = 0.;
1507  sumerr = 0.;
1508  } else {
1509  sumeff = (double) sumn / (double) sumd;
1510  sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1511  }
1512  h1sumL->SetBinContent(1, sumeff);
1513  h1sumL->SetBinError(1, sumerr);
1514 
1515  sumn = h1nume->Integral(13, 25);
1516  if (HI_pp_key) sumn = h1numb->Integral(13, 20); // 60-100 GeV
1517  sumd = h1dene->Integral(13, 25);
1518  if (HI_pp_key) sumd = h1denb->Integral(13, 20);
1519  if (sumd == 0.) {
1520  sumeff = 0.;
1521  sumerr = 0.;
1522  } else {
1523  sumeff = (double) sumn / (double) sumd;
1524  sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1525  }
1526  h1sumL->GetYaxis()->SetTitle("Efficiency");
1527  h1sumL->SetBinContent(2, sumeff);
1528  h1sumL->SetBinError(2, sumerr);
1529  h1sumL->SetMinimum(0.0);
1530  h1sumL->SetMaximum(1.05);
1531  efdir->cd();
1532  h1sumL->Write("", TObject::kOverwrite);
1533  }
1534  }
1535  mf.Write();
1536  } //procChainDQA_HighPt
1537  //===End HLTMuonw
1538 
1539  // ******************************************************//
1540  // ********************* generic ***********************//
1541  // ******************************************************//
1542  TString monalg[3] = {
1543  "_L2MuonSA", "_MuComb", "_EFmuon"
1544  };
1545  TString wrtalg[3] = {
1546  "_L1", "_L2MuonSA", "_MuComb"
1547  };
1548  TString numer, denom, effi;
1549  TString histdireff = eff_dir;
1550 
1551  TDirectory* efdir = mf.GetDirectory(eff_dir);
1552  if (!efdir) {
1553  if (fdbg) {
1554  std::cerr << "HLTMuonHistogramDivision: directory " << eff_dir << " not found" << std::endl;
1555  }
1556  return;
1557  }
1558 
1559  // processing Iso histograms in the same manner
1560  chainsGeneric.insert(chainsGeneric.end(), chainsEFiso.begin(), chainsEFiso.end());
1561 
1562  for (unsigned int i = 0; i < chainsGeneric.size(); i++) {
1563  TString chainName = chainsGeneric.at(i);
1564  if (fdbg) {
1565  std::cout << "proc generic " << chainName << std::endl;
1566  }
1567 
1568  //wrt CB muon && Upstream trigger
1569  for (int alg = 0; alg < 3; alg++) {
1570  denom = chainName + "_Turn_On_Curve_wrt_MuidCB_Denominator";
1571  numer = chainName + monalg[alg] + "_Turn_On_Curve_Numerator";
1572  effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB";
1573  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1574 
1575  denom = chainName + MSchainName + "_Turn_On_Curve_wrt_MuidCB_Denominator";
1576  numer = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_Numerator";
1577  effi = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB";
1578  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1579 
1580  // Summary all - removed
1581 
1582  denom = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator";
1583  numer = chainName + monalg[alg] + "_Turn_On_Curve_Numerator";
1584  effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg];
1585  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1586 
1587 
1588  denom = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator";
1589  numer = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_Numerator";
1590  effi = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg];
1591  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1592 
1593  // for ES ------------------------------------------------------------------------------------
1594  for (int i = 0; i <= maxESbr; i++) {
1595  if (!CB_mon_ESbr[i]) continue;
1596  if (0 == alg) {
1597  // L1 efficiency: new for 2011 HI runs and afterward
1598  // only division once since it is "the zero-th" algorithm
1599  denom = chainName + triggerES[i] + "_Turn_On_Curve_wrt_MuidCB_Denominator";
1600  numer = chainName + triggerES[i] + "_L2MuonSA" + "_Turn_On_Curve_wrt" + "_L1" + "_Denominator";
1601  effi = chainName + triggerES[i] + "_L1" + "_Turn_On_Curve_wrt_MuidCB";
1602  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1603 
1604  // Need to implement barrel and endcap ...
1605  for (int be = 0; be < 2; be++) {
1606  denom = chainName + triggerES[i] + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator";
1607  numer = chainName + triggerES[i] + "_L2MuonSA" + "_Turn_On_Curve_wrt" + "_L1" + bestr[be] +
1608  "_Denominator";
1609  effi = chainName + triggerES[i] + "_L1" + bestr[be] + "_Turn_On_Curve_wrt_MuidCB";
1610  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1611  const auto & [h1num, h1den] = getHistogramPair(nd_dir + numer, nd_dir + denom);
1612  if (!h1num) continue;
1613 
1614  if (ESINDEP == i) {
1615  // integrating over and fill in a summary histogram
1616  double sumeff {}, sumerr {};
1617  double sumn = h1num->Integral(iSTDL, iSTDH); // 60-100 GeV
1618  double sumd = h1den->Integral(iSTDL, iSTDH);
1619 
1620  if (sumd != 0.) {
1621  sumeff = (double) sumn / (double) sumd;
1622  sumerr = sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1623  }
1624 
1625  TString s = histdireff + chainName + "_L1plateau_wrtOffline_by_ESindep";
1626  TH1F* h1effL1 = getHPointer(s);
1627  if (!h1effL1) continue;
1628  h1effL1->SetBinContent(be + 1, sumeff);
1629  h1effL1->SetBinError(be + 1, sumerr);
1630  h1eff->SetMinimum(0.0);
1631  h1eff->SetMaximum(1.05);
1632  efdir->cd();
1633  h1effL1->Write("", TObject::kOverwrite);
1634  }
1635  }
1636  }
1637 
1638  denom = chainName + triggerES[i] + "_Turn_On_Curve_wrt_MuidCB_Denominator";
1639  numer = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_Numerator";
1640  effi = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt_MuidCB";
1641  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1642  const auto & [h1num, h1den] = getHistogramPair(nd_dir + numer, nd_dir + denom);
1643 
1644  // Summary ESid and ESindep
1645 
1646  if (!h1num) continue;
1647  if (0 == alg || 1 == alg || 2 == alg) {
1648  double sumd {}, sumn {}, sumeff {}, sumerr {};
1649  sumn = h1num->Integral(iSTDL, iSTDH);
1650  sumd = h1den->Integral(iSTDL, iSTDH);
1651 
1652  if (sumd != 0.) {
1653  sumeff = (double) sumn / (double) sumd;
1654  sumerr = std::sqrt((double) sumn * (1. - sumeff)) / (double) sumd;
1655  }
1656  int iholx = -1;
1657  if (0 == alg) {
1658  iholx = static_cast<int>(iL2MuonSA);
1659  } else if (1 == alg) {
1660  iholx = static_cast<int>(iMuComb);
1661  } else if (2 == alg) {
1662  iholx = static_cast<int>(iEFCB);
1663  }
1664 
1665  TString s = histdireff + chainName + "_highpt_effsummary_by" + triggerES[i];
1666  h1effsum = getHPointer(s);
1667  if (!h1effsum) continue;
1668  //
1669  h1effsum->GetYaxis()->SetTitleOffset(1.3);
1670  h1effsum->SetBinContent(iholx + 1, sumeff);
1671  h1effsum->SetBinError(iholx + 1, sumerr);
1672  h1effsum->SetMinimum(0.0);
1673  h1effsum->SetMaximum(1.05);
1674  efdir->cd();
1675  h1effsum->Write("", TObject::kOverwrite);
1676  }
1677 
1678  denom = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + "_Denominator";
1679  numer = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_Numerator";
1680  effi = chainName + triggerES[i] + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg];
1681  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1682  }
1683  // for ES : END ------------------------------------------------------------------------------
1684 
1685  // Barrel/Endcap
1686  if (0 == alg || 1 == alg || 2 == alg) {
1687  for (int be = 0; be < 2; be++) {
1688  denom = chainName + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator";
1689  numer = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1690  effi = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidCB";
1691  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1692  }
1693 
1694  for (int be = 0; be < 2; be++) {
1695  denom = chainName + MSchainName + "_Turn_On_Curve_wrt_MuidCB" + bestr[be] + "_Denominator";
1696  numer = chainName + MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1697  effi = chainName + MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_wrt_MuidCB";
1698  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1699  }
1700 
1701  for (int be = 0; be < 2; be++) {
1702  denom = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be] + "_Denominator";
1703  numer = chainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1704  effi = chainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be];
1705  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1706  }
1707 
1708 
1709  for (int be = 0; be < 2; be++) {
1710  denom = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be] +
1711  "_Denominator";
1712  numer = chainName + MSchainName + monalg[alg] + bestr[be] + "_Turn_On_Curve_Numerator";
1713  effi = chainName + MSchainName + monalg[alg] + "_Turn_On_Curve_wrt" + wrtalg[alg] + bestr[be];
1714  HLTMuonHDiv(mf, histdireff, numer, denom, effi, "_Fit");
1715  }
1716  }
1717  }
1718  }
1719  }//while (now just open bracket: 110728
1720  }//MonitoringFile::HLTMuonHistogramDivision
1721 
1723  TString sdir, TString snum, TString sden, TString seff, TString seffg) {
1724  auto getHPointer ATLAS_THREAD_SAFE = [&mf] ATLAS_NOT_THREAD_SAFE(const TString &hname)->TH1F * {
1725  TH1F* pH {};
1726  mf.get(hname, pH);
1727  if (!pH and fdbg) {
1728  std::cerr << "HLTMuon PostProcessing: no such histogram!! " << hname << std::endl;
1729  }
1730  return pH;
1731  };
1732  TH1F* h1tmpf(0);
1733  TH1F* h1num(0);
1734  TH1F* h1den(0);
1735  TGraphAsymmErrors* h1tmpfg = new TGraphAsymmErrors();
1736 
1737  ;
1738  TString stmp = seff + seffg;
1739 
1740  h1num = getHPointer(sdir + "NumDenom/" + snum);
1741  if (!h1num) return;
1742 
1743  h1den = getHPointer(sdir + "NumDenom/" + sden);
1744  if (!h1den) return;
1745 
1746  TDirectory* dir = mf.GetDirectory(sdir);
1747 
1748  h1tmpf = (TH1F*) h1den->Clone();
1749  h1tmpf->SetName(stmp);
1750  h1tmpf->SetTitle(stmp);
1751  h1tmpf->GetYaxis()->SetTitle("Efficiency");
1752  h1tmpf->Reset();
1753  h1tmpf->Divide(h1num, h1den, 1., 1., "B");
1754  h1tmpf->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1755  h1tmpf->SetMinimum(0.0);
1756  h1tmpfg->SetMaximum(1.05);
1757  h1tmpf->SetName(stmp);
1758  dir->cd();
1759  h1tmpf->Write();
1760  h1tmpfg->SetMarkerStyle(20);
1761  h1tmpfg->SetMinimum(0.0);
1762  h1tmpfg->SetMaximum(1.05);
1763  h1tmpfg->BayesDivide(h1num, h1den);
1764  h1tmpfg->GetYaxis()->SetTitle("Efficiency");
1765  h1tmpfg->GetXaxis()->SetTitle(h1den->GetXaxis()->GetTitle());
1766  dir->cd();
1767  h1tmpfg->SetName(stmp);
1768  h1tmpfg->Write();
1769  delete h1tmpfg;
1770  }
1771 }//namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
dqutils::ATLAS_NOT_THREAD_SAFE
void getImageBuffer ATLAS_NOT_THREAD_SAFE(TImage **img, TCanvas *myC, char **x, int *y)
Definition: HanOutputFile.cxx:1130
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TH1F::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:326
SGout2dot.alg
alg
Definition: SGout2dot.py:243
dqutils::MonitoringFile::HLTMuonHistogramDivision
static void HLTMuonHistogramDivision(const std::string &inFilename, TString &run_dir)
Definition: MonitoringFile_HLTMuonHistogramDivision.cxx:43
TH2F
Definition: rootspy.cxx:420
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:272
skel.it
it
Definition: skel.GENtoEVGEN.py:423
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
DQPostProcessTest.mf
mf
Definition: DQPostProcessTest.py:19
sTgcDigitEffiDump.effi
list effi
Definition: sTgcDigitEffiDump.py:38
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:92
BindingsTest.cut
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
Definition: BindingsTest.py:13
dqutils::MonitoringFile::PostProcessorFileWrapper
Definition: MonitoringFile.h:213
TH1F::SetBinContent
void SetBinContent(int, double)
Definition: rootspy.cxx:327
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
dqutils
Definition: CoolMdt.h:76
compute_lumi.denom
denom
Definition: compute_lumi.py:76
beamspotman.dir
string dir
Definition: beamspotman.py:623
dqutils::MonitoringFile::HLTMuonHDiv
static void HLTMuonHDiv(PostProcessorFileWrapper &mf, TString sdir, TString snum, TString sden, TString seff, TString seffg)
Definition: MonitoringFile_HLTMuonHistogramDivision.cxx:1722
python.copyTCTOutput.chains
chains
Definition: copyTCTOutput.py:81
MonitoringFile.h
TH1F
Definition: rootspy.cxx:320
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.TriggerAPI.TriggerAPISession.chainName
chainName
Definition: TriggerAPISession.py:353
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
PlotCalibFromCool.be
be
Definition: PlotCalibFromCool.py:398
fitman.k
k
Definition: fitman.py:528
PhysDESDM_Quirks.trigger
trigger
Definition: PhysDESDM_Quirks.py:27