Belle II Software  release-06-01-15
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 
12 // Belle 2 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 
50  // add canvases to MonitoringObject
55 
56 }
57 
59 {
60 }
61 
63 {
64  // can put the analysis code here or in endRun() function
65  // for the start tests we will store output only end of run so better to put code there
66 }
67 
69 {
70 
71  // get existing histograms produced by DQM modules
72  TH1* h_hlt = findHist("softwaretrigger/total_result");
73  TH1* h_skim = findHist("softwaretrigger/skim");
74  TH1* h_budget = findHist("timing_statistics/fullTimeHistogram");
75  TH1* h_processing = findHist("timing_statistics/processingTimeHistogram");
76  TH1* h_meantime = findHist("timing_statistics/meanTimeHistogram");
77  TH1* h_budg_unit = findHist("timing_statistics/fullTimeMeanPerUnitHistogram");
78  TH1* h_proc_unit = findHist("timing_statistics/processingTimeMeanPerUnitHistogram");
79  TH1* h_procs = findHist("timing_statistics/processesPerUnitHistogram");
80  TH1* h_l1 = findHist("softwaretrigger_before_filter/hlt_unit_number");
81  TH1* h_err_flag = findHist("softwaretrigger_before_filter/error_flag");
82  TH1* h_hlt_triggers = findHist("softwaretrigger/filter");
83  TH1* h_l1_triggers = findHist("TRGGDL/hGDL_psn_all");
84  TH1* h_l1_triggers_filt = findHist("softwaretrigger/l1_total_result");
85  TH1* h_l1_cat_w_overlap = findHist("TRGGDL/hGDL_psn_raw_rate_all");
86  TH1* h_l1_cat_wo_overlap = findHist("TRGGDL/hGDL_psn_effect_to_l1_all");
87  TH1* h_full_mem = findHist("timing_statistics/fullMemoryHistogram");
88 
89  // set the content of filter canvas
90  m_c_filter->Clear(); // clear existing content
91  m_c_filter->Divide(2, 2);
92  m_c_filter->cd(1);
93  if (h_hlt) h_hlt->Draw();
94  m_c_filter->cd(2);
95  if (h_hlt_triggers) h_hlt_triggers->Draw();
96  m_c_filter->cd(3);
97  if (h_err_flag) h_err_flag->Draw();
98 
99  // set the content of skim canvas
100  m_c_skim->Clear(); // clear existing content
101  m_c_skim->cd();
102  if (h_skim) h_skim->Draw();
103 
104  // set the content of hardware canvas
105  m_c_hardware->Clear(); // clear existing content
106  m_c_hardware->Divide(3, 3);
107  m_c_hardware->cd(1);
108  if (h_l1) h_l1->Draw();
109  m_c_hardware->cd(2);
110  if (h_budget) h_budget->Draw();
111  m_c_hardware->cd(3);
112  if (h_processing) h_processing->Draw();
113  m_c_hardware->cd(4);
114  if (h_budg_unit) h_budg_unit->Draw();
115  m_c_hardware->cd(5);
116  if (h_proc_unit) h_proc_unit->Draw();
117  m_c_hardware->cd(6);
118  if (h_meantime) h_meantime->Draw();
119  m_c_hardware->cd(7);
120  if (h_procs) h_procs->Draw();
121  m_c_hardware->cd(8);
122  if (h_full_mem) h_full_mem->Draw();
123 
124  // set the content of L1 canvas
125  m_c_l1->Clear(); // clear existing content
126  m_c_l1->Divide(2, 2);
127  m_c_l1->cd(1);
128  if (h_l1_triggers) h_l1_triggers->Draw();
129  m_c_l1->cd(2);
130  if (h_l1_triggers_filt) h_l1_triggers_filt->Draw();
131  m_c_l1->cd(3);
132  if (h_l1_cat_w_overlap) h_l1_cat_w_overlap->Draw();
133  m_c_l1->cd(4);
134  if (h_l1_cat_wo_overlap) h_l1_cat_wo_overlap->Draw();
135 
136  double n_hlt = 0.;
137  if (h_hlt) n_hlt = (double)h_hlt->GetBinContent((h_hlt->GetXaxis())->FindFixBin("total_result"));
138  m_monObj->setVariable("n_hlt", n_hlt);
139  double n_l1 = 0.;
140  if (h_l1) n_l1 = h_l1->GetEntries();
141  m_monObj->setVariable("n_l1", n_l1);
142  double n_procs = 0.;
143  if (h_procs) n_procs = h_procs->GetEntries();
144  m_monObj->setVariable("n_procs", n_procs);
145 
146  if (h_skim) {
147  // loop bins, add variable to monObj named as "effCS_" + bin label w/o "accept"
148  for (int ibin = 1; ibin < h_skim->GetXaxis()->GetNbins() + 1; ibin++) {
149  double nentr = (double)h_skim->GetBinContent(ibin);
150  std::string bin_name(h_skim->GetXaxis()->GetBinLabel(ibin));
151  m_monObj->setVariable(bin_name.replace(0, 6, "effCS"), nentr);
152  }
153  }
154 
155  if (h_l1_triggers) {
156  // loop bins, add variable to monObj named as "effCS_l1_" + bin label
157  for (int ibin = 1; ibin < h_l1_triggers->GetXaxis()->GetNbins() + 1; ibin++) {
158  double nentr = (double)h_l1_triggers->GetBinContent(ibin);
159  std::string bin_name(h_l1_triggers->GetXaxis()->GetBinLabel(ibin));
160  if (bin_name == "") continue;
161  m_monObj->setVariable(bin_name.insert(0, "effCS_l1_"), nentr);
162  }
163  }
164 
165  if (h_l1_triggers_filt) {
166  // loop bins, add variable to monObj named as "effCS_l1_fON_" + bin label
167  for (int ibin = 1; ibin < h_l1_triggers_filt->GetXaxis()->GetNbins() + 1; ibin++) {
168  double nentr = (double)h_l1_triggers_filt->GetBinContent(ibin);
169  std::string bin_name(h_l1_triggers_filt->GetXaxis()->GetBinLabel(ibin));
170  if (bin_name == "") continue;
171  m_monObj->setVariable(bin_name.insert(0, "effCS_l1_fON_"), nentr);
172  }
173  }
174 
175  if (h_hlt_triggers) {
176  // loop bins, add variable to monObj named as "effCS_hlt_" + bin label
177  for (int ibin = 1; ibin < h_hlt_triggers->GetXaxis()->GetNbins() + 1; ibin++) {
178  double nentr = (double)h_hlt_triggers->GetBinContent(ibin);
179  std::string bin_name(h_hlt_triggers->GetXaxis()->GetBinLabel(ibin));
180  bin_name = std::regex_replace(bin_name, std::regex("=="), "_eq_");
181  bin_name = std::regex_replace(bin_name, std::regex("\\."), "_");
182  m_monObj->setVariable(bin_name.insert(0, "effCS_hlt_"), nentr);
183  }
184  }
185 
186  if (h_meantime) {
187  // loop bins, add variable to monObj named as "secTime_" + bin label
188  for (int ibin = 1; ibin < h_meantime->GetXaxis()->GetNbins() + 1; ibin++) {
189  double nentr = (double)h_meantime->GetBinContent(ibin);
190  std::string bin_name(h_meantime->GetXaxis()->GetBinLabel(ibin));
191  m_monObj->setVariable(bin_name.insert(0, "secTime_"), nentr);
192  }
193  }
194 
195  if (h_err_flag) {
196  // loop bins, add variable to monObj named as "errFlag_" + bin label
197  for (int ibin = 1; ibin < h_err_flag->GetXaxis()->GetNbins() + 1; ibin++) {
198  double nentr = (double)h_err_flag->GetBinContent(ibin);
199  std::string bin_name(h_err_flag->GetXaxis()->GetBinLabel(ibin));
200  m_monObj->setVariable(bin_name.insert(0, "errFlag_"), nentr);
201  }
202  }
203 
204  if (h_l1_cat_w_overlap) {
205  // loop bins, add variable to monObj named as "l1_Ov_" + bin label
206  for (int ibin = 1; ibin < h_l1_cat_w_overlap->GetXaxis()->GetNbins() + 1; ibin++) {
207  double nentr = (double)h_l1_cat_w_overlap->GetBinContent(ibin);
208  std::string bin_name(h_l1_cat_w_overlap->GetXaxis()->GetBinLabel(ibin));
209  m_monObj->setVariable(bin_name.insert(0, "l1_Ov_"), nentr);
210  }
211  }
212 
213  if (h_l1_cat_wo_overlap) {
214  // loop bins, add variable to monObj named as "l1_noOv_" + bin label
215  for (int ibin = 1; ibin < h_l1_cat_wo_overlap->GetXaxis()->GetNbins() + 1; ibin++) {
216  double nentr = (double)h_l1_cat_wo_overlap->GetBinContent(ibin);
217  std::string bin_name(h_l1_cat_wo_overlap->GetXaxis()->GetBinLabel(ibin));
218  m_monObj->setVariable(bin_name.insert(0, "l1_noOv_"), nentr);
219  }
220  }
221 
222  double bgt = 0.;
223  if (h_budget) bgt = h_budget->GetMean();
224  m_monObj->setVariable("budget_time", bgt);
225 
226  m_monObj->setVariable("n_l1_x_budget_time", n_l1 * bgt);
227 
228  double procTime = 0.;
229  if (h_processing) procTime = h_processing->GetMean();
230  m_monObj->setVariable("processing_time", procTime);
231 
232  double fullMemory = 0.;
233  if (h_full_mem) fullMemory = h_full_mem->GetBinLowEdge(h_full_mem->FindLastBinAbove(0) + 1);
234  m_monObj->setVariable("full_memory", fullMemory);
235 
236  TH1* h_budgetUnit = nullptr;
237  TH1* h_memoryUnit = nullptr;
238 
239  for (unsigned int index = 1; index <= HLTUnits::max_hlt_units; index++) {
240  // add budget time per unit
241  h_budgetUnit = findHist(("timing_statistics/fullTimePerUnitHistogram_HLT" + std::to_string(index)).c_str());
242  double bgunit = 0.;
243  if (h_budgetUnit) bgunit = h_budgetUnit->GetMean();
244  m_monObj->setVariable(("budget_time_HLT" + std::to_string(index)).c_str(), bgunit);
245  // add processing time per unit
246  h_budgetUnit = findHist(("timing_statistics/processingTimePerUnitHistogram_HLT" + std::to_string(index)).c_str());
247  if (h_budgetUnit) bgunit = h_budgetUnit->GetMean();
248  else bgunit = 0.;
249  m_monObj->setVariable(("processing_time_HLT" + std::to_string(index)).c_str(), bgunit);
250  // add memory per unit
251  h_memoryUnit = findHist(("timing_statistics/fullMemoryPerUnitHistogram_HLT" + std::to_string(index)).c_str());
252  double memunit = 0.;
253  if (h_memoryUnit && bgunit > 0) memunit = h_memoryUnit->GetBinLowEdge(h_memoryUnit->FindLastBinAbove(0.) + 1);
254  m_monObj->setVariable(("memory_HLT" + std::to_string(index)).c_str(), memunit);
255  }
256 
257  B2DEBUG(20, "DQMHistAnalysisHLTMonObj : endRun called");
258 }
259 
261 {
262  B2DEBUG(20, "terminate called");
263 }
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
Abstract base class for different kinds of events.