ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_HLTMuonPostProcess.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
6//Methods to Process HLTMuon Histograms after merging.
7//Author: Akimasa Ishikawa (akimasa.ishikawa@cern.ch)
8//Date: Jan 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
35
36
37namespace dqutils {
38 static const bool fpdbg = false;
39 // static const bool fpdbg = true;
40
41 void
42 MonitoringFile::HLTMuonPostProcess(const std::string& inFilename, bool /* isIncremental */) {
43 if (fpdbg) std::cout << "Start HLTMuon post-processing" << std::endl;
44
45 //start postprocessing
46 std::string run_dir;
47 HLTMuonHistogramDivision(inFilename, run_dir);
48
49 //trigger overlap matrix
50 HLTMuonTriggerOverlapMatrix(inFilename, run_dir);
51
52 if (fpdbg) std::cout << "Finish HLTMuon post-processing" << std::endl;
53
54 return;
55 }//MonitoringFile::HLTMuonPostProcess
56
57 bool
58 MonitoringFile::HLTMuonCheckHistogram(TFile* f, const std::string& hname) {
59 if (!(f->Get(hname.c_str()))) {
60 if (fpdbg) {
61 std::cerr << "HLTMuon PostProcessing: no such histogram!! : " << hname << std::endl;
62 gDirectory->pwd();
63 gDirectory->ls();
64 }
65 return false;
66 }
67 return true;
68 }//MonitoringFile::HLTMuonCheckHistogram
69
70 void
71 MonitoringFile::HLTMuonTriggerOverlapMatrix(const std::string& inFilename, std::string& run_dir) {
72 if (fpdbg) std::cout << " Start to fill HLTMuon Trigger Overlap Matrix" << std::endl;
73
74 PostProcessorFileWrapper mf(inFilename, "HLT Trigger Overlap Matrix");
75 if (!mf.IsOpen()) {
76 std::cerr << "HLTMuonPostProcess(): "
77 << "Input file not opened \n";
78 return;
79 }
80 if (mf.GetSize() < 1000.) {
81 std::cerr << "HLTMuonPostProcess(): "
82 << "Input file empty \n";
83 return;
84 }
85 // get run directory name
86 //Seemingly unnecessary lines are necessary
87 TIter nextcd0(gDirectory->GetListOfKeys());
88 TKey* key0 = (TKey*) nextcd0();
89 TDirectory* dir0 = dynamic_cast<TDirectory*> (key0->ReadObj());
90 if (not dir0) {
91 std::cerr << "nullptr for dynamic cast in HLTMuonTriggerOverlapMatrix" << std::endl;
92 return;
93 }
94 dir0->cd();
96
97 TIter next_run(mf.GetListOfKeys());
98 TKey* key_run(0);
99 while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) { //== the while commented out at$
100 if (!key_run->IsFolder()) continue;
101 run_dir = key_run->GetName();
102 if (run_dir.find("run") == std::string::npos) {
103 continue;
104 }
105 break;
106 }
107 if (run_dir.find("run") == std::string::npos) {
108 std::cerr << "HLTMuon: unable to find run directory ..." << std::endl;
109 return;
110 }
111 int times = 1;
112 while (times--) { // just once
113 //run_dir = dir0->GetName();
114 if (fpdbg) {
115 std::cout << "HLTMuon: run directory is " << run_dir << std::endl;
116 }
117
118
119 //===HLTMuon
120 // std::string muon_dir = run_dir + "/HLT/MuonMon/";
121 std::string muon_dir = "/" + run_dir + "/HLT/MuonMon/";
122
123 std::string cm_dir = muon_dir + "Common/";
124
125 std::string sol = cm_dir + "Trigger_Overlap";
126 std::string solpt = cm_dir + "Trigger_Overlap_Including_Passthrough";
127 std::string solf = cm_dir + "Trigger_Overlap_Fraction";
128 std::string solfpt = cm_dir + "Trigger_Overlap_Fraction_Including_Passthrough";
129
130 TH2F* hol(0);
131 TH2F* holpt(0);
132 TH2F* holf(0);
133 TH2F* holfpt(0);
134
135 //Matrix
136 TDirectory* dir = mf.GetDirectory(cm_dir.c_str());
137 // if (fpdbg) { std::cerr << "matrix directory: " << cm_dir << std::endl; }
138 if (!dir) {
139 if (fpdbg) {
140 std::cerr << "HLTMuonTriggerOverlapMatrix: directory " << cm_dir << " not found" << std::endl;
141 }
142 return;
143 }
144
145 mf.get(sol.c_str(), hol);
146 // if (fpdbg) { std::cerr << "matrix file: " << sol << std::endl; }
147 if (!hol) {
148 if (fpdbg) {
149 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << sol << std::endl;
150 }
151 continue;
152 }
153 mf.get(solpt.c_str(), holpt);
154 if (!holpt) {
155 if (fpdbg) {
156 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << solpt << std::endl;
157 }
158 continue;
159 }
160 mf.get(solf.c_str(), holf);
161 if (!holf) {
162 if (fpdbg) {
163 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << solf << std::endl;
164 }
165 continue;
166 }
167 mf.get(solfpt.c_str(), holfpt);
168 if (!holfpt) {
169 if (fpdbg) {
170 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << solfpt << std::endl;
171 }
172 continue;
173 }
174
175 if (hol && holpt && holf && holfpt) {
176 holf->Reset();
177 holfpt->Reset();
178
179 for (int i = 0; i < hol->GetXaxis()->GetNbins(); i++) {
180 Float_t diag = hol->GetBinContent(i + 1, i + 1);
181 Float_t diagpt = holpt->GetBinContent(i + 1, i + 1);
182
183 for (int j = 0; j < hol->GetXaxis()->GetNbins(); j++) {
184 Float_t offdiag = hol->GetBinContent(i + 1, j + 1);
185 Float_t offdiagpt = holpt->GetBinContent(i + 1, j + 1);
186
187 Float_t frac = 0.;
188 Float_t efrac = 0.;
189
190 if (diag != 0.) {
191 frac = offdiag / diag;
192 efrac = sqrt(frac * (1. - frac) / diag);
193 }
194
195 Float_t fracpt = 0.;
196 Float_t efracpt = 0.;
197
198 if (diagpt != 0.) {
199 fracpt = offdiagpt / diagpt;
200 efracpt = sqrt(fracpt * (1. - fracpt) / diagpt);
201 }
202
203 holf->SetBinContent(i + 1, j + 1, frac);
204 holf->SetBinError(i + 1, j + 1, efrac);
205
206 holfpt->SetBinContent(i + 1, j + 1, fracpt);
207 holfpt->SetBinError(i + 1, j + 1, efracpt);
208 }//j
209 }//i
210
211 dir->cd();
212 holf->Write("", TObject::kOverwrite);
213 holfpt->Write("", TObject::kOverwrite);
214 }//if
215 mf.Write();
216 }//while
217 }//HLTMuonTriggerOverlapMatrix
218}//namespace
static void HLTMuonHistogramDivision(const std::string &inFilename, std::string &run_dir)
static void HLTMuonPostProcess(const std::string &inFilename, bool isIncremental=false)
static bool HLTMuonCheckHistogram(TFile *f, const std::string &hname)
static void HLTMuonTriggerOverlapMatrix(const std::string &inFilename, std::string &run_dir)