Belle II Software development
DQMHistAnalysisTrackingAbort.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#include <dqm/analysis/modules/DQMHistAnalysisTrackingAbort.h>
10
11#include <TROOT.h>
12#include <TString.h>
13#include <TH1F.h>
14#include <TH2F.h>
15
16#include <TMath.h>
17#include <iostream>
18
19using namespace Belle2;
20
21//-----------------------------------------------------------------
22// Register the Module
23//-----------------------------------------------------------------
24REG_MODULE(DQMHistAnalysisTrackingAbort);
25
26//-----------------------------------------------------------------
27// Implementation
28//-----------------------------------------------------------------
29
32{
33
34 setDescription("DQM Analysis Module of the Tracking HLT Plots.");
35
36 addParam("failureRateThreshold", m_failureRateThreshold,
37 "Maximum Fraction of Events in which Tracking Aborts before turning Canvas to Red. Will be taken from Epics by default, \
38 this value is only taken if Epics is not available!", double(m_failureRateThreshold));
39 addParam("minNoEvents", m_statThreshold,
40 "Minimum Number of Events before scaring CR shifters. Will be taken from Epics by default, \
41 this value is only taken if Epics is not available!", int(m_statThreshold));
42 addParam("printCanvas", m_printCanvas, "if True prints pdf of the analysis canvas", bool(m_printCanvas));
43
44}
45
46
47
49{
50 // get the abort rate and statThreshold from epics
51 double buffThreshold(NAN);
52 double buffMinEvents(NAN);
53 double dummyLowerAlarm, dummyLowerWarn, dummyUpperWarn, dummyUpperAlarm;
54
55 // read thresholds from EPICS
56 requestLimitsFromEpicsPVs("abortRate", dummyLowerAlarm, dummyLowerWarn, dummyUpperWarn, buffThreshold);
57 requestLimitsFromEpicsPVs("minNoEvents", dummyLowerAlarm, buffMinEvents, dummyUpperWarn, dummyUpperAlarm);
58
59 if (!std::isnan(buffThreshold)) {
60 B2INFO(getName() << ": Setting failure rate threshold from EPICS. New failureRateThreshold " << buffThreshold);
61 m_failureRateThreshold = buffThreshold;
62 }
63 if (!std::isnan(buffMinEvents)) {
64 B2INFO(getName() << ": Setting min number of events threshold from EPICS. New minNoEvents " << buffMinEvents);
65 m_statThreshold = buffMinEvents;
66 }
67
68}
69
70
72{
73
74 gROOT->cd();
75 m_cAbortRate = new TCanvas("TrackingAnalysis/c_TrackingAbort");
76 m_cAbortRate_BF = new TCanvas("TrackingAnalysis/c_TrackingAbort_BF");
77
78 m_cAbortRateIN = new TCanvas("TrackingAnalysis/c_TrackingAbortIN");
79 m_cAbortRateOUT = new TCanvas("TrackingAnalysis/c_TrackingAbortOUT");
80 m_cAbortRateIN_BF = new TCanvas("TrackingAnalysis/c_TrackingAbortIN_BF");
81 m_cAbortRateOUT_BF = new TCanvas("TrackingAnalysis/c_TrackingAbortOUT_BF");
82
83 // add MonitoringObject
84 m_monObj = getMonitoringObject("trackingHLT");
85
86 // register the PVs for setting thresholds
87 registerEpicsPV("TRACKING:minNoEvents", "minNoEvents");
88
89 // variables to be monitored via EPICS
90 //abort rates
91 registerEpicsPV("trackingHLT:abortRate", "abortRate");
92 registerEpicsPV("trackingHLT:abortRate_inActiveVeto", "abortRate_inActiveVeto");
93 registerEpicsPV("trackingHLT:abortRate_outActiveVeto", "abortRate_outActiveVeto");
94 registerEpicsPV("trackingHLT:abortRateBeforeFilter", "abortRateBeforeFilter");
95 registerEpicsPV("trackingHLT:abortRateBeforeFilter_inActiveVeto", "abortRateBeforeFilter_inActiveVeto");
96 registerEpicsPV("trackingHLT:abortRateBeforeFilter_outActiveVeto", "abortRateBeforeFilter_outActiveVeto");
97
98
99 //abort rate AFTER the Filter:
100 //must have THE SAME binning as mEventsWithAborts from TrackingAbortDQM
101 std::string histoName = "EventsWithAborts";
102 std::string histoTitle = "Fraction of Events With at Least one Abort [After Filter]";
103 m_hAbort = new TH1F(TString::Format("%s", histoName.c_str()),
104 TString::Format("%s", histoTitle.c_str()),
105 2, -0.5, 1.5);
106 m_hAbort->GetYaxis()->SetTitle("Number of Events");
107 m_hAbort->GetXaxis()->SetBinLabel(1, "No Abort");
108 m_hAbort->GetXaxis()->SetBinLabel(2, "At Least One Abort");
109 m_hAbort->SetMinimum(0.1);
110
111 //abort rate BEFORE the Filter:
112 //must have THE SAME binning as mEventsWithAborts from TrackingAbortDQM
113 histoName = "EventsWithAborts_beforeFilter";
114 histoTitle = "Fraction of Events With at Least one Abort [Before Filter]";
115 m_hAbort_BF = new TH1F(TString::Format("%s", histoName.c_str()),
116 TString::Format("%s", histoTitle.c_str()),
117 2, -0.5, 1.5);
118 m_hAbort_BF->GetYaxis()->SetTitle("Number of Events");
119 m_hAbort_BF->GetXaxis()->SetBinLabel(1, "No Abort");
120 m_hAbort_BF->GetXaxis()->SetBinLabel(2, "At Least One Abort");
121 m_hAbort_BF->SetMinimum(0.1);
122
123}
124
126{
127
128 //check Tracking Abort Rate AFTER the filter
129 TH1* hAbortIn = findHist("TrackingAbort/EventsWithAborts_IN");
130 TH1* hAbortOut = findHist("TrackingAbort/EventsWithAborts_OUT");
131
132 int nEventsIN = 0;
133 int nEventsOUT = 0;
134
135 if (hAbortIn != nullptr && hAbortOut != nullptr) {
136
137 nEventsIN = hAbortIn->GetEntries();
138 m_monObj->setVariable("nEvents_inActiveVeto", nEventsIN);
139 nEventsOUT = hAbortOut->GetEntries();
140 m_monObj->setVariable("nEvents_outActiveVeto", nEventsOUT);
141 const int nEvents = nEventsIN + nEventsOUT;
142
143 m_hAbort->SetBinContent(1, hAbortIn->GetBinContent(1) + hAbortOut->GetBinContent(1));
144 m_hAbort->SetBinContent(2, hAbortIn->GetBinContent(2) + hAbortOut->GetBinContent(2));
145
146 const double abortRate = (double)m_hAbort->GetBinContent(2) / (m_hAbort->GetBinContent(1) + m_hAbort->GetBinContent(2));
147 m_hAbort->SetTitle(Form("[After Filter] Fraction of Events in which Tracking Aborts = %.2f %%", abortRate * 100));
148
149 if (nEvents >= m_statThreshold) {
150 m_monObj->setVariable("abortRate", abortRate);
151 setEpicsPV("abortRate", abortRate);
152
153 const double abortRate_in = hAbortIn->GetMean();
154 m_monObj->setVariable("abortRate_inActiveVeto", abortRate_in);
155 setEpicsPV("abortRate_inActiveVeto", abortRate_in);
156
157 const double abortRate_out = hAbortOut->GetMean();
158 m_monObj->setVariable("abortRate_outActiveVeto", abortRate_out);
159 setEpicsPV("abortRate_outActiveVeto", abortRate_out);
160
161 }
162
163 //check if number of errors is above the allowed limit
164 const bool hasError = abortRate > m_failureRateThreshold;
165
166 m_cAbortRateIN->cd();
167 hAbortIn->Draw();
168
169 m_cAbortRateOUT->cd();
170 hAbortOut->Draw();
171
172 m_cAbortRate->cd();
173 m_hAbort->Draw();
174
175
176 auto state = makeStatus(nEvents >= m_statThreshold, false, hasError);
178
179 } else { // histograms not found
181 }
182
183 m_cAbortRate->Modified();
184 m_cAbortRate->Update();
185
186 //check Tracking Abort Rate BEFORE the filter
187
188 TH1* hAbortIn_BF = findHist("TrackingAbort_before_filter/EventsWithAborts_IN");
189 TH1* hAbortOut_BF = findHist("TrackingAbort_before_filter/EventsWithAborts_OUT");
190
191 int nEventsINbf = 0;
192 int nEventsOUTbf = 0;
193
194 if (hAbortIn_BF != nullptr && hAbortOut_BF != nullptr) {
195
196 nEventsINbf = hAbortIn_BF->GetEntries();
197 m_monObj->setVariable("nEventsBeforeFilter_inActiveVeto", nEventsINbf);
198 nEventsOUTbf = hAbortOut_BF->GetEntries();
199 m_monObj->setVariable("nEventsBeforeFilter_outActiveVeto", nEventsOUTbf);
200 const int nEvents_BF = nEventsINbf + nEventsOUTbf;
201
202 m_hAbort_BF->SetBinContent(1, hAbortIn_BF->GetBinContent(1) + hAbortOut_BF->GetBinContent(1));
203 m_hAbort_BF->SetBinContent(2, hAbortIn_BF->GetBinContent(2) + hAbortOut_BF->GetBinContent(2));
204
205 const double abortRate_BF = (double)m_hAbort_BF->GetBinContent(2) / (m_hAbort_BF->GetBinContent(1) + m_hAbort_BF->GetBinContent(2));
206 m_hAbort_BF->SetTitle(Form("[Before Filter] Fraction of Events in which Tracking Aborts = %.2f %%", abortRate_BF * 100));
207
208 if (nEvents_BF >= m_statThreshold) {
209 m_monObj->setVariable("abortRateBeforeFilter", abortRate_BF);
210 setEpicsPV("abortRateBeforeFilter", abortRate_BF);
211
212 const double abortRate_in = hAbortIn_BF->GetMean();
213 m_monObj->setVariable("abortRateBeforeFilter_inActiveVeto", abortRate_in);
214 setEpicsPV("abortRateBeforeFilter_inActiveVeto", abortRate_in);
215 const double abortRate_out = hAbortOut_BF->GetMean();
216 m_monObj->setVariable("abortRateBeforeFilter_outActiveVeto", abortRate_out);
217 setEpicsPV("abortRateBeforeFilter_outActiveVeto", abortRate_out);
218 }
219
220 m_cAbortRateIN_BF->cd();
221 hAbortIn_BF->Draw();
222
223 m_cAbortRateOUT_BF->cd();
224 hAbortOut_BF->Draw();
225
226 m_cAbortRate_BF->cd();
227 m_hAbort_BF->Draw();
228
229 }
230
231 //scale tracking abort reason histograms
232 TH1F* hAbortReason_in = (TH1F*)findHist("TrackingAbort/TrkAbortReason_IN");
233 if (hAbortReason_in != nullptr) scaleAndSendToMirabelle(hAbortReason_in, nEventsIN, "_inActiveVeto");
234 TH1F* hAbortReason_out = (TH1F*)findHist("TrackingAbort/TrkAbortReason_OUT");
235 if (hAbortReason_out != nullptr) scaleAndSendToMirabelle(hAbortReason_out, nEventsOUT, "_outActiveVeto");
236 TH1F* hAbortReason_in_BF = (TH1F*)findHist("TrackingAbort_before_filter/TrkAbortReason_IN");
237 if (hAbortReason_in_BF != nullptr) scaleAndSendToMirabelle(hAbortReason_in_BF, nEventsIN, "BeforeFilter_inActiveVeto");
238 TH1F* hAbortReason_out_BF = (TH1F*)findHist("TrackingAbort_before_filter/TrkAbortReason_OUT");
239 if (hAbortReason_out_BF != nullptr) scaleAndSendToMirabelle(hAbortReason_out_BF, nEventsOUT, "BeforeFilter_outActiveVeto");
240
241
242 //scale average histograms
243 TH1F* hAverage_in = (TH1F*)findHist("TrackingAbort/averages_IN");
244 if (hAverage_in != nullptr) scaleAndSendToMirabelle(hAverage_in, nEventsIN, "_inActiveVeto");
245
246 TH1F* hAverage_out = (TH1F*)findHist("TrackingAbort/averages_OUT");
247 if (hAverage_out != nullptr) scaleAndSendToMirabelle(hAverage_out, nEventsOUT, "_outActiveVeto");
248
249 TH1F* hAverage_in_BF = (TH1F*)findHist("TrackingAbort_before_filter/averages_IN");
250 if (hAverage_in_BF != nullptr) scaleAndSendToMirabelle(hAverage_in_BF, nEventsINbf, "BeforeFilter_inActiveVeto");
251
252 TH1F* hAverage_out_BF = (TH1F*)findHist("TrackingAbort_before_filter/averages_OUT");
253 if (hAverage_out_BF != nullptr) scaleAndSendToMirabelle(hAverage_out_BF, nEventsOUTbf, "BeforeFilter_outActiveVeto");
254
255 // average SVD L3U Occupancy to Mirabelle
256 TH1* hL3UOccIn = findHist("TrackingAbort/SVDL3UOcc_IN");
257 if (hL3UOccIn != nullptr) m_monObj->setVariable("svdL3UOcc_inActiveVeto", hL3UOccIn->GetMean());
258 TH1* hL3UOccOut = findHist("TrackingAbort/SVDL3UOcc_OUT");
259 if (hL3UOccOut != nullptr) m_monObj->setVariable("svdL3UOcc_outActiveVeto", hL3UOccOut->GetMean());
260 TH1* hL3UOccIn_BF = findHist("TrackingAbort_before_filter/SVDL3UOcc_IN");
261 if (hL3UOccIn_BF != nullptr) m_monObj->setVariable("svdL3UOccBeforeFilter_inActiveVeto", hL3UOccIn_BF->GetMean());
262 TH1* hL3UOccOut_BF = findHist("TrackingAbort_before_filter/SVDL3UOcc_OUT");
263 if (hL3UOccOut_BF != nullptr) m_monObj->setVariable("svdL3UOccBeforeFilter_outActiveVeto", hL3UOccOut_BF->GetMean());
264
265
266 // average n CDC extra hits to Mirabelle
267 TH1* hCDCExtraHitsIn = findHist("TrackingAbort/nCDCExtraHits_IN");
268 if (hCDCExtraHitsIn != nullptr) m_monObj->setVariable("nCDCExtraHits_inActiveVeto", hCDCExtraHitsIn->GetMean());
269 TH1* hCDCExtraHitsOut = findHist("TrackingAbort/nCDCExtraHits_OUT");
270 if (hCDCExtraHitsOut != nullptr) m_monObj->setVariable("nCDCExtraHits_outActiveVeto", hCDCExtraHitsOut->GetMean());
271 TH1* hCDCExtraHitsIn_BF = findHist("TrackingAbort_before_filter/nCDCExtraHits_IN");
272 if (hCDCExtraHitsIn_BF != nullptr) m_monObj->setVariable("nCDCExtraHitsBeforeFilter_inActiveVeto", hCDCExtraHitsIn_BF->GetMean());
273 TH1* hCDCExtraHitsOut_BF = findHist("TrackingAbort_before_filter/nCDCExtraHits_OUT");
274 if (hCDCExtraHitsOut_BF != nullptr) m_monObj->setVariable("nCDCExtraHitsBeforeFilter_outActiveVeto",
275 hCDCExtraHitsOut_BF->GetMean());
276
277 if (m_printCanvas) {
278 m_cAbortRate->Print("c_TrackingAbort.pdf[");
279 m_cAbortRate->Print("c_TrackingAbort.pdf");
280 m_cAbortRateIN->Print("c_TrackingAbort.pdf");
281 m_cAbortRateOUT->Print("c_TrackingAbort.pdf");
282 m_cAbortRateIN_BF->Print("c_TrackingAbort.pdf");
283 m_cAbortRateOUT_BF->Print("c_TrackingAbort.pdf");
284 m_cAbortRateOUT_BF->Print("c_TrackingAbort.pdf]");
285 }
286
287
288}
289
291{
292 delete m_hAbort;
293 delete m_hAbort_BF;
294 delete m_cAbortRate;
295 delete m_cAbortRate_BF;
296 delete m_cAbortRateIN;
297 delete m_cAbortRateIN_BF;
298 delete m_cAbortRateOUT;
299 delete m_cAbortRateOUT_BF;
300
301}
302
303void DQMHistAnalysisTrackingAbortModule::scaleAndSendToMirabelle(TH1F* hAverage, const int nEvents, const TString& tag)
304{
305
306 //scale the histogram to the number of events
307 hAverage->Scale(1. / nEvents);
308
309 const int nBins = hAverage->GetNbinsX();
310 for (int bin = 1; bin < nBins + 1; bin++) {
311 const TString binLabel = hAverage->GetXaxis()->GetBinLabel(bin);
312 const TString varName = TString::Format("%s%s", binLabel.Data(), tag.Data());
313 const float varValue = hAverage->GetBinContent(bin);
314 m_monObj->setVariable(varName.Data(), varValue);
315 }
316
317
318}
319
320
321
322
The base class for the histogram analysis module.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
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_StatusTooFew
Not enough entries/event to judge.
EStatus makeStatus(bool enough, bool warn_flag, bool error_flag)
Helper function to judge the status for coloring and EPICS.
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
Module function initialize.
int m_statThreshold
minimal number of events to judge
TH1F * m_hAbort_BF
totla abort (inside + outside) active veto region BEFORE FILTER
double m_failureRateThreshold
above this rate, there is maybe a problem?
TCanvas * m_cAbortRateIN
canvas for the abort rate inside the active veto region
MonitoringObject * m_monObj
Monitoring Object to be produced by this module, which contain defined canvases and monitoring variab...
void terminate() override final
Module function needed to delete pointer.
TCanvas * m_cAbortRate_BF
canvas for the abort rate plot BEFORE FILTER
TCanvas * m_cAbortRate
canvas for the abort rate plot
TH1F * m_hAbort
totla abort (inside + outside) active veto region
TCanvas * m_cAbortRateOUT
canvas for the abort rate outside the active veto region
void event() override final
Module function event.
bool m_printCanvas
if true print the pdf of the canvases
TCanvas * m_cAbortRateIN_BF
canvas for the abort rate inside the active veto region BEFORE FILTER
TCanvas * m_cAbortRateOUT_BF
canvas for the abort rate outside the active veto region BEFORE FILTER
void beginRun() override final
Module function doing stuff at beginning of a run.
void scaleAndSendToMirabelle(TH1F *hAverage, const int nEvents, const TString &tag)
scale hAverage and send bin contents to Mirabelle
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
const std::string & getName() const
Returns the name of the module.
Definition: Module.h:187
void setVariable(const std::string &var, float val, float upErr=-1., float dwErr=-1)
set value to float variable (new variable is made if not yet existing)
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.