Belle II Software development
DQMHistAnalysisSVDUnpacker.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 : DQMHistAnalysisSVDUnpacker.cc
10// Description : module for DQM histogram analysis of SVD unpacker fromat error
11//-
12
13
14#include <dqm/analysis/modules/DQMHistAnalysisSVDUnpacker.h>
15#include <vxd/geometry/GeoCache.h>
16
17#include <TROOT.h>
18#include <TStyle.h>
19#include <TString.h>
20#include <TAxis.h>
21
22#include <TMath.h>
23#include <iostream>
24
25using namespace std;
26using namespace Belle2;
27
28//-----------------------------------------------------------------
29// Register the Module
30//-----------------------------------------------------------------
31REG_MODULE(DQMHistAnalysisSVDUnpacker);
32
33//-----------------------------------------------------------------
34// Implementation
35//-----------------------------------------------------------------
36
39{
40 //Parameter definition
41 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: Constructor done.");
42
43 setDescription("DQM Analysis Module that produces colored canvas for a straightforward interpretation of the SVD Data Quality.");
44
45 addParam("unpackerErrorLevel", m_unpackError, "Maximum bin_content/ # events allowed before throwing ERROR", double(0.00001));
46 addParam("printCanvas", m_printCanvas, "if True prints pdf of the analysis canvas", bool(false));
47 addParam("samples3", m_3Samples, "if True 3 samples histograms analysis is performed", bool(false));
48 addParam("PVPrefix", m_pvPrefix, "PV Prefix", std::string("SVD:"));
49}
50
52
54{
55 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: initialized.");
56
57 m_legError = new TPaveText(-1, 54, 3, 57.5, "br");
58 m_legError->AddText("ERROR!!");
59 m_legError->SetFillColor(c_ColorError);
60 m_legError->SetTextColor(c_ColorDefault);
61
62
63 gROOT->cd();
64 m_cUnpacker = new TCanvas("SVDAnalysis/c_SVDDataFormat");
65 m_cUnpacker->SetGrid(1);
66
67 //register limits for EPICS
68 registerEpicsPV(m_pvPrefix + "UnpackError", "UnpackError");
69}
70
71
73{
74 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: beginRun called.");
75 m_cUnpacker->Clear();
76
77 //Retrieve limits from EPICS
78
79 double unpackWarnLo = 0.;
80 double unpackWarnUp = 0.;
81 double unpackErrorLo = 0.;
82 requestLimitsFromEpicsPVs("UnpackError", unpackErrorLo, unpackWarnLo, unpackWarnUp, m_unpackError);
83 B2DEBUG(10, " SVD unpack error threshold taken from EPICS configuration file:");
84 B2DEBUG(10, " DATA UNPACK: error > " << m_unpackError);
85}
86
88{
89 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: event called.");
90
91 //find nEvents
92 TH1* hnEvnts = findHist("SVDExpReco/SVDDQM_nEvents", true);
93 if (hnEvnts == NULL) {
94 B2INFO("no events, nothing to do here");
95 return;
96 } else {
97 B2DEBUG(10, "SVDExpReco/SVDDQM_nEvents found");
98 }
99
100 TH1* rtype = findHist("DQMInfo/rtype");
101 if (rtype)
102 B2DEBUG(10, "DQMInfo/rtype found");
103
104 m_runtype = rtype ? rtype->GetTitle() : "physics"; // per default
105
106 TString tmp = hnEvnts->GetTitle();
107 Int_t pos = tmp.Last('~');
108 if (pos == -1) pos = 0;
109
110 TString runID = tmp(pos, tmp.Length() - pos);
111 B2INFO("DQMHistAnalysisSVDUnpackerModule::runID = " << runID);
112 Float_t nEvents = hnEvnts->GetEntries();
113
114 //check DATA FORMAT
115 TH1* h = findHist("SVDUnpacker/DQMUnpackerHisto");
116
117 //test ERROR:
118 // h->SetBinContent(100,0.01);
119
120 if (h != NULL) {
121 h->SetTitle(Form("SVD Data Format Monitor %s", runID.Data()));
122 //check if number of errors is above the allowed limit
123 bool hasError = false;
124 for (int un = 0; un < h->GetNcells(); un++)
125 if (h->GetBinContent(un) / nEvents > m_unpackError)
126 hasError = true;
127 if (! hasError) {
128 m_cUnpacker->cd();
129 h->Draw("colztext");
130 h->SetStats(0);
132 } else {
133 m_cUnpacker->cd();
134 h->Draw("colztext");
135 h->SetStats(0);
136 m_legError->Draw();
138 }
139 if (nEvents > 0)
140 setEpicsPV("UnpackError", h->GetEntries() / nEvents);
141 } else {
142 B2INFO("Histogram SVDUnpacker/DQMUnpackerHisto from SVDUnpackerDQM not found!");
143 m_cUnpacker->cd();
145 }
146
147 m_cUnpacker->Modified();
148 m_cUnpacker->Update();
149
150 if (m_printCanvas)
151 m_cUnpacker->Print("c_SVDDataFormat.pdf");
152
153}
154
156{
157 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: endRun called");
158}
159
160
162{
163 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: terminate called");
164
165 delete m_cUnpacker;
166
167 delete m_legError;
168
169}
The base class for the histogram analysis module.
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).
@ c_ColorError
Analysis result: Severe issue found.
@ c_ColorDefault
default for non-coloring
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
@ c_StatusDefault
default for non-coloring
@ c_StatusError
Analysis result: Severe issue found.
@ c_StatusGood
Analysis result: Good.
int registerEpicsPV(std::string pvname, std::string keyname="")
EPICS related Functions.
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
void initialize() override final
Initializer.
TString m_runtype
string with runtype: physics or cosmic
std::string m_pvPrefix
string prefix for EPICS PVs
void terminate() override final
This method is called at the end of the event processing.
void event() override final
This method is called for each event.
bool m_printCanvas
if true print the pdf of the canvases
TCanvas * m_cUnpacker
Parameters accesible from basf2 scripts.
bool m_3Samples
if true enable 3 samples histograms analysis
void endRun() override final
This method is called if the current run ends.
void beginRun() override final
Called when entering a new run.
Double_t m_unpackError
Maximum bin_content/ # events allowed before throwing ERROR.
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.
STL namespace.