8 #include <dqm/analysis/modules/DQMHistAnalysisHLTModule.h>
9 #include <framework/core/ModuleParam.templateDetails.h>
12 #include <hlt/softwaretrigger/modules/dqm/SoftwareTriggerHLTDQMModule.h>
18 bool hasValue(
const std::string& name, TH1* histogram)
20 return histogram->GetXaxis()->FindFixBin(name.c_str()) != -1;
23 double getValue(
const std::string& name, TH1* histogram)
25 if (not hasValue(name, histogram)) {
26 B2ERROR(
"This histogram does not have this value! (fallback value = -1)"
27 <<
LogVar(
"histogram", histogram->GetName())
31 auto binNumber = histogram->GetXaxis()->FindFixBin(name.c_str());
32 return histogram->GetBinContent(binNumber);
38 DQMHistAnalysisHLTModule::DQMHistAnalysisHLTModule()
40 addParam(
"pvPrefix", m_pvPrefix,
"EPICS PV Name for the inst. luminosity", m_pvPrefix);
41 addParam(
"bhabhaName", m_bhabhaName,
"Name of the bhabha trigger to do a ratio against", m_bhabhaName);
42 addParam(
"columnMapping", m_columnMapping,
"Which columns to use for calculating ratios and cross sections", m_columnMapping);
43 addParam(
"l1Histograms", m_l1Histograms,
"Which l1 histograms to show", m_l1Histograms);
44 addParam(
"retentionPerUnit", m_retentionPerUnit,
"Which HLT filter lines to use for calculation retention rate per unit",
48 void DQMHistAnalysisHLTModule::initialize()
54 new TCanvas(
"HLT/Ratio"),
55 new TH1F(
"Ratio",
"Retention of selected HLT skims", 1, 0, 0)
57 m_hEfficiencyTotal = {
58 new TCanvas(
"HLT/RatioTotal"),
59 new TH1F(
"RatioTotal",
"Ratio of Tags to all events", 1, 0, 0)
62 new TCanvas(
"HLT/CrossSection"),
63 new TH1F(
"CrossSection",
"Cross Section of triggered Events", 1, 0, 0)
66 new TCanvas(
"HLT/RatioToBahbha"),
67 new TH1F(
"RatioToBahbha",
"Ratio to bhabha events", 1, 0, 0)
70 for (
const std::string& l1Name : m_l1Histograms) {
71 m_hl1Ratios.emplace(l1Name, std::make_pair(
72 new TCanvas((
"HLT/" + l1Name +
"RatioToL1").c_str()),
74 new TH1F((l1Name +
"RatioToL1").c_str(), (
"HLT Fractions for L1 " + l1Name).c_str(), 1, 0, 0)
78 for (
const std::string& filterLine : m_retentionPerUnit) {
79 m_hRetentionPerUnit.emplace(filterLine, std::make_pair(
80 new TCanvas((
"HLT/" + filterLine +
"_RetentionPerUnit").c_str()),
81 new TH1F((filterLine +
"_RetentionPerUnit").c_str(), (
"Retention rate per unit of: " + filterLine).c_str(),
82 SoftwareTrigger::HLTUnit::max_hlt_units + 1, 0,
83 SoftwareTrigger::HLTUnit::max_hlt_units + 1)
87 for (
auto& canvasAndHisto : {m_hEfficiencyTotal, m_hEfficiency, m_hCrossSection, m_hRatios}) {
88 auto* histogram = canvasAndHisto.second;
89 histogram->SetDirectory(0);
90 histogram->SetOption(
"bar");
91 histogram->SetFillStyle(0);
92 histogram->SetMinimum(0);
93 histogram->SetStats(
false);
94 histogram->Draw(
"hist");
97 for (
auto& nameAndcanvasAndHisto : m_hl1Ratios) {
98 auto* histogram = nameAndcanvasAndHisto.second.second;
99 histogram->SetDirectory(0);
100 histogram->SetOption(
"bar");
101 histogram->SetFillStyle(0);
102 histogram->SetStats(
false);
103 histogram->Draw(
"hist");
106 for (
auto& nameAndcanvasAndHisto : m_hRetentionPerUnit) {
107 auto* histogram = nameAndcanvasAndHisto.second.second;
108 histogram->SetDirectory(0);
109 histogram->SetOption(
"histe");
110 histogram->SetMinimum(0);
111 histogram->SetStats(
false);
116 new TCanvas(
"HLT/MeanTime"),
117 new TH1F(
"MeanTime",
"Mean processing time", 1, 0, 0)
120 m_hErrorFlagFraction = {
121 new TCanvas(
"HLT/ErrorFlagFraction"),
122 new TH1D(
"ErrorFlagFraction",
"Fraction of events with Error Flags", 1, 0, 0)
125 m_hFilteredFractionPerUnit = {
126 new TCanvas(
"HLT/FilteredFractionPerUnit"),
127 new TH1D(
"FilteredFractionPerUnit",
"Fraction of events filtered per unit", 1, 0, 0)
130 m_hMeanBudgetTimePerUnit = {
131 new TCanvas(
"HLT/MeanBudgetTimePerUnit"),
132 new TH1F(
"MeanBudgetTimePerUnit",
"Mean budget time per unit", 1, 0, 0)
135 m_hMeanProcessingTimePerUnit = {
136 new TCanvas(
"HLT/MeanProcessingTimePerUnit"),
137 new TH1F(
"MeanProcessingTimePerUnit",
"Mean processing time per unit", 1, 0, 0)
141 new TCanvas(
"HLT/MeanMemoryChange"),
142 new TH1F(
"MeanMemoryChange",
"Mean memory change [MB]", 1, 0, 0)
146 if (not m_pvPrefix.empty()) {
147 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
148 SEVCHK(ca_create_channel(m_pvPrefix.data(), NULL, NULL, 10, &m_epicschid),
"ca_create_channel failure");
149 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
155 void DQMHistAnalysisHLTModule::beginRun()
157 for (
auto& canvasAndHisto : {m_hEfficiencyTotal, m_hEfficiency, m_hCrossSection, m_hRatios, m_hMeanTime, m_hMeanBudgetTimePerUnit, m_hMeanProcessingTimePerUnit, m_hMeanMemory}) {
158 auto* canvas = canvasAndHisto.first;
162 for (
auto& canvasAndHisto : {m_hErrorFlagFraction, m_hFilteredFractionPerUnit}) {
163 auto* canvas = canvasAndHisto.first;
167 for (
auto& nameAndcanvasAndHisto : m_hl1Ratios) {
168 auto* canvas = nameAndcanvasAndHisto.second.first;
172 for (
auto& nameAndcanvasAndHisto : m_hRetentionPerUnit) {
173 auto* canvas = nameAndcanvasAndHisto.second.first;
178 void DQMHistAnalysisHLTModule::event()
180 auto* filterHistogram = findHist(
"softwaretrigger/filter");
181 auto* skimHistogram = findHist(
"softwaretrigger/skim");
182 auto* totalResultHistogram = findHist(
"softwaretrigger/total_result");
183 auto* hltUnitNumberHistogram = findHist(
"softwaretrigger_before_filter/hlt_unit_number");
184 auto* processesPerUnitHistogram = findHist(
"timing_statistics/processesPerUnitHistogram");
185 auto* meanTimeHistogram = findHist(
"timing_statistics/meanTimeHistogram");
186 auto* errorFlagHistogram = findHist(
"softwaretrigger_before_filter/error_flag");
187 auto* hltUnitNumberHistogram_filtered = findHist(
"softwaretrigger/hlt_unit_number_after_filter");
188 auto* fullTimeMeanPerUnitHistogram = findHist(
"timing_statistics/fullTimeMeanPerUnitHistogram");
189 auto* processingTimeMeanPerUnitHistogram = findHist(
"timing_statistics/processingTimeMeanPerUnitHistogram");
190 auto* meanMemoryHistogram = findHist(
"timing_statistics/meanMemoryHistogram");
192 if (not filterHistogram) {
193 B2ERROR(
"Can not find the filter histogram!");
196 if (not skimHistogram) {
197 B2ERROR(
"Can not find the skim histogram!");
200 if (not totalResultHistogram) {
201 B2ERROR(
"Can not find the total result histogram!");
204 if (not hltUnitNumberHistogram) {
205 B2ERROR(
"Can not find the HLT unit number histogram!");
208 if (not processesPerUnitHistogram) {
209 B2ERROR(
"Can not find the processes per unit histogram!");
212 if (not meanTimeHistogram) {
213 B2ERROR(
"Can not find the mean processing time histogram!");
216 if (not errorFlagHistogram) {
217 B2ERROR(
"Can not find the error flag histogram!");
220 if (not hltUnitNumberHistogram_filtered) {
221 B2ERROR(
"Can not find the HLT unit number after filter histogram!");
224 if (not fullTimeMeanPerUnitHistogram) {
225 B2ERROR(
"Can not find the HLT budget time per unit histogram!");
228 if (not processingTimeMeanPerUnitHistogram) {
229 B2ERROR(
"Can not find the HLT processing time per unit histogram!");
232 if (not meanMemoryHistogram) {
233 B2ERROR(
"Can not find the mean memory change histogram!");
237 m_hEfficiencyTotal.second->Reset();
238 m_hEfficiency.second->Reset();
239 m_hCrossSection.second->Reset();
240 m_hRatios.second->Reset();
242 double instLuminosity = 0;
243 double numberOfAcceptedHLTEvents = getValue(
"total_result", totalResultHistogram);
244 double numberOfBhabhaEvents = getValue(m_bhabhaName, skimHistogram);
245 double numberOfAllEvents = hltUnitNumberHistogram->GetEntries();
246 double numberOfProcesses = processesPerUnitHistogram->GetEntries();
249 if (not m_pvPrefix.empty()) {
250 SEVCHK(ca_get(DBR_DOUBLE, m_epicschid, (
void*)&instLuminosity),
"ca_get failure");
251 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
257 m_hEfficiencyTotal.second->Fill(
"total_result", numberOfAcceptedHLTEvents / numberOfAllEvents);
258 if (instLuminosity != 0) {
259 m_hCrossSection.second->Fill(
"total_result", numberOfAcceptedHLTEvents / numberOfAllEvents * instLuminosity);
261 m_hRatios.second->Fill(
"total_result", numberOfAcceptedHLTEvents / numberOfBhabhaEvents);
263 for (
const auto& columnMapping : m_columnMapping) {
264 const auto& from = columnMapping.first;
265 const auto& to = columnMapping.second;
268 if (hasValue(from, filterHistogram)) {
269 value = getValue(from, filterHistogram);
270 }
else if (hasValue(from, skimHistogram)) {
271 value = getValue(from, skimHistogram);
273 B2ERROR(
"Can not find value " << from <<
". Will not use it!");
277 m_hEfficiency.second->Fill(to.c_str(), value / numberOfAcceptedHLTEvents);
278 m_hEfficiencyTotal.second->Fill(to.c_str(), value / numberOfAllEvents);
279 if (instLuminosity != 0) {
280 m_hCrossSection.second->Fill(to.c_str(), value / numberOfAllEvents * instLuminosity);
282 m_hRatios.second->Fill(to.c_str(), value / numberOfBhabhaEvents);
285 for (
const std::string& l1Name : m_l1Histograms) {
286 auto* histogram = m_hl1Ratios.at(l1Name).second;
289 auto* l1Histogram = findHist(
"softwaretrigger/" + l1Name);
290 auto* l1TotalResultHistogram = findHist(
"softwaretrigger/l1_total_result");
292 if (not l1Histogram or not l1TotalResultHistogram) {
293 B2ERROR(
"Can not find L1 histograms from softwaretrigger!");
297 for (
const auto& columnMapping : m_columnMapping) {
298 const auto& from = columnMapping.first;
299 const auto& to = columnMapping.second;
301 if (not hasValue(from, l1Histogram)) {
302 B2ERROR(
"Can not find label " << from <<
" in l1 histogram " << l1Name);
306 if (not hasValue(l1Name, l1TotalResultHistogram)) {
307 B2ERROR(
"Can not find label " << l1Name <<
" in l1 total result histogram");
311 const double hltValueInL1Bin = getValue(from, l1Histogram);
312 const double l1TotalResult = getValue(l1Name, l1TotalResultHistogram);
314 histogram->Fill(to.c_str(), hltValueInL1Bin / l1TotalResult);
318 const auto from =
"hlt_result";
319 const auto to =
"hlt_result";
321 if (not hasValue(from, l1Histogram)) {
322 B2ERROR(
"Can not find label " << from <<
" in l1 histogram " << l1Name);
326 if (not hasValue(l1Name, l1TotalResultHistogram)) {
327 B2ERROR(
"Can not find label " << l1Name <<
" in l1 total result histogram");
331 const double hltValueInL1Bin = getValue(from, l1Histogram);
332 const double l1TotalResult = getValue(l1Name, l1TotalResultHistogram);
334 histogram->Fill(to, hltValueInL1Bin / l1TotalResult);
337 for (
const std::string& filterLine : m_retentionPerUnit) {
338 auto* histogram = m_hRetentionPerUnit.at(filterLine).second;
341 auto* filterLineHistogram = findHist(
"softwaretrigger/" + filterLine +
"_per_unit");
343 if (not filterLineHistogram) {
344 B2ERROR(
"Can not find " << filterLineHistogram <<
"_per_event histograms from softwaretrigger!");
348 for (
unsigned int i = 1; i <= SoftwareTrigger::HLTUnit::max_hlt_units + 1; i++) {
349 double totalUnitValue = hltUnitNumberHistogram->GetBinContent(i);
350 if (totalUnitValue == 0) {
351 histogram->Fill(i, 0);
353 double filterLineUnitValue = filterLineHistogram->GetBinContent(i);
354 histogram->SetBinContent(i, filterLineUnitValue / totalUnitValue);
359 m_hMeanTime.second = (TH1F*) meanTimeHistogram->Clone(
"MeanTime");
360 m_hMeanTime.second->Scale(1 / numberOfProcesses);
362 m_hMeanMemory.second = (TH1F*) meanMemoryHistogram->Clone(
"MeanMemoryChange");
363 m_hMeanMemory.second->Scale(1 / numberOfProcesses);
365 m_hErrorFlagFraction.second = (TH1D*) errorFlagHistogram->Clone(
"ErrorFlagFraction");
366 m_hErrorFlagFraction.second->Scale(1 / numberOfAllEvents);
367 m_hErrorFlagFraction.second->SetTitle(
"Fraction of events with error flags");
369 m_hFilteredFractionPerUnit.second = (TH1D*) hltUnitNumberHistogram_filtered->Clone(
"FilteredFractionPerUnit");
370 m_hFilteredFractionPerUnit.second->Divide(hltUnitNumberHistogram_filtered, hltUnitNumberHistogram);
371 m_hFilteredFractionPerUnit.second->SetTitle(
"Fraction of events filtered per unit");
373 m_hMeanBudgetTimePerUnit.second = (TH1F*) fullTimeMeanPerUnitHistogram->Clone(
"MeanBudgetTimePerUnit");
374 m_hMeanBudgetTimePerUnit.second->Divide(fullTimeMeanPerUnitHistogram, processesPerUnitHistogram);
376 m_hMeanProcessingTimePerUnit.second = (TH1F*) processingTimeMeanPerUnitHistogram->Clone(
"MeanProcessingTimePerUnit");
377 m_hMeanProcessingTimePerUnit.second->Divide(processingTimeMeanPerUnitHistogram, processesPerUnitHistogram);
379 for (
auto& canvasAndHisto : {m_hEfficiencyTotal, m_hEfficiency, m_hCrossSection, m_hRatios, m_hMeanTime, m_hMeanBudgetTimePerUnit, m_hMeanProcessingTimePerUnit, m_hMeanMemory}) {
380 auto* canvas = canvasAndHisto.first;
381 auto* histogram = canvasAndHisto.second;
384 histogram->LabelsDeflate(
"X");
385 histogram->Draw(
"hist");
390 for (
auto& canvasAndHisto : {m_hErrorFlagFraction, m_hFilteredFractionPerUnit}) {
391 auto* canvas = canvasAndHisto.first;
392 auto* histogram = canvasAndHisto.second;
395 histogram->LabelsDeflate(
"X");
396 histogram->Draw(
"hist");
397 histogram->SetStats(
false);
402 for (
auto& nameAndCanvasAndHisto : m_hl1Ratios) {
403 auto* canvas = nameAndCanvasAndHisto.second.first;
404 auto* histogram = nameAndCanvasAndHisto.second.second;
407 histogram->LabelsDeflate(
"X");
408 histogram->Draw(
"hist");
413 for (
auto& nameAndCanvasAndHisto : m_hRetentionPerUnit) {
414 auto* canvas = nameAndCanvasAndHisto.second.first;
415 auto* histogram = nameAndCanvasAndHisto.second.second;
418 histogram->Draw(
"hist");
424 void DQMHistAnalysisHLTModule::terminate()
427 if (not m_pvPrefix.empty()) {
428 SEVCHK(ca_clear_channel(m_epicschid),
"ca_clear_channel failure");
429 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
Class to store variables with their name which were sent to the logging service.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.