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>
15 #include <framework/core/ModuleParam.templateDetails.h>
22 using namespace SoftwareTrigger;
28 setDescription(
"Monitor Physics Trigger");
29 setPropertyFlags(c_ParallelProcessingCertified);
32 m_param_variableIdentifiers = {};
34 m_param_cutResultIdentifiers[
"filter"][
"filter"] = {
"total_result"};
36 addParam(
"cutResultIdentifiers", m_param_cutResultIdentifiers,
37 "Which cuts should be reported? Please remember to include the total_result also, if wanted.",
38 m_param_cutResultIdentifiers);
40 addParam(
"cutResultIdentifiersIgnored", m_param_cutResultIdentifiersIgnored,
41 "Which cuts should be ignored? This will display cleaner trigger lines, e.g. to clear them from bhabha contamination. "
42 "Vetoes on skims do not apply in filter plot and vice versa.",
43 m_param_cutResultIdentifiersIgnored);
45 addParam(
"cutResultIdentifiersPerUnit", m_param_cutResultIdentifiersPerUnit,
46 "Which cuts should be reported per unit?",
47 m_param_cutResultIdentifiersPerUnit);
49 addParam(
"variableIdentifiers", m_param_variableIdentifiers,
50 "Which variables should be reported?",
51 m_param_variableIdentifiers);
53 addParam(
"l1Identifiers", m_param_l1Identifiers,
54 "Which l1 identifiers to report?",
55 m_param_l1Identifiers);
57 addParam(
"additionalL1Identifiers", m_param_additionalL1Identifiers,
58 "Which additional l1 identifiers to be added to the l1 total result plot?",
59 m_param_additionalL1Identifiers);
61 addParam(
"createTotalResultHistograms", m_param_create_total_result_histograms,
62 "Create total result histogram?",
65 addParam(
"createExpRunEventHistograms", m_param_create_exp_run_event_histograms,
66 "Create exp/run/event histograms?",
69 addParam(
"createHLTUnitHistograms", m_param_create_hlt_unit_histograms,
70 "Create HLT unit histograms?",
73 addParam(
"createErrorFlagHistograms", m_param_create_error_flag_histograms,
74 "Create Error Flag histograms?",
77 addParam(
"histogramDirectoryName", m_param_histogramDirectoryName,
78 "SoftwareTrigger DQM histograms will be put into this directory", m_param_histogramDirectoryName);
80 addParam(
"pathLocation", m_param_pathLocation,
81 "Location of the module in the path: before filter or after filter", m_param_pathLocation);
86 TDirectory* oldDirectory =
nullptr;
89 oldDirectory = gDirectory;
96 const unsigned int numberOfBins = 50;
97 const double lowerX = 0;
98 const double upperX = 50;
105 const std::string& title = cutIdentifier.first;
107 const std::string& baseIdentifier = mapVal.first;
108 const auto& cuts = mapVal.second;
109 const int numberOfFlags = cuts.size();
112 if (title == baseIdentifier)
114 new TH1F((title +
"_nobhabha").c_str(), (
"Events triggered in HLT " + baseIdentifier).c_str(),
119 new TH1F((baseIdentifier +
"_" + title +
"_nobhabha").c_str(),
120 (
"Events triggered in HLT " + baseIdentifier +
" : " + title).c_str(),
124 if (title == baseIdentifier)
126 new TH1F(title.c_str(), (
"Events triggered in HLT " + baseIdentifier).c_str(),
131 new TH1F((baseIdentifier +
"_" + title).c_str(), (
"Events triggered in HLT " + baseIdentifier +
" : " + title).c_str(),
142 for (
const std::string& cutTitle : cuts) {
151 new TH1F(
"total_result",
"Total Result of HLT (absolute numbers)", 1, 0, 0));
159 m_l1Histograms.emplace(trigger,
new TH1F(trigger.c_str(), (
"Events triggered in L1 " + trigger).c_str(), 1, 0, 0));
169 new TH1F(
"l1_total_result",
"Events triggered in L1 (total results)", 1, 0, 0));
170 m_l1Histograms[
"l1_total_result"]->SetXTitle(
"Total L1 Cut Result");
176 m_l1Histograms[
"l1_total_result"]->SetBins(numberOfL1Flags, 0, numberOfL1Flags);
181 m_l1Histograms[
"l1_total_result"]->GetXaxis()->SetBinLabel(l1Index, l1Trigger.c_str());
185 m_l1Histograms[
"l1_total_result"]->GetXaxis()->SetBinLabel(l1Index, l1Trigger.c_str());
190 m_runInfoHistograms.emplace(
"run_number",
new TH1D(
"run_number",
"Run Number", 100, 0, 10000));
191 m_runInfoHistograms.emplace(
"event_number",
new TH1D(
"event_number",
"Event Number", 100, 0, 1'000'000));
192 m_runInfoHistograms.emplace(
"experiment_number",
new TH1D(
"experiment_number",
"Experiment Number", 50, 0, 50));
244 B2WARNING(
"HLT unit number not found");
255 const std::string& variable = variableNameAndTH1F.first;
256 TH1F* histogram = variableNameAndTH1F.second;
260 B2ERROR(
"Variable " << variable <<
" configured for SoftwareTriggerDQM plotting is not available");
262 const double value =
m_variables->getVariable(variable);
263 histogram->Fill(value);
272 const std::string& title = cutIdentifier.first;
274 const std::string& baseIdentifier = mapVal.first;
275 const auto& cuts = mapVal.second;
281 for (
const std::string& cutTitleIgnored : cutsIgnored) {
282 const std::string& cutNameIgnored = cutTitleIgnored.substr(0, cutTitleIgnored.find(
"\\"));
285 auto const cutEntryIgnored = results.find(fullCutIdentifierIgnored);
287 if (cutEntryIgnored != results.end()) {
288 if (cutEntryIgnored->second > 0) skip =
true;
293 for (
const std::string& cutTitle : cuts) {
295 const std::string& cutName = cutTitle.substr(0, cutTitle.find(
"\\"));
301 auto const cutEntry = results.find(fullCutIdentifier);
303 if (cutEntry != results.end()) {
304 const int cutResult = cutEntry->second;
305 if (cutResult > 0 and not skip) {
312 if (title == baseIdentifier) {
314 const int cutResult =
static_cast<int>(
m_triggerResult->getResult(totalCutIdentifier));
328 const std::string& cutName = cutIdentifierPerUnit.substr(0, cutIdentifierPerUnit.find(
"\\"));
332 auto const cutEntry = results.find(fullCutIdentifier);
334 if (cutEntry != results.end()) {
335 const int cutResult = cutEntry->second;
347 const int triggerBit =
m_l1NameLookup->getoutbitnum(l1Trigger.c_str());
348 if (triggerBit < 0) {
349 B2WARNING(
"Could not find"
350 <<
LogVar(
"L1 trigger line", l1Trigger));
356 }
catch (
const std::exception&) {
357 triggerResult =
false;
365 if (not triggerResult) {
370 const std::string& title = cutIdentifier.first;
372 const std::string& baseIdentifier = mapVal.first;
373 const auto& cuts = mapVal.second;
375 if (title == baseIdentifier) {
376 for (
const std::string& cutTitle : cuts) {
377 const std::string& cutName = cutTitle.substr(0, cutTitle.find(
"\\"));
381 auto const cutEntry = results.find(fullCutIdentifier);
383 if (cutEntry != results.end()) {
384 const int cutResult = cutEntry->second;
398 const int triggerBit =
m_l1NameLookup->getoutbitnum(l1Trigger.c_str());
399 if (triggerBit < 0) {
400 B2WARNING(
"Could not find"
401 <<
LogVar(
"L1 trigger line", l1Trigger));
407 }
catch (
const std::exception&) {
408 triggerResult =
false;
426 (
bool)(
m_eventMetaData->getErrorFlag() & EventMetaData::EventErrorFlag::c_B2LinkPacketCRCError));
428 (
bool)(
m_eventMetaData->getErrorFlag() & EventMetaData::EventErrorFlag::c_B2LinkEventCRCError));
430 (
bool)(
m_eventMetaData->getErrorFlag() & EventMetaData::EventErrorFlag::c_HLTCrash));
432 (
bool)(
m_eventMetaData->getErrorFlag() & EventMetaData::EventErrorFlag::c_ReconstructionAbort));
443 [](
auto & it) { it.second->Reset(); });
445 [](
auto & it) { it.second->Reset(); });
447 [](
auto & it) { it.second->Reset(); });
449 [](
auto & it) { it.second->Reset(); });
451 [](
auto & it) { it.second->Reset(); });
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
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...
Module defining the STM histograms.
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.
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.
DBObjPtr< TRGGDLDBFTDLBits > m_l1NameLookup
Dataobjects.
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.
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.
static constexpr char hlt_unit_file[]
Location of HLT unit number information.
static constexpr unsigned int max_hlt_units
Maximum number of HLT units used during the experiment.
Abstract base class for different kinds of events.