Belle II Software  release-08-01-10
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 #include <TPaveText.h>
17 
18 using namespace std;
19 using namespace Belle2;
20 
21 //-----------------------------------------------------------------
22 // Register the Module
23 //-----------------------------------------------------------------
24 REG_MODULE(DQMHistAnalysisRunNr);
25 
26 //-----------------------------------------------------------------
27 // Implementation
28 //-----------------------------------------------------------------
29 
30 DQMHistAnalysisRunNrModule::DQMHistAnalysisRunNrModule()
32 {
33  // This module CAN NOT be run in parallel!
34  setDescription("DQM Analysis for RunNr/Mixing Check");
35 
36  //Parameter definition
37  addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of Histogram dir", std::string("DAQ"));
38  addParam("Prefix", m_prefix, "Prefix HLT or ERECO");
39 
40  B2DEBUG(99, "DQMHistAnalysisRunNr: Constructor done.");
41 }
42 
44 {
45 }
46 
48 {
50 
51  gROOT->cd(); // this seems to be important, or strange things happen
52 
53  m_cRunNr = new TCanvas((m_histogramDirectoryName + "/c_RunNr").data());
54 
55  // m_monObj->addCanvas(m_cRunNr);// useful?
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  auto leg = new TPaveText(0.6, 0.6, 0.95, 0.95, "NDC");
70  leg->SetFillColor(kWhite);
71  leg->AddText("No data yet");
72  leg->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 leg = new TPaveText(0.6, 0.6, 0.95, 0.95, "NDC");
87  leg->SetFillColor(kWhite);
88 
89  auto name = "hRunnr";
90  auto hist = findHist(m_histogramDirectoryName, name, true); // only if updated
91  if (hist) {
92  double mean = 0.0; // must be double, mean of histogram -> runnr
93  int status = c_StatusTooFew; // must be int, epics alarm status 0 = no data, 2 = o.k., 4 = not o.k.
94  m_cRunNr->Clear();
95  m_cRunNr->cd();
96  hist->SetStats(kFALSE); // get rid of annoying box, we have our own
97  hist->Draw("hist");
98  mean = hist->GetMean();
99  if (hist->GetEntries() > 0) {
100  leg->AddText("Contains Run: Entries");
101  // loop over bins and check if more than one is used
102  int nfilled = 0;
103  for (int i = 0; i <= hist->GetXaxis()->GetNbins() + 1; i++) {
104  // resizeable histogram, thus there should never be under or overflow. still we loop over them
105  if (hist->GetBinContent(i) > 0) {
106  nfilled++;
107  TString tmp;
108  tmp.Form("%ld: %ld", (long int)hist->GetXaxis()->GetBinCenter(i), (long int)hist->GetBinContent(i));
109  leg->AddText(tmp);
110  }
111  }
112  // Check number of bins filled
113  if (nfilled > 1) {
114  // problem
115  status = c_StatusError;
116  } else if (nfilled == 1) {
117  // ok
118  status = c_StatusGood;
119  }// else nfilled=0, status stays 0 (no data)
120  }
121 
122  if (status == c_StatusTooFew) {
123  // no data (empty) or no histogram
124  m_cRunNr->Pad()->SetFillColor(c_ColorTooFew);// Magenta or Gray
125  leg->AddText("No data yet");
126  } else if (status == c_StatusGood) {
127  // only one run
128  m_cRunNr->Pad()->SetFillColor(c_ColorGood);// Green
129  } else { /*if ( status==4 )*/
130  // anything else is bad
131  m_cRunNr->Pad()->SetFillColor(c_ColorError);// Red
132  }
133 
134  leg->Draw();
135 
136  m_cRunNr->Modified();
137  m_cRunNr->Update();
139 
140  setEpicsPV("Alarm", status);
141  setEpicsPV("RunNr", mean);
142  }
143 }
144 
146 {
147  B2DEBUG(99, "DQMHistAnalysisRunNr: terminate called");
148 }
149 
The base class for the histogram analysis module.
int registerEpicsPV(std::string pvname, std::string keyname="", bool update_pvs=true)
EPICS related Functions.
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.
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
static MonitoringObject * getMonitoringObject(const std::string &histname)
Get MonitoringObject with given name (new object is created if non-existing)
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.