Belle II Software  release-08-01-10
DQMHistAnalysisIP.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 : DQMHistAnalysisIP.cc
10 // Description : Mean for IP position with delta histogramming
11 //-
12 
13 
14 #include <dqm/analysis/modules/DQMHistAnalysisIP.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(DQMHistAnalysisIP);
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
28 DQMHistAnalysisIPModule::DQMHistAnalysisIPModule()
30 {
31  // This module CAN NOT be run in parallel!
32  setDescription("Modify and analyze the data quality histograms of IP Monitoring");
33 
34  //Parameter definition
35  addParam("HistoName", m_histoName, "Name of Histogram (excl dir)", std::string(""));
36  addParam("HistoDirectory", m_histoDirectory, "Name of Histogram dir", std::string(""));
37  addParam("PVName", m_pvPrefix, "PV Prefix and Name", std::string("DQM:TEST:hist:"));
38  addParam("MonitorPrefix", m_monPrefix, "Monitor Prefix");// force to be set!
39  addParam("minEntries", m_minEntries, "minimum number of new Entries for a fit", 1000);
40  B2DEBUG(20, "DQMHistAnalysisIP: Constructor done.");
41 }
42 
44 {
45  B2DEBUG(20, "DQMHistAnalysisIP: initialized.");
46 
48 
49  // register delta
51 
52  // prefer to change canvas name to monitorPrefix, but then changes on the web gui are needed :-(
53  m_c1 = new TCanvas((m_histoDirectory + "/" + m_histoName + "_fit").data());
54 
55  m_line = new TLine(0, 10, 0, 0);
56  m_line->SetVertical(true);
57  m_line->SetLineColor(8);
58  m_line->SetLineWidth(3);
59  m_line2 = new TLine(0, 10, 0, 0);
60  m_line2->SetVertical(true);
61  m_line2->SetLineColor(9);
62  m_line2->SetLineWidth(3);
63 
65 
66  registerEpicsPV(m_pvPrefix + "Mean", "Mean");
67  registerEpicsPV(m_pvPrefix + "RMS", "RMS");
68  registerEpicsPV(m_pvPrefix + "Median", "Median");
69  updateEpicsPVs(5.0);
70 }
71 
72 
74 {
75  B2DEBUG(20, "DQMHistAnalysisIP: beginRun called.");
76  m_c1->Clear();
77 }
78 
80 {
81  auto delta = getDelta(m_histoDirectory, m_histoName);
82  // do not care about initial filling handling. we wont show or update unless we reach the min req entries
83  UpdateCanvas(m_c1->GetName(), delta != nullptr);
84  if (delta != nullptr) {
85  m_c1->Clear();
86  m_c1->cd();// necessary!
87  delta->Draw("hist");
88  // we modify the current delta histogram, that is bad habit
89  // but as long as no one else uses it, it may be o.k.
90  // for more severe changes, maybe better work on a clone?
91  delta->ResetStats(); // kills the Mean from filling, now only use bin values excl over/underflow
92  double x = delta->GetMean();// must be double bc of EPICS below
93  double w = delta->GetRMS();// must be double bc of EPICS below
94  double q = 0.5; // array size one for quantiles
95  double m = 0; // array of size 1 for result = median
96  delta->ComputeIntegral(); // precaution
97  delta->GetQuantiles(1, &m, &q);
98  double y1 = delta->GetMaximum();
99  double y2 = delta->GetMinimum();
100  B2DEBUG(20, "Fit " << x << "," << w << "," << y1 << "," << y2);
101  m_line->SetY1(y1 + (y1 - y2) * 0.05);
102  m_line->SetX1(x);
103  m_line->SetX2(x);
104  m_line2->SetY1(y1 + (y1 - y2) * 0.05);
105  m_line2->SetX1(m);
106  m_line2->SetX2(m);
107  delta->GetXaxis()->SetRangeUser(x - 3 * w, x + 3 * w);
108  m_line->Draw();
109  m_line2->Draw();
110  m_c1->Modified();
111  m_c1->Update();
112 
113  m_monObj->setVariable(m_monPrefix + "_median", m);
114  m_monObj->setVariable(m_monPrefix + "_mean", x);
115  m_monObj->setVariable(m_monPrefix + "_width", w);
116 
117  B2DEBUG(20, "Now update Epics PVs");
118  setEpicsPV("Mean", x);
119  setEpicsPV("RMS", w);
120  setEpicsPV("Median", m);
121  updateEpicsPVs(5.0);
122  }
123 }
int m_minEntries
Update entry interval.
void initialize() override final
Initializer.
std::string m_histoName
The name of the histogram.
std::string m_pvPrefix
The prefix of PV.
MonitoringObject * m_monObj
Monitoring Object.
std::string m_monPrefix
The prefix for MonitoringObj.
void event() override final
This method is called for each event.
TCanvas * m_c1
The drawing canvas.
void beginRun() override final
Called when entering a new run.
TLine * m_line
The line for the mean result.
std::string m_histoDirectory
The name of the histogram dir.
TLine * m_line2
The line for the median result.
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)
int updateEpicsPVs(float timeout)
Update all EPICS PV (flush to network)
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.
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.