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 TH1* h = findHist("SVDUnpacker/DQMUnpackerHisto");
107
108 //test ERROR:
109 // h->SetBinContent(100,0.01);
110
111 if (h != NULL) {
112 h->SetTitle(Form("SVD Data Format Monitor %s", runID.Data()));
113 //check if number of errors is above the allowed limit
114 bool hasError = false;
115 for (int un = 0; un < h->GetNcells(); un++)
116 if (h->GetBinContent(un) / nEvents > m_unpackError)
117 hasError = true;
118
119 if (!hasError) {
120 m_cUnpacker->cd();
121 h->Draw("colztext");
122 h->SetStats(0);
124 } else {
125 m_cUnpacker->cd();
126 h->Draw("colztext");
127 h->SetStats(0);
129 }
130 if (nEvents > 0)
131 setEpicsPV("UnpackError", h->GetEntries() / nEvents);
132 } else {
133 B2INFO("Histogram SVDUnpacker/DQMUnpackerHisto from SVDUnpackerDQM not found!");
134 m_cUnpacker->cd();
137 }
138
139 if (m_printCanvas)
140 m_cUnpacker->Print("c_SVDDataFormat.pdf");
141
142}
143
145{
146 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: endRun called");
147}
148
149
151{
152 B2DEBUG(10, "DQMHistAnalysisSVDUnpacker: terminate called");
153
154 delete m_cUnpacker;
155}
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.
Class definition for common method.
void setStatusOfCanvas(int status, TCanvas *canvas, bool plotLeg=true, bool online=false)
set status of Canvas
TPaveText * m_legProblem
plot legend, problem
void initialize() override final
Initializer.
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.