ATLAS Offline Software
MonitoringFile_HLTMETDQFlagSummary.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 /* HLTMET Post Processing Method: In the HLT/MET[Mon/Mon_allCells/Mon_FEB]/DQPlots directory, there are
6  * three summary histograms: L2_MET-status, EF_MET_status and and compN_compSumEt_lin
7  * and lumi-block based histogram: trmet_lbn_flag
8  * This post-processing method fills these histograms appropriately
9  * Author : Venkatesh Kaushik <venkat.kaushik@cern.ch>
10  * Date : Mar 2010
11  */
12 
14 
15 #include <iostream>
16 #include <iomanip>
17 #include <algorithm>
18 #include <fstream>
19 #include <cmath>
20 #include <cstdlib>
21 #include <sstream>
22 #include <vector>
23 #include <utility>
24 #include <map>
25 #include <string>
26 
27 #include "TH1F.h"
28 #include "TH1I.h"
29 #include "TH2F.h"
30 #include "TFile.h"
31 #include "TClass.h"
32 #include "TKey.h"
33 #include "TMath.h"
34 #include "TF1.h"
35 #include "TTree.h"
36 #include "TBranch.h"
37 
38 namespace dqutils {
39  //---------------------------------------------------------------------------------------------------
40  // Method to obtain summary DQFlags
41  //---------------------------------------------------------------------------------------------------
42  void MonitoringFile::HLTMETDQFlagSummary(TFile* f, TString& run_dir) {
43  bool dbgLevel = false;
44 
45  if (dbgLevel) std::cout << "--> HLTMETDQFlagSummary: Updating histograms in HLT/METMon*/DQPlots " << std::endl;
46 
47  f->cd("/");
48  TIter next_run(f->GetListOfKeys());
49  TKey* key_run(0);
50  while ((key_run = dynamic_cast<TKey*> (next_run())) != 0) {
51  if (!key_run->IsFolder()) continue;
52  run_dir = key_run->GetName();
53  if (!run_dir.Contains("run")) {
54  continue;
55  }
56 
57  TDirectory* tdir_run = dynamic_cast<TDirectory*>(key_run);
58 
59  std::string run_dir2 = run_dir.Data();
60 
61  // all merged root files have the structure "rootfile.root:/run_NNNNNNN"
62  // use that to extract run number
63  //int run_number = atoi( (run_dir2.substr(4, run_dir2.size()-4 )).c_str() );
64  //run_number=run_number;
65 
66  // begin HLTMET
67  // note 1: prefix all dirs and hists with '/'
68  // note 2: missing dir => return
69  // note 3: missing hist => continue
70  TString hlt_top = run_dir + "/HLT"; // toplevel
71  TString met_efdir = "/EFMissingET_Fex"; // EF dir
72  TString met_l2dir = "/L2MissingET_Fex"; // L2 dir
73  TString dqflag_dir = "/DQFlags"; // DQ flags dir
74 
75  std::vector<TString> met_fexs, met_l2hists, met_efhists;
76  // expect the following fex dirs
77  met_fexs.push_back("/METMon");
78  //met_fexs.push_back("/METMon_FEB");
79  //met_fexs.push_back("/METMon_allCells");
80 
81  // expect the following histograms
82  met_l2hists.push_back("/L2_MET_status");
83  met_l2hists.push_back("/L2_MEx_log");
84  met_l2hists.push_back("/L2_MEy_log");
85  met_l2hists.push_back("/L2_MET_log");
86  met_l2hists.push_back("/L2_SumEt_log");
87 
88  met_efhists.push_back("/EF_MET_status");
89  met_efhists.push_back("/EF_MET_lin");
90  met_efhists.push_back("/EF_MET_lin1");
91  met_efhists.push_back("/EF_SumEt_lin");
92  met_efhists.push_back("/EF_MET_phi");
93  met_efhists.push_back("/EF_MET_phi1");
94  met_efhists.push_back("/EF_MEx_log");
95  met_efhists.push_back("/EF_MEy_log");
96  met_efhists.push_back("/compN_compSumEt_lin");
97  met_efhists.push_back("/compN_EF_MET_status");
98 
99  std::vector<TString> lbnDirs;
100  TString lbn_dqhist = "/trmet_lbn_flag";
101  size_t lbn_range = HLTMETGetDQLBNRange(tdir_run, lbnDirs);
102 
103  //std::cout << "lbn_range = " << lbn_range << std::endl;
104 
105  // Get EF/L2 status histograms for default Fex
106  for (std::vector<TString>::iterator itFex = met_fexs.begin(); itFex != met_fexs.end(); ++itFex) {
107  TString theL2Path = hlt_top + (*itFex) + met_l2dir;
108  TString theEFPath = hlt_top + (*itFex) + met_efdir;
109  TString theDQPath = hlt_top + (*itFex) + dqflag_dir;
110 
111  TDirectory* dirl2 = f->GetDirectory(theL2Path);
112  if (!dirl2) {
113  std::cerr << "--> HLTMETDQFlagSummary: directory " << theL2Path << " not found" << std::endl;
114  return;
115  }
116  TDirectory* diref = f->GetDirectory(theEFPath);
117  if (!diref) {
118  std::cerr << "--> HLTMETDQFlagSummary: directory " << theEFPath << " not found" << std::endl;
119  return;
120  }
121  TDirectory* dirdq = f->GetDirectory(theDQPath);
122  if (!dirdq) {
123  std::cerr << "--> HLTMETDQFlagSummary: directory " << theDQPath << " not found" << std::endl;
124  return;
125  }
126  // loop over L2 hists and copy to DQFlags
127  for (std::vector<TString>::iterator itHist = met_l2hists.begin(); itHist != met_l2hists.end(); ++itHist) {
128  TString histL2 = (theL2Path + *itHist);
129  TString histL2C = (theDQPath + *itHist);
130  TH1* hl2(0), *hl2c(0);
131  if (!f->Get(histL2)) {
132  if (dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histL2 << std::endl;
133  continue;
134  }
135  if (!f->Get(histL2C)) {
136  if (dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histL2C << std::endl;
137  continue;
138  }
139  hl2 = (TH1*) (f->Get(histL2));
140  // check if MET_status histogram is emtpy
141  bool save_status_hist = false;
142  if (*itHist == "/L2_MET_status") {
143  if (hl2->GetMaximum() < 1.e-3) {
144  save_status_hist = true;
145  for (int ibin = 1; ibin <= hl2->GetNbinsX(); ibin++) {
146  hl2->SetBinContent(ibin, 0.05);
147  }
148  }
149  }
150  hl2c = (TH1*) (f->Get(histL2C));
151  hl2c->Reset();
152  hl2c->Add(hl2);
153  //hl2c->Sumw2();
154  //std::cout << "--> HLTMETDQFlagSummary: added histograms " << histL2 << "\t and " << histL2C << std::endl;
155  dirdq->cd();
156  hl2c->Write("", TObject::kOverwrite);
157  if (save_status_hist) {
158  if (f->cd(theL2Path)) hl2->Write("", TObject::kOverwrite);
159  }
160  } // end loop over l2 hists
161 
162  // loop over EF hists and copy to DQFlags
163  for (std::vector<TString>::iterator itHist = met_efhists.begin(); itHist != met_efhists.end(); ++itHist) {
164  TString histEF = (theEFPath + *itHist);
165  TString histEFC = (theDQPath + *itHist);
166  TH1* hef(0), *hefc(0);
167  if (!f->Get(histEF)) {
168  if (dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histEF << std::endl;
169  continue;
170  }
171  if (!f->Get(histEFC)) {
172  if (dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histEFC << std::endl;
173  continue;
174  }
175  hef = (TH1*) (f->Get(histEF));
176  bool save_status_hist = false;
177  if (*itHist == "/EF_MET_status") {
178  if (hef->GetMaximum() < 1.e-3) {
179  save_status_hist = true;
180  for (int ibin = 1; ibin <= hef->GetNbinsX(); ibin++) {
181  hef->SetBinContent(ibin, 0.05);
182  }
183  }
184  }
185  hefc = (TH1*) (f->Get(histEFC));
186  hefc->Reset();
187  hefc->Add(hef);
188  //hefc->Sumw2();
189  dirdq->cd();
190  if (save_status_hist) {
191  if (f->cd(theEFPath)) hef->Write("", TObject::kOverwrite);
192  }
193  hefc->Write("", TObject::kOverwrite);
194  } // end loop over ef hists
195 
196  // resize lbn based histogram
197  if (lbn_range > 0) {
198  TString histLBN = theDQPath + lbn_dqhist;
199  TH1* hlb(0);
200  if (!f->Get(histLBN)) {
201  if (dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histLBN << std::endl;
202  continue;
203  }
204  hlb = (TH1*) (f->Get(histLBN));
205  unsigned int nbinx = (unsigned int) hlb->GetNbinsX(), nbiny = (unsigned int) hlb->GetNbinsY(), k = 1;
206  if (nbinx != nbiny) continue;
207 
208  if (lbn_range < nbinx) {
209  hlb->GetXaxis()->SetRangeUser(0, Double_t(lbn_range));
210  hlb->GetYaxis()->SetRangeUser(0, Double_t(lbn_range));
211  }
212  TH1I* hlbstat(0);
213  for (std::vector<TString>::iterator it = lbnDirs.begin(); it != lbnDirs.end(); ++it, ++k) {
214  if (k > nbinx) continue;
215  TString histLBstat = run_dir + TString("/") + *it + TString("/HLT") + (*itFex) + "/lbnstatus/EF_MET_status";
216  if (!f->Get(histLBstat)) {
217  if (dbgLevel) std::cerr << "--> HLTMETDQFlagSummary: no histogram " << histLBstat << std::endl;
218  continue;
219  }
220  hlbstat = (TH1I*) (f->Get(histLBstat));
221  int flag = HLTMETGetStatusPerBin(hlbstat, 17, 29, 32, 32);
222  //std::cout << "--> HLTMETDQFlagSummary: " << *it << "\t: flag = " << flag << std::endl;
223  TString label = *it;
224  label.ReplaceAll("lowStat_", "");
225  hlb->GetXaxis()->SetBinLabel(k, label.Data());
226  hlb->GetYaxis()->SetBinLabel(k, label.Data());
227  hlb->SetBinContent(k, k, flag);
228  } // end for
229  hlb->Write("", TObject::kOverwrite);
230  } else {
231  std::cerr << "--> HLTMETDQFlagSummary: lowStat_* directories: found none " << std::endl;
232  }
233  } // end loop over fexs
234  } // end while loop over all keys
235  } // end method MonitoringFile::HLTMETDQFlagSummary
236 
237  //---------------------------------------------------------------------------------------------------
238  // Method to get lowStat_* directories
239  //---------------------------------------------------------------------------------------------------
240  size_t MonitoringFile::HLTMETGetDQLBNRange(TDirectory*& run_dir, std::vector<TString>& lbnDirs) {
241  if (!run_dir) return 0;
242 
243  lbnDirs.clear();
244 
245  bool dbgLevel = false;
246  if (dbgLevel) std::cout << "--> HLTMETGetDQLBNRange: lowStat_* directories: ";
247  run_dir->cd();
248 
249  TIter next_lbn(run_dir->GetListOfKeys());
250  TKey* key_lbn(0);
251  TString lbn_dir = "";
252  // loop over all objects
253  while ((key_lbn = dynamic_cast<TKey*> (next_lbn())) != 0) {
254  if (!key_lbn->IsFolder()) continue;
255  lbn_dir = key_lbn->GetName();
256  if (!lbn_dir.Contains("lowStat_")) {
257  continue;
258  }
259  lbnDirs.push_back(lbn_dir);
260  //std::cout << "dir = " << lbn_dir << "\tuuid = " << uuid.AsString() << "\ttime = " << dtme.GetTime() <<
261  // std::endl;
262  }
263  unsigned int nLBNDirs = lbnDirs.size();
264  if (dbgLevel) std::cout << "found " << nLBNDirs << std::endl;
265  return nLBNDirs;
266  } // end method MonitoringFile::HLTMETGetDQLBNRange
267 
268  //---------------------------------------------------------------------------------------------------
269  // Method to Get Status flags per lbn block
270  //---------------------------------------------------------------------------------------------------
271  int MonitoringFile::HLTMETGetStatusPerBin(TH1I*& hist, int yellmin, int yellmax, int redmin, int redmax) {
272  if (!hist) return 0;
273 
274  TString hname = hist->GetName();
275  int flag = 10; // 1 == GREEN, 2 == YELLOW, 3 == RED
276  float epsilon = 1.e-3;
277  int nbins = (int) hist->GetNbinsX();
278  yellmin = (yellmin > 0 && yellmin <= nbins) ? yellmin : 1;
279  yellmax = (yellmax > 0 && yellmax <= nbins) ? yellmax : nbins;
280  redmin = (redmin > 0 && redmin <= nbins) ? redmin : 1;
281  redmax = (redmax > 0 && redmax <= nbins) ? redmax : nbins;
282  for (int k = 1; k <= nbins; k++) {
283  float theVal = hist->GetBinContent(k);
284  // at least one bin > 0
285  if (theVal > epsilon) {
286  if (k >= yellmin && k <= yellmax) flag = 100;
287  if (k >= redmin && k <= redmax) flag = 1000;
288  } // end if
289  } // end for
290  return flag;
291  } // end method MonitoringFile::HLTMETGetStatusPerBin
292 } // end namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:279
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
plotmaker.hist
hist
Definition: plotmaker.py:148
skel.it
it
Definition: skel.GENtoEVGEN.py:396
master.flag
bool flag
Definition: master.py:29
hist_file_dump.f
f
Definition: hist_file_dump.py:135
dqutils
Definition: CoolMdt.h:76
dqutils::MonitoringFile::HLTMETGetStatusPerBin
static int HLTMETGetStatusPerBin(TH1I *&hist, int ymin, int ymax, int rmin, int rmax)
Definition: MonitoringFile_HLTMETDQFlagSummary.cxx:271
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
MonitoringFile.h
dqutils::MonitoringFile::HLTMETDQFlagSummary
static void HLTMETDQFlagSummary(TFile *f, TString &run_dir)
Definition: MonitoringFile_HLTMETDQFlagSummary.cxx:42
dqutils::MonitoringFile::HLTMETGetDQLBNRange
static size_t HLTMETGetDQLBNRange(TDirectory *&run_dir, std::vector< TString > &lbnDirs)
Definition: MonitoringFile_HLTMETDQFlagSummary.cxx:240
fitman.k
k
Definition: fitman.py:528