Belle II Software development
DQMHistAnalysisPXDDAQ.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// File : DQMHistAnalysisPXDDAQ.cc
10// Description : Analysis of PXD DAQ and Issues
11//-
12
13
14#include <dqm/analysis/modules/DQMHistAnalysisPXDDAQ.h>
15#include <TROOT.h>
16
17using namespace std;
18using namespace Belle2;
19
20//-----------------------------------------------------------------
21// Register the Module
22//-----------------------------------------------------------------
23REG_MODULE(DQMHistAnalysisPXDDAQ);
24
25//-----------------------------------------------------------------
26// Implementation
27//-----------------------------------------------------------------
28
31{
32 // This module CAN NOT be run in parallel!
33 setDescription("DQM Analysis for PXD DAQ Statistics and Issues");
34
35 // Parameter definition
36 addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of Histogram dir", std::string("PXDDAQ"));
37 addParam("minEntries", m_minEntries, "minimum number of new entries for last time slot", 10000);
38 B2DEBUG(1, "DQMHistAnalysisPXDDAQ: Constructor done.");
39
40}
41
43{
44}
45
47{
48 B2DEBUG(1, "DQMHistAnalysisPXDDAQ: initialized.");
49
51
52 gROOT->cd(); // this seems to be important, or strange things happen
53
54 m_cDAQError = new TCanvas((m_histogramDirectoryName + "/c_DAQError").data());
55 m_cMissingDHC = new TCanvas((m_histogramDirectoryName + "/c_MissingDHC").data());
56 m_cMissingDHE = new TCanvas((m_histogramDirectoryName + "/c_MissingDHE").data());
57 m_cMissingDHP = new TCanvas((m_histogramDirectoryName + "/c_MissingDHP").data());
58 m_cStatistic = new TCanvas((m_histogramDirectoryName + "/c_Statistic").data());
59 m_cStatisticUpd = new TCanvas((m_histogramDirectoryName + "/c_StatisticUpd").data());
61 HistDelta::c_Underflow, m_minEntries, 1); // register delta
62
68
69 m_hMissingDHC = new TH2F("hPXDMissingDHC", "PXD Missing DHC", 16, 0, 16, 2, 0, 2);
70 m_hMissingDHE = new TH2F("hPXDMissingDHE", "PXD Missing DHE", 64, 0, 64, 2, 0, 2);
71
72 registerEpicsPV("PXD:DAQ:HLTRej", "HLTReject");
73 registerEpicsPV("PXD:DAQ:Trunc", "Trunc");
74 registerEpicsPV("PXD:DAQ:HER_Trunc", "HER_Trunc");
75 registerEpicsPV("PXD:DAQ:LER_Trunc", "LER_Trunc");
76 registerEpicsPV("PXD:DAQ:CM63", "CM63");
77 registerEpicsPV("PXD:DAQ:HER_CM63", "HER_CM63");
78 registerEpicsPV("PXD:DAQ:LER_CM63", "LER_CM63");
79 registerEpicsPV("PXD:DAQ:HER_CM63_1ms", "HER_CM63_1ms");
80 registerEpicsPV("PXD:DAQ:LER_CM63_1ms", "LER_CM63_1ms");
81 registerEpicsPV("PXD:DAQ:HER_Trunc_1ms", "HER_Trunc_1ms");
82 registerEpicsPV("PXD:DAQ:LER_Trunc_1ms", "LER_Trunc_1ms");
83 registerEpicsPV("PXD:DAQ:MissFrame", "MissFrame");
84 registerEpicsPV("PXD:DAQ:Timeout", "Timeout");
85 registerEpicsPV("PXD:DAQ:LinkDown", "LinkDown");
86 registerEpicsPV("PXD:DAQ:Mismatch", "Mismatch");
87 registerEpicsPV("PXD:DAQ:HER_Miss", "HER_Miss");
88 registerEpicsPV("PXD:DAQ:LER_Miss", "LER_Miss");
89 registerEpicsPV("PXD:DAQ:HER_Miss_1ms", "HER_Miss_1ms");
90 registerEpicsPV("PXD:DAQ:LER_Miss_1ms", "LER_Miss_1ms");
91 registerEpicsPV("PXD:DAQ:unused", "unused");
92}
93
95{
96 B2DEBUG(1, "DQMHistAnalysisPXDDAQ: beginRun called.");
97
98 m_cMissingDHP->Clear();
99 m_cMissingDHE->Clear();
100 m_cMissingDHC->Clear();
101 m_cStatistic->Clear();
102 m_cStatisticUpd->Clear();
103}
104
106{
107// double data = 0.0;
108 if (m_cMissingDHP == nullptr || m_cMissingDHE == nullptr || m_cMissingDHC == nullptr
109 || m_cStatistic == nullptr) return; // we could assume this
110
111 {
112 std::string name = "PXDDAQError";
113
114// if (m_hDAQError) { delete m_hDAQError; m_hDAQError = nullptr;}
115
116 auto hh1 = findHist(m_histogramDirectoryName, name, true);
117 if (hh1) {
118 m_cDAQError->Clear();
119 m_cDAQError->cd();
120 m_hDAQError = (TH1D*)hh1->DrawClone("text");
121 m_hDAQError->SetName("hPXDDAQError");
122 m_hDAQError->SetTitle("PXD Fraction of DAQ Errors");
123 if (m_hDAQError->GetBinContent(0)) {
124 m_hDAQError->Scale(1.0 / m_hDAQError->GetBinContent(0));
125 }
126 m_hDAQError->Draw("text,hist");
128 }
129 }
130 {
131 // DHC histogram
132 std::string name = "PXDDAQDHCError";
133
134 auto hh1 = findHist(m_histogramDirectoryName, name, true);
135 if (hh1) {
136 auto events = hh1->GetBinContent(hh1->GetBin(-1, -1));
137 m_cMissingDHC->Clear();
138 m_cMissingDHC->cd();
139 // first, we have to relate the per-DHC overflow (DHC object count) to the overall overflow (event count)
140 // second, we have to relate the "fake data" DHC bin to the per-DHC overflow (DHC object count)
141 m_hMissingDHC->Reset();
142 for (int i = 0; i < 16; i++) {
143 auto dhecount = hh1->GetBinContent(hh1->GetBin(i, -1));
144 if (events > 0) m_hMissingDHC->Fill((double)i, 0.0, 1.0 - dhecount / events);
145 // c_FAKE_NO_DATA_TRIG = 1ull << 29,
146 if (dhecount > 0) m_hMissingDHC->Fill((double)i, 1.0, hh1->GetBinContent(hh1->GetBin(i, 29) / dhecount));
147 }
148 m_hMissingDHC->Draw("text");
150 }
151 }
152
153 {
154 // DHE histogram
155 std::string name = "PXDDAQDHEError";
156
157 auto hh1 = findHist(m_histogramDirectoryName, name, true);
158 if (hh1) {
159 auto events = hh1->GetBinContent(hh1->GetBin(-1, -1));
160 // first, we have to relate the per-DHE overflow (DHE object count) to the overall overflow (event count)
161 // second, we have to relate the "fake data" DHE bin to the per-DHE overflow (DHE object count)
162 m_cMissingDHE->Clear();
163 m_cMissingDHE->cd();
164 m_hMissingDHE->Reset();
165 for (int i = 0; i < 64; i++) {
166 auto dhecount = hh1->GetBinContent(hh1->GetBin(i, -1));
167 if (events > 0) m_hMissingDHE->Fill((double)i, 0.0, 1.0 - dhecount / events);
168 // c_FAKE_NO_DATA_TRIG = 1ull << 29,
169 if (dhecount > 0) m_hMissingDHE->Fill((double)i, 1.0, hh1->GetBinContent(hh1->GetBin(i, 29) / dhecount));
170 }
171 m_hMissingDHE->Draw("text");
173 }
174 }
175
176 {
177 // DHP histogram
178 //if (m_hMissingDHP) { delete m_hMissingDHP; m_hMissingDHP = nullptr;}
179
180 std::string name = "PXDDAQDHPDataMissing";
181
182 auto hh1 = findHist(m_histogramDirectoryName, name, true);
183 if (hh1) {
184 m_cMissingDHP->Clear();
185
186 m_cMissingDHP->cd();
187 m_hMissingDHP = (TH1F*)hh1->DrawClone("text");
188 if (m_hMissingDHP->GetBinContent(0)) {
189 m_hMissingDHP->Scale(1.0 / m_hMissingDHP->GetBinContent(0));
190 m_hMissingDHP->Draw("text");
191 }
192 m_cMissingDHP->Modified();
193 m_cMissingDHP->Update();
195 }
196 // double data = m_hMissingDHP->Max???;
197 //
198 // m_monObj->setVariable("missingDHPFraction", data);
199 //
200 }
201
202 std::string name = "PXDDAQStat";
203
204 auto* statsum = findHist(m_histogramDirectoryName, name, true);
205 if (statsum) {
206 // Stat histogram
207 //if (m_hStatistic) { delete m_hStatistic; m_hStatistic = nullptr;}
208 m_cStatistic->cd();
209 m_hStatistic = (TH1D*)statsum->DrawClone("text");
210 if (m_hStatistic->GetBinContent(0)) {
211 m_hStatistic->Scale(1.0 / m_hStatistic->GetBinContent(0));
212 m_hStatistic->Draw("text");
213 }
214 m_cStatistic->Modified();
215 m_cStatistic->Update();
217 }
218
219 // now the important part, check fraction of "errors" and export
220 double data_HLTRej = 0.0;
221 double data_Trunc = 0.0;
222 double data_HER_Trunc = 0.0;
223 double data_LER_Trunc = 0.0;
224 double data_CM63 = 0.0;
225 double data_HER_CM63 = 0.0;
226 double data_LER_CM63 = 0.0;
227 double data_HER_CM63_1ms = 0.0;
228 double data_LER_CM63_1ms = 0.0;
229 double data_HER_Trunc_1ms = 0.0;
230 double data_LER_Trunc_1ms = 0.0;
231 double data_MissFrame = 0.0;
232 double data_Timeout = 0.0;
233 double data_LinkDown = 0.0;
234 double data_Mismatch = 0.0;
235 double data_HER_Miss = 0.0;
236 double data_LER_Miss = 0.0;
237 double data_HER_Miss_1ms = 0.0;
238 double data_LER_Miss_1ms = 0.0;
239 double data_unused = 0.0;
240
241 bool update_epics = false;
242
243 auto* delta = getDelta(m_histogramDirectoryName, name); // only updated by default
244 if (delta) {
245 gROOT->cd();
246 m_cStatisticUpd->Clear();
247 m_cStatisticUpd->cd();// necessary!
248 delta->Draw("hist");
249 // now check that we have enough stats for useful export
250 double scale = delta->GetBinContent(0);// underflow is event counter
251 if (scale >= m_minEntries) {
252 if (scale != 0.0) scale = 1.0 / scale; // just avoid divide by zero, should never happen
253 data_HLTRej = delta->GetBinContent(1 + 0) * scale;
254 data_Trunc = delta->GetBinContent(1 + 1) * scale;
255 data_HER_Trunc = delta->GetBinContent(1 + 2) * scale;
256 data_LER_Trunc = delta->GetBinContent(1 + 3) * scale;
257 data_CM63 = delta->GetBinContent(1 + 4) * scale;
258 data_HER_CM63 = delta->GetBinContent(1 + 5) * scale;
259 data_LER_CM63 = delta->GetBinContent(1 + 6) * scale;
260 data_HER_CM63_1ms = delta->GetBinContent(1 + 7) * scale;
261 data_LER_CM63_1ms = delta->GetBinContent(1 + 8) * scale;
262 data_HER_Trunc_1ms = delta->GetBinContent(1 + 9) * scale;
263 data_LER_Trunc_1ms = delta->GetBinContent(1 + 10) * scale;
264 data_MissFrame = delta->GetBinContent(1 + 11) * scale;
265 data_Timeout = delta->GetBinContent(1 + 12) * scale;
266 data_LinkDown = delta->GetBinContent(1 + 13) * scale;
267 data_Mismatch = delta->GetBinContent(1 + 14) * scale;
268 data_HER_Miss = delta->GetBinContent(1 + 15) * scale;
269 data_LER_Miss = delta->GetBinContent(1 + 16) * scale;
270 data_HER_Miss_1ms = delta->GetBinContent(1 + 17) * scale;
271 data_LER_Miss_1ms = delta->GetBinContent(1 + 18) * scale;
272 data_unused = delta->GetBinContent(1 + 19) * scale;
273 update_epics = true;
274 }
275 m_cStatisticUpd->Modified();
276 m_cStatisticUpd->Update();
277 }
278
279 if (update_epics) {
280 m_monObj->setVariable("HLTReject", data_HLTRej);
281 m_monObj->setVariable("Trunc", data_Trunc);
282 m_monObj->setVariable("HER_Trunc", data_HER_Trunc);
283 m_monObj->setVariable("LER_Trunc", data_LER_Trunc);
284 m_monObj->setVariable("CM63", data_CM63);
285 m_monObj->setVariable("HER_CM63", data_HER_CM63);
286 m_monObj->setVariable("LER_CM63", data_LER_CM63);
287 m_monObj->setVariable("HER_CM63_1ms", data_HER_CM63_1ms);
288 m_monObj->setVariable("LER_CM63_1ms", data_LER_CM63_1ms);
289 m_monObj->setVariable("HER_Trunc_1ms", data_HER_Trunc_1ms);
290 m_monObj->setVariable("LER_Trunc_1ms", data_LER_Trunc_1ms);
291 m_monObj->setVariable("MissFrame", data_MissFrame);
292 m_monObj->setVariable("Timeout", data_Timeout);
293 m_monObj->setVariable("LinkDown", data_LinkDown);
294 m_monObj->setVariable("Mismatch", data_Mismatch);
295 m_monObj->setVariable("HER_Miss", data_HER_Miss);
296 m_monObj->setVariable("LER_Miss", data_LER_Miss);
297 m_monObj->setVariable("HER_Miss_1ms", data_HER_Miss_1ms);
298 m_monObj->setVariable("LER_Miss_1ms", data_LER_Miss_1ms);
299
300 setEpicsPV("HLTReject", data_HLTRej);
301 setEpicsPV("Trunc", data_Trunc);
302 setEpicsPV("HER_Trunc", data_HER_Trunc);
303 setEpicsPV("LER_Trunc", data_LER_Trunc);
304 setEpicsPV("CM63", data_CM63);
305 setEpicsPV("HER_CM63", data_HER_CM63);
306 setEpicsPV("LER_CM63", data_LER_CM63);
307 setEpicsPV("HER_CM63_1ms", data_HER_CM63_1ms);
308 setEpicsPV("LER_CM63_1ms", data_LER_CM63_1ms);
309 setEpicsPV("HER_Trunc_1ms", data_HER_Trunc_1ms);
310 setEpicsPV("LER_Trunc_1ms", data_LER_Trunc_1ms);
311 setEpicsPV("MissFrame", data_MissFrame);
312 setEpicsPV("Timeout", data_Timeout);
313 setEpicsPV("LinkDown", data_LinkDown);
314 setEpicsPV("Mismatch", data_Mismatch);
315 setEpicsPV("HER_Miss", data_HER_Miss);
316 setEpicsPV("LER_Miss", data_LER_Miss);
317 setEpicsPV("HER_Miss_1ms", data_HER_Miss_1ms);
318 setEpicsPV("LER_Miss_1ms", data_LER_Miss_1ms);
319 setEpicsPV("unused", data_unused);
320 }
321}
322
324{
325 B2DEBUG(1, "DQMHistAnalysisPXDDAQ: terminate called.");
326 // delete dynamical variables
327 if (m_cDAQError) delete m_cDAQError;
328 if (m_cMissingDHC) delete m_cMissingDHC;
329 if (m_cMissingDHE) delete m_cMissingDHE;
330 if (m_cMissingDHP) delete m_cMissingDHP;
331 if (m_cStatistic) delete m_cStatistic;
333
334 if (m_hMissingDHC) delete m_hMissingDHC;
335 if (m_hMissingDHE) delete m_hMissingDHE;
336}
The base class for the histogram analysis module.
bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
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 UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
void terminate(void) override final
Terminator.
int m_minEntries
Update entry interval.
void initialize(void) override final
Initializer.
TH1D * m_hStatistic
Histogram covering stat.
MonitoringObject * m_monObj
Monitoring Object.
std::string m_histogramDirectoryName
name of histogram directory
TH2F * m_hMissingDHC
Histogram covering all DHC modules.
TH1 * m_hDAQError
Histogram covering all error types.
TH1F * m_hMissingDHP
Histogram covering all modules*DHP.
TH2F * m_hMissingDHE
Histogram covering all DHE modules.
void beginRun(void) override final
Called when entering a new run.
void event(void) override final
This method is called for each event.
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.
STL namespace.