Belle II Software development
DQMHistAnalysisECLOutOfTimeDigits.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//THIS MODULE
10#include <dqm/analysis/modules/DQMHistAnalysisECLOutOfTimeDigits.h>
11
12//ROOT
13#include <TF1.h>
14#include <TH1F.h>
15
16using namespace Belle2;
17
18REG_MODULE(DQMHistAnalysisECLOutOfTimeDigits);
19
22{
23 B2DEBUG(20, "DQMHistAnalysisECLOutOfTimeDigits: Constructor done.");
24 setDescription("Module to collect and process 'out of time' ECL digits");
25 addParam("pvPrefix", m_pvPrefix, "Prefix to use for PVs registered by this module",
26 std::string("ECL:out_of_time_digits:"));
27 addParam("onlyIfUpdated", m_onlyIfUpdated, "If true (default), update EPICS PVs only if there histograms were updated.",
28 true);
29}
30
31
33{
34 // Register EPICS PVs
35 for (auto& event_type : {"rand", "dphy", "physics"}) {
36 for (auto& ecl_part : {"All", "FWDEndcap", "Barrel", "BWDEndcap"}) {
37 std::string pv_name = event_type + std::string(":") + ecl_part;
38 registerEpicsPV(m_pvPrefix + pv_name, pv_name);
39 }
40 }
41
43
44 B2DEBUG(20, "DQMHistAnalysisECLOutOfTimeDigits: initialized.");
45}
46
48{
49 //== Get DQM info
50 for (auto& event_type : {"rand", "dphy", "physics"}) {
51 for (auto& ecl_part : {"All", "FWDEndcap", "Barrel", "BWDEndcap"}) {
52 std::string pv_name = event_type + std::string(":") + ecl_part;
53 std::string var_name = pv_name;
54 std::replace(var_name.begin(), var_name.end(), ':', '_');
55
56 m_out_of_time_digits[pv_name] = 0;
57
58 std::string hist_name = "ECL/out_of_time_" + var_name;
59 auto hist = (TH1F*)findHist(hist_name, m_onlyIfUpdated);
60
61 if (!hist) continue;
62
63 m_out_of_time_digits[pv_name] = hist->GetMean();
64
65 //== Set EPICS PVs
66
67 double selected_value = m_out_of_time_digits[pv_name];
68 setEpicsPV(pv_name, selected_value);
69 }
70 }
71}
72
74{
75 B2DEBUG(20, "DQMHistAnalysisECLOutOfTimeDigits: endRun called");
76
77 auto main_hist = (TH1F*)findHist("ECL/out_of_time_physics_All");
78
79 if (main_hist == nullptr) {
80 m_monObj->setVariable("comment_out_of_time_digits", "No ECL out-of-time ECLCalDigits histograms available");
81 B2INFO("Histogram named ECL/out_of_time_physics_All is not found.");
82 return;
83 }
84
85 TF1 gaus("fit_func", "gaus");
86
87 for (auto& event_type : {"rand", "dphy", "physics"}) {
88 for (auto& ecl_part : {"All", "FWDEndcap", "Barrel", "BWDEndcap"}) {
89 std::string pv_name = event_type + std::string(":") + ecl_part;
90 std::string hist_name = "ECL/out_of_time_" + pv_name;
91 std::string var_name = "out_of_time_digits_" + pv_name;
92
93 std::replace(hist_name.begin(), hist_name.end(), ':', '_');
94 std::replace(var_name.begin(), var_name.end(), ':', '_');
95
96 // If enough statistics, obtain more detailed information for MiraBelle
97 auto hist = (TH1F*)findHist(hist_name);
98 if (hist && hist->GetEntries() > 1000) {
99 // Fit the histogram to get the peak of a distribution
100 hist->Fit(&gaus);
101 m_monObj->setVariable(var_name, gaus.GetParameter(1));
102 m_monObj->setVariable(var_name + "_stddev", gaus.GetParameter(2));
103 } else {
104 // Use simple mean from the histogram
105 m_monObj->setVariable(var_name, m_out_of_time_digits[pv_name]);
106 m_monObj->setVariable(var_name + "_stddev", 0);
107 }
108 }
109 }
110}
111
112
void initialize() override final
Initialize the module.
std::map< std::string, double > m_out_of_time_digits
Out-of-time ECLCalDigits for several cases.
DQMHistAnalysisECLOutOfTimeDigitsModule()
< derived from DQMHistAnalysisModule class.
std::string m_pvPrefix
Prefix to use for PVs registered by this module.
bool m_onlyIfUpdated
If true (default), update EPICS PVs only if there were changes in the histograms.
The base class for the histogram analysis module.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
int registerEpicsPV(std::string pvname, std::string keyname="")
EPICS related Functions.
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setVariable(const std::string &var, float val, float upErr=-1., float dwErr=-1)
set value to float variable (new variable is made if not yet existing)
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.