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 //check data errors
89 auto hErr = findHist("SVDUnpacker/DQMErrorEventsHisto");
90
91 Float_t ratio = 0;
92
93 if (hErr != NULL) {
94 Float_t events = hErr->GetBinContent(1) + hErr->GetBinContent(2);
95 Float_t errors = hErr->GetBinContent(2);
96
97 if (events > 0) {
98 ratio = errors / events;
99 setEpicsPV("UnpackError", ratio);
100 }
101 } else {
102 B2INFO("Histogram SVDUnpacker/DQMErrorEventsHisto from SVDUnpackerDQM not found!");
103 return;
104 }
105
106 TString tmp = hErr->GetTitle();
107 Int_t pos = tmp.Last('~');
108 Int_t pos1 = tmp.Last('#');
109 if (pos == -1) pos = 0;
110 if (pos1 == -1) pos1 = 0;
111
112 TString runID = tmp(pos, pos1 - pos);
113 B2INFO("DQMHistAnalysisSVDUnpackerModule::runID = " << runID);
114
115 //check DATA FORMAT
116 auto h = findHist("SVDUnpacker/DQMUnpackerHisto");
117
118 if (h != NULL) {
119 bool hasError = false;
120
121 h->SetTitle(Form("SVD Data Format Monitor %s", runID.Data()));
122
123 if (ratio > m_unpackError)
124 hasError = true;
125
126 if (!hasError) {
127 m_cUnpacker->cd();
128 h->Draw("colztext");
129 h->SetStats(0);
131 } else {
132 m_cUnpacker->cd();
133 h->Draw("colztext");
134 h->SetStats(0);
136 }
137 } else {
138 B2INFO("Histogram SVDUnpacker/DQMUnpackerHisto from SVDUnpackerDQM not found!");
139 m_cUnpacker->cd();
142 }
143
144 if (m_printCanvas)
145 m_cUnpacker->Print("c_SVDDataFormat.pdf");
146}
147
149{
150 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: endRun called");
151}
152
153
155{
156 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: terminate called");
157
158 delete m_cUnpacker;
159}
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.