Belle II Software  release-06-00-14
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 include
10 #include <dqm/analysis/modules/DQMHistAnalysisHLTMonObj.h>
11 // software trigger include
12 #include <hlt/softwaretrigger/modules/dqm/SoftwareTriggerHLTDQMModule.h>
13 //DQM
14 #include <dqm/analysis/modules/DQMHistAnalysis.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 //-----------------------------------------------------------------
20 // Register module
21 //-----------------------------------------------------------------
22 
23 REG_MODULE(DQMHistAnalysisHLTMonObj);
24 
25 DQMHistAnalysisHLTMonObjModule::DQMHistAnalysisHLTMonObjModule()
27 {
28  setDescription("Produces MonitoringObject for the HLT from the available DQM histograms");
30 }
31 
33 {
34 }
35 
37 {
38  // make monitoring object related to this module
39  // if monitoring object already exists this will return pointer to it
41 
42  // make canvases to be added to MonitoringObject
43  m_c_filter = new TCanvas("Filter", "filter", 750, 400);
44  m_c_skim = new TCanvas("Skim" , "skim", 400, 400);
45  m_c_hardware = new TCanvas("Hardware", "hardware", 1000, 1000);
46  m_c_l1 = new TCanvas("L1", "l1", 750, 400);
47 
48  // add canvases to MonitoringObject
53 
54 }
55 
57 {
58 }
59 
61 {
62  // can put the analysis code here or in endRun() function
63  // for the start tests we will store output only end of run so better to put code there
64 }
65 
67 {
68 
69  // get existing histograms produced by DQM modules
70  TH1* h_hlt = findHist("softwaretrigger/total_result");
71  TH1* h_skim = findHist("softwaretrigger/skim");
72  TH1* h_budget = findHist("timing_statistics/fullTimeHistogram");
73  TH1* h_processing = findHist("timing_statistics/processingTimeHistogram");
74  TH1* h_meantime = findHist("timing_statistics/meanTimeHistogram");
75  TH1* h_budg_unit = findHist("timing_statistics/fullTimeMeanPerUnitHistogram");
76  TH1* h_proc_unit = findHist("timing_statistics/processingTimeMeanPerUnitHistogram");
77  TH1* h_procs = findHist("timing_statistics/processesPerUnitHistogram");
78  TH1* h_l1 = findHist("softwaretrigger_before_filter/hlt_unit_number");
79  TH1* h_err_flag = findHist("softwaretrigger_before_filter/error_flag");
80  TH1* h_hlt_triggers = findHist("softwaretrigger/filter");
81  TH1* h_l1_triggers = findHist("TRGGDL/hGDL_psn_all");
82  TH1* h_l1_triggers_filt = findHist("softwaretrigger/l1_total_result");
83  TH1* h_l1_cat_w_overlap = findHist("TRGGDL/hGDL_psn_raw_rate_all");
84  TH1* h_l1_cat_wo_overlap = findHist("TRGGDL/hGDL_psn_effect_to_l1_all");
85  TH1* h_full_mem = findHist("timing_statistics/fullMemoryHistogram");
86 
87  // set the content of filter canvas
88  m_c_filter->Clear(); // clear existing content
89  m_c_filter->Divide(2, 2);
90  m_c_filter->cd(1);
91  if (h_hlt) h_hlt->Draw();
92  m_c_filter->cd(2);
93  if (h_hlt_triggers) h_hlt_triggers->Draw();
94  m_c_filter->cd(3);
95  if (h_err_flag) h_err_flag->Draw();
96 
97  // set the content of skim canvas
98  m_c_skim->Clear(); // clear existing content
99  m_c_skim->cd();
100  if (h_skim) h_skim->Draw();
101 
102  // set the content of hardware canvas
103  m_c_hardware->Clear(); // clear existing content
104  m_c_hardware->Divide(3, 3);
105  m_c_hardware->cd(1);
106  if (h_l1) h_l1->Draw();
107  m_c_hardware->cd(2);
108  if (h_budget) h_budget->Draw();
109  m_c_hardware->cd(3);
110  if (h_processing) h_processing->Draw();
111  m_c_hardware->cd(4);
112  if (h_budg_unit) h_budg_unit->Draw();
113  m_c_hardware->cd(5);
114  if (h_proc_unit) h_proc_unit->Draw();
115  m_c_hardware->cd(6);
116  if (h_meantime) h_meantime->Draw();
117  m_c_hardware->cd(7);
118  if (h_procs) h_procs->Draw();
119  m_c_hardware->cd(8);
120  if (h_full_mem) h_full_mem->Draw();
121 
122  // set the content of L1 canvas
123  m_c_l1->Clear(); // clear existing content
124  m_c_l1->Divide(2, 2);
125  m_c_l1->cd(1);
126  if (h_l1_triggers) h_l1_triggers->Draw();
127  m_c_l1->cd(2);
128  if (h_l1_triggers_filt) h_l1_triggers_filt->Draw();
129  m_c_l1->cd(3);
130  if (h_l1_cat_w_overlap) h_l1_cat_w_overlap->Draw();
131  m_c_l1->cd(4);
132  if (h_l1_cat_wo_overlap) h_l1_cat_wo_overlap->Draw();
133 
134  double n_hlt = 0.;
135  if (h_hlt) n_hlt = (double)h_hlt->GetBinContent((h_hlt->GetXaxis())->FindFixBin("total_result"));
136  m_monObj->setVariable("n_hlt", n_hlt);
137  double n_l1 = 0.;
138  if (h_l1) n_l1 = h_l1->GetEntries();
139  m_monObj->setVariable("n_l1", n_l1);
140  double n_procs = 0.;
141  if (h_procs) n_procs = h_procs->GetEntries();
142  m_monObj->setVariable("n_procs", n_procs);
143 
144  if (h_skim) {
145  // loop bins, add variable to monObj named as "effCS_" + bin label w/o "accept"
146  for (int ibin = 1; ibin < h_skim->GetXaxis()->GetNbins() + 1; ibin++) {
147  double nentr = (double)h_skim->GetBinContent(ibin);
148  std::string bin_name(h_skim->GetXaxis()->GetBinLabel(ibin));
149  m_monObj->setVariable(bin_name.replace(0, 6, "effCS"), nentr);
150  }
151  }
152 
153  if (h_l1_triggers) {
154  // loop bins, add variable to monObj named as "effCS_l1_" + bin label
155  for (int ibin = 1; ibin < h_l1_triggers->GetXaxis()->GetNbins() + 1; ibin++) {
156  double nentr = (double)h_l1_triggers->GetBinContent(ibin);
157  std::string bin_name(h_l1_triggers->GetXaxis()->GetBinLabel(ibin));
158  if (bin_name == "") continue;
159  m_monObj->setVariable(bin_name.insert(0, "effCS_l1_"), nentr);
160  }
161  }
162 
163  if (h_l1_triggers_filt) {
164  // loop bins, add variable to monObj named as "effCS_l1_fON_" + bin label
165  for (int ibin = 1; ibin < h_l1_triggers_filt->GetXaxis()->GetNbins() + 1; ibin++) {
166  double nentr = (double)h_l1_triggers_filt->GetBinContent(ibin);
167  std::string bin_name(h_l1_triggers_filt->GetXaxis()->GetBinLabel(ibin));
168  if (bin_name == "") continue;
169  m_monObj->setVariable(bin_name.insert(0, "effCS_l1_fON_"), nentr);
170  }
171  }
172 
173  if (h_hlt_triggers) {
174  // loop bins, add variable to monObj named as "effCS_hlt_" + bin label
175  for (int ibin = 1; ibin < h_hlt_triggers->GetXaxis()->GetNbins() + 1; ibin++) {
176  double nentr = (double)h_hlt_triggers->GetBinContent(ibin);
177  std::string bin_name(h_hlt_triggers->GetXaxis()->GetBinLabel(ibin));
178  bin_name = std::regex_replace(bin_name, std::regex("=="), "_eq_");
179  bin_name = std::regex_replace(bin_name, std::regex("\\."), "_");
180  m_monObj->setVariable(bin_name.insert(0, "effCS_hlt_"), nentr);
181  }
182  }
183 
184  if (h_meantime) {
185  // loop bins, add variable to monObj named as "secTime_" + bin label
186  for (int ibin = 1; ibin < h_meantime->GetXaxis()->GetNbins() + 1; ibin++) {
187  double nentr = (double)h_meantime->GetBinContent(ibin);
188  std::string bin_name(h_meantime->GetXaxis()->GetBinLabel(ibin));
189  m_monObj->setVariable(bin_name.insert(0, "secTime_"), nentr);
190  }
191  }
192 
193  if (h_err_flag) {
194  // loop bins, add variable to monObj named as "errFlag_" + bin label
195  for (int ibin = 1; ibin < h_err_flag->GetXaxis()->GetNbins() + 1; ibin++) {
196  double nentr = (double)h_err_flag->GetBinContent(ibin);
197  std::string bin_name(h_err_flag->GetXaxis()->GetBinLabel(ibin));
198  m_monObj->setVariable(bin_name.insert(0, "errFlag_"), nentr);
199  }
200  }
201 
202  if (h_l1_cat_w_overlap) {
203  // loop bins, add variable to monObj named as "l1_Ov_" + bin label
204  for (int ibin = 1; ibin < h_l1_cat_w_overlap->GetXaxis()->GetNbins() + 1; ibin++) {
205  double nentr = (double)h_l1_cat_w_overlap->GetBinContent(ibin);
206  std::string bin_name(h_l1_cat_w_overlap->GetXaxis()->GetBinLabel(ibin));
207  m_monObj->setVariable(bin_name.insert(0, "l1_Ov_"), nentr);
208  }
209  }
210 
211  if (h_l1_cat_wo_overlap) {
212  // loop bins, add variable to monObj named as "l1_noOv_" + bin label
213  for (int ibin = 1; ibin < h_l1_cat_wo_overlap->GetXaxis()->GetNbins() + 1; ibin++) {
214  double nentr = (double)h_l1_cat_wo_overlap->GetBinContent(ibin);
215  std::string bin_name(h_l1_cat_wo_overlap->GetXaxis()->GetBinLabel(ibin));
216  m_monObj->setVariable(bin_name.insert(0, "l1_noOv_"), nentr);
217  }
218  }
219 
220  double bgt = 0.;
221  if (h_budget) bgt = h_budget->GetMean();
222  m_monObj->setVariable("budget_time", bgt);
223 
224  m_monObj->setVariable("n_l1_x_budget_time", n_l1 * bgt);
225 
226  double procTime = 0.;
227  if (h_processing) procTime = h_processing->GetMean();
228  m_monObj->setVariable("processing_time", procTime);
229 
230  double fullMemory = 0.;
231  if (h_full_mem) fullMemory = h_full_mem->GetBinLowEdge(h_full_mem->FindLastBinAbove(0) + 1);
232  m_monObj->setVariable("full_memory", fullMemory);
233 
234  TH1* h_budgetUnit = nullptr;
235  TH1* h_memoryUnit = nullptr;
236 
237  for (unsigned int index = 1; index <= SoftwareTrigger::HLTUnit::max_hlt_units; index++) {
238  // add budget time per unit
239  h_budgetUnit = findHist(("timing_statistics/fullTimePerUnitHistogram_HLT" + std::to_string(index)).c_str());
240  double bgunit = 0.;
241  if (h_budgetUnit) bgunit = h_budgetUnit->GetMean();
242  m_monObj->setVariable(("budget_time_HLT" + std::to_string(index)).c_str(), bgunit);
243  // add processing time per unit
244  h_budgetUnit = findHist(("timing_statistics/processingTimePerUnitHistogram_HLT" + std::to_string(index)).c_str());
245  if (h_budgetUnit) bgunit = h_budgetUnit->GetMean();
246  else bgunit = 0.;
247  m_monObj->setVariable(("processing_time_HLT" + std::to_string(index)).c_str(), bgunit);
248  // add memory per unit
249  h_memoryUnit = findHist(("timing_statistics/fullMemoryPerUnitHistogram_HLT" + std::to_string(index)).c_str());
250  double memunit = 0.;
251  if (h_memoryUnit && bgunit > 0) memunit = h_memoryUnit->GetBinLowEdge(h_memoryUnit->FindLastBinAbove(0.) + 1);
252  m_monObj->setVariable(("memory_HLT" + std::to_string(index)).c_str(), memunit);
253  }
254 
255  B2DEBUG(20, "DQMHistAnalysisHLTMonObj : endRun called");
256 }
257 
259 {
260  B2DEBUG(20, "terminate called");
261 }
TCanvas * m_c_skim
Canvas with histograms related to HLT skims.
TCanvas * m_c_l1
Canvas with histograms related to L1.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
MonitoringObject * m_monObj
MonitoringObject to be produced by this module.
virtual void beginRun() override
Begin run function.
TCanvas * m_c_filter
Canvas with histograms related to HLT filter.
TCanvas * m_c_hardware
Canvas with histograms related to HLT hardware.
The base class for the histogram analysis module.
static TH1 * findHist(const std::string &histname)
Find histogram.
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
static constexpr unsigned int max_hlt_units
Maximum number of HLT units used during the experiment.
Abstract base class for different kinds of events.