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{
45
46 gROOT->cd(); // this seems to be important, or strange things happen
47
48 m_cRunNr = new TCanvas((m_histogramDirectoryName + "/c_RunNr").data());
49
50 // m_monObj->addCanvas(m_cRunNr);// useful?
51 m_legend = new TPaveText(0.6, 0.6, 0.95, 0.95, "NDC");
52
53 registerEpicsPV("DAQ:" + m_prefix + ":RunNr:RunNr", "RunNr");
54 registerEpicsPV("DAQ:" + m_prefix + ":RunNr:Alarm", "Alarm");
55
56 B2DEBUG(99, "DQMHistAnalysisRunNr: initialized.");
57}
58
60{
61 B2DEBUG(99, "DQMHistAnalysisRunNr: beginRun called.");
62
63 m_cRunNr->Clear();
64 m_cRunNr->Pad()->SetFillColor(c_ColorTooFew);// Magenta or Gray
65 m_legend->Clear();
66 m_legend->SetFillColor(kWhite);
67 m_legend->AddText("No data yet");
68 m_legend->Draw();
69
70 // make sure we reset at run start to retrigger the alarm
71 double mean = 0.0; // must be double, mean of histogram -> runnr
72 int status = 0; // must be int, epics alarm status 0 = no data, 2 = o.k., 4 = not o.k.
73 // if status & runnr valid
74 setEpicsPV("Alarm", status); // reset alarm status at run start
75 setEpicsPV("RunNr", mean);
76}
77
79{
80 if (!m_cRunNr) return;
81
82 auto name = "hRunnr";
83 auto hist = findHist(m_histogramDirectoryName, name, true); // only if updated
84 if (hist) {
85 double mean = 0.0; // must be double, mean of histogram -> runnr
86 int status = c_StatusTooFew; // must be int, epics alarm status 0 = no data, 2 = o.k., 4 = not o.k.
87 m_cRunNr->Clear();
88 m_cRunNr->cd();
89 m_legend->Clear();
90 m_legend->SetFillColor(kWhite);
91 hist->SetStats(kFALSE); // get rid of annoying box, we have our own
92 hist->Draw("hist");
93 mean = hist->GetMean();
94 if (hist->GetEntries() > 0) {
95 m_legend->AddText("Contains Run: Entries");
96 // loop over bins and check if more than one is used
97 int nfilled = 0;
98 for (int i = 0; i <= hist->GetXaxis()->GetNbins() + 1; i++) {
99 // resizeable histogram, thus there should never be under or overflow. still we loop over them
100 if (hist->GetBinContent(i) > 0) {
101 nfilled++;
102 TString tmp;
103 tmp.Form("%ld: %ld", (long int)hist->GetXaxis()->GetBinCenter(i), (long int)hist->GetBinContent(i));
104 m_legend->AddText(tmp);
105 }
106 }
107 // Check number of bins filled
108 if (nfilled > 1) {
109 // problem
110 status = c_StatusError;
111 } else if (nfilled == 1) {
112 // ok
113 status = c_StatusGood;
114 }// else nfilled=0, status stays 0 (no data)
115 }
116
117 if (status == c_StatusTooFew) {
118 // no data (empty) or no histogram
119 m_cRunNr->Pad()->SetFillColor(c_ColorTooFew);// Magenta or Gray
120 m_legend->AddText("No data yet");
121 } else if (status == c_StatusGood) {
122 // only one run
123 m_cRunNr->Pad()->SetFillColor(c_ColorGood);// Green
124 } else { /*if ( status==4 )*/
125 // anything else is bad
126 m_cRunNr->Pad()->SetFillColor(c_ColorError);// Red
127 }
128
129 m_legend->Draw();
130
131 m_cRunNr->Modified();
132 m_cRunNr->Update();
134
135 setEpicsPV("Alarm", status);
136 setEpicsPV("RunNr", mean);
137 }
138}
139
141{
142 B2DEBUG(99, "DQMHistAnalysisRunNr: terminate called");
143 if (m_cRunNr) delete m_cRunNr;
144 if (m_legend) delete m_legend;
145}
146
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).
@ c_ColorError
Analysis result: Severe issue found.
@ c_ColorTooFew
Not enough entries/event to judge.
@ c_ColorGood
Analysis result: Good.
static void UpdateCanvas(const std::string &name, bool updated=true)
Mark canvas as updated (or not)
DQMHistAnalysisModule()
Constructor / Destructor.
@ c_StatusTooFew
Not enough entries/event to judge.
@ c_StatusError
Analysis result: Severe issue found.
@ c_StatusGood
Analysis result: Good.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
STL namespace.