Belle II Software  release-08-00-10
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 <framework/logging/Logger.h>
16 #include <mdst/dataobjects/TRGSummary.h>
17 
18 /* ROOT headers. */
19 #include <TDirectory.h>
20 #include <TH1F.h>
21 
22 /* C++ headers. */
23 #include <stdexcept>
24 
25 //NAMESPACE(S)
26 using namespace Belle2;
27 
28 REG_MODULE(ECLDQMOutOfTimeDigits);
29 
31  : HistoModule()
32 {
33  //Set module properties.
34  setDescription("ECL Data Quality monitoring module. See header file for the detailed description.");
35  setPropertyFlags(c_ParallelProcessingCertified); // specify parallel processing.
36 
37  addParam("histogramDirectoryName", m_histogramDirectoryName,
38  "histogram directory in ROOT file", std::string("ECL"));
39 }
40 
42 {
43 }
44 
45 
47 {
48  TDirectory* oldDir = gDirectory;
49 
50  // Create a separate histogram directory and cd into it.
51 
52  TDirectory* dirDAQ = dynamic_cast<TDirectory*>(oldDir->Get(m_histogramDirectoryName.c_str()));
53  if (!dirDAQ) dirDAQ = oldDir->mkdir(m_histogramDirectoryName.c_str());
54  dirDAQ->cd();
55 
56  // Create all necessary histograms for out-of-time ECLCalDigits counts
57  for (auto& event_type : {"rand", "dphy", "physics"}) {
58  for (auto& ecl_part : {"All", "FWDEndcap", "Barrel", "BWDEndcap"}) {
59  std::string key_name = event_type + std::string("_") + ecl_part;
60  TString hist_name = "out_of_time_" + key_name;
61  // Max possible value in the histogram is 8736 (=total number of crystals
62  // in ECL), however the overflow over 2000 is not relevant for the
63  // distribution shape.
64  h_out_of_time[key_name] = new TH1F(hist_name, "", 250, 0, 2000);
65 
66  // Set titles
67  h_out_of_time[key_name]->GetXaxis()->SetTitle("Out-of-time ECLCalDigits");
68  TString title = "Out-of-time ECLCalDigits";
69  title += " (";
70  title += ecl_part;
71  title += " of ECL, ";
72  title += event_type;
73  title += " events)";
74  h_out_of_time[key_name]->SetTitle(title);
75  }
76  }
77 
78  //cd into parent directory.
79  oldDir->cd();
80 }
81 
83 {
84  REG_HISTOGRAM; // required to register histograms to HistoManager.
85 }
86 
88 {
89  std::for_each(h_out_of_time.begin(), h_out_of_time.end(), [](auto & it) {it.second->Reset();});
90 }
91 
93 {
94  // If TRGSummary is not available, we assume that all events are physics events
95  if (!m_l1Trigger.isValid()) return "physics";
96 
97  if (isRandomTrigger()) return "rand";
98 
99  bool bhatrig = false;
100  try { bhatrig = m_l1Trigger->testInput("bha_delay"); }
101  catch (const std::exception&) { bhatrig = false; }
102 
103  if (bhatrig) return "dphy";
104 
105  return "physics";
106 }
107 
109 {
110  std::string event_type = getEventType();
111 
112  for (auto& ecl_part : {"All", "FWDEndcap", "Barrel", "BWDEndcap"}) {
113  std::string key_name = event_type + std::string("_") + ecl_part;
114  std::string var_name = "nECLOutOfTimeCrystals";
115  if (std::string(ecl_part) != "All") var_name += ecl_part;
116  auto var = Variable::Manager::Instance().getVariable(var_name);
117  if (!var) continue;
118  double value = std::get<double>(var->function(nullptr));
119  h_out_of_time[key_name]->Fill(value);
120  }
121 }
122 
124 {
125 }
126 
127 
129 {
130 }
131 
133 {
134  if (!m_l1Trigger.isValid()) return false;
135  return m_l1Trigger->getTimType() == TRGSummary::ETimingType::TTYP_RAND ||
136  m_l1Trigger->getTimType() == TRGSummary::ETimingType::TTYP_POIS;
137 }
138 
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
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
REG_MODULE(arichBtest)
Register the Module.
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
Abstract base class for different kinds of events.