Belle II Software  release-08-01-10
DQMHistAnalysisHLTMonObj.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 // Own header.
10 #include <dqm/analysis/modules/DQMHistAnalysisHLTMonObj.h>
11 
12 // Basf2 headers.
13 #include <hlt/utilities/Units.h>
14 
15 // C++ headers
16 #include <regex>
17 
18 using namespace std;
19 using namespace Belle2;
20 
21 //-----------------------------------------------------------------
22 // Register module
23 //-----------------------------------------------------------------
24 
25 REG_MODULE(DQMHistAnalysisHLTMonObj);
26 
27 DQMHistAnalysisHLTMonObjModule::DQMHistAnalysisHLTMonObjModule()
29 {
30  setDescription("Produces MonitoringObject for the HLT from the available DQM histograms");
32 }
33 
35 {
36 }
37 
39 {
40  // make monitoring object related to this module
41  // if monitoring object already exists this will return pointer to it
43 
44  // make canvases to be added to MonitoringObject
45  m_c_filter = new TCanvas("Filter", "filter", 750, 400);
46  m_c_skim = new TCanvas("Skim", "skim", 400, 400);
47  m_c_hardware = new TCanvas("Hardware", "hardware", 1000, 1000);
48  m_c_l1 = new TCanvas("L1", "l1", 750, 400);
49  m_c_ana_eff_shifter = new TCanvas("ana_eff_shifter", "ana_eff_shifter", 1000, 1000);
50 
51  // add canvases to MonitoringObject
57 }
58 
59 
61 {
62 
63  // get existing histograms produced by DQM modules
64  TH1* h_hlt = findHist("softwaretrigger/total_result");
65  TH1* h_skim = findHist("softwaretrigger/skim");
66  TH1* h_budget = findHist("timing_statistics/fullTimeHistogram");
67  TH1* h_processing = findHist("timing_statistics/processingTimeHistogram");
68  TH1* h_meantime = findHist("timing_statistics/meanTimeHistogram");
69  TH1* h_budg_unit = findHist("timing_statistics/fullTimeMeanPerUnitHistogram");
70  TH1* h_proc_unit = findHist("timing_statistics/processingTimeMeanPerUnitHistogram");
71  TH1* h_procs = findHist("timing_statistics/processesPerUnitHistogram");
72  TH1* h_l1 = findHist("softwaretrigger_before_filter/hlt_unit_number");
73  TH1* h_err_flag = findHist("softwaretrigger_before_filter/error_flag");
74  TH1* h_hlt_triggers = findHist("softwaretrigger/filter");
75  TH1* h_l1_triggers = findHist("TRGGDL/hGDL_psn_all");
76  TH1* h_l1_triggers_filt = findHist("softwaretrigger/l1_total_result");
77  TH1* h_l1_cat_w_overlap = findHist("TRGGDL/hGDL_psn_raw_rate_all");
78  TH1* h_l1_cat_wo_overlap = findHist("TRGGDL/hGDL_psn_effect_to_l1_all");
79  TH1* h_full_mem = findHist("timing_statistics/fullMemoryHistogram");
80  TCanvas* c_GDL_ana_eff_shifter = findCanvas("TRGGDL/hGDL_ana_eff_shifter");
81  TH1* h_GDL_ana_eff_shifter = nullptr;
82 
83  if (c_GDL_ana_eff_shifter) {
84  c_GDL_ana_eff_shifter->cd();
85  h_GDL_ana_eff_shifter = dynamic_cast<TH1*>(gPad->GetPrimitive("hGDL_ana_eff_shifter"));
86  }
87 
88  // set the content of filter canvas
89  m_c_filter->Clear(); // clear existing content
90  m_c_filter->Divide(2, 2);
91  m_c_filter->cd(1);
92  if (h_hlt) h_hlt->Draw();
93  m_c_filter->cd(2);
94  if (h_hlt_triggers) h_hlt_triggers->Draw();
95  m_c_filter->cd(3);
96  if (h_err_flag) h_err_flag->Draw();
97 
98  // set the content of skim canvas
99  m_c_skim->Clear(); // clear existing content
100  m_c_skim->cd();
101  if (h_skim) h_skim->Draw();
102 
103  // set the content of hardware canvas
104  m_c_hardware->Clear(); // clear existing content
105  m_c_hardware->Divide(3, 3);
106  m_c_hardware->cd(1);
107  if (h_l1) h_l1->Draw();
108  m_c_hardware->cd(2);
109  if (h_budget) h_budget->Draw();
110  m_c_hardware->cd(3);
111  if (h_processing) h_processing->Draw();
112  m_c_hardware->cd(4);
113  if (h_budg_unit) h_budg_unit->Draw();
114  m_c_hardware->cd(5);
115  if (h_proc_unit) h_proc_unit->Draw();
116  m_c_hardware->cd(6);
117  if (h_meantime) h_meantime->Draw();
118  m_c_hardware->cd(7);
119  if (h_procs) h_procs->Draw();
120  m_c_hardware->cd(8);
121  if (h_full_mem) h_full_mem->Draw();
122 
123  // set the content of L1 canvas
124  m_c_l1->Clear(); // clear existing content
125  m_c_l1->Divide(2, 2);
126  m_c_l1->cd(1);
127  if (h_l1_triggers) h_l1_triggers->Draw();
128  m_c_l1->cd(2);
129  if (h_l1_triggers_filt) h_l1_triggers_filt->Draw();
130  m_c_l1->cd(3);
131  if (h_l1_cat_w_overlap) h_l1_cat_w_overlap->Draw();
132  m_c_l1->cd(4);
133  if (h_l1_cat_wo_overlap) h_l1_cat_wo_overlap->Draw();
134 
135 // set the content of ana_eff_shifter canvas
136  m_c_ana_eff_shifter->Clear();
137  m_c_ana_eff_shifter->cd();
138  if (h_GDL_ana_eff_shifter) h_GDL_ana_eff_shifter->Draw();
139 
140  double n_hlt = 0.;
141  if (h_hlt) n_hlt = (double)h_hlt->GetBinContent((h_hlt->GetXaxis())->FindFixBin("total_result"));
142  m_monObj->setVariable("n_hlt", n_hlt);
143  double n_l1 = 0.;
144  if (h_l1) n_l1 = h_l1->GetEntries();
145  m_monObj->setVariable("n_l1", n_l1);
146  double n_procs = 0.;
147  if (h_procs) n_procs = h_procs->GetEntries();
148  m_monObj->setVariable("n_procs", n_procs);
149 
150  if (h_skim) {
151  // loop bins, add variable to monObj named as "effCS_" + bin label w/o "accept"
152  for (int ibin = 1; ibin < h_skim->GetXaxis()->GetNbins() + 1; ibin++) {
153  double nentr = (double)h_skim->GetBinContent(ibin);
154  std::string bin_name(h_skim->GetXaxis()->GetBinLabel(ibin));
155  m_monObj->setVariable(bin_name.replace(0, 6, "effCS"), nentr);
156  }
157  }
158 
159  if (h_l1_triggers) {
160  // loop bins, add variable to monObj named as "effCS_l1_" + bin label
161  for (int ibin = 1; ibin < h_l1_triggers->GetXaxis()->GetNbins() + 1; ibin++) {
162  double nentr = (double)h_l1_triggers->GetBinContent(ibin);
163  std::string bin_name(h_l1_triggers->GetXaxis()->GetBinLabel(ibin));
164  if (bin_name == "") continue;
165  m_monObj->setVariable(bin_name.insert(0, "effCS_l1_"), nentr);
166  }
167  }
168 
169  if (h_l1_triggers_filt) {
170  // loop bins, add variable to monObj named as "effCS_l1_fON_" + bin label
171  for (int ibin = 1; ibin < h_l1_triggers_filt->GetXaxis()->GetNbins() + 1; ibin++) {
172  double nentr = (double)h_l1_triggers_filt->GetBinContent(ibin);
173  std::string bin_name(h_l1_triggers_filt->GetXaxis()->GetBinLabel(ibin));
174  if (bin_name == "") continue;
175  m_monObj->setVariable(bin_name.insert(0, "effCS_l1_fON_"), nentr);
176  }
177  }
178 
179  if (h_hlt_triggers) {
180  // loop bins, add variable to monObj named as "effCS_hlt_" + bin label
181  for (int ibin = 1; ibin < h_hlt_triggers->GetXaxis()->GetNbins() + 1; ibin++) {
182  double nentr = (double)h_hlt_triggers->GetBinContent(ibin);
183  std::string bin_name(h_hlt_triggers->GetXaxis()->GetBinLabel(ibin));
184  bin_name = std::regex_replace(bin_name, std::regex("=="), "_eq_");
185  bin_name = std::regex_replace(bin_name, std::regex("\\."), "_");
186  m_monObj->setVariable(bin_name.insert(0, "effCS_hlt_"), nentr);
187  }
188  }
189 
190  if (h_meantime) {
191  // loop bins, add variable to monObj named as "secTime_" + bin label
192  for (int ibin = 1; ibin < h_meantime->GetXaxis()->GetNbins() + 1; ibin++) {
193  double nentr = (double)h_meantime->GetBinContent(ibin);
194  std::string bin_name(h_meantime->GetXaxis()->GetBinLabel(ibin));
195  m_monObj->setVariable(bin_name.insert(0, "secTime_"), nentr);
196  }
197  }
198 
199  if (h_err_flag) {
200  // loop bins, add variable to monObj named as "errFlag_" + bin label
201  for (int ibin = 1; ibin < h_err_flag->GetXaxis()->GetNbins() + 1; ibin++) {
202  double nentr = (double)h_err_flag->GetBinContent(ibin);
203  std::string bin_name(h_err_flag->GetXaxis()->GetBinLabel(ibin));
204  m_monObj->setVariable(bin_name.insert(0, "errFlag_"), nentr);
205  }
206  }
207 
208  if (h_l1_cat_w_overlap) {
209  // loop bins, add variable to monObj named as "l1_Ov_" + bin label
210  for (int ibin = 1; ibin < h_l1_cat_w_overlap->GetXaxis()->GetNbins() + 1; ibin++) {
211  double nentr = (double)h_l1_cat_w_overlap->GetBinContent(ibin);
212  std::string bin_name(h_l1_cat_w_overlap->GetXaxis()->GetBinLabel(ibin));
213  m_monObj->setVariable(bin_name.insert(0, "l1_Ov_"), nentr);
214  }
215  }
216 
217  if (h_l1_cat_wo_overlap) {
218  // loop bins, add variable to monObj named as "l1_noOv_" + bin label
219  for (int ibin = 1; ibin < h_l1_cat_wo_overlap->GetXaxis()->GetNbins() + 1; ibin++) {
220  double nentr = (double)h_l1_cat_wo_overlap->GetBinContent(ibin);
221  std::string bin_name(h_l1_cat_wo_overlap->GetXaxis()->GetBinLabel(ibin));
222  m_monObj->setVariable(bin_name.insert(0, "l1_noOv_"), nentr);
223  }
224  }
225 
226  if (h_GDL_ana_eff_shifter) {
227  // loop bins, add variable to monObj named as "GDLanaEffShifter_" + bin label
228  for (int ibin = 1; ibin < h_GDL_ana_eff_shifter->GetXaxis()->GetNbins() + 1; ibin++) {
229  double nentr = (double)h_GDL_ana_eff_shifter->GetBinContent(ibin);
230  std::string bin_name(h_GDL_ana_eff_shifter->GetXaxis()->GetBinLabel(ibin));
231  m_monObj->setVariable(bin_name.insert(0, "GDLanaEffShifter_"), nentr);
232  }
233  }
234 
235  double bgt = 0.;
236  if (h_budget) bgt = h_budget->GetMean();
237  m_monObj->setVariable("budget_time", bgt);
238 
239  m_monObj->setVariable("n_l1_x_budget_time", n_l1 * bgt);
240 
241  double procTime = 0.;
242  if (h_processing) procTime = h_processing->GetMean();
243  m_monObj->setVariable("processing_time", procTime);
244 
245  double fullMemory = 0.;
246  if (h_full_mem) fullMemory = h_full_mem->GetBinLowEdge(h_full_mem->FindLastBinAbove(0) + 1);
247  m_monObj->setVariable("full_memory", fullMemory);
248 
249  TH1* h_budgetUnit = nullptr;
250  TH1* h_memoryUnit = nullptr;
251 
252  for (unsigned int index = 1; index <= HLTUnits::max_hlt_units; index++) {
253  // add budget time per unit
254  h_budgetUnit = findHist(("timing_statistics/fullTimePerUnitHistogram_HLT" + std::to_string(index)).c_str());
255  double bgunit = 0.;
256  if (h_budgetUnit) bgunit = h_budgetUnit->GetMean();
257  m_monObj->setVariable(("budget_time_HLT" + std::to_string(index)).c_str(), bgunit);
258  // add processing time per unit
259  h_budgetUnit = findHist(("timing_statistics/processingTimePerUnitHistogram_HLT" + std::to_string(index)).c_str());
260  if (h_budgetUnit) bgunit = h_budgetUnit->GetMean();
261  else bgunit = 0.;
262  m_monObj->setVariable(("processing_time_HLT" + std::to_string(index)).c_str(), bgunit);
263  // add memory per unit
264  h_memoryUnit = findHist(("timing_statistics/fullMemoryPerUnitHistogram_HLT" + std::to_string(index)).c_str());
265  double memunit = 0.;
266  if (h_memoryUnit && bgunit > 0) memunit = h_memoryUnit->GetBinLowEdge(h_memoryUnit->FindLastBinAbove(0.) + 1);
267  m_monObj->setVariable(("memory_HLT" + std::to_string(index)).c_str(), memunit);
268  }
269 
270  B2DEBUG(20, "DQMHistAnalysisHLTMonObj : endRun called");
271 }
272 
274 {
275  B2DEBUG(20, "terminate called");
276 }
TCanvas * m_c_ana_eff_shifter
Canvas with histogram related to ana_eff_shifter.
TCanvas * m_c_skim
Canvas with histograms related to HLT skims.
void initialize() override final
Initialize the Module.
TCanvas * m_c_l1
Canvas with histograms related to L1.
MonitoringObject * m_monObj
MonitoringObject to be produced by this module.
void terminate() override final
Termination action.
TCanvas * m_c_filter
Canvas with histograms related to HLT filter.
void endRun() override final
End-of-run action.
TCanvas * m_c_hardware
Canvas with histograms related to HLT hardware.
The base class for the histogram analysis module.
TCanvas * findCanvas(TString cname)
Find canvas by name.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
static MonitoringObject * getMonitoringObject(const std::string &histname)
Get MonitoringObject with given name (new object is created if non-existing)
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
void setVariable(const std::string &var, float val, float upErr=-1., float dwErr=-1)
set value to float variable (new variable is made if not yet existing)
void addCanvas(TCanvas *canv)
Add Canvas to monitoring object.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.