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
18using namespace Belle2;
19
20REG_MODULE(DQMHistAnalysisECLShapers);
21
24{
25 B2DEBUG(20, "DQMHistAnalysisECLShapers: Constructor done.");
26 setDescription("Processes information involving ECL pedestals (widths and rms).");
27
28 addParam("pvPrefix", m_pvPrefix, "Prefix to use for PVs registered by this module",
29 std::string("ECL:"));
30}
31
32
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
49
50 m_c_main = new TCanvas("ecl_main");
52
53 B2DEBUG(20, "DQMHistAnalysisECLShapers: initialized.");
54}
55
57{
58 B2DEBUG(20, "DQMHistAnalysisECLShapers: beginRun called.");
59}
60
62{
63 TH1* h_fail_crateid = findHist("ECL/fail_crateid");
64 TProfile* h_pedrms_cellid = (TProfile*)findHist("ECL/pedrms_cellid");
65
66 if (h_pedrms_cellid != NULL) {
67 // Using multiset to automatically sort the added values.
68 std::multiset<double> barrel_pedwidth;
69 std::multiset<double> bwd_pedwidth;
70 std::multiset<double> fwd_pedwidth;
71
72 for (int i = 0; i < 8736; i++) {
73 const int cellid = i + 1;
74 if (h_pedrms_cellid->GetBinEntries(cellid) < 100) continue;
75 double pedrms = h_pedrms_cellid->GetBinContent(cellid);
76 if (cellid < 1153) {
77 fwd_pedwidth.insert(pedrms);
78 } else if (cellid < 7777) {
79 barrel_pedwidth.insert(pedrms);
80 } else {
81 bwd_pedwidth.insert(pedrms);
82 }
83 }
84
85 // Use approximate conversion factor
86 // to convert from ADC units to MeV.
87 const double adc_to_mev = 0.05;
88
89 m_pedwidth_max[0] = robust_max(fwd_pedwidth) * adc_to_mev;
90 m_pedwidth_max[1] = robust_max(barrel_pedwidth) * adc_to_mev;
91 m_pedwidth_max[2] = robust_max(bwd_pedwidth) * adc_to_mev;
92 m_pedwidth_max[3] = *std::max(&m_pedwidth_max[0], &m_pedwidth_max[2]);
93 } else {
94 for (int i = 0; i < 4; i++) {
95 m_pedwidth_max[i] = 0;
96 }
97 }
98
99 //== Set EPICS PVs
100
101 if (h_fail_crateid != NULL) {
102 // Set fit consistency check PVs
103 for (int i = 0; i < c_collector_count; i++) {
104 std::string pv_name = (boost::format("logic_check:crate%02d") %
105 (i + 1)).str();
106 int errors_count = h_fail_crateid->GetBinContent(i + 1);
107 setEpicsPV(pv_name, errors_count);
108 }
109 // Set pedestal width PVs
110 static const char* part_id[] = {"fw", "br", "bw", "al"};
111 for (int i = 0; i < 4; i++) {
112 if (m_pedwidth_max[i] <= 0) continue;
113 std::string pv_name = "pedwidth:max_";
114 pv_name += part_id[i];
115 setEpicsPV(pv_name, m_pedwidth_max[i]);
116 }
117 }
118}
119
121{
122 B2DEBUG(20, "DQMHistAnalysisECLShapers: endRun called");
123
124 //= Set the contents of ECL monitoring object
125 m_c_main->Clear(); // clear existing content
126
127 TProfile* h_pedrms_cellid = (TProfile*)findHist("ECL/pedrms_cellid");
128 if (h_pedrms_cellid == nullptr) {
129 m_monObj->setVariable("comment", "No ECL pedestal width histograms available");
130 B2INFO("Histogram named ECL/pedrms_cellid is not found.");
131 return;
132 }
133
134 m_c_main->cd();
135 h_pedrms_cellid->Draw();
136
137 // set values of monitoring variables (if variable already exists this will
138 // change its value, otherwise it will insert new variable)
139 m_monObj->setVariable("pedwidthFWD", m_pedwidth_max[0]);
140 m_monObj->setVariable("pedwidthBarrel", m_pedwidth_max[1]);
141 m_monObj->setVariable("pedwidthBWD", m_pedwidth_max[2]);
142 m_monObj->setVariable("pedwidthTotal", m_pedwidth_max[3]);
143}
144
145
146double DQMHistAnalysisECLShapersModule::robust_max(std::multiset<double> values)
147{
148 int len = values.size();
149 if (len < 10) {
150 return 0;
151 }
152 // Move end iterator back by 10% to remove
153 // noisy values.
154 auto end_iter = std::prev(values.end(), len * 0.1);
155
156 return *end_iter;
157}
158
void initialize() override final
Initialize the module.
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)
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 addCanvas(TCanvas *canv)
Add Canvas to monitoring object.
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.