Belle II Software development
DQMHistAnalysisPXDBow.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#include <dqm/analysis/modules/DQMHistAnalysisPXDBow.h>
10
11#include <tracking/dbobjects/ROICalculationParameters.h>
12#include <vxd/geometry/GeoCache.h>
13
14using namespace Belle2;
15
16//-----------------------------------------------------------------
17// Register the Module
18//-----------------------------------------------------------------
19REG_MODULE(DQMHistAnalysisPXDBow);
20
21//-----------------------------------------------------------------
22// Implementation
23//-----------------------------------------------------------------
24
27{
28 setDescription("DQMHistAnalysisModule to monitor the PXD bowing");
29
31 addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where the histogram is placed",
32 std::string("PXDBow/"));
33 addParam("moduleName", m_moduleName,
34 "Layer_ladder_sensor numbers of the module which residual histogram will be plotted on the DQM, if empty all histogram are plotted",
35 std::string(""));
36 addParam("statThreshold", m_statThreshold,
37 "minimum number of entries needed to calculate the mean in the delta distribution of the sagitta",
39 addParam("sagittaThreshold", m_sagittaThreshold,
40 "threshold for the warning related to the sagitta",
42 addParam("sagittaErrorThreshold", m_sagittaErrorThreshold,
43 "threshold for the error related to the sagitta",
45 addParam("roiThreshold", m_roiThreshold,
46 "threshold for the warning related to the roi",
48 B2DEBUG(20, "DQMHistAnalysisPXDBow: Constructor done.");
49}
50
51
53{
54 B2DEBUG(20, "DQMHistAnalysisPXDBow: initialized.");
55
57
59 std::vector<VxdID> sensors = geo.getListOfSensors();
60 int validModule = 0;
61 for (VxdID& aVxdID : sensors) {
62 VXD::SensorInfoBase info = geo.getSensorInfo(aVxdID);
63 if (info.getType() != VXD::SensorInfoBase::PXD || aVxdID.getSensorNumber() != 1) continue;
64 m_PXDModules.push_back(aVxdID);
65
66 auto buff = (std::string)aVxdID;
67 replace(buff.begin(), buff.end(), '.', '_');
69 if (!hasDeltaPar(m_histogramDirectoryName, "resV_" + buff))
70 addDeltaPar(m_histogramDirectoryName, "resV_" + buff, HistDelta::c_Entries, m_statThreshold, 1);
71 if (!hasDeltaPar(m_histogramDirectoryName, "sagitta_" + buff))
72 addDeltaPar(m_histogramDirectoryName, "sagitta_" + buff, HistDelta::c_Entries, m_statThreshold, 1);
74 registerEpicsPV("PXD:meanResV:" + buff, "meanResV:" + (std::string)aVxdID);
75 registerEpicsPV("PXD:sigmaResV:" + buff, "sigmaResV:" + (std::string)aVxdID);
76 registerEpicsPV("PXD:sagitta:" + buff, "sagitta:" + (std::string)aVxdID);
77 if (VxdID(m_moduleName) == aVxdID) {
78 validModule++;
79 }
80 }
81
82 if (m_PXDModules.size() == 0) {
83 B2WARNING("No PXDModules in Geometry found!");
84 }
85
86 if (validModule == 0 and m_moduleName != "") {
87 B2WARNING("Invalid moduleName, only empty value or PXD forward modules (eg \"2.2.1\") are acceptable, nameModule parameter set to default (empty)");
88 m_moduleName = "";
89 }
90 if (m_moduleName == "") {
91 B2INFO("Plotting the histogram for all forward sensors");
92 for (VxdID& aPXDModule : m_PXDModules) {
93 auto buff = (std::string)aPXDModule;
94 replace(buff.begin(), buff.end(), '.', '_');
95 m_cResV[buff] = new TCanvas((m_histogramDirectoryName + std::string("c_resV_") + buff).c_str());
96 }
97 } else {
98 B2INFO("Plotting histogram for module " << m_moduleName);
99 auto buff = m_moduleName;
100 replace(buff.begin(), buff.end(), '.', '_');
101 m_cResV[buff] = new TCanvas((m_histogramDirectoryName + std::string("c_resV_") + buff).c_str());
102 }
103
104
105}
106
108{
109 B2DEBUG(20, "DQMHistAnalysisPXDBow : beginRun called");
110
111 for (auto& pair : m_cResV) {
112 pair.second->Clear();
113 }
114
117 if (!roiParams.isValid()) B2WARNING("Cannot get roi parameters, ROI v half size defined as default (0.1 cm)");
118 else m_roiThreshold = roiParams->getSigmaSystV() * roiParams->getNumSigmaTotV() / 2;
119}
120
122{
123 for (VxdID& aPXDModule : m_PXDModules) {
124 auto buff = (std::string)aPXDModule;
125 std::replace(buff.begin(), buff.end(), '.', '_');
126
127 TH1* hV = getDelta(m_histogramDirectoryName + "resV_" + buff, 0, true);
128 TH1* hS = getDelta(m_histogramDirectoryName + "sagitta_" + buff, true);
129 if (hS != NULL && hV != NULL) {
130 bool enough = false, warnflag = false, errorflag = false;
131 B2DEBUG(20, "Histos sagitta" << buff << " and resV_" << buff << " found");
132 if (hS->GetEntries() > m_statThreshold) {
133 enough = true;
134
136 double meanResV = hV->GetMean();
137 double stdResV = hV->GetStdDev();
138 double resV = std::abs(meanResV) + 3 * stdResV;
139 double bowAmplitude = hS->GetMean();
140
141 if (std::abs(bowAmplitude) > m_sagittaErrorThreshold) errorflag = true;
142 else if (resV > m_roiThreshold
143 || std::abs(bowAmplitude) > m_sagittaThreshold) warnflag = true;
144
145 setEpicsPV("meanResV:" + buff, meanResV);
146 setEpicsPV("stdResV:" + buff, stdResV);
147 setEpicsPV("sagitta:" + buff, bowAmplitude);
148 } else
149 enough = false;
150
151 if (m_moduleName == "" or aPXDModule == VxdID(m_moduleName)) {
152 plotCanvas(enough, errorflag, warnflag, buff);
153 }
154 } else B2DEBUG(20, "Histo sagitta/resV_" << buff << " not found");
155 }
156}
157
158void DQMHistAnalysisPXDBowModule::plotCanvas(bool enough, bool errorflag, bool warnflag, std::string buff)
159{
160 TH1* h = findHist(m_histogramDirectoryName + "resV_" + buff, true);
161 if (h != NULL) {
162 m_hResV[buff].Clear();
163 h->Copy(m_hResV[buff]);
164 m_hResV[buff].SetName((std::string("ResV_") + buff).c_str());
165 m_hResV[buff].SetTitle((std::string("v residuals ") + buff).c_str());
166 m_cResV[buff]->Clear();
167 m_cResV[buff]->cd();
168 m_hResV[buff].Draw();
169 EStatus status = makeStatus(enough, errorflag, warnflag);
170 colorizeCanvas(m_cResV[buff], status);
171 }
172}
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing objects in the database.
Definition DBObjPtr.h:21
static bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
int registerEpicsPV(const std::string &pvname, const std::string &keyname="")
EPICS related Functions.
static void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static void colorizeCanvas(TCanvas *canvas, EStatus status)
Helper function for Canvas colorization.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
DQMHistAnalysisModule()
Constructor / Destructor.
EStatus
Status flag of histogram/canvas.
static EStatus makeStatus(bool enough, bool warn_flag, bool error_flag)
Helper function to judge the status for coloring and EPICS.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
float m_statThreshold
Threshold values for statistic flag on the plotted histograms.
void initialize() override final
Initializer.
float m_sagittaThreshold
Threshold values for warning flag on the sagitta.
void event() override final
This method is called for each event.
std::map< std::string, TCanvas * > m_cResV
Data members.
std::vector< VxdID > m_PXDModules
vector for the IDs of all forward PXD Modules to iterate over
std::string m_histogramDirectoryName
Parameters accessible from basf2 scripts.
std::string m_moduleName
name of the module which distribution will be plotted on the dqm, if empty all forward modules will b...
void beginRun() override final
Called when entering a new run.
std::map< std::string, TH1F > m_hResV
The final histograms.
float m_roiThreshold
Threshold values for warning flag on the resV, the value is related on the dimesion of the ROI.
void plotCanvas(bool enough, bool errorflag, bool warnflag, std::string buff)
Plot the histogram of the module with ID buff and colorize the canvas using the stat,...
float m_sagittaErrorThreshold
Threshold values for error flag on the sagitta.
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Class to facilitate easy access to sensor information of the VXD like coordinate transformations or p...
Definition GeoCache.h:38
const std::vector< VxdID > getListOfSensors() const
Get list of all sensors.
Definition GeoCache.cc:59
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a reference 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:32
STL class.
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.