Belle II Software development
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// Roofit headers
16#include <RooAddPdf.h>
17#include <RooArgList.h>
18#include <RooArgSet.h>
19#include <RooChebychev.h>
20#include <RooDataHist.h>
21#include <RooFit.h>
22#include <RooFitResult.h>
23#include <RooGaussian.h>
24#include <RooMsgService.h>
25#include <RooRealVar.h>
26
27// C++ headers
28#include <regex>
29
30using namespace std;
31using namespace Belle2;
32
33//-----------------------------------------------------------------
34// Register module
35//-----------------------------------------------------------------
36
37REG_MODULE(DQMHistAnalysisHLTMonObj);
38
41{
42 setDescription("Produces MonitoringObject for the HLT from the available DQM histograms");
44}
45
49
51{
52 // make monitoring object related to this module
53 // if monitoring object already exists this will return pointer to it
55
56 // make canvases to be added to MonitoringObject
57 m_c_filter = new TCanvas("Filter", "filter", 750, 400);
58 m_c_skim = new TCanvas("Skim", "skim", 400, 400);
59 m_c_hardware = new TCanvas("Hardware", "hardware", 1000, 1000);
60 m_c_l1 = new TCanvas("L1", "l1", 750, 400);
61 m_c_ana_eff_shifter = new TCanvas("ana_eff_shifter", "ana_eff_shifter", 1000, 1000);
62
63 // add canvases to MonitoringObject
64 m_monObj->addCanvas(m_c_filter);
65 m_monObj->addCanvas(m_c_skim);
66 m_monObj->addCanvas(m_c_hardware);
67 m_monObj->addCanvas(m_c_l1);
68 m_monObj->addCanvas(m_c_ana_eff_shifter);
69
70
71 //--- HLTPrefilter monitoring ---//
72 //--- Fit variables ---//
73 m_KsInvMass = new RooRealVar("m_KsInvMass", "M", 0.45, 0.55);
74
75 //--- Signal double gaussian ---//
76 m_mean1 = new RooRealVar("#mu_{1}", "MEAN of 1st gaussian", 0.498, 0.49, 0.51);
77 m_sigma1 = new RooRealVar("#sigma_{1}", "Sigma of 1st gaussian", 0.002, 0.0001, 0.05);
78 m_gauss1 = new RooGaussian("gauss1", "1st gaussian PDF", *m_KsInvMass, *m_mean1, *m_sigma1);
79
80 m_sigma2 = new RooRealVar("#sigma_{2}", "Sigma of 1st gaussian", 0.02, 0.0001, 0.05);
81 m_gauss2 = new RooGaussian("gauss2", "2nd gaussian PDF", *m_KsInvMass, *m_mean1, *m_sigma2);
82
83 m_frac = new RooRealVar("frac", "fraction", 0.6, 0.4, 0.8);
84 m_double_gauss = new RooAddPdf("double_gauss", "add two gaussian", RooArgList(*m_gauss1, *m_gauss2), RooArgSet(*m_frac));
85
86 //--- Chebychev background first order ---//
87 m_slope = new RooRealVar("s", "Slope of Polynomial", 0.5, -2.0, 2.0);
88 m_chebpol = new RooChebychev("chebpol", "Chebshev Polynomial ", *m_KsInvMass, RooArgList(*m_slope));
89
90 //--- Signal and Background yields ---//
91 m_sig = new RooRealVar("N_{sig}", "SIGNAL EVENTS", 1000, 10, 5000000);
92 m_bkg = new RooRealVar("N_{bkg}", "SIGNAL EVENTS", 2000, 100, 20000000);
93
94 //--- Total fit pdf ---//
95 m_KsPdf = new RooAddPdf("m_KsPdf", "Two Gaussian + Pol1 background", RooArgList(*m_double_gauss, *m_chebpol), RooArgList(*m_sig,
96 *m_bkg));
97
98}
99
100
102{
103
104 // get existing histograms produced by DQM modules
105 TH1* h_hlt = findHist("softwaretrigger/total_result");
106 TH1* h_skim = findHist("softwaretrigger/skim");
107 TH1* h_budget = findHist("timing_statistics/fullTimeHistogram");
108 TH1* h_processing = findHist("timing_statistics/processingTimeHistogram");
109 TH1* h_proc_passive = findHist("timing_statistics/processingTimePassiveVeto");
110 TH1* h_proc_active = findHist("timing_statistics/processingTimeNotPassiveVeto");
111 TH1* h_proc_prefilter_time = findHist("timing_statistics/processingTimeNotPassiveVetoTimingCut");
112 TH1* h_proc_prefilter_cdcecl = findHist("timing_statistics/processingTimeNotPassiveVetoCDCECLCut");
113 TH1* h_meantime = findHist("timing_statistics/meanTimeHistogram");
114 TH1* h_budg_unit = findHist("timing_statistics/fullTimeMeanPerUnitHistogram");
115 TH1* h_proc_unit = findHist("timing_statistics/processingTimeMeanPerUnitHistogram");
116 TH1* h_procs = findHist("timing_statistics/processesPerUnitHistogram");
117 TH1* h_l1 = findHist("softwaretrigger_before_filter/hlt_unit_number");
118 TH1* h_err_flag = findHist("softwaretrigger_before_filter/error_flag");
119 TH1* h_hlt_triggers = findHist("softwaretrigger/filter");
120 TH1* h_l1_triggers = findHist("TRGGDL/hGDL_psn_all");
121 TH1* h_l1_triggers_filt = findHist("softwaretrigger/l1_total_result");
122 TH1* h_l1_cat_w_overlap = findHist("TRGGDL/hGDL_psn_raw_rate_all");
123 TH1* h_l1_cat_wo_overlap = findHist("TRGGDL/hGDL_psn_effect_to_l1_all");
124 TH1* h_full_mem = findHist("timing_statistics/fullMemoryHistogram");
125 TCanvas* c_GDL_ana_eff_shifter = findCanvas("TRGGDL/hGDL_ana_eff_shifter");
126 TH1* h_GDL_ana_eff_shifter = nullptr;
127
128 if (c_GDL_ana_eff_shifter) {
129 c_GDL_ana_eff_shifter->cd();
130 h_GDL_ana_eff_shifter = dynamic_cast<TH1*>(gPad->GetPrimitive("hGDL_ana_eff_shifter"));
131 }
132
133 // set the content of filter canvas
134 m_c_filter->Clear(); // clear existing content
135 m_c_filter->Divide(2, 2);
136 m_c_filter->cd(1);
137 if (h_hlt) h_hlt->Draw();
138 m_c_filter->cd(2);
139 if (h_hlt_triggers) h_hlt_triggers->Draw();
140 m_c_filter->cd(3);
141 if (h_err_flag) h_err_flag->Draw();
142
143 // set the content of skim canvas
144 m_c_skim->Clear(); // clear existing content
145 m_c_skim->cd();
146 if (h_skim) h_skim->Draw();
147
148 // set the content of hardware canvas
149 m_c_hardware->Clear(); // clear existing content
150 m_c_hardware->Divide(3, 3);
151 m_c_hardware->cd(1);
152 if (h_l1) h_l1->Draw();
153 m_c_hardware->cd(2);
154 if (h_budget) h_budget->Draw();
155 m_c_hardware->cd(3);
156 if (h_processing) h_processing->Draw();
157 m_c_hardware->cd(4);
158 if (h_budg_unit) h_budg_unit->Draw();
159 m_c_hardware->cd(5);
160 if (h_proc_unit) h_proc_unit->Draw();
161 m_c_hardware->cd(6);
162 if (h_meantime) h_meantime->Draw();
163 m_c_hardware->cd(7);
164 if (h_procs) h_procs->Draw();
165 m_c_hardware->cd(8);
166 if (h_full_mem) h_full_mem->Draw();
167
168 // set the content of L1 canvas
169 m_c_l1->Clear(); // clear existing content
170 m_c_l1->Divide(2, 2);
171 m_c_l1->cd(1);
172 if (h_l1_triggers) h_l1_triggers->Draw();
173 m_c_l1->cd(2);
174 if (h_l1_triggers_filt) h_l1_triggers_filt->Draw();
175 m_c_l1->cd(3);
176 if (h_l1_cat_w_overlap) h_l1_cat_w_overlap->Draw();
177 m_c_l1->cd(4);
178 if (h_l1_cat_wo_overlap) h_l1_cat_wo_overlap->Draw();
179
180// set the content of ana_eff_shifter canvas
181 m_c_ana_eff_shifter->Clear();
183 if (h_GDL_ana_eff_shifter) h_GDL_ana_eff_shifter->Draw();
184
185 double n_hlt = 0.;
186 if (h_hlt) n_hlt = (double)h_hlt->GetBinContent((h_hlt->GetXaxis())->FindFixBin("total_result"));
187 m_monObj->setVariable("n_hlt", n_hlt);
188 double n_l1 = 0.;
189 if (h_l1) n_l1 = h_l1->GetEntries();
190 m_monObj->setVariable("n_l1", n_l1);
191 double n_procs = 0.;
192 if (h_procs) n_procs = h_procs->GetEntries();
193 m_monObj->setVariable("n_procs", n_procs);
194
195 if (h_skim) {
196 // loop bins, add variable to monObj named as "effCS_" + bin label w/o "accept"
197 for (int ibin = 1; ibin < h_skim->GetXaxis()->GetNbins() + 1; ibin++) {
198 double nentr = (double)h_skim->GetBinContent(ibin);
199 std::string bin_name(h_skim->GetXaxis()->GetBinLabel(ibin));
200 m_monObj->setVariable(bin_name.replace(0, 6, "effCS"), nentr);
201 }
202 }
203
204 if (h_l1_triggers) {
205 // loop bins, add variable to monObj named as "effCS_l1_" + bin label
206 for (int ibin = 1; ibin < h_l1_triggers->GetXaxis()->GetNbins() + 1; ibin++) {
207 double nentr = (double)h_l1_triggers->GetBinContent(ibin);
208 std::string bin_name(h_l1_triggers->GetXaxis()->GetBinLabel(ibin));
209 if (bin_name == "") continue;
210 m_monObj->setVariable(bin_name.insert(0, "effCS_l1_"), nentr);
211 }
212 }
213
214 if (h_l1_triggers_filt) {
215 // loop bins, add variable to monObj named as "effCS_l1_fON_" + bin label
216 for (int ibin = 1; ibin < h_l1_triggers_filt->GetXaxis()->GetNbins() + 1; ibin++) {
217 double nentr = (double)h_l1_triggers_filt->GetBinContent(ibin);
218 std::string bin_name(h_l1_triggers_filt->GetXaxis()->GetBinLabel(ibin));
219 if (bin_name == "") continue;
220 m_monObj->setVariable(bin_name.insert(0, "effCS_l1_fON_"), nentr);
221 }
222 }
223
224 if (h_hlt_triggers) {
225 // loop bins, add variable to monObj named as "effCS_hlt_" + bin label
226 for (int ibin = 1; ibin < h_hlt_triggers->GetXaxis()->GetNbins() + 1; ibin++) {
227 double nentr = (double)h_hlt_triggers->GetBinContent(ibin);
228 std::string bin_name(h_hlt_triggers->GetXaxis()->GetBinLabel(ibin));
229 bin_name = std::regex_replace(bin_name, std::regex("=="), "_eq_");
230 bin_name = std::regex_replace(bin_name, std::regex("\\."), "_");
231 m_monObj->setVariable(bin_name.insert(0, "effCS_hlt_"), nentr);
232 }
233 }
234
235 if (h_meantime) {
236 // loop bins, add variable to monObj named as "secTime_" + bin label
237 for (int ibin = 1; ibin < h_meantime->GetXaxis()->GetNbins() + 1; ibin++) {
238 double nentr = (double)h_meantime->GetBinContent(ibin);
239 std::string bin_name(h_meantime->GetXaxis()->GetBinLabel(ibin));
240 m_monObj->setVariable(bin_name.insert(0, "secTime_"), nentr);
241 }
242 }
243
244 if (h_err_flag) {
245 // loop bins, add variable to monObj named as "errFlag_" + bin label
246 for (int ibin = 1; ibin < h_err_flag->GetXaxis()->GetNbins() + 1; ibin++) {
247 double nentr = (double)h_err_flag->GetBinContent(ibin);
248 std::string bin_name(h_err_flag->GetXaxis()->GetBinLabel(ibin));
249 m_monObj->setVariable(bin_name.insert(0, "errFlag_"), nentr);
250 }
251 }
252
253 if (h_l1_cat_w_overlap) {
254 // loop bins, add variable to monObj named as "l1_Ov_" + bin label
255 for (int ibin = 1; ibin < h_l1_cat_w_overlap->GetXaxis()->GetNbins() + 1; ibin++) {
256 double nentr = (double)h_l1_cat_w_overlap->GetBinContent(ibin);
257 std::string bin_name(h_l1_cat_w_overlap->GetXaxis()->GetBinLabel(ibin));
258 m_monObj->setVariable(bin_name.insert(0, "l1_Ov_"), nentr);
259 }
260 }
261
262 if (h_l1_cat_wo_overlap) {
263 // loop bins, add variable to monObj named as "l1_noOv_" + bin label
264 for (int ibin = 1; ibin < h_l1_cat_wo_overlap->GetXaxis()->GetNbins() + 1; ibin++) {
265 double nentr = (double)h_l1_cat_wo_overlap->GetBinContent(ibin);
266 std::string bin_name(h_l1_cat_wo_overlap->GetXaxis()->GetBinLabel(ibin));
267 m_monObj->setVariable(bin_name.insert(0, "l1_noOv_"), nentr);
268 }
269 }
270
271 if (h_GDL_ana_eff_shifter) {
272 // loop bins, add variable to monObj named as "GDLanaEffShifter_" + bin label
273 for (int ibin = 1; ibin < h_GDL_ana_eff_shifter->GetXaxis()->GetNbins() + 1; ibin++) {
274 double nentr = (double)h_GDL_ana_eff_shifter->GetBinContent(ibin);
275 std::string bin_name(h_GDL_ana_eff_shifter->GetXaxis()->GetBinLabel(ibin));
276 m_monObj->setVariable(bin_name.insert(0, "GDLanaEffShifter_"), nentr);
277 }
278 }
279
280 double bgt = 0.;
281 if (h_budget) bgt = h_budget->GetMean();
282 m_monObj->setVariable("budget_time", bgt);
283
284 m_monObj->setVariable("n_l1_x_budget_time", n_l1 * bgt);
285
286 double procTime = 0.;
287 if (h_processing) procTime = h_processing->GetMean();
288 m_monObj->setVariable("processing_time", procTime);
289
290 double procTimePassive = 0.;
291 if (h_proc_passive) procTimePassive = h_proc_passive->GetMean();
292 m_monObj->setVariable("processing_time_passive", procTimePassive);
293
294 double procTimeActive = 0.;
295 if (h_proc_active) procTimeActive = h_proc_active->GetMean();
296 m_monObj->setVariable("processing_time_active", procTimeActive);
297
298 double procTimePrefilterTiming = 0.;
299 if (h_proc_prefilter_time) procTimePrefilterTiming = h_proc_prefilter_time->GetMean();
300 m_monObj->setVariable("processing_time_prefilter_time", procTimePrefilterTiming);
301
302 double procTimePrefilterCDCECL = 0.;
303 if (h_proc_prefilter_cdcecl) procTimePrefilterCDCECL = h_proc_prefilter_cdcecl->GetMean();
304 m_monObj->setVariable("processing_time_prefilter_CDCECL", procTimePrefilterCDCECL);
305
306
307 double fullMemory = 0.;
308 if (h_full_mem) fullMemory = h_full_mem->GetBinLowEdge(h_full_mem->FindLastBinAbove(0) + 1);
309 m_monObj->setVariable("full_memory", fullMemory);
310
311 TH1* h_budgetUnit = nullptr;
312 TH1* h_memoryUnit = nullptr;
313
314 for (unsigned int index = 1; index <= HLTUnits::max_hlt_units; index++) {
315 // add budget time per unit
316 h_budgetUnit = findHist(("timing_statistics/fullTimePerUnitHistogram_HLT" + std::to_string(index)).c_str());
317 double bgunit = 0.;
318 if (h_budgetUnit) bgunit = h_budgetUnit->GetMean();
319 m_monObj->setVariable(("budget_time_HLT" + std::to_string(index)).c_str(), bgunit);
320 // add processing time per unit
321 h_budgetUnit = findHist(("timing_statistics/processingTimePerUnitHistogram_HLT" + std::to_string(index)).c_str());
322 if (h_budgetUnit) bgunit = h_budgetUnit->GetMean();
323 else bgunit = 0.;
324 m_monObj->setVariable(("processing_time_HLT" + std::to_string(index)).c_str(), bgunit);
325 // add memory per unit
326 h_memoryUnit = findHist(("timing_statistics/fullMemoryPerUnitHistogram_HLT" + std::to_string(index)).c_str());
327 double memunit = 0.;
328 if (h_memoryUnit && bgunit > 0) memunit = h_memoryUnit->GetBinLowEdge(h_memoryUnit->FindLastBinAbove(0.) + 1);
329 m_monObj->setVariable(("memory_HLT" + std::to_string(index)).c_str(), memunit);
330 }
331
332 //--- HLTprefilter monitoring ---//
333
334 // Silence uneccesary warnings //
335 RooMsgService::instance().setSilentMode(true);
336 RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING);
337
338 double nKs_all = 0;
339 double nKs_active = 0;
340 double nKs_activeNotTime = 0;
341 double nKs_activeNotCDCECL = 0;
342
343 auto m_hKshortAllH = findHist("PhysicsObjects/hist_nKshortAllH");
344 auto m_hKshortActiveH = findHist("PhysicsObjects/hist_nKshortActiveH");
345 auto m_hKshortActiveNotTimeH = findHist("PhysicsObjects/hist_nKshortActiveNotTimeH");
346 auto m_hKshortActiveNotCDCECLH = findHist("PhysicsObjects/hist_nKshortActiveNotCDCECLH");
347
348 if (m_hKshortAllH) {
349 RooDataHist* KsHist_all = new RooDataHist("KsHist_all", "Histogram data", RooArgList(*m_KsInvMass), m_hKshortAllH);
350 m_KsPdf->fitTo(*KsHist_all, RooFit::Minos(true));
351 nKs_all = m_sig->getValV();
352 delete KsHist_all;
353 }
354 m_monObj->setVariable("nKs_all_hlt", nKs_all);
355
356 if (m_hKshortActiveH) {
357 RooDataHist* KsHist_active = new RooDataHist("KsHist_active", "Histogram data", RooArgList(*m_KsInvMass), m_hKshortActiveH);
358 m_KsPdf->fitTo(*KsHist_active, RooFit::Minos(true));
359 nKs_active = m_sig->getValV();
360 delete KsHist_active;
361 }
362 m_monObj->setVariable("nKs_activeVeto_hlt", nKs_active);
363
364 if (m_hKshortActiveNotTimeH) {
365 RooDataHist* KsHist_activeNotTime = new RooDataHist("KsHist_activeNotTime", "Histogram data", RooArgList(*m_KsInvMass),
366 m_hKshortActiveNotTimeH);
367 m_KsPdf->fitTo(*KsHist_activeNotTime, RooFit::Minos(true));
368 nKs_activeNotTime = m_sig->getValV();
369 delete KsHist_activeNotTime;
370 }
371 m_monObj->setVariable("nKs_activeVetoPrefilterTime_hlt", nKs_activeNotTime);
372
373 if (m_hKshortActiveNotCDCECLH) {
374 RooDataHist* KsHist_activeNotCDCECL = new RooDataHist("KsHist_activeNotCDCECL", "Histogram data", RooArgList(*m_KsInvMass),
375 m_hKshortActiveNotCDCECLH);
376 m_KsPdf->fitTo(*KsHist_activeNotCDCECL, RooFit::Minos(true));
377 nKs_activeNotCDCECL = m_sig->getValV();
378 delete KsHist_activeNotCDCECL;
379 }
380
381 m_monObj->setVariable("nKs_activeVetoPrefilterCDCECL_hlt", nKs_activeNotCDCECL);
382
383
384 B2DEBUG(20, "DQMHistAnalysisHLTMonObj : endRun called");
385}
386
388{
389 delete m_KsInvMass;
390 delete m_mean1;
391 delete m_sigma1;
392 delete m_gauss1;
393 delete m_mean2;
394 delete m_sigma2;
395 delete m_gauss2;
396 delete m_double_gauss;
397 delete m_slope;
398 delete m_chebpol;
399 delete m_sig;
400 delete m_bkg;
401 delete m_KsPdf;
402
403 B2DEBUG(20, "terminate called");
404}
RooRealVar * m_bkg
Number of background from fit.
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.
RooRealVar * m_frac
*Fraction of first gaussian in double gaussian
RooRealVar * m_mean2
Mean of first gaussian.
void initialize() override final
Initialize the Module.
RooRealVar * m_sigma1
*Sigma of second gaussian
RooRealVar * m_KsInvMass
Invariant mass of KS for HLTPrefilter monitoring.
TCanvas * m_c_l1
Canvas with histograms related to L1.
RooChebychev * m_chebpol
First order polynomial.
RooRealVar * m_sig
Number of Ks events from fit.
RooRealVar * m_mean1
*Mean of first gaussian
MonitoringObject * m_monObj
MonitoringObject to be produced by this module.
void terminate() override final
Termination action.
RooRealVar * m_slope
Slope for first order polynomial.
TCanvas * m_c_filter
Canvas with histograms related to HLT filter.
void endRun() override final
End-of-run action.
RooAddPdf * m_KsPdf
Fit PDF for Ks invariant mass.
RooRealVar * m_sigma2
*Sigma of second gaussian
RooAddPdf * m_double_gauss
Sum of two gaussian.
TCanvas * m_c_hardware
Canvas with histograms related to HLT hardware.
TCanvas * findCanvas(TString cname)
Find canvas by name.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
DQMHistAnalysisModule()
Constructor / Destructor.
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
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
STL namespace.