Belle II Software development
DQMHistAnalysisRunNr.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8//+
9// File : DQMHistAnalysisRunNr.cc
10// Description : DQM Analysis for RunNr Check
11//-
12
13
14#include <dqm/analysis/modules/DQMHistAnalysisRunNr.h>
15#include <TROOT.h>
16
17using namespace std;
18using namespace Belle2;
19
20//-----------------------------------------------------------------
21// Register the Module
22//-----------------------------------------------------------------
23REG_MODULE(DQMHistAnalysisRunNr);
24
25//-----------------------------------------------------------------
26// Implementation
27//-----------------------------------------------------------------
28
31{
32 // This module CAN NOT be run in parallel!
33 setDescription("DQM Analysis for RunNr/Mixing Check");
34
35 //Parameter definition
36 addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of Histogram dir", std::string("DAQ"));
37 addParam("Prefix", m_prefix, "Prefix HLT or ERECO");
38
39 B2DEBUG(99, "DQMHistAnalysisRunNr: Constructor done.");
40}
41
43{
44}
45
47{
49
50 gROOT->cd(); // this seems to be important, or strange things happen
51
52 m_cRunNr = new TCanvas((m_histogramDirectoryName + "/c_RunNr").data());
53
54 // m_monObj->addCanvas(m_cRunNr);// useful?
55 m_legend = new TPaveText(0.6, 0.6, 0.95, 0.95, "NDC");
56
57 registerEpicsPV("DAQ:" + m_prefix + ":RunNr:RunNr", "RunNr");
58 registerEpicsPV("DAQ:" + m_prefix + ":RunNr:Alarm", "Alarm");
59
60 B2DEBUG(99, "DQMHistAnalysisRunNr: initialized.");
61}
62
64{
65 B2DEBUG(99, "DQMHistAnalysisRunNr: beginRun called.");
66
67 m_cRunNr->Clear();
68 m_cRunNr->Pad()->SetFillColor(c_ColorTooFew);// Magenta or Gray
69 m_legend->Clear();
70 m_legend->SetFillColor(kWhite);
71 m_legend->AddText("No data yet");
72 m_legend->Draw();
73
74 // make sure we reset at run start to retrigger the alarm
75 double mean = 0.0; // must be double, mean of histogram -> runnr
76 int status = 0; // must be int, epics alarm status 0 = no data, 2 = o.k., 4 = not o.k.
77 // if status & runnr valid
78 setEpicsPV("Alarm", status); // reset alarm status at run start
79 setEpicsPV("RunNr", mean);
80}
81
83{
84 if (!m_cRunNr) return;
85
86 auto name = "hRunnr";
87 auto hist = findHist(m_histogramDirectoryName, name, true); // only if updated
88 if (hist) {
89 double mean = 0.0; // must be double, mean of histogram -> runnr
90 int status = c_StatusTooFew; // must be int, epics alarm status 0 = no data, 2 = o.k., 4 = not o.k.
91 m_cRunNr->Clear();
92 m_cRunNr->cd();
93 m_legend->Clear();
94 m_legend->SetFillColor(kWhite);
95 hist->SetStats(kFALSE); // get rid of annoying box, we have our own
96 hist->Draw("hist");
97 mean = hist->GetMean();
98 if (hist->GetEntries() > 0) {
99 m_legend->AddText("Contains Run: Entries");
100 // loop over bins and check if more than one is used
101 int nfilled = 0;
102 for (int i = 0; i <= hist->GetXaxis()->GetNbins() + 1; i++) {
103 // resizeable histogram, thus there should never be under or overflow. still we loop over them
104 if (hist->GetBinContent(i) > 0) {
105 nfilled++;
106 TString tmp;
107 tmp.Form("%ld: %ld", (long int)hist->GetXaxis()->GetBinCenter(i), (long int)hist->GetBinContent(i));
108 m_legend->AddText(tmp);
109 }
110 }
111 // Check number of bins filled
112 if (nfilled > 1) {
113 // problem
114 status = c_StatusError;
115 } else if (nfilled == 1) {
116 // ok
117 status = c_StatusGood;
118 }// else nfilled=0, status stays 0 (no data)
119 }
120
121 if (status == c_StatusTooFew) {
122 // no data (empty) or no histogram
123 m_cRunNr->Pad()->SetFillColor(c_ColorTooFew);// Magenta or Gray
124 m_legend->AddText("No data yet");
125 } else if (status == c_StatusGood) {
126 // only one run
127 m_cRunNr->Pad()->SetFillColor(c_ColorGood);// Green
128 } else { /*if ( status==4 )*/
129 // anything else is bad
130 m_cRunNr->Pad()->SetFillColor(c_ColorError);// Red
131 }
132
133 m_legend->Draw();
134
135 m_cRunNr->Modified();
136 m_cRunNr->Update();
138
139 setEpicsPV("Alarm", status);
140 setEpicsPV("RunNr", mean);
141 }
142}
143
145{
146 B2DEBUG(99, "DQMHistAnalysisRunNr: terminate called");
147 if (m_cRunNr) delete m_cRunNr;
148 if (m_legend) delete m_legend;
149}
150
The base class for the histogram analysis module.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
@ c_ColorError
Analysis result: Severe issue found.
@ c_ColorTooFew
Not enough entries/event to judge.
@ c_ColorGood
Analysis result: Good.
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
@ c_StatusTooFew
Not enough entries/event to judge.
@ c_StatusError
Analysis result: Severe issue found.
@ c_StatusGood
Analysis result: Good.
int registerEpicsPV(std::string pvname, std::string keyname="")
EPICS related Functions.
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
void terminate(void) override final
This method is called at the end of the event processing.
void initialize(void) override final
Initializer.
std::string m_prefix
HLT/ERECO prefix for EPICS PVs.
MonitoringObject * m_monObj
Monitoring Object.
std::string m_histogramDirectoryName
name of histogram directory
void beginRun(void) override final
Called when entering a new run.
void event(void) override final
This method is called for each event.
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.