Belle II Software  release-08-01-10
DQMHistAnalysisPXDReduction.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 : DQMHistAnalysisPXDReduction.cc
10 // Description : Analysis of PXD Reduction
11 //-
12 
13 
14 #include <dqm/analysis/modules/DQMHistAnalysisPXDReduction.h>
15 #include <TROOT.h>
16 #include <TLatex.h>
17 #include <vxd/geometry/GeoCache.h>
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 //-----------------------------------------------------------------
23 // Register the Module
24 //-----------------------------------------------------------------
25 REG_MODULE(DQMHistAnalysisPXDReduction);
26 
27 //-----------------------------------------------------------------
28 // Implementation
29 //-----------------------------------------------------------------
30 
31 DQMHistAnalysisPXDReductionModule::DQMHistAnalysisPXDReductionModule()
33 {
34  // This module CAN NOT be run in parallel!
35  setDescription("PXD DQM analysis module for ONSEN Data Reduction Monitoring");
36 
37  // Parameter definition
38  addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of Histogram dir", std::string("PXDDAQ"));
39  addParam("lowarnlimit", m_lowarnlimit, "Mean Reduction Low Warn limit for alarms", 0.99);
40  addParam("LowErrorlimit", m_loerrorlimit, "Mean Reduction Low limit for alarms", 0.90);
41  addParam("HighWarnlimit", m_hiwarnlimit, "Mean Reduction High Warn limit for alarms", 1.01);
42  addParam("HighErrorlimit", m_hierrorlimit, "Mean Reduction High limit for alarms", 1.10);
43  addParam("minEntries", m_minEntries, "minimum number of new entries for last time slot", 1000);
44  addParam("excluded", m_excluded, "excluded module (indizes starting from 0 to 39)");
45  B2DEBUG(1, "DQMHistAnalysisPXDReduction: Constructor done.");
46 }
47 
49 {
50 }
51 
53 {
54  B2DEBUG(1, "DQMHistAnalysisPXDReduction: initialized.");
55 
58 
59  //collect the list of all PXD Modules in the geometry here
60  std::vector<VxdID> sensors = geo.getListOfSensors();
61  for (VxdID& aVxdID : sensors) {
62  VXD::SensorInfoBase info = geo.getSensorInfo(aVxdID);
63  if (info.getType() != VXD::SensorInfoBase::PXD) continue;
64  m_PXDModules.push_back(aVxdID); // reorder, sort would be better
65  }
66  std::sort(m_PXDModules.begin(), m_PXDModules.end()); // back to natural order
67 
68  gROOT->cd(); // this seems to be important, or strange things happen
69 
70  if (m_PXDModules.size() == 0) {
71  // Backup if no geometry is present (testing...)
72  B2WARNING("No PXDModules in Geometry found! Use hard-coded setup.");
73  std::vector <string> mod = {
74  "1.1.1", "1.1.2", "1.2.1", "1.2.2", "1.3.1", "1.3.2", "1.4.1", "1.4.2",
75  "1.5.1", "1.5.2", "1.6.1", "1.6.2", "1.7.1", "1.7.2", "1.8.1", "1.8.2",
76  "2.1.1", "2.1.2", "2.2.1", "2.2.2", "2.3.1", "2.3.2", "2.4.1", "2.4.2",
77  "2.5.1", "2.5.2", "2.6.1", "2.6.2", "2.7.1", "2.7.2", "2.8.1", "2.8.2",
78  "2.9.1", "2.9.2", "2.10.1", "2.10.2", "2.11.1", "2.11.2", "2.12.1", "2.12.2"
79  };
80  for (auto& it : mod) m_PXDModules.push_back(VxdID(it));
81  }
82 
83  m_cReduction = new TCanvas((m_histogramDirectoryName + "/c_Reduction").data());
84  m_hReduction = new TH1F("hPXDReduction", "PXD Reduction; Module; Reduction", m_PXDModules.size(), 0, m_PXDModules.size());
85  m_hReduction->SetDirectory(0);// dont mess with it, this is MY histogram
86  m_hReduction->SetStats(false);
87  for (unsigned int i = 0; i < m_PXDModules.size(); i++) {
88  TString ModuleName = (std::string)m_PXDModules[i];
89  m_hReduction->GetXaxis()->SetBinLabel(i + 1, ModuleName);
91  "PXDDAQDHEDataReduction_" + (std::string)m_PXDModules[i])) addDeltaPar(m_histogramDirectoryName,
92  "PXDDAQDHEDataReduction_" + (std::string)m_PXDModules[i], HistDelta::c_Entries, m_minEntries,
93  1); // register delta
94  }
95  //Unfortunately this only changes the labels, but can't fill the bins by the VxdIDs
96  m_hReduction->Draw("");
98 
100  m_line1 = new TLine(0, 10, m_PXDModules.size(), 10);
101 // m_line2 = new TLine(0, 16, m_PXDModules.size(), 16);
102 // m_line3 = new TLine(0, 3, m_PXDModules.size(), 3);
103  m_line1->SetHorizontal(true);
104  m_line1->SetLineColor(3);// Green
105  m_line1->SetLineWidth(3);
106 // m_line2->SetHorizontal(true);
107 // m_line2->SetLineColor(1);// Black
108 // m_line2->SetLineWidth(3);
109 // m_line3->SetHorizontal(true);
110 // m_line3->SetLineColor(1);
111 // m_line3->SetLineWidth(3);
112 
113  registerEpicsPV("PXD:Red:Status", "Status");
114  registerEpicsPV("PXD:Red:Value", "Value");
115 }
116 
117 
119 {
120  B2DEBUG(1, "DQMHistAnalysisPXDReduction: beginRun called.");
121 
122  m_cReduction->Clear();
123  m_hReduction->Reset(); // dont sum up!!!
124 
126 }
127 
129 {
130  if (!m_cReduction) return;
131 
132  double ireduction = 0.0;
133  int ireductioncnt = 0;
134 
135  bool anyupdate = false;
136  for (unsigned int i = 0; i < m_PXDModules.size(); i++) {
137  std::string name = "PXDDAQDHEDataReduction_" + (std::string)m_PXDModules[i ];
138  // std::replace( name.begin(), name.end(), '.', '_');
139 
140  TH1* hh1 = getDelta(m_histogramDirectoryName, name);
141  // no inital sampling, we should get lenty of statistics
142  if (hh1) {
143  auto mean = hh1->GetMean();
144  m_hReduction->SetBinContent(i + 1, mean);
145  anyupdate = true;
146  }
147  }
148 
149  if (!anyupdate) return; // nothing new -> no update
150 
151  // calculate the mean of the mean
152  for (unsigned int i = 0; i < m_PXDModules.size(); i++) {
153  // ignore modules in exclude list
154  if (std::find(m_excluded.begin(), m_excluded.end(), i) != m_excluded.end()) continue;
155  auto mean = m_hReduction->GetBinContent(i + 1);
156  if (mean > 0) { // onyl for valid values
157  ireduction += mean; // well fit would be better
158  ireductioncnt++;
159  }
160  }
161 
162  m_cReduction->cd();
163 
164  double value = ireductioncnt > 0 ? ireduction / ireductioncnt : 0;
165 
166  int status = 0;
167 // not enough Entries
168  if (ireductioncnt < 15) { // still have to see how to handle masked modules
169  status = 0; // Grey
170  m_cReduction->Pad()->SetFillColor(kGray);// Magenta or Gray
171  } else {
172  if (value > m_hierrorlimit || value < m_loerrorlimit) {
173  m_cReduction->Pad()->SetFillColor(kRed);// Red
174  status = 4;
175  } else if (value > m_hiwarnlimit || value < m_lowarnlimit) {
176  m_cReduction->Pad()->SetFillColor(kYellow);// Yellow
177  status = 3;
178  } else {
179  m_cReduction->Pad()->SetFillColor(kGreen);// Green
180  status = 2;
181 // } else {
182 // we wont use white anymore here
183 // m_cReduction->Pad()->SetFillColor(kWhite);// White
184 // status = 1; // White
185  }
186  }
187 
188  if (m_hReduction) {
189  m_hReduction->Draw("");
190  if (status != 0) {
191  m_line1->SetY1(value);
192  m_line1->SetY2(value); // aka SetHorizontal
193  m_line1->Draw();
194  }
195 // m_line2->Draw();
196 // m_line3->Draw();
197  for (auto& it : m_excluded) {
198  auto tt = new TLatex(it + 0.5, 0, (" " + std::string(m_PXDModules[it]) + " Module is excluded, please ignore").c_str());
199  tt->SetTextSize(0.035);
200  tt->SetTextAngle(90);// Rotated
201  tt->SetTextAlign(12);// Centered
202  tt->Draw();
203  }
204  }
205 
206  m_monObj->setVariable("reduction", value);
207 
209  m_cReduction->Modified();
210  m_cReduction->Update();
211 
212  // better only update if statistics is reasonable, we dont want "0" drops between runs!
213  setEpicsPV("Status", status);
214  setEpicsPV("Value", value);
215 }
216 
218 {
219  B2DEBUG(1, "DQMHistAnalysisPXDReduction: terminate called");
220 }
221 
The base class for the histogram analysis module.
bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
int registerEpicsPV(std::string pvname, std::string keyname="", bool update_pvs=true)
EPICS related Functions.
void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
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)
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
void terminate(void) override final
This method is called at the end of the event processing.
TH1F * m_hReduction
Histogram covering all modules.
void initialize(void) override final
Initializer.
MonitoringObject * m_monObj
Monitoring Object.
std::vector< VxdID > m_PXDModules
IDs of all PXD Modules to iterate over.
std::string m_histogramDirectoryName
name of histogram directory
TLine * m_line1
Line in the Canvas to guide the eye.
std::vector< int > m_excluded
Indizes of excluded PXD Modules.
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 setVariable(const std::string &var, float val, float upErr=-1., float dwErr=-1)
set value to float variable (new variable is made if not yet existing)
void addCanvas(TCanvas *canv)
Add Canvas to monitoring object.
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
const std::vector< VxdID > getListOfSensors() const
Get list of all sensors.
Definition: GeoCache.cc:59
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:67
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
Base class to provide Sensor Information for PXD and SVD.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
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.