Belle II Software  release-06-00-14
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 Reduction
11 //-
12 
13 
14 #include <dqm/analysis/modules/DQMHistAnalysisPXDDAQ.h>
15 #include <TROOT.h>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(DQMHistAnalysisPXDDAQ)
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
31 {
32  // This module CAN NOT be run in parallel!
33 
34  //Parameter definition
35  addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of Histogram dir", std::string("PXDDAQ"));
36  addParam("PVPrefix", m_pvPrefix, "PV Prefix", std::string("DQM:PXD:DAQ:"));
37  addParam("useEpics", m_useEpics, "useEpics", true);
38  B2DEBUG(1, "DQMHistAnalysisPXDDAQ: Constructor done.");
39 
40 }
41 
42 DQMHistAnalysisPXDDAQModule::~DQMHistAnalysisPXDDAQModule()
43 {
44 #ifdef _BELLE2_EPICS
45  if (m_useEpics) {
46  if (ca_current_context()) ca_context_destroy();
47  }
48 #endif
49 }
50 
51 void DQMHistAnalysisPXDDAQModule::initialize()
52 {
53  B2DEBUG(1, "DQMHistAnalysisPXDDAQ: initialized.");
54 
55  m_monObj = getMonitoringObject("pxd");
56 
57  gROOT->cd(); // this seems to be important, or strange things happen
58 
59  m_cDAQError = new TCanvas((m_histogramDirectoryName + "/c_DAQError").data());
60  m_cMissingDHC = new TCanvas((m_histogramDirectoryName + "/c_MissingDHC").data());
61  m_cMissingDHE = new TCanvas((m_histogramDirectoryName + "/c_MissingDHE").data());
62  m_cMissingDHP = new TCanvas((m_histogramDirectoryName + "/c_MissingDHP").data());
63  m_cStatistic = new TCanvas((m_histogramDirectoryName + "/c_Statistic").data());
64 
65  m_monObj->addCanvas(m_cDAQError);
66  m_monObj->addCanvas(m_cMissingDHC);
67  m_monObj->addCanvas(m_cMissingDHE);
68  m_monObj->addCanvas(m_cMissingDHP);
69  m_monObj->addCanvas(m_cStatistic);
70 
71  m_hMissingDHC = new TH2F("hPXDMissingDHC", "PXD Missing DHC", 16, 0, 16, 2, 0, 2);
72  m_hMissingDHE = new TH2F("hPXDMissingDHE", "PXD Missing DHE", 64, 0, 64, 2, 0, 2);
73 
74 #ifdef _BELLE2_EPICS
75  mychid.resize(20);
76  if (m_useEpics) {
77  if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback), "ca_context_create");
78  SEVCHK(ca_create_channel((m_pvPrefix + "HLTRej").data(), NULL, NULL, 10, &mychid[0]), "ca_create_channel failure");
79  SEVCHK(ca_create_channel((m_pvPrefix + "Trunc").data(), NULL, NULL, 10, &mychid[1]), "ca_create_channel failure");
80  SEVCHK(ca_create_channel((m_pvPrefix + "HER_Trunc").data(), NULL, NULL, 10, &mychid[2]), "ca_create_channel failure");
81  SEVCHK(ca_create_channel((m_pvPrefix + "LER_Trunc").data(), NULL, NULL, 10, &mychid[3]), "ca_create_channel failure");
82  SEVCHK(ca_create_channel((m_pvPrefix + "CM63").data(), NULL, NULL, 10, &mychid[4]), "ca_create_channel failure");
83  SEVCHK(ca_create_channel((m_pvPrefix + "HER_CM63").data(), NULL, NULL, 10, &mychid[5]), "ca_create_channel failure");
84  SEVCHK(ca_create_channel((m_pvPrefix + "LER_CM63").data(), NULL, NULL, 10, &mychid[6]), "ca_create_channel failure");
85  SEVCHK(ca_create_channel((m_pvPrefix + "HER_CM63_1ms").data(), NULL, NULL, 10, &mychid[7]), "ca_create_channel failure");
86  SEVCHK(ca_create_channel((m_pvPrefix + "LER_CM63_1ms").data(), NULL, NULL, 10, &mychid[8]), "ca_create_channel failure");
87  SEVCHK(ca_create_channel((m_pvPrefix + "HER_Trunc_1ms").data(), NULL, NULL, 10, &mychid[9]), "ca_create_channel failure");
88  SEVCHK(ca_create_channel((m_pvPrefix + "LER_Trunc_1ms").data(), NULL, NULL, 10, &mychid[10]), "ca_create_channel failure");
89  SEVCHK(ca_create_channel((m_pvPrefix + "MissFrame").data(), NULL, NULL, 10, &mychid[11]), "ca_create_channel failure");
90  SEVCHK(ca_create_channel((m_pvPrefix + "Timeout").data(), NULL, NULL, 10, &mychid[12]), "ca_create_channel failure");
91  SEVCHK(ca_create_channel((m_pvPrefix + "LinkDown").data(), NULL, NULL, 10, &mychid[13]), "ca_create_channel failure");
92  SEVCHK(ca_create_channel((m_pvPrefix + "Mismatch").data(), NULL, NULL, 10, &mychid[14]), "ca_create_channel failure");
93  SEVCHK(ca_create_channel((m_pvPrefix + "HER_Miss").data(), NULL, NULL, 10, &mychid[15]), "ca_create_channel failure");
94  SEVCHK(ca_create_channel((m_pvPrefix + "LER_Miss").data(), NULL, NULL, 10, &mychid[16]), "ca_create_channel failure");
95  SEVCHK(ca_create_channel((m_pvPrefix + "HER_Miss_1ms").data(), NULL, NULL, 10, &mychid[17]), "ca_create_channel failure");
96  SEVCHK(ca_create_channel((m_pvPrefix + "LER_Miss_1ms").data(), NULL, NULL, 10, &mychid[18]), "ca_create_channel failure");
97  SEVCHK(ca_create_channel((m_pvPrefix + "unused").data(), NULL, NULL, 10, &mychid[19]), "ca_create_channel failure");
98  SEVCHK(ca_pend_io(5.0), "ca_pend_io failure");
99  }
100 #endif
101 }
102 
103 void DQMHistAnalysisPXDDAQModule::beginRun()
104 {
105  B2DEBUG(1, "DQMHistAnalysisPXDDAQ: beginRun called.");
106 
107  m_cMissingDHP->Clear();
108 }
109 
110 void DQMHistAnalysisPXDDAQModule::event()
111 {
112 // double data = 0.0;
113  if (m_cMissingDHP == nullptr || m_cMissingDHE == nullptr || m_cMissingDHC == nullptr
114  || m_cStatistic == nullptr) return; // we could assume this
115 
116  m_cDAQError->Clear();
117  m_cMissingDHP->Clear();
118  m_cMissingDHE->Clear();
119  m_cMissingDHC->Clear();
120  m_cStatistic->Clear();
121 
122 
123  {
124  std::string name = "PXDDAQError";
125 
126  if (m_hDAQError) { delete m_hDAQError; m_hDAQError = nullptr;}
127 
128  TH1* hh1 = findHist(name);
129  if (hh1 == NULL) {
130  hh1 = findHist(m_histogramDirectoryName, name);
131  }
132  m_cDAQError->cd();
133  if (hh1) {
134  m_hDAQError = (TH1F*)hh1->DrawClone("text");
135  m_hDAQError->SetName("hPXDDAQError");
136  m_hDAQError->SetTitle("PXD Fraction of DAQ Errors");
137  if (m_hDAQError->GetBinContent(0)) {
138  m_hDAQError->Scale(1.0 / m_hDAQError->GetBinContent(0));
139  }
140  m_hDAQError->Draw("text,hist");
141  }
142  }
143  {
144  // DHC histogram
145  std::string name = "PXDDAQDHCError";
146 
147  TH1* hh1 = findHist(name);
148  if (hh1 == NULL) {
149  hh1 = findHist(m_histogramDirectoryName, name);
150  }
151  m_cMissingDHC->cd();
152  if (hh1) {
153  auto events = hh1->GetBinContent(hh1->GetBin(-1, -1));
154  // first, we have to relate the per-DHC overflow (DHC object count) to the overall overflow (event count)
155  // second, we have to relate the "fake data" DHC bin to the per-DHC overflow (DHC object count)
156  m_hMissingDHC->Reset();
157  for (int i = 0; i < 16; i++) {
158  auto dhecount = hh1->GetBinContent(hh1->GetBin(i, -1));
159  if (events > 0) m_hMissingDHC->Fill((double)i, 0.0, 1.0 - dhecount / events);
160  // c_FAKE_NO_DATA_TRIG = 1ull << 29,
161  if (dhecount > 0) m_hMissingDHC->Fill((double)i, 1.0, hh1->GetBinContent(hh1->GetBin(i, 29) / dhecount));
162  }
163  m_hMissingDHC->Draw("text");
164  }
165  }
166 
167  {
168  // DHE histogram
169  std::string name = "PXDDAQDHEError";
170 
171  TH1* hh1 = findHist(name);
172  if (hh1 == NULL) {
173  hh1 = findHist(m_histogramDirectoryName, name);
174  }
175  m_cMissingDHE->cd();
176  if (hh1) {
177  auto events = hh1->GetBinContent(hh1->GetBin(-1, -1));
178  // first, we have to relate the per-DHE overflow (DHE object count) to the overall overflow (event count)
179  // second, we have to relate the "fake data" DHE bin to the per-DHE overflow (DHE object count)
180  m_hMissingDHE->Reset();
181  for (int i = 0; i < 64; i++) {
182  auto dhecount = hh1->GetBinContent(hh1->GetBin(i, -1));
183  if (events > 0) m_hMissingDHE->Fill((double)i, 0.0, 1.0 - dhecount / events);
184  // c_FAKE_NO_DATA_TRIG = 1ull << 29,
185  if (dhecount > 0) m_hMissingDHE->Fill((double)i, 1.0, hh1->GetBinContent(hh1->GetBin(i, 29) / dhecount));
186  }
187  m_hMissingDHE->Draw("text");
188  }
189  }
190 
191  {
192  // DHP histogram
193  if (m_hMissingDHP) { delete m_hMissingDHP; m_hMissingDHP = nullptr;}
194 
195  std::string name = "PXDDAQDHPDataMissing";
196 
197  TH1* hh1 = findHist(name);
198  if (hh1 == NULL) {
199  hh1 = findHist(m_histogramDirectoryName, name);
200  }
201  m_cMissingDHP->cd();
202  if (hh1) {
203  m_hMissingDHP = (TH1F*)hh1->DrawClone("text");
204  if (m_hMissingDHP->GetBinContent(0)) {
205  m_hMissingDHP->Scale(1.0 / m_hMissingDHP->GetBinContent(0));
206  m_hMissingDHP->Draw("text");
207  }
208  }
209  // double data = m_hMissingDHP->Max???;
210  //
211  // m_monObj->setVariable("missingDHPFraction", data);
212  //
213  m_cMissingDHP->Modified();
214  m_cMissingDHP->Update();
215  }
216 
217  double data_HLTRej = 0.0;
218  double data_Trunc = 0.0;
219  double data_HER_Trunc = 0.0;
220  double data_LER_Trunc = 0.0;
221  double data_CM63 = 0.0;
222  double data_HER_CM63 = 0.0;
223  double data_LER_CM63 = 0.0;
224  double data_HER_CM63_1ms = 0.0;
225  double data_LER_CM63_1ms = 0.0;
226  double data_HER_Trunc_1ms = 0.0;
227  double data_LER_Trunc_1ms = 0.0;
228  double data_MissFrame = 0.0;
229  double data_Timeout = 0.0;
230  double data_LinkDown = 0.0;
231  double data_Mismatch = 0.0;
232  double data_HER_Miss = 0.0;
233  double data_LER_Miss = 0.0;
234  double data_HER_Miss_1ms = 0.0;
235  double data_LER_Miss_1ms = 0.0;
236  double data_unused = 0.0;
237 
238  // Stat histogram
239  if (m_hStatistic) { delete m_hStatistic; m_hStatistic = nullptr;}
240 
241  std::string name = "PXDDAQStat";
242 
243  TH1* hh1 = findHist(name);
244  if (hh1 == NULL) {
245  hh1 = findHist(m_histogramDirectoryName, name);
246  }
247  m_cStatistic->cd();
248  if (hh1) {
249  m_hStatistic = (TH1F*)hh1->DrawClone("text");
250  if (m_hStatistic->GetBinContent(0)) {
251  m_hStatistic->Scale(1.0 / m_hStatistic->GetBinContent(0));
252  m_hStatistic->Draw("text");
253  }
254  double scale = hh1->GetBinContent(0);// underflow is event counter
255  if (scale != 0.0) scale = 1.0 / scale; // just avoid dive by zero
256  data_HLTRej = hh1->GetBinContent(1 + 0) * scale;
257  data_Trunc = hh1->GetBinContent(1 + 1) * scale;
258  data_HER_Trunc = hh1->GetBinContent(1 + 2) * scale;
259  data_LER_Trunc = hh1->GetBinContent(1 + 3) * scale;
260  data_CM63 = hh1->GetBinContent(1 + 4) * scale;
261  data_HER_CM63 = hh1->GetBinContent(1 + 5) * scale;
262  data_LER_CM63 = hh1->GetBinContent(1 + 6) * scale;
263  data_HER_CM63_1ms = hh1->GetBinContent(1 + 7) * scale;
264  data_LER_CM63_1ms = hh1->GetBinContent(1 + 8) * scale;
265  data_HER_Trunc_1ms = hh1->GetBinContent(1 + 9) * scale;
266  data_LER_Trunc_1ms = hh1->GetBinContent(1 + 10) * scale;
267  data_MissFrame = hh1->GetBinContent(1 + 11) * scale;
268  data_Timeout = hh1->GetBinContent(1 + 12) * scale;
269  data_LinkDown = hh1->GetBinContent(1 + 13) * scale;
270  data_Mismatch = hh1->GetBinContent(1 + 14) * scale;
271  data_HER_Miss = hh1->GetBinContent(1 + 15) * scale;
272  data_LER_Miss = hh1->GetBinContent(1 + 16) * scale;
273  data_HER_Miss_1ms = hh1->GetBinContent(1 + 17) * scale;
274  data_LER_Miss_1ms = hh1->GetBinContent(1 + 18) * scale;
275  data_unused = hh1->GetBinContent(1 + 19) * scale;
276  }
277 
278  m_monObj->setVariable("HLTReject", data_HLTRej);
279  m_monObj->setVariable("Trunc", data_Trunc);
280  m_monObj->setVariable("HER_Trunc", data_HER_Trunc);
281  m_monObj->setVariable("LER_Trunc", data_LER_Trunc);
282  m_monObj->setVariable("CM63", data_CM63);
283  m_monObj->setVariable("HER_CM63", data_HER_CM63);
284  m_monObj->setVariable("LER_CM63", data_LER_CM63);
285  m_monObj->setVariable("HER_CM63_1ms", data_HER_CM63_1ms);
286  m_monObj->setVariable("LER_CM63_1ms", data_LER_CM63_1ms);
287  m_monObj->setVariable("HER_Trunc_1ms", data_HER_Trunc_1ms);
288  m_monObj->setVariable("LER_Trunc_1ms", data_LER_Trunc_1ms);
289  m_monObj->setVariable("MissFrame", data_MissFrame);
290  m_monObj->setVariable("Timeout", data_Timeout);
291  m_monObj->setVariable("LinkDown", data_LinkDown);
292  m_monObj->setVariable("Mismatch", data_Mismatch);
293  m_monObj->setVariable("HER_Miss", data_HER_Miss);
294  m_monObj->setVariable("LER_Miss", data_LER_Miss);
295  m_monObj->setVariable("HER_Miss_1ms", data_HER_Miss_1ms);
296  m_monObj->setVariable("LER_Miss_1ms", data_LER_Miss_1ms);
297 
298  m_cStatistic->Modified();
299  m_cStatistic->Update();
300 
301 #ifdef _BELLE2_EPICS
302  if (m_useEpics) {
303  SEVCHK(ca_put(DBR_DOUBLE, mychid[0], (void*)&data_HLTRej), "ca_set failure");
304  SEVCHK(ca_put(DBR_DOUBLE, mychid[1], (void*)&data_Trunc), "ca_set failure");
305  SEVCHK(ca_put(DBR_DOUBLE, mychid[2], (void*)&data_HER_Trunc), "ca_set failure");
306  SEVCHK(ca_put(DBR_DOUBLE, mychid[3], (void*)&data_LER_Trunc), "ca_set failure");
307  SEVCHK(ca_put(DBR_DOUBLE, mychid[4], (void*)&data_CM63), "ca_set failure");
308  SEVCHK(ca_put(DBR_DOUBLE, mychid[5], (void*)&data_HER_CM63), "ca_set failure");
309  SEVCHK(ca_put(DBR_DOUBLE, mychid[6], (void*)&data_LER_CM63), "ca_set failure");
310  SEVCHK(ca_put(DBR_DOUBLE, mychid[7], (void*)&data_HER_CM63_1ms), "ca_set failure");
311  SEVCHK(ca_put(DBR_DOUBLE, mychid[8], (void*)&data_LER_CM63_1ms), "ca_set failure");
312  SEVCHK(ca_put(DBR_DOUBLE, mychid[9], (void*)&data_HER_Trunc_1ms), "ca_set failure");
313  SEVCHK(ca_put(DBR_DOUBLE, mychid[10], (void*)&data_LER_Trunc_1ms), "ca_set failure");
314  SEVCHK(ca_put(DBR_DOUBLE, mychid[11], (void*)&data_MissFrame), "ca_set failure");
315  SEVCHK(ca_put(DBR_DOUBLE, mychid[12], (void*)&data_Timeout), "ca_set failure");
316  SEVCHK(ca_put(DBR_DOUBLE, mychid[13], (void*)&data_LinkDown), "ca_set failure");
317  SEVCHK(ca_put(DBR_DOUBLE, mychid[14], (void*)&data_Mismatch), "ca_set failure");
318  SEVCHK(ca_put(DBR_DOUBLE, mychid[15], (void*)&data_HER_Miss), "ca_set failure");
319  SEVCHK(ca_put(DBR_DOUBLE, mychid[16], (void*)&data_LER_Miss), "ca_set failure");
320  SEVCHK(ca_put(DBR_DOUBLE, mychid[17], (void*)&data_HER_Miss_1ms), "ca_set failure");
321  SEVCHK(ca_put(DBR_DOUBLE, mychid[18], (void*)&data_LER_Miss_1ms), "ca_set failure");
322  SEVCHK(ca_put(DBR_DOUBLE, mychid[19], (void*)&data_unused), "ca_set failure");
323  // write out
324  SEVCHK(ca_pend_io(5.0), "ca_pend_io failure");
325  }
326 #endif
327 }
328 
329 void DQMHistAnalysisPXDDAQModule::terminate()
330 {
331  B2DEBUG(1, "DQMHistAnalysisPXDDAQ: terminate called");
332  // should delete canvas here, maybe hist, too? Who owns it?
333 }
334 
The base class for the histogram analysis module.
DQM Histogram Analysis for PXD DAQ.
#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.