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