Belle II Software development
DQMHistAnalysisECLShapers.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/DQMHistAnalysisECLShapers.h>
11
12//ROOT
13#include <TProfile.h>
14
15//boost
16#include "boost/format.hpp"
17
18//std
19#include <numeric>
20
21using namespace Belle2;
22
23REG_MODULE(DQMHistAnalysisECLShapers);
24
27{
28 B2DEBUG(20, "DQMHistAnalysisECLShapers: Constructor done.");
29 setDescription("Processes information involving ECL pedestals (widths and rms).");
30
31 addParam("pvPrefix", m_pvPrefix, "Prefix to use for PVs registered by this module",
32 std::string("ECL:"));
33}
34
36{
37 for (int i = 0; i < c_collector_count; i++) {
38 std::string pv_name = (boost::format("logic_check:crate%02d") %
39 (i + 1)).str();
40 registerEpicsPV(m_pvPrefix + pv_name, pv_name);
41 }
42 for (auto part_id : {"fw", "br", "bw", "al"}) {
43 std::string pv_name = "pedwidth:max_";
44 pv_name += part_id;
45 registerEpicsPV(m_pvPrefix + pv_name, pv_name);
46
47 pv_name = "pedwidth:avg_";
48 pv_name += part_id;
49 registerEpicsPV(m_pvPrefix + pv_name, pv_name);
50 }
51
53
54 m_c_main = new TCanvas("ecl_main");
55 m_monObj->addCanvas(m_c_main);
56
57 B2DEBUG(20, "DQMHistAnalysisECLShapers: initialized.");
58}
59
61{
62 B2DEBUG(20, "DQMHistAnalysisECLShapers: beginRun called.");
63}
64
66{
67 TH1* h_fail_crateid = findHist("ECL/fail_crateid");
68 TProfile* h_pedrms_cellid = (TProfile*)findHist("ECL/pedrms_cellid");
69
70 if (h_pedrms_cellid != NULL) {
71 double pedwidth_sum = 0;
72 // Using multiset to automatically sort the added values.
73 // (so we can easily calculate the max value)
74 std::multiset<double> barrel_pedwidth;
75 std::multiset<double> bwd_pedwidth;
76 std::multiset<double> fwd_pedwidth;
77
78 for (int i = 0; i < ECLElementNumbers::c_NCrystals; i++) {
79 const int cellid = i + 1;
80 if (h_pedrms_cellid->GetBinEntries(cellid) < 100) continue;
81 double pedrms = h_pedrms_cellid->GetBinContent(cellid);
82 pedwidth_sum += pedrms;
83 if (cellid < 1153) {
84 fwd_pedwidth.insert(pedrms);
85 } else if (cellid < 7777) {
86 barrel_pedwidth.insert(pedrms);
87 } else {
88 bwd_pedwidth.insert(pedrms);
89 }
90 }
91
92 // Use approximate conversion factor
93 // to convert from ADC units to MeV.
94 const double adc_to_mev = 0.05;
95
96 m_pedwidth_max[0] = robust_max(fwd_pedwidth) * adc_to_mev;
97 m_pedwidth_max[1] = robust_max(barrel_pedwidth) * adc_to_mev;
98 m_pedwidth_max[2] = robust_max(bwd_pedwidth) * adc_to_mev;
99 m_pedwidth_max[3] = *std::max_element(&m_pedwidth_max[0], &m_pedwidth_max[2]);
100
101 // Sum of a given multiset
102 auto sum = [](std::multiset<double> x) { return std::accumulate(x.begin(), x.end(), 0.0); };
103
104 m_pedwidth_avg[0] = sum(fwd_pedwidth) / fwd_pedwidth.size() * adc_to_mev;
105 m_pedwidth_avg[1] = sum(barrel_pedwidth) / barrel_pedwidth.size() * adc_to_mev;
106 m_pedwidth_avg[2] = sum(bwd_pedwidth) / bwd_pedwidth.size() * adc_to_mev;
107 m_pedwidth_avg[3] = pedwidth_sum / ECLElementNumbers::c_NCrystals * adc_to_mev;
108 } else {
109 for (int i = 0; i < 4; i++) {
110 m_pedwidth_max[i] = 0;
111 m_pedwidth_avg[i] = 0;
112 }
113 }
114
115 //== Set EPICS PVs
116
117 if (h_fail_crateid != NULL) {
118 // Set fit consistency check PVs
119 for (int i = 0; i < c_collector_count; i++) {
120 std::string pv_name = (boost::format("logic_check:crate%02d") %
121 (i + 1)).str();
122 int errors_count = h_fail_crateid->GetBinContent(i + 1);
123 setEpicsPV(pv_name, errors_count);
124 }
125 // Set pedestal width PVs
126 static const char* part_id[] = {"fw", "br", "bw", "al"};
127 for (int i = 0; i < 4; i++) {
128 if (m_pedwidth_max[i] <= 0) continue;
129 std::string pv_name = "pedwidth:max_";
130 pv_name += part_id[i];
131 setEpicsPV(pv_name, m_pedwidth_max[i]);
132 }
133 for (int i = 0; i < 4; i++) {
134 if (m_pedwidth_avg[i] <= 0) continue;
135 std::string pv_name = "pedwidth:avg_";
136 pv_name += part_id[i];
137 setEpicsPV(pv_name, m_pedwidth_avg[i]);
138 }
139 }
140}
141
143{
144 B2DEBUG(20, "DQMHistAnalysisECLShapers: endRun called");
145
146 //= Set the contents of ECL monitoring object
147 m_c_main->Clear(); // clear existing content
148
149 TProfile* h_pedrms_cellid = (TProfile*)findHist("ECL/pedrms_cellid");
150 if (h_pedrms_cellid == nullptr) {
151 m_monObj->setVariable("comment", "No ECL pedestal width histograms available");
152 B2INFO("Histogram named ECL/pedrms_cellid is not found.");
153 return;
154 }
155
156 m_c_main->cd();
157 h_pedrms_cellid->Draw();
158
159 // set values of monitoring variables (if variable already exists this will
160 // change its value, otherwise it will insert new variable)
161 m_monObj->setVariable("pedwidthmaxFWD", m_pedwidth_max[0]);
162 m_monObj->setVariable("pedwidthmaxBarrel", m_pedwidth_max[1]);
163 m_monObj->setVariable("pedwidthmaxBWD", m_pedwidth_max[2]);
164 m_monObj->setVariable("pedwidthmaxTotal", m_pedwidth_max[3]);
165 m_monObj->setVariable("pedwidthavgFWD", m_pedwidth_avg[0]);
166 m_monObj->setVariable("pedwidthavgBarrel", m_pedwidth_avg[1]);
167 m_monObj->setVariable("pedwidthavgBWD", m_pedwidth_avg[2]);
168 m_monObj->setVariable("pedwidthavgTotal", m_pedwidth_avg[3]);
169}
170
171
172double DQMHistAnalysisECLShapersModule::robust_max(std::multiset<double> values)
173{
174 int len = values.size();
175 if (len < 10) {
176 return 0;
177 }
178 // Move end iterator back by 10% to remove
179 // noisy values.
180 auto end_iter = std::prev(values.end(), len * 0.1);
181
182 return *end_iter;
183}
184
void initialize() override final
Initialize the module.
double m_pedwidth_avg[4]
Average pedestal width array See m_pedwidth_max for the details.
DQMHistAnalysisECLShapersModule()
< derived from DQMHistAnalysisModule class.
std::string m_pvPrefix
Prefix to use for PVs registered by this module.
MonitoringObject * m_monObj
monitoring object
double robust_max(std::multiset< double > values)
Remove upper 10% of the values, return the maximum in the remaining 90%.
double m_pedwidth_max[4]
Max pedestal width array [0] -> Max pedestal width in FWD endcap [1] -> Max pedestal width in barrel ...
void event() override final
Event processor.
TCanvas * m_c_main
main panel for monitoring object
void endRun() override final
Call when a run ends.
void beginRun() override final
Call when a run begins.
static const int c_collector_count
Number of ECLCollector modules (normally 52)
int registerEpicsPV(const std::string &pvname, const std::string &keyname="")
EPICS related Functions.
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).
DQMHistAnalysisModule()
Constructor / Destructor.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.