Belle II Software development
DQMHistAnalysisTOP.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#include <dqm/analysis/modules/DQMHistAnalysisTOP.h>
10#include <boost/format.hpp>
11#include <boost/algorithm/string.hpp>
12#include <TClass.h>
13#include <TF1.h>
14#include <TROOT.h>
15#include <TStyle.h>
16#include <TProfile.h>
17#include <TProfile2D.h>
18#include <TString.h>
19#include <map>
20
21using namespace std;
22using namespace Belle2;
23using boost::format;
24
25//-----------------------------------------------------------------
26// Register the Module
27//-----------------------------------------------------------------
28REG_MODULE(DQMHistAnalysisTOP);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
35{
36 // Set description
37 setDescription("Histogram analysis module for TOP DQM.");
38
39 // Add parameters
40 addParam("asicWindowsBand", m_asicWindowsBand,
41 "lower and upper bin of a band denoting good windows", m_asicWindowsBand);
42 addParam("asicWindowsAlarmLevels", m_asicWindowsAlarmLevels,
43 "alarm levels for the fraction of windows outside the band (yellow, red)", m_asicWindowsAlarmLevels);
44 addParam("eventMonitorAlarmLevels", m_eventMonitorAlarmLevels,
45 "alarm levels for the fraction of desynchronized digits (yellow, red)", m_eventMonitorAlarmLevels);
46 addParam("unpackerErrAlarmLevels", m_unpackerErrAlarmLevels,
47 "alarm levels for the fraction of unpacker errors (yellow, red)", m_unpackerErrAlarmLevels);
48 addParam("junkHitsAlarmLevels", m_junkHitsAlarmLevels,
49 "alarm levels for the fraction of junk hits (yellow, red)", m_junkHitsAlarmLevels);
50 addParam("deadChannelsAlarmLevels", m_deadChannelsAlarmLevels,
51 "alarm levels for the fraction of dead + hot channels (yellow, red)", m_deadChannelsAlarmLevels);
52 addParam("backgroundAlarmLevels", m_backgroundAlarmLevels,
53 "alarm levels for background rates [MHz/PMT] (yellow, red)", m_backgroundAlarmLevels);
54 addParam("photonYieldsAlarmLevels", m_photonYieldsAlarmLevels,
55 "alarm levels for the number of photons per track (red, yellow)", m_photonYieldsAlarmLevels);
56 addParam("excludedBoardstacks", m_excludedBoardstacks,
57 "boarstacks to be excluded from alarming. Names are given like '5c', '13d' etc.", m_excludedBoardstacks);
58 addParam("pvPrefix", m_pvPrefix, "Epics PV prefix", std::string("TOP:"));
59 addParam("injectionBGAlarmLevels", m_injectionBGAlarmLevels,
60 "alarm levels for injection background (in % of events)", m_injectionBGAlarmLevels);
61 addParam("timingAlarmLevels", m_timingAlarmLevels,
62 "alarm levels for time distribution (residual fraction w.r.t reference plot)", m_timingAlarmLevels);
63 addParam("eventT0MeanAlarmLevels", m_eventT0MeanAlarmLevels,
64 "alarm levels for mean of event T0 [ns]", m_eventT0MeanAlarmLevels);
65 addParam("eventT0RmsAlarmLevels", m_eventT0RmsAlarmLevels,
66 "alarm levels for r.m.s. of event T0 [ns]", m_eventT0RmsAlarmLevels);
67 addParam("offsetMeanAlarmLevels", m_offsetMeanAlarmLevels,
68 "alarm levels for mean of bunch offset [ns]", m_offsetMeanAlarmLevels);
69 addParam("offsetRmsAlarmLevels", m_offsetRmsAlarmLevels,
70 "alarm levels for r.m.s. of bunch offset [ns]", m_offsetRmsAlarmLevels);
71
72 B2DEBUG(20, "DQMHistAnalysisTOP: Constructor done.");
73}
74
75
77{
78
79 // check module parameters
80
81 if (m_asicWindowsBand.size() != 2) B2ERROR("Parameter list 'asicWindowsBand' must contain two numbers");
82 if (m_asicWindowsAlarmLevels.size() != 2) B2ERROR("Parameter list 'asicWindowsAlarmLevels' must contain two numbers");
83 if (m_eventMonitorAlarmLevels.size() != 2) B2ERROR("Parameter list 'eventMonitorAlarmLevels' must contain two numbers");
84 if (m_unpackerErrAlarmLevels.size() != 2) B2ERROR("Parameter list 'unpackerErrAlarmLevels' must contain two numbers");
85 if (m_junkHitsAlarmLevels.size() != 2) B2ERROR("Parameter list 'junkHitsAlarmLevels' must contain two numbers");
86 if (m_deadChannelsAlarmLevels.size() != 2) B2ERROR("Parameter list 'deadChannelsAlarmLevels' must contain two numbers");
87 if (m_backgroundAlarmLevels.size() != 2) B2ERROR("Parameter list 'backgroundAlarmLevels' must contain two numbers");
88 if (m_photonYieldsAlarmLevels.size() != 2) B2ERROR("Parameter list 'photonYieldsAlarmLevels' must contain two numbers");
89 if (m_injectionBGAlarmLevels.size() != 2) B2ERROR("Parameter list 'injectionBGAlarmLevels' must contain two numbers");
90 if (m_timingAlarmLevels.size() != 2) B2ERROR("Parameter list 'timingAlarmLevels' must contain two numbers");
91 if (m_eventT0MeanAlarmLevels.size() != 2) B2ERROR("Parameter list 'eventT0MeanAlarmLevels' must contain two numbers");
92 if (m_eventT0RmsAlarmLevels.size() != 2) B2ERROR("Parameter list 'eventT0RmsAlarmLevels' must contain two numbers");
93 if (m_offsetMeanAlarmLevels.size() != 2) B2ERROR("Parameter list 'offsetMeanAlarmLevels' must contain two numbers");
94 if (m_offsetRmsAlarmLevels.size() != 2) B2ERROR("Parameter list 'offsetRmsAlarmLevels' must contain two numbers");
95
96 // make a map of boardstack names to ID's
97
98 int id = 1;
99 for (int slot = 1; slot <= 16; slot++) {
100 string slotstr = to_string(slot);
101 for (std::string bs : {"a", "b", "c", "d"}) {
102 m_bsmap[slotstr + bs] = id;
103 id++;
104 }
105 }
106
107 // parse excluded boardstacks
108
110
111 // MiraBelle monitoring
112
114
115 // Epics used to pass values to shifter's page (output only)
116
117 registerEpicsPV(m_pvPrefix + "badBoardstacks", "badBoardstacks");
118 registerEpicsPV(m_pvPrefix + "badCarriers", "badCarriers");
119 registerEpicsPV(m_pvPrefix + "badAsics", "badAsics");
120 registerEpicsPV(m_pvPrefix + "badPMTs", "badPMTs");
121 registerEpicsPV(m_pvPrefix + "numExcludedBS", "numExcludedBS");
122 registerEpicsPV(m_pvPrefix + "histoAlarmState", "histoAlarmState"); // to pass overall state to central alarm overview panel
123
124 // Epics used to get limits from configuration file - override module parameters (input only)
125
126 registerEpicsPV(m_pvPrefix + "asicWindowsBand", "asicWindowsBand");
127 registerEpicsPV(m_pvPrefix + "asicWindowsAlarmLevels", "asicWindowsAlarmLevels");
128 registerEpicsPV(m_pvPrefix + "eventMonitorAlarmLevels", "eventMonitorAlarmLevels");
129 registerEpicsPV(m_pvPrefix + "unpackerErrAlarmLevels", "unpackerErrAlarmLevels");
130 registerEpicsPV(m_pvPrefix + "junkHitsAlarmLevels", "junkHitsAlarmLevels");
131 registerEpicsPV(m_pvPrefix + "deadChannelsAlarmLevels", "deadChannelsAlarmLevels");
132 registerEpicsPV(m_pvPrefix + "backgroundAlarmLevels", "backgroundAlarmLevels"); // also output
133 registerEpicsPV(m_pvPrefix + "photonYieldsAlarmLevels", "photonYieldsAlarmLevels");
134 registerEpicsPV(m_pvPrefix + "excludedBoardstacks", "excludedBoardstacks");
135
136 registerEpicsPV(m_pvPrefix + "injectionBGAlarmLevels", "injectionBGAlarmLevels"); // also output
137 registerEpicsPV(m_pvPrefix + "timingAlarmLevels", "timingAlarmLevels");
138 registerEpicsPV(m_pvPrefix + "eventT0MeanAlarmLevels", "eventT0MeanAlarmLevels");
139 registerEpicsPV(m_pvPrefix + "eventT0RmsAlarmLevels", "eventT0RmsAlarmLevels");
140 registerEpicsPV(m_pvPrefix + "offsetMeanAlarmLevels", "offsetMeanAlarmLevels");
141 registerEpicsPV(m_pvPrefix + "offsetRmsAlarmLevels", "offsetRmsAlarmLevels");
142
143 // new canvases, histograms and graphic primitives
144
145 gROOT->cd();
146
147 m_c_photonYields = new TCanvas("TOP/c_photonYields", "c_photonYields");
148 m_c_backgroundRates = new TCanvas("TOP/c_backgroundRates", "c_backgroundRates");
149
150 m_deadFraction = new TH1F("TOP/deadFraction", "Fraction of dead channels in included boardstacks", 16, 0.5, 16.5);
151 m_deadFraction->SetXTitle("slot number");
152 m_deadFraction->SetYTitle("fraction");
153 m_hotFraction = new TH1F("TOP/hotFraction", "Fraction of hot channels in included boardstacks", 16, 0.5, 16.5);
154 m_hotFraction->SetXTitle("slot number");
155 m_hotFraction->SetYTitle("fraction");
156 m_excludedFraction = new TH1F("TOP/excludedFraction", "Fraction of hot and dead channels in excluded bordstacks", 16, 0.5, 16.5);
157 m_excludedFraction->SetXTitle("slot number");
158 m_excludedFraction->SetYTitle("fraction");
159 m_activeFraction = new TH1F("TOP/activeFraction", "Fraction of active channels", 16, 0.5, 16.5);
160 m_activeFraction->SetXTitle("slot number");
161 m_activeFraction->SetYTitle("fraction");
162 m_c_deadAndHot = new TCanvas("TOP/c_deadAndHotChannels", "c_deadAndHotChannels");
163
164 m_junkFraction = new TH1F("TOP/junkFraction", "Fraction of junk hits per boardstack", 64, 1, 17);
165 m_junkFraction->SetXTitle("slot number");
166 m_junkFraction->SetYTitle("fraction");
167 m_junkFraction->GetXaxis()->SetNdivisions(16);
168 m_junkFraction->GetXaxis()->CenterLabels();
169 // note: titles are intentionally the same since this one is plotted first
170 m_excludedBSHisto = new TH1F("TOP/excludedBSHisto", "Fraction of junk hits per boardstack", 64, 1, 17);
171 m_excludedBSHisto->SetXTitle("slot number");
172 m_excludedBSHisto->SetYTitle("fraction");
173 m_excludedBSHisto->GetXaxis()->SetNdivisions(16);
174 m_excludedBSHisto->GetXaxis()->CenterLabels();
175 m_c_junkFraction = new TCanvas("TOP/c_junkFraction", "c_junkFraction");
176
177 for (int slot = 1; slot <= 16; slot++) {
178 string hname = "TOP/pmtHitRates_" + to_string(slot);
179 string htitle = "PMT hits per event for slot #" + to_string(slot);
180 auto* h = new TH1F(hname.c_str(), htitle.c_str(), 32, 0.5, 32.5);
181 h->SetXTitle("PMT number");
182 h->SetYTitle("Number of good hits per event");
183 m_pmtHitRates.push_back(h);
184 string cname = "TOP/c_pmtHitRates_" + to_string(slot);
185 string ctitle = "c_pmtHitRates_" + to_string(slot);
186 m_c_pmtHitRates.push_back(new TCanvas(cname.c_str(), ctitle.c_str()));
187 }
188
189 for (std::string name : {
190 "nhitInjLER", "nhitInjHER", "nhitInjLERcut", "nhitInjHERcut",
191 "eventInjLER", "eventInjHER", "eventInjLERcut", "eventInjHERcut"
192 }) {
193 for (std::string proj : {"_px", "_py"}) {
194 std::string cname = "TOP/c_" + name + proj;
195 m_c_injBGs[cname] = new TCanvas(cname.c_str(), (name + proj).c_str());
196 }
197 }
198
199 m_c_skipProcFlagFract = new TCanvas("TOP/c_skipProcFlagFract", "c_skipProcFlagFract");
200 m_c_injVetoFlagFract = new TCanvas("TOP/c_injVetoFlagFract", "c_injVetoFlagFract");
201
202 m_text1 = new TPaveText(0.125, 0.8, 0.675, 0.88, "NDC");
203 m_text1->SetFillColorAlpha(kWhite, 0);
204 m_text1->SetBorderSize(0);
205 m_text2 = new TPaveText(0.55, 0.8, 0.85, 0.89, "NDC");
206 m_text2->SetFillColorAlpha(kWhite, 0);
207 m_text2->SetBorderSize(0);
208 m_text3 = new TPaveText(0.47, 0.8, 0.85, 0.89, "NDC");
209 m_text3->SetFillColorAlpha(kWhite, 0);
210 m_text3->SetBorderSize(0);
211 m_text4 = new TPaveText(0.125, 0.8, 0.675, 0.88, "NDC");
212 m_text4->SetFillColorAlpha(kWhite, 0);
213 m_text4->SetBorderSize(0);
214
216
217 B2DEBUG(20, "DQMHistAnalysisTOP: initialized.");
218}
219
220
222{
223 m_mirabelleVariables.clear();
224
225 B2DEBUG(20, "DQMHistAnalysisTOP: beginRun called.");
226}
227
228
230{
231 // get type of the run (TODO: to be replaced with base class function when fixed)
232 auto* rtype = findHist("DQMInfo/rtype");
233 m_runType = rtype ? rtype->GetTitle() : "";
234 m_IsNullRun = (m_runType == "null");
235
236 // get number of events processed with TOPDQM module
237 auto* goodHitsPerEvent = findHist("TOP/goodHitsPerEventAll");
238 m_numEvents = goodHitsPerEvent ? goodHitsPerEvent->GetEntries() : 0;
239
240 bool zeroSupp = gStyle->GetHistMinimumZero();
241 gStyle->SetHistMinimumZero(true);
242
243 // update alarm levels and other parameters from EpicsPVs
244 updateLimits();
245
246 // reset overall alarm state
247 m_alarmStateOverall = c_Gray;
248
249 // Update window_vs_slot canvas w/ alarming
251
252 // Update event desynchronization monitor w/ alarming
254
255 // Update unpacker errors w/ alarming
257
258 // Update number of good hits per event w/ alarming (injection BG)
260
261 // Update event T0 w/ alarming
263
264 // Update bunch offset w/ alarming
266
267 // Fraction of dead and hot channels
268 const auto* activeFraction = makeDeadAndHotFractionsPlot();
269
270 // Photon yields and background rates, corrected for dead and hot channels
271 makePhotonYieldsAndBGRatePlots(activeFraction);
272
273 // Fractions of junk hits
275
276 // Set z-axis range to 3 times the average for good hits, 30 times the average for junk hits
277 setZAxisRange("TOP/good_hits_xy_", 3);
278 setZAxisRange("TOP/bad_hits_xy_", 30);
279 setZAxisRange("TOP/good_hits_asics_", 3);
280 setZAxisRange("TOP/bad_hits_asics_", 30);
281
282 // Background subtracted time distributions (only for physics runs)
283 if (m_runType == "physics") {
284 const auto* trackHits = static_cast<TH2F*>(findHist("TOP/trackHits"));
285 makeBGSubtractedTimingPlot("goodHitTimes", trackHits, 0);
286 for (int slot = 1; slot <= 16; slot++) {
287 makeBGSubtractedTimingPlot("good_timing_" + to_string(slot), trackHits, slot);
288 }
289 }
290
291 // Update timing plot w/ alarming
293
294 // PMT hit rates
296
297 // Injection BG
299
300 // normalize histogram for injection veto flags check
301 auto* injVetoFlagDiff = static_cast<TH1F*>(findHist("TOP/injVetoFlagDiff"));
302 if (injVetoFlagDiff) injVetoFlagDiff->Scale(1 / injVetoFlagDiff->Integral(), "nosw2");
303
304 // make flag fraction plots
307
308 // set gridx in some canvases
309 setGridX("TOP/c_injVetoFlag");
310 setGridX("TOP/c_skipProcFlag");
311 setGridX("TOP/c_PSBypassMode");
312 setGridX("TOP/c_unpackErr");
313
314 // Set Epics variables
316
317 gStyle->SetHistMinimumZero(zeroSupp);
318}
319
320
322{
323 // add MiraBelle monitoring
324
325 for (const auto& var : m_mirabelleVariables) {
326 m_monObj->setVariable(var.first, var.second);
327 B2DEBUG(20, var.first << " " << var.second);
328 }
329
330 B2DEBUG(20, "DQMHistAnalysisTOP : endRun called");
331}
332
333
335{
336 B2DEBUG(20, "terminate called");
337}
338
339
341{
342 int alarmState = c_Gray;
343 m_text1->Clear();
344
345 auto* hraw = static_cast<TH2F*>(findHist("TOP/window_vs_slot"));
346 if (hraw) {
347 auto* px = hraw->ProjectionX("tmp_px");
348 auto* band = hraw->ProjectionX("TOP/windowFractions", m_asicWindowsBand[0], m_asicWindowsBand[1]);
349 band->Add(px, band, 1, -1);
350 double total = px->Integral();
351 double totalWindowFraction = (total != 0) ? band->Integral() / total : 0;
352 band->Divide(band, px);
353 setMiraBelleVariables("RateBadRaw_slot", band);
354 m_mirabelleVariables["RateBadRaw_all"] = totalWindowFraction;
355 if (total > 0) {
356 alarmState = getAlarmState(totalWindowFraction, m_asicWindowsAlarmLevels);
357 m_text1->AddText(Form("Fraction outside red lines: %.2f %%", totalWindowFraction * 100.0));
358 }
359 delete px;
360 delete band;
361 }
362
363 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
364
365 auto* canvas = findCanvas("TOP/c_window_vs_slot");
366 if (canvas) {
367 canvas->Clear();
368 canvas->cd();
369 if (hraw) hraw->Draw();
370 m_text1->Draw();
371 for (auto* line : m_asicWindowsBandLines) line->Draw();
372 canvas->Pad()->SetFrameFillColor(10);
373 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
374 canvas->Modified();
375 }
376}
377
378
380{
381 int alarmState = c_Gray;
382 m_text2->Clear();
383
384 auto* evtMonitor = static_cast<TH1F*>(findHist("TOP/BoolEvtMonitor"));
385 if (evtMonitor) {
386 double totalEvts = evtMonitor->Integral();
387 double badEvts = evtMonitor->GetBinContent(2);
388 if (totalEvts > 0) {
389 double badRatio = badEvts / totalEvts;
390 alarmState = getAlarmState(badRatio, m_eventMonitorAlarmLevels);
391 m_text2->AddText(Form("Fraction: %.4f %%", badRatio * 100.0));
392 }
393 }
394
395 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
396
397 auto* canvas = findCanvas("TOP/c_BoolEvtMonitor");
398 if (canvas) {
399 canvas->cd();
400 m_text2->Draw();
401 canvas->Pad()->SetFrameFillColor(10);
402 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
403 canvas->Modified();
404 }
405}
406
407
409{
410 int alarmState = c_Gray;
411
412 auto* hist = static_cast<TH1F*>(findHist("TOP/unpackErr"));
413 if (hist) {
414 double hmax = 0;
415 for (int i = 1; i <= hist->GetNbinsX(); i++) {
416 hmax = std::max(hmax, hist->GetBinContent(i) - 3 * hist->GetBinError(i));
417 }
418 alarmState = getAlarmState(hmax, m_unpackerErrAlarmLevels);
419 }
420
421 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
422
423 auto* canvas = findCanvas("TOP/c_unpackErr");
424 if (canvas) {
425 canvas->cd();
426 canvas->Pad()->SetFrameFillColor(10);
427 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
428 canvas->Modified();
429 }
430}
431
432
434{
435 int alarmState = c_Gray;
436 m_text4->Clear();
437
438 double fract = 0;
439 double xcut = 0;
440 double ymax = 0;
441 auto* h = static_cast<TH1F*>(findHist("TOP/goodHitsPerEventAll"));
442 if (h) {
443 double totalEvts = h->GetEntries();
444 if (totalEvts > 1000) {
445 // fraction of events with more than xcut hits - these are mostly containing injection BG
446 xcut = h->GetBinCenter(h->GetMaximumBin()) + 900;
447 ymax = h->GetMaximum() / 2;
448 fract = h->Integral(h->FindBin(xcut), h->GetNbinsX() + 1) / totalEvts * 100; // in %
449 alarmState = getAlarmState(fract, m_injectionBGAlarmLevels);
450 m_text4->AddText(Form("Events w/ Injection BG: %.2f %%", fract));
451 }
452 }
453
454 setEpicsPV("injectionBGAlarmLevels", fract);
455 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
456
457 auto* canvas = findCanvas("TOP/c_goodHitsPerEventAll");
458 if (canvas) {
459 canvas->cd();
460 if (not m_injBGCutLine) {
461 m_injBGCutLine = new TLine(xcut, 0, xcut, ymax);
462 m_injBGCutLine->SetLineWidth(2);
463 m_injBGCutLine->SetLineColor(kRed);
464 m_injBGCutLine->Draw("same");
465 } else {
466 m_injBGCutLine->SetX1(xcut);
467 m_injBGCutLine->SetX2(xcut);
468 m_injBGCutLine->SetY2(ymax);
469 }
470 m_text4->Draw();
471 canvas->Pad()->SetFrameFillColor(10);
472 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
473 canvas->Modified();
474 }
475}
476
477
479{
480 int alarmState = c_Gray;
481
482 auto* h = static_cast<TH1F*>(findHist("TOP/eventT0"));
483 if (h) {
484 double totalEvts = h->GetEntries();
485 if (totalEvts > 100) {
486 double mean = h->GetMean();
487 double rms = h->GetRMS();
488 alarmState = std::max(getAlarmState(fabs(mean), m_eventT0MeanAlarmLevels), getAlarmState(rms, m_eventT0RmsAlarmLevels));
489 }
490 }
491
492 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
493
494 auto* canvas = findCanvas("TOP/c_eventT0");
495 if (canvas) {
496 canvas->cd();
497 canvas->Pad()->SetFrameFillColor(10);
498 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
499 canvas->Modified();
500 }
501}
502
503
505{
506 int alarmState = c_Gray;
507
508 auto* h = static_cast<TH1F*>(findHist("TOP/bunchOffset"));
509 if (h) {
510 double totalEvts = h->GetEntries();
511 if (totalEvts > 100) {
512 double mean = h->GetMean();
513 double rms = h->GetRMS();
514 alarmState = std::max(getAlarmState(fabs(mean), m_offsetMeanAlarmLevels), getAlarmState(rms, m_offsetRmsAlarmLevels));
515 }
516 }
517
518 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
519
520 auto* canvas = findCanvas("TOP/c_bunchOffset");
521 if (canvas) {
522 canvas->cd();
523 canvas->Pad()->SetFrameFillColor(10);
524 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
525 canvas->Modified();
526 }
527}
528
529
531{
532 int alarmState = c_Gray;
533
534 auto* h = static_cast<TH1F*>(findHist("TOP/goodHitTimes"));
535 auto* href = static_cast<TH1F*>(findRefHist("TOP/goodHitTimes"));
536 if (h and href) {
537 double n = h->Integral();
538 double nref = href->Integral();
539 if (n > 0 and nref > 0 and sameHistDefinition(h, href)) {
540 auto* h_clone = static_cast<TH1F*>(h->Clone("tmp"));
541 auto* href_clone = static_cast<TH1F*>(href->Clone("tmpref"));
542 h_clone->Scale(1 / n);
543 href_clone->Scale(1 / nref);
544 h_clone->Add(h_clone, href_clone, 1, -1);
545 double sumDiff = 0;
546 double errDiff = 0;
547 for (int i = 1; i <= h_clone->GetNbinsX(); i++) {
548 sumDiff += fabs(h_clone->GetBinContent(i));
549 errDiff += pow(h_clone->GetBinError(i), 2);
550 }
551 errDiff = sqrt(errDiff);
552 if (sumDiff < 5 * errDiff) sumDiff = 0; // difference not significant
553 alarmState = getAlarmState(sumDiff, m_timingAlarmLevels);
554 delete h_clone;
555 delete href_clone;
556 }
557 }
558
559 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
560
561 auto* canvas = findCanvas("TOP/c_goodHitTimes");
562 if (canvas) {
563 canvas->cd();
564 canvas->Pad()->SetFrameFillColor(10);
565 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
566 canvas->Modified();
567 }
568}
569
571{
572 if (h1->GetNbinsX() != h2->GetNbinsX()) return false;
573 if (h1->GetXaxis()->GetXmin() != h2->GetXaxis()->GetXmin()) return false;
574 if (h1->GetXaxis()->GetXmax() != h2->GetXaxis()->GetXmax()) return false;
575 return true;
576}
577
579{
580 m_deadFraction->Reset();
581 m_hotFraction->Reset();
582 m_excludedFraction->Reset();
583 m_activeFraction->Reset();
584 double inactiveFract = 0; // max inactive channel fraction when some boardstacks are excluded from alarming
585
586 for (int slot = 1; slot <= 16; slot++) {
587 auto* h = static_cast<TH1F*>(findHist("TOP/good_channel_hits_" + std::to_string(slot)));
588 if (not h) continue;
589
590 auto cuts = getDeadAndHotCuts(h);
591 double deadCut = cuts.first;
592 double hotCut = cuts.second;
593 double deadFract = 0;
594 double hotFract = 0;
595 double deadFractIncl = 0;
596 double hotFractIncl = 0;
597 for (int chan = 0; chan < h->GetNbinsX(); chan++) {
598 double y = h->GetBinContent(chan + 1);
599 int bs = chan / 128 + (slot - 1) * 4;
600 bool included = m_includedBoardstacks[bs];
601 if (y <= deadCut) {
602 deadFract += 1;
603 if (included) deadFractIncl += 1;
604 } else if (y > hotCut) {
605 hotFract += 1;
606 if (included) hotFractIncl += 1;
607 }
608 }
609 deadFract /= h->GetNbinsX();
610 hotFract /= h->GetNbinsX();
611 deadFractIncl /= h->GetNbinsX();
612 hotFractIncl /= h->GetNbinsX();
613 m_deadFraction->SetBinContent(slot, deadFractIncl);
614 m_hotFraction->SetBinContent(slot, hotFractIncl);
615 m_excludedFraction->SetBinContent(slot, deadFract - deadFractIncl + hotFract - hotFractIncl);
616 m_activeFraction->SetBinContent(slot, 1 - deadFract - hotFract);
617 inactiveFract = std::max(inactiveFract, deadFractIncl + hotFractIncl);
618 }
619
620 setMiraBelleVariables("ActiveChannelFraction_slot", m_activeFraction);
621
622 int alarmState = c_Gray;
623 if (m_activeFraction->Integral() > 0) {
624 alarmState = getAlarmState(inactiveFract, m_deadChannelsAlarmLevels);
625 }
626
627 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
628
629 m_deadFraction->SetFillColor(1);
630 m_deadFraction->SetLineColor(1);
631 m_deadFraction->GetXaxis()->SetNdivisions(16);
632
633 m_hotFraction->SetFillColor(2);
634 m_hotFraction->SetLineColor(2);
635 m_hotFraction->GetXaxis()->SetNdivisions(16);
636
637 m_excludedFraction->SetFillColor(kGray);
638 m_excludedFraction->SetLineColor(kGray);
639 m_excludedFraction->GetXaxis()->SetNdivisions(16);
640
641 m_activeFraction->SetFillColor(0);
642 m_activeFraction->GetXaxis()->SetNdivisions(16);
643
644 auto* canvas = m_c_deadAndHot;
645 canvas->Clear();
646 canvas->cd();
647 canvas->Pad()->SetFrameFillColor(10);
648 if (not m_stack) {
649 m_stack = new THStack("TOP/stack", "Fraction of dead and hot channels");
654 }
655 m_stack->Draw();
656
657 for (auto* line : m_deadChannelsAlarmLines) line->Draw("same");
658
659 if (not m_legend) {
660 m_legend = new TLegend(0.8, 0.87, 0.99, 0.99);
661 m_legend->AddEntry(m_hotFraction, "hot");
662 m_legend->AddEntry(m_deadFraction, "dead");
663 m_legend->AddEntry(m_excludedFraction, "excluded");
664 }
665 m_legend->Draw("same");
666
667 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
668 canvas->Modified();
669
670 return m_activeFraction;
671}
672
673
675{
676 for (auto* canvas : {m_c_photonYields, m_c_backgroundRates}) {
677 canvas->Clear();
678 canvas->Pad()->SetFrameFillColor(10);
679 canvas->Pad()->SetFillColor(getAlarmColor(c_Gray));
680 canvas->Modified();
681 }
682 m_averageRate = 0;
683
684 auto* signalHits = static_cast<TProfile*>(findHist("TOP/signalHits"));
685 if (not signalHits) return;
686
687 auto* backgroundHits = static_cast<TProfile*>(findHist("TOP/backgroundHits"));
688 if (not backgroundHits) return;
689
690 if (m_photonYields) delete m_photonYields;
691 m_photonYields = signalHits->ProjectionX("TOP/photonYields");
693 m_backgroundRates = backgroundHits->ProjectionX("TOP/backgroundRates");
694 auto* activeFract = static_cast<TH1F*>(activeFraction->Clone("tmp"));
695 for (int i = 1; i <= activeFract->GetNbinsX(); i++) activeFract->SetBinError(i, 0);
696
698 m_photonYields->Divide(m_photonYields, activeFract);
699 setMiraBelleVariables("PhotonsPerTrack_slot", m_photonYields);
700
701 int alarmState = c_Gray;
702 if (signalHits->GetEntries() > 0 and activeFraction->Integral() > 0) {
703 double hmin = 1000;
704 for (int i = 1; i <= m_photonYields->GetNbinsX(); i++) {
705 if (signalHits->GetBinEntries(i) < 10) continue;
706 hmin = std::min(hmin, m_photonYields->GetBinContent(i) + 3 * m_photonYields->GetBinError(i));
707 }
708 if (hmin < 1000) alarmState = getAlarmState(hmin, m_photonYieldsAlarmLevels, false);
709 }
710 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
711
712 m_photonYields->SetTitle("Number of photons per track");
713 m_photonYields->SetYTitle("photons per track");
714 m_photonYields->SetMarkerStyle(24);
715 m_photonYields->GetXaxis()->SetNdivisions(16);
716
717 auto* canvas = m_c_photonYields;
718 canvas->cd();
719 m_photonYields->SetMinimum(0);
720 m_photonYields->Draw();
721 for (auto* line : m_photonYieldsAlarmLines) line->Draw("same");
722 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
723 canvas->Modified();
724
725 m_backgroundRates->Scale(1.0 / 50.0e-3 / 32); // measured in 50 ns window, 32 PMT's ==> rate in MHz/PMT
726 m_backgroundRates->Divide(m_backgroundRates, activeFract);
727 setMiraBelleVariables("BackgroundRate_slot", m_backgroundRates);
728
729 alarmState = c_Gray;
730 m_text3->Clear();
731 if (backgroundHits->GetEntries() > 100 and activeFraction->Integral() > 0) {
732 int status = m_backgroundRates->Fit("pol0", "Q0");
733 if (status == 0) {
734 auto* fun = m_backgroundRates->GetFunction("pol0");
735 if (fun) {
736 m_averageRate = fun->GetParameter(0);
737 double error = fun->GetParError(0);
738 alarmState = getAlarmState(m_averageRate - 3 * error, m_backgroundAlarmLevels);
739 m_text3->AddText(Form("Average: %.2f MHz/PMT", m_averageRate));
740 }
741 }
742 }
743 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
744
745 m_backgroundRates->SetTitle("Background rates");
746 m_backgroundRates->SetYTitle("background rate [MHz/PMT]");
747 m_backgroundRates->SetMarkerStyle(24);
748 m_backgroundRates->GetXaxis()->SetNdivisions(16);
749
750 canvas = m_c_backgroundRates;
751 canvas->cd();
752 m_backgroundRates->SetMinimum(0);
753 m_backgroundRates->Draw();
754 for (auto* line : m_backgroundAlarmLines) line->Draw("same");
755 m_text3->Draw();
756 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
757 canvas->Modified();
758
759 delete activeFract;
760}
761
762
764{
765 m_junkFraction->Reset();
766 m_excludedBSHisto->Reset();
767 auto* allHits = static_cast<TH1D*>(m_junkFraction->Clone("tmp"));
768 for (int slot = 1; slot <= 16; slot++) {
769 auto* good = static_cast<TH1F*>(findHist("TOP/good_channel_hits_" + std::to_string(slot)));
770 if (not good) continue;
771 auto* bad = static_cast<TH1F*>(findHist("TOP/bad_channel_hits_" + std::to_string(slot)));
772 if (not bad) continue;
773 for (int i = 0; i < 512; i++) {
774 int bs = i / 128;
775 allHits->Fill(slot + bs / 4.0, good->GetBinContent(i + 1) + bad->GetBinContent(i + 1));
776 m_junkFraction->Fill(slot + bs / 4.0, bad->GetBinContent(i + 1));
777 }
778 }
779
780 m_junkFraction->Divide(m_junkFraction, allHits, 1, 1, "B");
781
782 int alarmState = c_Gray;
783 if (allHits->Integral() > 0) {
784 double hmax = 0;
785 for (size_t i = 0; i < m_includedBoardstacks.size(); i++) {
786 if (m_includedBoardstacks[i]) hmax = std::max(hmax, m_junkFraction->GetBinContent(i + 1));
787 else m_excludedBSHisto->SetBinContent(i + 1, 1);
788 }
789 alarmState = getAlarmState(hmax, m_junkHitsAlarmLevels);
790 }
791 delete allHits;
792 m_alarmStateOverall = std::max(m_alarmStateOverall, alarmState);
793
794 auto* canvas = m_c_junkFraction;
795 canvas->Clear();
796 canvas->cd();
797 canvas->SetGridx();
798 canvas->Pad()->SetFrameFillColor(10);
799 canvas->Pad()->SetFillColor(getAlarmColor(alarmState));
800 m_excludedBSHisto->SetFillColor(kGray);
801 m_excludedBSHisto->SetLineColor(kGray);
802 m_excludedBSHisto->GetYaxis()->SetRangeUser(0, 1);
803 m_excludedBSHisto->Draw();
804 m_junkFraction->SetMarkerStyle(24);
805 // m_junkFraction->GetYaxis()->SetRangeUser(0, 1); // Note: m_junkFraction->GetMaximum() will now give 1 and not the histogram maximum!
806 m_junkFraction->Draw("same");
807 for (auto* line : m_junkHitsAlarmLines) line->Draw("same");
808 canvas->Modified();
809}
810
811
812void DQMHistAnalysisTOPModule::setZAxisRange(const std::string& name, double scale)
813{
814 double totalHits = 0;
815 std::vector<TH2F*> histos;
816 for (int slot = 1; slot <= 16; slot++) {
817 TH2F* h = static_cast<TH2F*>(findHist(name + std::to_string(slot)));
818 if (not h) continue;
819 histos.push_back(h);
820 totalHits += h->Integral();
821 }
822 if (histos.empty()) return;
823 double average = totalHits / 512 / histos.size(); // per pixel or asic channel
824
825 for (auto* h : histos) h->GetZaxis()->SetRangeUser(0, std::max(average * scale, 1.0));
826}
827
828
829void DQMHistAnalysisTOPModule::makeBGSubtractedTimingPlot(const std::string& name, const TH2F* trackHits, int slot)
830{
831 auto* canvas = findCanvas("TOP/c_" + name);
832 if (not canvas) return;
833
834 auto* h = static_cast<TH1F*>(findHist("TOP/" + name));
835 if (not h) return;
836
837 auto* hb = static_cast<TH1F*>(findHist("TOP/" + name + "BG"));
838 if (not hb) return;
839
840 if (trackHits) {
841 // use the ratio of events w/ and w/o track in the slot to scale the background
842 double s = (slot == 0) ? trackHits->Integral(1, 16, 2, 2) : trackHits->GetBinContent(slot, 2);
843 if (s == 0) return;
844 double sb = (slot == 0) ? trackHits->Integral(1, 16, 1, 1) : trackHits->GetBinContent(slot, 1);
845 if (sb == 0) return;
846 h->Add(h, hb, 1, -s / sb);
847 } else {
848 // use the content of bins at t < 0 to scale the background
849 int i0 = h->GetXaxis()->FindBin(0.); // bin at t = 0
850 double s = h->Integral(1, i0);
851 if (s == 0) return;
852 double sb = hb->Integral(1, i0);
853 if (sb == 0) return;
854 if (s / sb > 1) return; // this can happen due to low statistics and is not reliable
855 h->Add(h, hb, 1, -s / sb);
856 }
857
858 TString title = TString(h->GetTitle()) + " (BG subtracted)";
859 h->SetTitle(title);
860
861 canvas->Clear();
862 canvas->cd();
863 h->Draw();
864 canvas->Modified();
865}
866
867
869{
870 auto* h0 = static_cast<TH1F*>(findHist("TOP/goodHitsPerEventAll"));
871 if (not h0) return;
872 double numEvents = h0->GetEntries();
873 if (numEvents == 0) return;
874
875 int numSlots = m_pmtHitRates.size();
876 for (int slot = 1; slot <= numSlots; slot++) {
877 string name = "TOP/good_hits_xy_" + to_string(slot);
878 auto* hxy = static_cast<TH2F*>(findHist(name));
879 if (not hxy) continue;
880 std::vector<double> pmts(32, 0);
881 for (int row = 0; row < 8; row++) {
882 for (int col = 0; col < 64; col++) {
883 int pmt = col / 4 + (row / 4) * 16;
884 pmts[pmt] += hxy->GetBinContent(col + 1, row + 1);
885 }
886 }
887 auto* h = m_pmtHitRates[slot - 1];
888 for (size_t i = 0; i < pmts.size(); i++) {
889 h->SetBinContent(i + 1, pmts[i] / numEvents);
890 }
891 auto* canvas = m_c_pmtHitRates[slot - 1];
892 canvas->Clear();
893 canvas->cd();
894 h->SetMinimum(0);
895 h->Draw();
896 canvas->Modified();
897 }
898}
899
900
902{
903 for (std::string name : {"nhitInjLER", "nhitInjHER", "nhitInjLERcut", "nhitInjHERcut"}) {
904 std::string hname = "TOP/" + name;
905 auto* h = static_cast<TProfile2D*>(findHist(hname));
906 if (not h) continue;
907 for (std::string proj : {"_px", "_py"}) {
908 std::string cname = "TOP/c_" + name + proj;
909 auto* canvas = m_c_injBGs[cname];
910 if (not canvas) continue;
911 canvas->Clear();
912 canvas->cd();
913 auto& hproj = m_profiles[cname];
914 if (hproj) delete hproj;
915 hproj = (proj == "_px") ? h->ProfileX((hname + proj).c_str()) : h->ProfileY((hname + proj).c_str());
916 std::string xtitle = (proj == "_px") ? h->GetXaxis()->GetTitle() : h->GetYaxis()->GetTitle();
917 hproj->SetXTitle(xtitle.c_str());
918 hproj->SetYTitle(h->GetZaxis()->GetTitle());
919 hproj->SetMinimum(0);
920 hproj->Draw("hist");
921 canvas->Modified();
922 }
923 }
924
925 for (std::string name : {"eventInjLER", "eventInjHER", "eventInjLERcut", "eventInjHERcut"}) {
926 std::string hname = "TOP/" + name;
927 auto* h = static_cast<TH2F*>(findHist(hname));
928 if (not h) continue;
929 for (std::string proj : {"_px", "_py"}) {
930 std::string cname = "TOP/c_" + name + proj;
931 auto* canvas = m_c_injBGs[cname];
932 if (not canvas) continue;
933 canvas->Clear();
934 canvas->cd();
935 auto& hproj = m_projections[cname];
936 if (hproj) delete hproj;
937 hproj = (proj == "_px") ? h->ProjectionX((hname + proj).c_str()) : h->ProjectionY((hname + proj).c_str());
938 std::string xtitle = (proj == "_px") ? h->GetXaxis()->GetTitle() : h->GetYaxis()->GetTitle();
939 hproj->SetXTitle(xtitle.c_str());
940 hproj->SetYTitle(h->GetZaxis()->GetTitle());
941 hproj->SetMinimum(0);
942 hproj->Draw("hist");
943 canvas->Modified();
944 }
945 }
946
947}
948
949void DQMHistAnalysisTOPModule::makeFlagFractPlot(const std::string& hname, TH1* histogram, TCanvas* canvas)
950{
951 if (histogram) delete histogram;
952 auto* h = static_cast<TH2F*>(findHist(hname));
953 if (not h) return;
954
955 histogram = h->ProjectionX((hname + "Fract").c_str(), 2, 2);
956 auto* px = h->ProjectionX("tmp");
957 histogram->Divide(histogram, px, 1, 1, "B");
958 delete px;
959 histogram->SetTitle(TString(h->GetTitle()) + " is set");
960 histogram->SetYTitle("fraction of events");
961 histogram->SetMarkerStyle(24);
962 histogram->SetMinimum(0);
963
964 if (not canvas) return;
965 canvas->Clear();
966 canvas->SetGridx();
967 canvas->cd();
968 histogram->Draw();
969 canvas->Modified();
970}
971
972void DQMHistAnalysisTOPModule::setMiraBelleVariables(const std::string& variableName, const TH1* histogram)
973{
974 for (int slot = 1; slot <= 16; slot++) {
975 auto vname = variableName + std::to_string(slot);
976 double value = histogram ? histogram->GetBinContent(slot) : 0;
977 m_mirabelleVariables[vname] = value;
978 }
979}
980
981
982int DQMHistAnalysisTOPModule::getAlarmState(double value, const std::vector<double>& alarmLevels, bool bigRed) const
983{
984 if (m_IsNullRun or m_numEvents < 1000) return c_Gray;
985
986 if (bigRed) {
987 if (value < alarmLevels[0]) return c_Green;
988 else if (value < alarmLevels[1]) return c_Yellow;
989 else return c_Red;
990 } else {
991 if (value < alarmLevels[0]) return c_Red;
992 else if (value < alarmLevels[1]) return c_Yellow;
993 else return c_Green;
994 }
995}
996
997
998void DQMHistAnalysisTOPModule::setAlarmLines(const std::vector<double>& alarmLevels, double xmin, double xmax,
999 std::vector<TLine*>& alarmLines, bool bigRed)
1000{
1001 std::vector<int> colors = {kOrange, kRed};
1002 if (not bigRed) std::reverse(colors.begin(), colors.end());
1003 for (size_t i = 0; i < std::min(colors.size(), alarmLevels.size()); i++) {
1004 if (i < alarmLines.size()) {
1005 auto* line = alarmLines[i];
1006 line->SetX1(xmin);
1007 line->SetX2(xmax);
1008 line->SetY1(alarmLevels[i]);
1009 line->SetY2(alarmLevels[i]);
1010 } else {
1011 auto* line = new TLine(xmin, alarmLevels[i], xmax, alarmLevels[i]);
1012 line->SetLineWidth(2);
1013 line->SetLineStyle(2);
1014 line->SetLineColor(colors[i]);
1015 alarmLines.push_back(line);
1016 }
1017 }
1018}
1019
1020
1022{
1023 for (size_t i = 0; i < m_asicWindowsBand.size(); i++) {
1024 double y = m_asicWindowsBand[i];
1025 if (i < m_asicWindowsBandLines.size()) {
1026 auto* line = m_asicWindowsBandLines[i];
1027 line->SetY1(y);
1028 line->SetY2(y);
1029 } else {
1030 auto* line = new TLine(0.5, y, 16.5, y);
1031 line->SetLineWidth(2);
1032 line->SetLineColor(kRed);
1033 m_asicWindowsBandLines.push_back(line);
1034 }
1035 }
1036
1041}
1042
1043
1044std::pair<double, double> DQMHistAnalysisTOPModule::getDeadAndHotCuts(const TH1* h)
1045{
1046 std::vector<double> binContents;
1047 for (int k = 1; k <= h->GetNbinsY(); k++) {
1048 for (int i = 1; i <= h->GetNbinsX(); i++) {
1049 binContents.push_back(h->GetBinContent(i, k));
1050 }
1051 }
1052
1053 double mean = 0;
1054 double rms = h->GetMaximum();
1055 for (int iter = 0; iter < 5; iter++) {
1056 double sumy = 0;
1057 double sumyy = 0;
1058 int n = 0;
1059 for (auto y : binContents) {
1060 if (y == 0 or fabs(y - mean) > 3 * rms) continue;
1061 sumy += y;
1062 sumyy += y * y;
1063 n++;
1064 }
1065 if (n == 0) continue;
1066 mean = sumy / n;
1067 rms = sqrt(sumyy / n - mean * mean);
1068 }
1069
1070 return std::make_pair(mean / 5, std::max(mean * 2, mean + 6 * rms));
1071}
1072
1073
1075{
1076 int badBoardstacks = 0;
1077 int badCarriers = 0;
1078 int badAsics = 0;
1079 for (int slot = 1; slot <= 16; slot++) {
1080 std::string hname = "TOP/good_hits_asics_" + to_string(slot);
1081 auto* h = static_cast<TH2F*>(findHist(hname));
1082 if (not h) continue;
1083
1084 auto cuts = getDeadAndHotCuts(h);
1085 double deadCut = cuts.first;
1086 double hotCut = cuts.second;
1087 std::vector<int> asics(64, 0);
1088 std::vector<int> carriers(16, 0);
1089 std::vector<int> boardstacks(4, 0);
1090 for (int asic = 0; asic < 64; asic++) {
1091 int carrier = asic / 4;
1092 int boardstack = carrier / 4;
1093 for (int chan = 0; chan < 8; chan++) {
1094 double y = h->GetBinContent(asic + 1, chan + 1);
1095 if (y > deadCut and y <= hotCut) {
1096 asics[asic]++;
1097 carriers[carrier]++;
1098 boardstacks[boardstack]++;
1099 }
1100 }
1101 }
1102 for (int n : asics) if (n == 0) badAsics++;
1103 for (int n : carriers) if (n == 0) badCarriers++;
1104 for (int n : boardstacks) if (n == 0) badBoardstacks++;
1105 }
1106 badAsics -= badCarriers * 4;
1107 badCarriers -= badBoardstacks * 4;
1108
1109 int badPMTs = 0;
1110 for (int slot = 1; slot <= 16; slot++) {
1111 std::string hname = "TOP/good_hits_xy_" + to_string(slot);
1112 auto* h = static_cast<TH2F*>(findHist(hname));
1113 if (not h) continue;
1114
1115 auto cuts = getDeadAndHotCuts(h);
1116 double deadCut = cuts.first;
1117 double hotCut = cuts.second;
1118 std::vector<int> pmts(32, 0);
1119 for (int row = 0; row < 8; row++) {
1120 for (int col = 0; col < 64; col++) {
1121 double y = h->GetBinContent(col + 1, row + 1);
1122 if (y > deadCut and y <= hotCut) {
1123 int pmt = col / 4 + (row / 4) * 16;
1124 pmts[pmt]++;
1125 }
1126 }
1127 }
1128 for (int n : pmts) if (n == 0) badPMTs++;
1129 }
1130 badPMTs -= badBoardstacks * 8;
1131
1132 setEpicsPV("badBoardstacks", badBoardstacks);
1133 setEpicsPV("badCarriers", badCarriers);
1134 setEpicsPV("badAsics", badAsics);
1135 setEpicsPV("badPMTs", badPMTs);
1136 int numBS = 0;
1137 for (auto included : m_includedBoardstacks) if (not included) numBS++;
1138 setEpicsPV("numExcludedBS", numBS);
1140 setEpicsPV("backgroundAlarmLevels", m_averageRate);
1141
1142 B2DEBUG(20, "badBoardstacks: " << badBoardstacks);
1143 B2DEBUG(20, "badCarriers: " << badCarriers);
1144 B2DEBUG(20, "badAsics: " << badAsics);
1145 B2DEBUG(20, "badPMTs: " << badPMTs);
1146 B2DEBUG(20, "excludedBS: " << numBS);
1147 B2DEBUG(20, "histoAlarmState: " << getOffcialAlarmStatus(m_alarmStateOverall));
1148 B2DEBUG(20, "backgroundAlarmLevels" << m_averageRate);
1149}
1150
1152{
1153 double unused = 0;
1154
1155 double yLo = m_asicWindowsBand[0];
1156 double yHi = m_asicWindowsBand[1];
1157 requestLimitsFromEpicsPVs("asicWindowsBand", yLo, unused, unused, yHi);
1158 m_asicWindowsBand[0] = yLo;
1159 m_asicWindowsBand[1] = yHi;
1160
1161 requestLimitsFromEpicsPVs("asicWindowsAlarmLevels", unused, unused, m_asicWindowsAlarmLevels[0], m_asicWindowsAlarmLevels[1]);
1162 requestLimitsFromEpicsPVs("eventMonitorAlarmLevels", unused, unused, m_eventMonitorAlarmLevels[0], m_eventMonitorAlarmLevels[1]);
1163 requestLimitsFromEpicsPVs("unpackerErrAlarmLevels", unused, unused, m_unpackerErrAlarmLevels[0], m_unpackerErrAlarmLevels[1]);
1164 requestLimitsFromEpicsPVs("junkHitsAlarmLevels", unused, unused, m_junkHitsAlarmLevels[0], m_junkHitsAlarmLevels[1]);
1165 requestLimitsFromEpicsPVs("deadChannelsAlarmLevels", unused, unused, m_deadChannelsAlarmLevels[0], m_deadChannelsAlarmLevels[1]);
1166 requestLimitsFromEpicsPVs("backgroundAlarmLevels", unused, unused, m_backgroundAlarmLevels[0], m_backgroundAlarmLevels[1]);
1167 requestLimitsFromEpicsPVs("photonYieldsAlarmLevels", m_photonYieldsAlarmLevels[0], m_photonYieldsAlarmLevels[1], unused, unused);
1168
1169 requestLimitsFromEpicsPVs("injectionBGAlarmLevels", unused, unused, m_injectionBGAlarmLevels[0], m_injectionBGAlarmLevels[1]);
1170 requestLimitsFromEpicsPVs("timingAlarmLevels", unused, unused, m_timingAlarmLevels[0], m_timingAlarmLevels[1]);
1171 requestLimitsFromEpicsPVs("eventT0MeanAlarmLevels", unused, unused, m_eventT0MeanAlarmLevels[0], m_eventT0MeanAlarmLevels[1]);
1172 requestLimitsFromEpicsPVs("eventT0RmsAlarmLevels", unused, unused, m_eventT0RmsAlarmLevels[0], m_eventT0RmsAlarmLevels[1]);
1173 requestLimitsFromEpicsPVs("offsetMeanAlarmLevels", unused, unused, m_offsetMeanAlarmLevels[0], m_offsetMeanAlarmLevels[1]);
1174 requestLimitsFromEpicsPVs("offsetRmsAlarmLevels", unused, unused, m_offsetRmsAlarmLevels[0], m_offsetRmsAlarmLevels[1]);
1175
1176 setAlarmLines();
1177
1178 bool status = false;
1179 std::string excludedBS = getEpicsStringPV("excludedBoardstacks", status);
1180
1181 if (status) {
1182 m_excludedBoardstacks.clear();
1183 std::string name;
1184 for (auto c : excludedBS) {
1185 if (isspace(c)) continue;
1186 else if (ispunct(c)) {
1187 if (not name.empty()) {
1188 m_excludedBoardstacks.push_back(name);
1189 name.clear();
1190 }
1191 } else name.push_back(c);
1192 }
1193 if (not name.empty()) {
1194 m_excludedBoardstacks.push_back(name);
1195 }
1197 }
1198
1199 B2DEBUG(20, "asicWindowsBand: [" << m_asicWindowsBand[0] << ", " << m_asicWindowsBand[1] << "]");
1200 B2DEBUG(20, "asicWindowsAlarmLevels: [" << m_asicWindowsAlarmLevels[0] << ", " << m_asicWindowsAlarmLevels[1] << "]");
1201 B2DEBUG(20, "eventMonitorAlarmLevels: [" << m_eventMonitorAlarmLevels[0] << ", " << m_eventMonitorAlarmLevels[1] << "]");
1202 B2DEBUG(20, "unpackerErrAlarmLevels: [" << m_unpackerErrAlarmLevels[0] << ", " << m_unpackerErrAlarmLevels[1] << "]");
1203 B2DEBUG(20, "junkHitsAlarmLevels: [" << m_junkHitsAlarmLevels[0] << ", " << m_junkHitsAlarmLevels[1] << "]");
1204 B2DEBUG(20, "deadChannelsAlarmLevels: [" << m_deadChannelsAlarmLevels[0] << ", " << m_deadChannelsAlarmLevels[1] << "]");
1205 B2DEBUG(20, "backgroundAlarmLevels: [" << m_backgroundAlarmLevels[0] << ", " << m_backgroundAlarmLevels[1] << "]");
1206 B2DEBUG(20, "photonYieldsAlarmLevels: [" << m_photonYieldsAlarmLevels[0] << ", " << m_photonYieldsAlarmLevels[1] << "]");
1207
1208 B2DEBUG(20, "injectionBGAlarmLevels: [" << m_injectionBGAlarmLevels[0] << ", " << m_injectionBGAlarmLevels[1] << "]");
1209 B2DEBUG(20, "timingAlarmLevels: [" << m_timingAlarmLevels[0] << ", " << m_timingAlarmLevels[1] << "]");
1210 B2DEBUG(20, "eventT0MeanAlarmLevels: [" << m_eventT0MeanAlarmLevels[0] << ", " << m_eventT0MeanAlarmLevels[1] << "]");
1211 B2DEBUG(20, "eventT0RmsAlarmLevels: [" << m_eventT0RmsAlarmLevels[0] << ", " << m_eventT0RmsAlarmLevels[1] << "]");
1212 B2DEBUG(20, "offsetMeanAlarmLevels: [" << m_offsetMeanAlarmLevels[0] << ", " << m_offsetMeanAlarmLevels[1] << "]");
1213 B2DEBUG(20, "offsetRmsAlarmLevels: [" << m_offsetRmsAlarmLevels[0] << ", " << m_offsetRmsAlarmLevels[1] << "]");
1214
1215 std::string ss;
1216 for (const auto& s : m_excludedBoardstacks) ss += "'" + s + "', ";
1217 if (ss.size() > 2) {ss.pop_back(); ss.pop_back();}
1218 B2DEBUG(20, "excludedBoardstacks: [" << ss << "]");
1219
1220}
1221
1222void DQMHistAnalysisTOPModule::setIncludedBoardstacks(const std::vector<std::string>& excludedBoardstacks)
1223{
1224 m_includedBoardstacks.clear();
1225 m_includedBoardstacks.resize(64, true);
1226
1227 for (const auto& bsname : excludedBoardstacks) {
1228 int id = m_bsmap[bsname];
1229 if (id > 0) m_includedBoardstacks[id - 1] = false;
1230 else B2ERROR("Invalid boardstack name: " << bsname);
1231 }
1232}
1233
1234void DQMHistAnalysisTOPModule::setGridX(const std::string& cname)
1235{
1236 auto* canvas = findCanvas(cname);
1237 if (not canvas) return;
1238 canvas->SetGridx();
1239 canvas->Modified();
1240}
static TCanvas * findCanvas(TString cname)
Find canvas by name.
static TH1 * findRefHist(const std::string &histname, ERefScaling scaling=ERefScaling::c_RefScaleNone, const TH1 *hist=nullptr)
Get referencehistogram from list (no other search).
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.
std::string getEpicsStringPV(const std::string &keyname, bool &status)
Read value from a EPICS PV.
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
void updateEventMonitorCanvas()
Updates canvas of event desynchronization monitor w/ alarming.
TH1D * m_skipProcFlagFract
fraction of events w/ skip processing flag set vs.
std::vector< int > m_asicWindowsBand
lower and upper bin of a band denoting good windows
static void setZAxisRange(const std::string &name, double scale)
Sets z-axis range of 2D histograms.
TCanvas * m_c_photonYields
Canvas: photon yields per slot.
std::vector< double > m_offsetRmsAlarmLevels
alarm levels for r.m.s.
void initialize() override final
Initializer.
void makePMTHitRatesPlots()
Makes plots of the number of PMT hits per event.
TH1F * m_excludedFraction
fraction of dead and hot channels per slot in excluded boardstacks only
void updateEventT0Canvas()
Updates canvas of event T0 w/ alarming.
std::vector< double > m_deadChannelsAlarmLevels
alarm levels for the fraction of dead + hot channels
std::vector< double > m_asicWindowsAlarmLevels
alarm levels for fraction of windows outside the band
TPaveText * m_text2
text to be written to event desynchonization monitor
TCanvas * m_c_junkFraction
Canvas: fraction of junk hits per boardstack.
THStack * m_stack
stack for drawing dead, hot and active channel fractions
const TH1F * makeDeadAndHotFractionsPlot()
Makes a plot of dead and hot channel fractions per slot.
static void makeBGSubtractedTimingPlot(const std::string &name, const TH2F *trackHits, int slot)
Makes background subtracted time distribution plot.
void updateTimingCanvas()
Updates canvas of timing plot w/ alarming.
void updateUnpackerErrCanvas()
Updates canvas of unpacker errors w/ alarming.
TPaveText * m_text3
text to be written to background rates
std::vector< TLine * > m_deadChannelsAlarmLines
lines representing alarm levels
std::vector< TCanvas * > m_c_pmtHitRates
Canvases of PMT hits per event (index = slot - 1)
int m_alarmStateOverall
overall alarm state of histograms to be sent by EpicsPV
TPaveText * m_text1
text to be written to window_vs_slot
std::vector< TLine * > m_photonYieldsAlarmLines
lines representing alarm levels
static std::pair< double, double > getDeadAndHotCuts(const TH1 *h)
Returns cut levels for dead and hot channels.
std::vector< double > m_offsetMeanAlarmLevels
alarm levels for mean of bunch offset [ns]
std::vector< bool > m_includedBoardstacks
boardstacks included in alarming
static bool sameHistDefinition(TH1 *h1, TH1 *h2)
Checks if histograms are defined in the same way (nbins, xmin, xmax)
TPaveText * m_text4
text to be written to number of good hits per event
std::string m_pvPrefix
Epics PV prefix.
TH1D * m_photonYields
photon yields per slot
TH1D * m_backgroundRates
background rates per slot
MonitoringObject * m_monObj
MiraBelle monitoring object.
TCanvas * m_c_backgroundRates
Canvas: background rates per slot.
std::map< std::string, TCanvas * > m_c_injBGs
Canvases for projections of injection BG histograms.
std::vector< double > m_eventMonitorAlarmLevels
alarm levels for fraction of desynchronized digits
static void makeFlagFractPlot(const std::string &hname, TH1 *histogram, TCanvas *canvas)
Makes a plot of fraction of events with the flag is set.
void terminate() override final
This method is called at the end of the event processing.
std::map< std::string, double > m_mirabelleVariables
variables for MiraBelle
void setAlarmLines()
Sets all alarm lines.
TH1F * m_activeFraction
fraction of active channels per slot
int getAlarmColor(unsigned alarmState) const
Converts alarm state to color.
std::vector< double > m_eventT0MeanAlarmLevels
alarm levels for mean of event T0 [ns]
void event() override final
This method is called for each event.
void makeInjectionBGPlots()
Makes projections of injection BG plots.
static void setGridX(const std::string &canvasName)
Sets grid x on the canvas.
std::vector< double > m_photonYieldsAlarmLevels
alarm levels for the number of photons per track
TCanvas * m_c_skipProcFlagFract
Canvas: fraction of events w/ skip processing flag set vs.
TCanvas * m_c_injVetoFlagFract
Canvas: fraction of events w/ injection veto flag set vs.
std::vector< TLine * > m_junkHitsAlarmLines
lines representing alarm levels
void setIncludedBoardstacks(const std::vector< std::string > &excludedBoardstacks)
Sets flags for boardstacks to be included in alarming.
std::vector< double > m_injectionBGAlarmLevels
alarm levels for injection background (in % of events)
TH1F * m_deadFraction
fraction of dead channels per slot (included boardstacks only)
double m_averageRate
average BG rate (to pass to EpicsPV)
TH1F * m_hotFraction
fraction of hot channels per slot (included boardstacks only)
std::vector< std::string > m_excludedBoardstacks
list of boarstacks to be excluded from alarming
void makePhotonYieldsAndBGRatePlots(const TH1F *activeFraction)
Make plots of dead-and-hot-channel corrected photon yields and BG rates per slot.
TH1F * m_junkFraction
fraction of junk hits per boardstack
void endRun() override final
This method is called if the current run ends.
int getAlarmState(double value, const std::vector< double > &alarmLevels, bool bigRed=true) const
Returns alarm state.
std::vector< double > m_eventT0RmsAlarmLevels
alarm levels for r.m.s.
std::vector< TLine * > m_asicWindowsBandLines
lines denoting a band of good windows
void makeJunkFractionPlot()
Makes a plot of fractions of junk hits per boardstack.
void beginRun() override final
Called when entering a new run.
TLegend * m_legend
legend for dead and hot channels
TCanvas * m_c_deadAndHot
Canvas: fractin of dead and hot channels.
std::vector< TLine * > m_backgroundAlarmLines
lines representing alarm levels
std::vector< double > m_unpackerErrAlarmLevels
alarm levels for the fraction of unpacker errors
void updateWindowVsSlotCanvas()
Updates canvas of window_vs_slot w/ alarming.
TH1D * m_injVetoFlagFract
fraction of events w/ injection veto flag set vs.
double m_numEvents
number of events processed with TOPDQM module
std::map< std::string, int > m_bsmap
a map of boardstack names to ID's
std::vector< double > m_backgroundAlarmLevels
alarm levels for background rates [MHz/PMT]
std::map< std::string, TH1D * > m_projections
projections of injection BG
void updateBunchOffsetCanvas()
Updates canvas of bunch offset w/ alarming.
void setEpicsVariables()
Calculates and sets epics variables.
std::vector< double > m_junkHitsAlarmLevels
alarm levels for the fraction of junk hits
bool m_IsNullRun
Run type flag for null runs.
void updateNGoodHitsCanvas()
Updates canvas of number of good hits per event w/ alarming (injection BG)
TLine * m_injBGCutLine
a line denoting the cut on the number of hits for injection BG counting
std::vector< double > m_timingAlarmLevels
alarm levels for time distribution (fraction of area difference)
int getOffcialAlarmStatus(unsigned alarmState) const
Converts alarm state to official status (see EStatus of the base class)
std::vector< TH1F * > m_pmtHitRates
histograms of PMT hits per event (index = slot - 1)
TH1F * m_excludedBSHisto
histogram to show excluded boardstacks on junk fraction plot
std::map< std::string, TProfile * > m_profiles
profiles of injection BG
void updateLimits()
Updates limits defined by module parameters using EpicsPVs.
void setMiraBelleVariables(const std::string &variableName, const TH1 *histogram)
Sets MiraBelle variables from the histogram with bins corresponding to slot numbers.
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
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28
Abstract base class for different kinds of events.
STL namespace.