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{
53 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: initialized.");
54
55 m_legProblem->Clear();
56 m_legProblem->AddText("ERROR!!");
57
58 gROOT->cd();
59 m_cUnpacker = new TCanvas("SVDAnalysis/c_SVDDataFormat");
60 m_cUnpacker->SetGrid(1);
61
62 //register limits for EPICS
63 registerEpicsPV(m_pvPrefix + "UnpackError", "UnpackError");
64}
65
66
68{
69 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: beginRun called.");
70 m_cUnpacker->Clear();
71
72 //Retrieve limits from EPICS
73
74 double unpackWarnLo = 0.;
75 double unpackWarnUp = 0.;
76 double unpackErrorLo = 0.;
77 requestLimitsFromEpicsPVs("UnpackError", unpackErrorLo, unpackWarnLo, unpackWarnUp, m_unpackError);
78 B2DEBUG(10, " SVD unpack error threshold taken from EPICS configuration file:");
79 B2DEBUG(10, " DATA UNPACK: error > " << m_unpackError);
80}
81
83{
84 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: event called.");
85
86 //check data errors
87 auto hErr = findHist("SVDUnpacker/DQMErrorEventsHisto");
88
89 Float_t ratio = 0;
90
91 if (hErr != NULL) {
92 Float_t events = hErr->GetBinContent(1) + hErr->GetBinContent(2);
93 Float_t errors = hErr->GetBinContent(2);
94
95 if (events > 0) {
96 ratio = errors / events;
97 setEpicsPV("UnpackError", ratio);
98 }
99 } else {
100 B2INFO("Histogram SVDUnpacker/DQMErrorEventsHisto from SVDUnpackerDQM not found!");
101 return;
102 }
103
104 TString tmp = hErr->GetTitle();
105 Int_t pos = tmp.Last('~');
106 Int_t pos1 = tmp.Last('#');
107 if (pos == -1) pos = 0;
108 if (pos1 == -1) pos1 = 0;
109
110 TString runID = tmp(pos, pos1 - pos);
111 B2INFO("DQMHistAnalysisSVDUnpackerModule::runID = " << runID);
112
113 //check DATA FORMAT
114 auto h = findHist("SVDUnpacker/DQMUnpackerHisto");
115
116 if (h != NULL) {
117 bool hasError = false;
118
119 h->SetTitle(Form("SVD Data Format Monitor %s", runID.Data()));
120
121 if (ratio > m_unpackError)
122 hasError = true;
123
124 if (!hasError) {
125 m_cUnpacker->cd();
126 h->Draw("colztext");
127 h->SetStats(0);
129 } else {
130 m_cUnpacker->cd();
131 h->Draw("colztext");
132 h->SetStats(0);
134 }
135 } else {
136 B2INFO("Histogram SVDUnpacker/DQMUnpackerHisto from SVDUnpackerDQM not found!");
137 m_cUnpacker->cd();
140 }
141
142 if (m_printCanvas)
143 m_cUnpacker->Print("c_SVDDataFormat.pdf");
144}
145
147{
148 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: endRun called");
149}
150
151
153{
154 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: terminate called");
155
156 delete m_cUnpacker;
157}
int registerEpicsPV(const std::string &pvname, const std::string &keyname="")
EPICS related Functions.
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).
@ c_StatusDefault
default for non-coloring
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
TPaveText * m_legProblem
plot legend, problem
DQMHistAnalysisSVDModule(bool panelTop=false, bool online=false, bool groupIDs=false)
Constructor.
void setStatusOfCanvas(int status, TCanvas *canvas, bool plotLeg=true, int histoType=kOffline)
set status of Canvas
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.