Belle II Software development
eclDQMOutOfTimeDigits.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 <ecl/modules/eclDQMOutOfTimeDigits/eclDQMOutOfTimeDigits.h>
11
12/* Basf2 headers. */
13#include <analysis/VariableManager/Manager.h>
14#include <framework/core/HistoModule.h>
15#include <mdst/dataobjects/TRGSummary.h>
16
17/* ROOT headers. */
18#include <TDirectory.h>
19#include <TH1F.h>
20
21/* C++ headers. */
22#include <stdexcept>
23
24//NAMESPACE(S)
25using namespace Belle2;
26
27REG_MODULE(ECLDQMOutOfTimeDigits);
28
30 : HistoModule()
31{
32 //Set module properties.
33 setDescription("ECL Data Quality monitoring module. See header file for the detailed description.");
34 setPropertyFlags(c_ParallelProcessingCertified); // specify parallel processing.
35
36 addParam("histogramDirectoryName", m_histogramDirectoryName,
37 "histogram directory in ROOT file", std::string("ECL"));
38}
39
41{
42}
43
44
46{
47 TDirectory* oldDir = gDirectory;
48
49 // Create a separate histogram directory and cd into it.
50
51 TDirectory* dirDAQ = dynamic_cast<TDirectory*>(oldDir->Get(m_histogramDirectoryName.c_str()));
52 if (!dirDAQ) dirDAQ = oldDir->mkdir(m_histogramDirectoryName.c_str());
53 dirDAQ->cd();
54
55 // Create all necessary histograms for out-of-time ECLCalDigits counts
56 for (auto& event_type : {"rand", "dphy", "physics"}) {
57 for (auto& ecl_part : {"All", "FWDEndcap", "Barrel", "BWDEndcap"}) {
58 std::string key_name = event_type + std::string("_") + ecl_part;
59 TString hist_name = "out_of_time_" + key_name;
60 // Max possible value in the histogram is 8736 (=total number of crystals
61 // in ECL), however the overflow over 2000 is not relevant for the
62 // distribution shape.
63 h_out_of_time[key_name] = new TH1F(hist_name, "", 250, 0, 2000);
64
65 // Set titles
66 h_out_of_time[key_name]->GetXaxis()->SetTitle("Out-of-time ECLCalDigits");
67 TString title = "Out-of-time ECLCalDigits";
68 title += " (";
69 title += ecl_part;
70 title += " of ECL, ";
71 title += event_type;
72 title += " events)";
73 h_out_of_time[key_name]->SetTitle(title);
74 }
75 }
76
77 //cd into parent directory.
78 oldDir->cd();
79}
80
82{
83 REG_HISTOGRAM; // required to register histograms to HistoManager.
84}
85
87{
88 std::for_each(h_out_of_time.begin(), h_out_of_time.end(), [](auto & it) {it.second->Reset();});
89}
90
92{
93 // If TRGSummary is not available, we assume that all events are physics events
94 if (!m_l1Trigger.isValid()) return "physics";
95
96 if (isRandomTrigger()) return "rand";
97
98 bool bhatrig = false;
99 try { bhatrig = m_l1Trigger->testInput("bha_delay"); }
100 catch (const std::exception&) { bhatrig = false; }
101
102 if (bhatrig) return "dphy";
103
104 return "physics";
105}
106
108{
109 std::string event_type = getEventType();
110
111 for (auto& ecl_part : {"All", "FWDEndcap", "Barrel", "BWDEndcap"}) {
112 std::string key_name = event_type + std::string("_") + ecl_part;
113 std::string var_name = "nECLOutOfTimeCrystals";
114 if (std::string(ecl_part) != "All") var_name += ecl_part;
115 auto var = Variable::Manager::Instance().getVariable(var_name);
116 if (!var) continue;
117 double value = std::get<double>(var->function(nullptr));
118 h_out_of_time[key_name]->Fill(value);
119 }
120}
121
123{
124}
125
126
128{
129}
130
132{
133 if (!m_l1Trigger.isValid()) return false;
134 return m_l1Trigger->getTimType() == TRGSummary::ETimingType::TTYP_RAND ||
136}
137
virtual void initialize() override
Initialize the module.
StoreObjPtr< TRGSummary > m_l1Trigger
StoreObjPtr TRGSummary
virtual void event() override
Event processor.
virtual void endRun() override
Call when a run ends.
ECLDQMOutOfTimeDigitsModule()
< derived from HistoModule class.
virtual void terminate() override
Terminate.
virtual void beginRun() override
Call when a run begins.
std::string m_histogramDirectoryName
Histogram directory in ROOT file.
std::string getEventType()
Return type of the current event.
std::map< std::string, TH1F * > h_out_of_time
Single-value histograms to hold the average value for out-of-time ECLCalDigits.
virtual void defineHisto() override
Function to define histograms.
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
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
@ TTYP_POIS
poisson random trigger
Definition: TRGSummary.h:73
@ TTYP_RAND
random trigger events
Definition: TRGSummary.h:67
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
Definition: Manager.cc:57
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:25
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#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.