Belle II Software  release-08-00-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 
69  // make sure we reset at run start to retrigger the alarm
70  double mean = 0.0; // must be double, mean of histogram -> runnr
71  int status = 0; // must be int, epics alarm status 0 = no data, 2 = o.k., 4 = not o.k.
72  // if status & runnr valid
73  setEpicsPV("Alarm", status);
74  setEpicsPV("RunNr", mean);
75 }
76 
78 {
79  if (!m_cRunNr) return;
80  double mean = 0.0; // must be double, mean of histogram -> runnr
81  int status = 0; // must be int, epics alarm status 0 = no data, 2 = o.k., 4 = not o.k.
82 
83  m_cRunNr->cd();
84  m_cRunNr->Clear();
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  TH1* hh1 = findHist(name);
91  if (hh1 == NULL) {
93  }
94  if (hh1) {
95  hh1->SetStats(kFALSE); // get rid of annoying box, we have our own
96  hh1->Draw("hist");
97  mean = hh1->GetMean();
98  if (hh1->GetEntries() > 0) {
99  leg->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 <= hh1->GetXaxis()->GetNbins() + 1; i++) {
103  // resizeable histogram, thus there should never be under or overflow. still we loop over them
104  if (hh1->GetBinContent(i) > 0) {
105  nfilled++;
106  TString tmp;
107  tmp.Form("%ld: %ld", (long int)hh1->GetXaxis()->GetBinCenter(i), (long int)hh1->GetBinContent(i));
108  leg->AddText(tmp);
109  }
110  }
111  // Check number of bins filled
112  if (nfilled > 1) {
113  // problem
114  status = 4;
115  } else if (nfilled == 1) {
116  // ok
117  status = 2;
118  }// else nfilled=0, status stays 0 (no data)
119  }
120  }
121 
122  if (status == 0) {
123  // no data (empty) or no histogram
124  m_cRunNr->Pad()->SetFillColor(kGray);// Magenta or Gray
125  leg->AddText("No data yet");
126  } else if (status == 2) {
127  // only one run
128  m_cRunNr->Pad()->SetFillColor(kGreen);// Green
129  } else { /*if ( status==4 )*/
130  // anything else is bad
131  m_cRunNr->Pad()->SetFillColor(kRed);// Red
132  }
133 
134  leg->Draw();
135 
136  m_cRunNr->Modified();
137  m_cRunNr->Update();
138 
139  setEpicsPV("Alarm", status);
140  setEpicsPV("RunNr", mean);
141 }
142 
144 {
145  B2DEBUG(99, "DQMHistAnalysisRunNr: terminate called");
146 }
147 
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).
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
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.