8#include <hlt/softwaretrigger/modules/dqm/SoftwareTriggerHLTDQMModule.h>
10#include <TDirectory.h>
12#include <hlt/softwaretrigger/core/SoftwareTriggerDBHandler.h>
13#include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
14#include <hlt/utilities/Units.h>
16#include <framework/core/ModuleParam.templateDetails.h>
23using namespace SoftwareTrigger;
38 "Which cuts should be reported? Please remember to include the total_result also, if wanted.",
42 "Which cuts should be ignored? This will display cleaner trigger lines, e.g. to clear them from bhabha contamination. "
43 "Vetoes on skims do not apply in filter plot and vice versa.",
47 "Which cuts should be reported per unit?",
51 "Which variables should be reported?",
55 "Which l1 identifiers to report?",
59 "Which additional l1 identifiers to be added to the l1 total result plot?",
63 "Create total result histogram?",
67 "Create exp/run/event histograms?",
71 "Create HLT unit histograms?",
75 "Create Error Flag histograms?",
87 TDirectory* oldDirectory =
nullptr;
90 oldDirectory = gDirectory;
97 const unsigned int numberOfBins = 50;
98 const double lowerX = 0;
99 const double upperX = 50;
105 m_l1Histograms.emplace(trigger,
new TH1F(trigger.c_str(), (
"Events triggered in L1 " + trigger).c_str(), 150, 0, 150));
113 const std::string& title = cutIdentifier.first;
115 const std::string& baseIdentifier = mapVal.first;
116 const auto& cuts = mapVal.second;
118 if (title == baseIdentifier) {
119 for (
const std::string& cutTitle : cuts) {
121 m_l1Histograms[trigger]->GetXaxis()->SetBinLabel(index, cutTitle.c_str());
126 m_l1Histograms[trigger]->GetXaxis()->SetBinLabel(index,
"hlt_result");
132 const std::string& title = cutIdentifier.first;
134 const std::string& baseIdentifier = mapVal.first;
135 const auto& cuts = mapVal.second;
136 const int numberOfFlags = cuts.size();
139 if (title == baseIdentifier)
141 new TH1F((title +
"_nobhabha").c_str(), (
"Events triggered in HLT " + baseIdentifier).c_str(),
146 new TH1F((baseIdentifier +
"_" + title +
"_nobhabha").c_str(),
147 (
"Events triggered in HLT " + baseIdentifier +
" : " + title).c_str(),
151 if (title == baseIdentifier)
153 new TH1F(title.c_str(), (
"Events triggered in HLT " + baseIdentifier).c_str(),
158 new TH1F((baseIdentifier +
"_" + title).c_str(), (
"Events triggered in HLT " + baseIdentifier +
" : " + title).c_str(),
169 for (
const std::string& cutTitle : cuts) {
178 new TH1F(
"total_result",
"Total Result of HLT (absolute numbers)", 1, 0, 0));
185 new TH1F(
"l1_total_result",
"Events triggered in L1 (total results)", 1, 0, 0));
186 m_l1Histograms[
"l1_total_result"]->SetXTitle(
"Total L1 Cut Result");
192 m_l1Histograms[
"l1_total_result"]->SetBins(numberOfL1Flags, 0, numberOfL1Flags);
197 m_l1Histograms[
"l1_total_result"]->GetXaxis()->SetBinLabel(l1Index, l1Trigger.c_str());
201 m_l1Histograms[
"l1_total_result"]->GetXaxis()->SetBinLabel(l1Index, l1Trigger.c_str());
206 m_runInfoHistograms.emplace(
"run_number",
new TH1D(
"run_number",
"Run Number", 100, 0, 10000));
207 m_runInfoHistograms.emplace(
"event_number",
new TH1D(
"event_number",
"Event Number", 100, 0, 1'000'000));
208 m_runInfoHistograms.emplace(
"experiment_number",
new TH1D(
"experiment_number",
"Experiment Number", 50, 0, 50));
214 (
"Number of events per HLT unit " +
m_param_pathLocation).c_str(), HLTUnits::max_hlt_units + 1, 0,
215 HLTUnits::max_hlt_units + 1));
218 (
"Number of events per HLT unit " +
m_param_pathLocation).c_str(), HLTUnits::max_hlt_units + 1, 0,
219 HLTUnits::max_hlt_units + 1));
225 (
"Events triggered per unit in HLT : " + cutIdentifierPerUnit).c_str(), HLTUnits::max_hlt_units + 1, 0,
226 HLTUnits::max_hlt_units + 1));
253 FILE* pipe = popen(
"hostname -d",
"r");
256 std::string host =
"";
258 while (fgets(buffer,
sizeof(buffer), pipe) !=
nullptr) {
264 if (host.length() == 5) {
267 B2WARNING(
"HLT unit number not found");
270 B2WARNING(
"HLT unit number not found");
281 const std::string& variable = variableNameAndTH1F.first;
282 TH1F* histogram = variableNameAndTH1F.second;
286 B2ERROR(
"Variable " << variable <<
" configured for SoftwareTriggerDQM plotting is not available");
288 const double value =
m_variables->getVariable(variable);
289 histogram->Fill(value);
298 const std::string& title = cutIdentifier.first;
300 const std::string& baseIdentifier = mapVal.first;
301 const auto& cuts = mapVal.second;
307 for (
const std::string& cutTitleIgnored : cutsIgnored) {
308 const std::string& cutNameIgnored = cutTitleIgnored.substr(0, cutTitleIgnored.find(
"\\"));
311 auto const cutEntryIgnored = results.find(fullCutIdentifierIgnored);
313 if (cutEntryIgnored != results.end()) {
314 if (cutEntryIgnored->second > 0) skip =
true;
319 for (
const std::string& cutTitle : cuts) {
321 const std::string& cutName = cutTitle.substr(0, cutTitle.find(
"\\"));
327 auto const cutEntry = results.find(fullCutIdentifier);
329 if (cutEntry != results.end()) {
330 const int cutResult = cutEntry->second;
331 if (cutResult > 0 and not skip) {
338 if (title == baseIdentifier) {
340 const int cutResult =
static_cast<int>(
m_triggerResult->getResult(totalCutIdentifier));
354 const std::string& cutName = cutIdentifierPerUnit.substr(0, cutIdentifierPerUnit.find(
"\\"));
358 auto const cutEntry = results.find(fullCutIdentifier);
360 if (cutEntry != results.end()) {
361 const int cutResult = cutEntry->second;
376 }
catch (
const std::exception&) {
379 }
catch (
const std::exception&) {
380 triggerResult =
false;
389 if (not triggerResult) {
395 const std::string& title = cutIdentifier.first;
397 const std::string& baseIdentifier = mapVal.first;
398 const auto& cuts = mapVal.second;
400 if (title == baseIdentifier) {
401 for (
const std::string& cutTitle : cuts) {
403 const std::string& cutName = cutTitle.substr(0, cutTitle.find(
"\\"));
407 auto const cutEntry = results.find(fullCutIdentifier);
409 if (cutEntry != results.end()) {
410 const int cutResult = cutEntry->second;
421 if (totalResult > 0) {
431 }
catch (
const std::exception&) {
434 }
catch (
const std::exception&) {
435 triggerResult =
false;
471 [](
auto & it) { it.second->Reset(); });
473 [](
auto & it) { it.second->Reset(); });
475 [](
auto & it) { it.second->Reset(); });
477 [](
auto & it) { it.second->Reset(); });
479 [](
auto & it) { it.second->Reset(); });
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
static bool getFinalTriggerDecision(const SoftwareTriggerResult &result, bool forgetTotalResult=false)
Calculate the final cut decision using all "total_results" of all sub triggers in the software trigge...
static std::string makeFullCutName(const std::string &baseCutIdentifier, const std::string &cutIdentifier)
Helper function to compile the full identifier from the base and the specific cut name.
static std::string makeTotalResultName(const std::string &baseIdentifier="all")
Handy function to create the name related to the total result of a specific trigger stage (either fil...
std::map< std::string, TH1D * > m_runInfoHistograms
histograms with the run information
std::map< std::string, std::map< std::string, std::vector< std::string > > > m_param_cutResultIdentifiers
Which cuts should be reported? Please remember to include the total_result also, if wanted.
std::map< std::string, TH1F * > m_l1Histograms
histogram with the L1 information
int m_hlt_unit
HLT unit number of the machine used.
void initialize() override
Module functions to be called from main process.
void event() override
Module functions to be called from event process.
StoreObjPtr< SoftwareTriggerResult > m_triggerResult
STM cut results.
SoftwareTriggerHLTDQMModule()
Constructor / Destructor.
std::vector< std::string > m_param_l1Identifiers
Which L1 cuts should be reported?
std::map< std::string, TH1F * > m_cutResultPerUnitHistograms
histograms for the final sw trigger decisions for each base identifier per unit
std::map< std::string, TH1F * > m_triggerVariablesHistograms
histograms for the software trigger variables in all calculators (although maybe not filled)
std::map< std::string, std::vector< std::string > > m_param_cutResultIdentifiersIgnored
Which cuts should be ignored? This can be used to clear trigger lines from e.g. bhabha contamination.
StoreObjPtr< EventMetaData > m_eventMetaData
Event Info.
std::string m_param_pathLocation
Location of the module in the path: before filter or after filter.
void beginRun() override
Reset all histogram entries for a new run.
std::map< std::string, TH1F * > m_cutResultHistograms
histograms for the final sw trigger decisions for each base identifier
bool m_param_create_error_flag_histograms
Create error flag histograms?
std::vector< std::string > m_param_additionalL1Identifiers
Which additional L1 cuts should be added to the L1 total result plot?
bool m_param_create_hlt_unit_histograms
Create HLT unit number histograms?
StoreObjPtr< TRGSummary > m_l1TriggerResult
L1 cut results.
std::vector< std::string > m_param_cutResultIdentifiersPerUnit
Which cuts should be reported per unit?
bool m_param_create_total_result_histograms
Create total result histogram?
std::vector< std::string > m_param_variableIdentifiers
Which variables should be reported?
bool m_param_create_exp_run_event_histograms
Create exp/run/event number histograms?
std::string m_param_histogramDirectoryName
Directory to put the generated histograms.
StoreObjPtr< SoftwareTriggerVariables > m_variables
STM cut variables.
void defineHisto() override
Histogram definition.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.