Belle II Software development
DQMHistAnalysisTrackingHLT.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/DQMHistAnalysisTrackingHLT.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 std;
20using namespace Belle2;
21
22//-----------------------------------------------------------------
23// Register the Module
24//-----------------------------------------------------------------
25REG_MODULE(DQMHistAnalysisTrackingHLT);
26
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
33{
34
35 setDescription("DQM Analysis Module of the Tracking HLT Plots.");
36
37 addParam("minNoEvents", m_statThreshold,
38 "Minimum Number of Events before scaring CR shifters. Will be taken from Epics by default, \
39 this value is only taken if Epics is not available!", int(m_statThreshold));
40 addParam("printCanvas", m_printCanvas, "if True prints pdf of the analysis canvas", bool(m_printCanvas));
41
42}
43
44
45
47{
48 // get the abort rate and statThreshold from epics
49 double buffMinEvents(NAN);
50 double dummyLowerAlarm, dummyUpperWarn, dummyUpperAlarm;
51
52 // read thresholds from EPICS
53 requestLimitsFromEpicsPVs("minNoEvents", dummyLowerAlarm, buffMinEvents, dummyUpperWarn, dummyUpperAlarm);
54
55 if (!std::isnan(buffMinEvents)) {
56 B2INFO(getName() << ": Setting min number of events threshold from EPICS. New minNoEvents " << buffMinEvents);
57 m_statThreshold = buffMinEvents;
58 }
59
60}
61
62
64{
65
66 gROOT->cd();
67 m_cAbortRateHER = new TCanvas("TrackingAnalysis/c_AbortRateHER");
68 m_cAbortRateLER = new TCanvas("TrackingAnalysis/c_AbortRateLER");
69
70 // add MonitoringObject
71 m_monObj = getMonitoringObject("trackingHLT");
72
73 // register the PVs for setting thresholds
74 registerEpicsPV("TRACKING:minNoEvents", "minNoEvents");
75
76 // variables to be monitored via EPICS
77 registerEpicsPV("trackingHLT:nTracksPerEvent", "nTracksPerEvent");
78 registerEpicsPV("trackingHLT:nVXDTracksPerEvent", "nVXDTracksPerEvent");
79 registerEpicsPV("trackingHLT:nCDCTracksPerEvent", "nCDCTracksPerEvent");
80 registerEpicsPV("trackingHLT:nVXDCDCTracksPerEvent", "nVXDCDCTracksPerEvent");
81
82}
83
85{
86
87 // check tracking abort rate VS time after last HER injection and time within a beam cycle HER
88 TH2F* hAbortHER = dynamic_cast<TH2F*>(findHist("TrackingHLTDQM/TrkAbortVsTimeHER"));
89 TH2F* hAllHER = dynamic_cast<TH2F*>(findHist("TrackingHLTDQM/allEvtsVsTimeHER"));
90 if (hAbortHER != nullptr && hAllHER != nullptr) {
91
92 TH2F* hAbortRateHER = new TH2F(*hAbortHER);
93
94 for (int i = 0; i < hAbortRateHER->GetXaxis()->GetNbins(); i++)
95 for (int j = 0; j < hAbortRateHER->GetYaxis()->GetNbins(); j++) {
96 int den = hAllHER->GetBinContent(i + 1, j + 1);
97 int num = hAbortHER->GetBinContent(i + 1, j + 1);
98
99 if (den > 0) hAbortRateHER->SetBinContent(i + 1, j + 1, num * 1. / den);
100 else hAbortRateHER->SetBinContent(i + 1, j + 1, 0);
101 }
102
103 m_cAbortRateHER->cd();
105 hAbortRateHER->SetTitle("Fraction of Events with Tracking Aborts vs HER injection");
106 hAbortRateHER->GetZaxis()->SetTitle("Fraction of events / bin");
107 hAbortRateHER->Draw("colz");
108
109
110 } else
112
113 if (m_printCanvas)
114 m_cAbortRateHER->Print("c_AbortRateHER.pdf");
115
116
117 // check tracking abort rate VS time after last LER injection and time within a beam cycle LER
118 TH2F* hAbortLER = dynamic_cast<TH2F*>(findHist("TrackingHLTDQM/TrkAbortVsTimeLER"));
119 TH2F* hAllLER = dynamic_cast<TH2F*>(findHist("TrackingHLTDQM/allEvtsVsTimeLER"));
120
121 if (hAbortLER != nullptr && hAllLER != nullptr) {
122
123 TH2F* hAbortRateLER = new TH2F(*hAbortLER);
124
125 for (int i = 0; i < hAbortRateLER->GetXaxis()->GetNbins(); i++)
126 for (int j = 0; j < hAbortRateLER->GetYaxis()->GetNbins(); j++) {
127 int den = hAllLER->GetBinContent(i + 1, j + 1);
128 int num = hAbortLER->GetBinContent(i + 1, j + 1);
129
130 if (den > 0) hAbortRateLER->SetBinContent(i + 1, j + 1, num * 1. / den);
131 else hAbortRateLER->SetBinContent(i + 1, j + 1, 0);
132 }
133
134 m_cAbortRateLER->cd();
136 hAbortRateLER->SetTitle("Fraction of Events with Tracking Aborts vs LER injection");
137 hAbortRateLER->GetZaxis()->SetTitle("Fraction of events / bin");
138 hAbortRateLER->Draw("colz");
139
140 } else
142
143 if (m_printCanvas)
144 m_cAbortRateLER->Print("c_AbortRateLER.pdf");
145
146 // add average number of tracks per event to Mirabelle
147 TH1* hnTracks = findHist("TrackingHLTDQM/NoOfTracks");
148 if (hnTracks != nullptr && hnTracks->GetEntries() >= m_statThreshold) {
149 double averageNTracks = hnTracks->GetMean();
150 m_monObj->setVariable("nTracksPerEvent", averageNTracks);
151 setEpicsPV("nTracksPerEvent", averageNTracks);
152 }
153
154 TH1* hnVXDTracks = findHist("TrackingHLTDQM/NoOfTracksInVXDOnly");
155 if (hnVXDTracks != nullptr && hnVXDTracks->GetEntries() >= m_statThreshold) {
156 double averageNVXDTracks = hnVXDTracks->GetMean();
157 m_monObj->setVariable("nVXDTracksPerEvent", averageNVXDTracks);
158 setEpicsPV("nVXDTracksPerEvent", averageNVXDTracks);
159 }
160
161 TH1* hnCDCTracks = findHist("TrackingHLTDQM/NoOfTracksInCDCOnly");
162 if (hnCDCTracks != nullptr && hnCDCTracks->GetEntries() >= m_statThreshold) {
163 double averageNCDCTracks = hnCDCTracks->GetMean();
164 m_monObj->setVariable("nCDCTracksPerEvent", averageNCDCTracks);
165 setEpicsPV("nCDCTracksPerEvent", averageNCDCTracks);
166 }
167
168 TH1* hnVXDCDCTracks = findHist("TrackingHLTDQM/NoOfTracksInVXDCDC");
169 if (hnVXDCDCTracks != nullptr && hnVXDCDCTracks->GetEntries() >= m_statThreshold) {
170 double averageNVXDCDCTracks = hnVXDCDCTracks->GetMean();
171 m_monObj->setVariable("nVXDCDCTracksPerEvent", averageNVXDCDCTracks);
172 setEpicsPV("nVXDCDCTracksPerEvent", averageNVXDCDCTracks);
173 }
174
175}
176
177
178
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_StatusDefault
default for non-coloring
@ c_StatusTooFew
Not enough entries/event to judge.
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
MonitoringObject * m_monObj
Monitoring Object to be produced by this module, which contain defined canvases and monitoring variab...
void event() override final
Module function event.
TCanvas * m_cAbortRateHER
canvas for the 2D abort rate plot for HER
TCanvas * m_cAbortRateLER
canvas for the 2D abort rate plot for LER
bool m_printCanvas
if true print the pdf of the canvases
void beginRun() override final
Module function doing stuff at beginning of a run.
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.
STL namespace.