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_legProblem->Clear();
58 m_legProblem->AddText("ERROR!!");
59
60 gROOT->cd();
61 m_cUnpacker = new TCanvas("SVDAnalysis/c_SVDDataFormat");
62 m_cUnpacker->SetGrid(1);
63
64 //register limits for EPICS
65 registerEpicsPV(m_pvPrefix + "UnpackError", "UnpackError");
66}
67
68
70{
71 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: beginRun called.");
72 m_cUnpacker->Clear();
73
74 //Retrieve limits from EPICS
75
76 double unpackWarnLo = 0.;
77 double unpackWarnUp = 0.;
78 double unpackErrorLo = 0.;
79 requestLimitsFromEpicsPVs("UnpackError", unpackErrorLo, unpackWarnLo, unpackWarnUp, m_unpackError);
80 B2DEBUG(10, " SVD unpack error threshold taken from EPICS configuration file:");
81 B2DEBUG(10, " DATA UNPACK: error > " << m_unpackError);
82}
83
85{
86 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: event called.");
87
88 //find nEvents
89 TH1* hnEvnts = findHist("SVDExpReco/SVDDQM_nEvents", true);
90 if (hnEvnts == NULL) {
91 B2INFO("no events, nothing to do here");
92 return;
93 } else {
94 B2DEBUG(10, "SVDExpReco/SVDDQM_nEvents found");
95 }
96
97 TString tmp = hnEvnts->GetTitle();
98 Int_t pos = tmp.Last('~');
99 if (pos == -1) pos = 0;
100
101 TString runID = tmp(pos, tmp.Length() - pos);
102 B2INFO("DQMHistAnalysisSVDUnpackerModule::runID = " << runID);
103 Float_t nEvents = hnEvnts->GetEntries();
104
105 //check DATA FORMAT
106 auto h = findHist("SVDUnpacker/DQMUnpackerHisto");
107
108 if (h != NULL) {
109 h->SetTitle(Form("SVD Data Format Monitor %s", runID.Data()));
110 //check if number of errors is above the allowed limit
111 Int_t nXbins = h->GetXaxis()->GetNbins();
112 Int_t nYbins = h->GetYaxis()->GetNbins();
113
114 //test ERROR:
115// h->SetBinContent(10, 20, 1000000);
116// h->SetBinContent(10, 40, 10000000);
117
118 Float_t maxCnts = 0;
119 bool hasError = false;
120 for (int i = 0; i < nXbins - 1; ++i) { // exclude SEU recovery
121 for (int j = 0; j < nYbins; ++j) {
122 Float_t counts = h->GetBinContent(i + 1, j + 1);
123 if (counts > maxCnts)
124 maxCnts = counts;
125
126 if (counts / nEvents > m_unpackError) {
127 hasError = true;
128 }
129 }
130 }
131
132 if (!hasError) {
133 m_cUnpacker->cd();
134 h->Draw("colztext");
135 h->SetStats(0);
137 } else {
138 m_cUnpacker->cd();
139 h->Draw("colztext");
140 h->SetStats(0);
142 }
143 if (nEvents > 0)
144 setEpicsPV("UnpackError", maxCnts / nEvents);
145 } else {
146 B2INFO("Histogram SVDUnpacker/DQMUnpackerHisto from SVDUnpackerDQM not found!");
147 m_cUnpacker->cd();
150 }
151
152 if (m_printCanvas)
153 m_cUnpacker->Print("c_SVDDataFormat.pdf");
154
155}
156
158{
159 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: endRun called");
160}
161
162
164{
165 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: terminate called");
166
167 delete m_cUnpacker;
168}
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).
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
@ c_StatusDefault
default for non-coloring
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.
DQMHistAnalysisSVDModule(bool panelTop=false, bool online=false)
Constructor.
void setStatusOfCanvas(int status, TCanvas *canvas, bool plotLeg=true, bool online=false)
set status of Canvas
TPaveText * m_legProblem
plot legend, problem
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: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.
STL namespace.