ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_HLTMuonPostProcess.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 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 TString 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, TString& hname) {
59 if (!(f->Get(hname))) {
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, TString& 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.Contains("run")) {
103 continue;
104 }
105 break;
106 }
107 if (!run_dir.Contains("run")) {
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 std::string run_dir2 = run_dir.Data();
119 //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() );
120 //run_number=run_number;
121
122 //===HLTMuon
123 // TString muon_dir = run_dir + "/HLT/MuonMon/";
124 TString muon_dir = "/" + run_dir + "/HLT/MuonMon/";
125
126 TString cm_dir = muon_dir + "Common/";
127
128 TString sol = cm_dir + "Trigger_Overlap";
129 TString solpt = cm_dir + "Trigger_Overlap_Including_Passthrough";
130 TString solf = cm_dir + "Trigger_Overlap_Fraction";
131 TString solfpt = cm_dir + "Trigger_Overlap_Fraction_Including_Passthrough";
132
133 TH2F* hol(0);
134 TH2F* holpt(0);
135 TH2F* holf(0);
136 TH2F* holfpt(0);
137
138 //Matrix
139 TDirectory* dir = mf.GetDirectory(cm_dir);
140 // if (fpdbg) { std::cerr << "matrix directory: " << cm_dir << std::endl; }
141 if (!dir) {
142 if (fpdbg) {
143 std::cerr << "HLTMuonTriggerOverlapMatrix: directory " << cm_dir << " not found" << std::endl;
144 }
145 return;
146 }
147
148 mf.get(sol, hol);
149 // if (fpdbg) { std::cerr << "matrix file: " << sol << std::endl; }
150 if (!hol) {
151 if (fpdbg) {
152 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << sol << std::endl;
153 }
154 continue;
155 }
156 mf.get(solpt, holpt);
157 if (!holpt) {
158 if (fpdbg) {
159 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << solpt << std::endl;
160 }
161 continue;
162 }
163 mf.get(solf, holf);
164 if (!holf) {
165 if (fpdbg) {
166 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << solf << std::endl;
167 }
168 continue;
169 }
170 mf.get(solfpt, holfpt);
171 if (!holfpt) {
172 if (fpdbg) {
173 std::cerr << "HLTMuon PostProcessing: no such histogram!! " << solfpt << std::endl;
174 }
175 continue;
176 }
177
178 if (hol && holpt && holf && holfpt) {
179 holf->Reset();
180 holfpt->Reset();
181
182 for (int i = 0; i < hol->GetXaxis()->GetNbins(); i++) {
183 Float_t diag = hol->GetBinContent(i + 1, i + 1);
184 Float_t diagpt = holpt->GetBinContent(i + 1, i + 1);
185
186 for (int j = 0; j < hol->GetXaxis()->GetNbins(); j++) {
187 Float_t offdiag = hol->GetBinContent(i + 1, j + 1);
188 Float_t offdiagpt = holpt->GetBinContent(i + 1, j + 1);
189
190 Float_t frac = 0.;
191 Float_t efrac = 0.;
192
193 if (diag != 0.) {
194 frac = offdiag / diag;
195 efrac = sqrt(frac * (1. - frac) / diag);
196 }
197
198 Float_t fracpt = 0.;
199 Float_t efracpt = 0.;
200
201 if (diagpt != 0.) {
202 fracpt = offdiagpt / diagpt;
203 efracpt = sqrt(fracpt * (1. - fracpt) / diagpt);
204 }
205
206 holf->SetBinContent(i + 1, j + 1, frac);
207 holf->SetBinError(i + 1, j + 1, efrac);
208
209 holfpt->SetBinContent(i + 1, j + 1, fracpt);
210 holfpt->SetBinError(i + 1, j + 1, efracpt);
211 }//j
212 }//i
213
214 dir->cd();
215 holf->Write("", TObject::kOverwrite);
216 holfpt->Write("", TObject::kOverwrite);
217 }//if
218 mf.Write();
219 }//while
220 }//HLTMuonTriggerOverlapMatrix
221}//namespace
static void HLTMuonHistogramDivision(const std::string &inFilename, TString &run_dir)
static void HLTMuonPostProcess(const std::string &inFilename, bool isIncremental=false)
static void HLTMuonTriggerOverlapMatrix(const std::string &inFilename, TString &run_dir)
static bool HLTMuonCheckHistogram(TFile *f, TString &hname)