Belle II Software development
DQMHistAnalysisTRGEFF.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// Own header.
10#include <dqm/analysis/modules/DQMHistAnalysisTRGEFF.h>
11
12#include <TH1F.h>
13#include <TH2F.h>
14#include <TCanvas.h>
15#include <TPaveText.h>
16#include <TLine.h>
17#include <TClass.h>
18#include <TStyle.h>
19#include <TROOT.h>
20
21#include <fstream>
22#include <iostream>
23#include <vector>
24#include <algorithm>
25
26using namespace std;
27using namespace Belle2;
28
29//-----------------------------------------------------------------
30// Register module
31//-----------------------------------------------------------------
32
33REG_MODULE(DQMHistAnalysisTRGEFF);
34
37{
38 // set module description (e.g. insert text)
39 setDescription("Modify and analyze the data quality histograms of TRGEFF");
41 addParam("alert", m_enableAlert, "Enable color alert", true);
42}
43
45{
46
47}
48
50{
51 gROOT->cd();
52
53 m_cPt_eff = new TCanvas("TRGEFF/c_hPt_eff");
54 m_cPhi_eff = new TCanvas("TRGEFF/c_hPhi_eff");
55 m_nobha_cPt_eff = new TCanvas("TRGEFF/c_nobha_hPt_eff");
56 m_cP3_z_eff = new TCanvas("TRGEFF/c_hP3_z_eff");
57 m_cP3_y_eff = new TCanvas("TRGEFF/c_hP3_y_eff");
58 m_nobha_cP3_z_eff = new TCanvas("TRGEFF/c_nobha_hP3_z_eff");
59 m_nobha_cP3_y_eff = new TCanvas("TRGEFF/c_nobha_hP3_y_eff");
60 m_c_fyo_dphi_eff = new TCanvas("TRGEFF/c_fyo_dphi_eff");
61 m_c_nobha_fyo_dphi_eff = new TCanvas("TRGEFF/c_nobha_fyo_dphi_eff");
62 m_c_stt_phi_eff = new TCanvas("TRGEFF/c_stt_phi_eff");
63 m_c_stt_P3_eff = new TCanvas("TRGEFF/c_stt_P3_eff");
64 m_c_stt_theta_eff = new TCanvas("TRGEFF/c_stt_theta_eff");
65 m_c_nobha_stt_phi_eff = new TCanvas("TRGEFF/c_nobha_stt_phi_eff");
66 m_c_nobha_stt_P3_eff = new TCanvas("TRGEFF/c_nobha_stt_P3_eff");
67 m_c_nobha_stt_theta_eff = new TCanvas("TRGEFF/c_nobha_stt_theta_eff");
68 m_c_hie_E_eff = new TCanvas("TRGEFF/c_hie_E_eff");
69 m_c_nobha_hie_E_eff = new TCanvas("TRGEFF/c_nobha_hie_E_eff");
70 m_c_ecltiming_E_eff = new TCanvas("TRGEFF/c_ecltiming_E_eff");
71 m_c_ecltiming_theta_eff = new TCanvas("TRGEFF/c_ecltiming_theta_eff");
72 m_c_ecltiming_phi_eff = new TCanvas("TRGEFF/c_ecltiming_phi_eff");
73 m_c_klmhit_phi_eff = new TCanvas("TRGEFF/c_klmhit_phi_eff");
74 m_c_klmhit_theta_eff = new TCanvas("TRGEFF/c_klmhit_theta_eff");
75 m_c_eklmhit_phi_eff = new TCanvas("TRGEFF/c_eklmhit_phi_eff");
76 m_c_eklmhit_theta_eff = new TCanvas("TRGEFF/c_eklmhit_theta_eff");
77
78
80 // the MonitoringObject
106
108 m_efficiencyList.clear();
110 // Histogram names, efficiency pointers, corresponding canvases and title
111 {"TRGEFF/hPt_psnecl", &m_hPt_eff, m_cPt_eff, "f with Pt [GeV]"},
112 {"TRGEFF/hPhi_psnecl", &m_hPhi_eff, m_cPhi_eff, "f with #phi [degree]"},
113 {"TRGEFF/nobha_hPt_psnecl", &m_nobha_hPt_eff, m_nobha_cPt_eff, "nobha f with Pt [GeV]"},
114 {"TRGEFF/hP3_z_psnecl", &m_hP3_z_eff, m_cP3_z_eff, "z with P [GeV]"},
115 {"TRGEFF/hP3_y_psnecl", &m_hP3_y_eff, m_cP3_y_eff, "y with P [GeV]"},
116 {"TRGEFF/nobha_hP3_z_psnecl", &m_nobha_hP3_z_eff, m_nobha_cP3_z_eff, "nobha z with P [GeV]"},
117 {"TRGEFF/nobha_hP3_y_psnecl", &m_nobha_hP3_y_eff, m_nobha_cP3_y_eff, "nobha y with P [GeV]"},
118 {"TRGEFF/fyo_dphi_psnecl", &m_fyo_dphi_eff, m_c_fyo_dphi_eff, "fyo with #Delta#phi [degree]"},
119 {"TRGEFF/nobha_fyo_dphi_psnecl", &m_nobha_fyo_dphi_eff, m_c_nobha_fyo_dphi_eff, "nobha fyo with #Delta#phi [degree]"},
120 {"TRGEFF/stt_phi_psnecl", &m_stt_phi_eff, m_c_stt_phi_eff, "stt with #phi [degree]"},
121 {"TRGEFF/stt_P3_psnecl", &m_stt_P3_eff, m_c_stt_P3_eff, "stt with P [GeV]"},
122 {"TRGEFF/stt_theta_psnecl", &m_stt_theta_eff, m_c_stt_theta_eff, "stt with #theta [degree]"},
123 {"TRGEFF/nobha_stt_phi_psnecl", &m_nobha_stt_phi_eff, m_c_nobha_stt_phi_eff, "nobha stt with #phi [degree]"},
124 {"TRGEFF/nobha_stt_P3_psnecl", &m_nobha_stt_P3_eff, m_c_nobha_stt_P3_eff, "nobha stt with P [GeV]"},
125 {"TRGEFF/nobha_stt_theta_psnecl", &m_nobha_stt_theta_eff, m_c_nobha_stt_theta_eff, "nobha stt with #theta [degree]"},
126 {"TRGEFF/hie_E_psnecl", &m_hie_E_eff, m_c_hie_E_eff, "hie with E [GeV]"},
127 {"TRGEFF/nobha_hie_E_psnecl", &m_nobha_hie_E_eff, m_c_nobha_hie_E_eff, "nobha hie with E [GeV]"},
128 {"TRGEFF/ecltiming_E_psnecl", &m_ecltiming_E_eff, m_c_ecltiming_E_eff, "ecltiming with E [GeV]"},
129 {"TRGEFF/ecltiming_theta_psnecl", &m_ecltiming_theta_eff, m_c_ecltiming_theta_eff, "ecltiming with #theta [degree]"},
130 {"TRGEFF/ecltiming_phi_psnecl", &m_ecltiming_phi_eff, m_c_ecltiming_phi_eff, "ecltiming with #phi [degree]"},
131 {"TRGEFF/klmhit_phi_psnecl", &m_klmhit_phi_eff, m_c_klmhit_phi_eff, "klmhit with #phi [degree]"},
132 {"TRGEFF/klmhit_theta_psnecl", &m_klmhit_theta_eff, m_c_klmhit_theta_eff, "klmhit with #theta [degree]"},
133 {"TRGEFF/eklmhit_phi_psnecl", &m_eklmhit_phi_eff, m_c_eklmhit_phi_eff, "eklmhit with #phi [degree]"},
134 {"TRGEFF/eklmhit_theta_psnecl", &m_eklmhit_theta_eff, m_c_eklmhit_theta_eff, "eklmhit with #theta [degree]"}
135
136 // Add more entries as needed
137 };
138
139 B2DEBUG(1, "DQMHistAnalysisTRGEFF: initialized.");
140}
141
142
144{
145 B2DEBUG(1, "DQMHistAnalysisTRGEFF: event start.");
146 m_IsPhysicsRun = (getRunType() == "physics");
147 m_IsCosmicRun = (getRunType() == "cosmic");
148 m_IsDebugRun = (getRunType() == "debug");
149
150 //if (m_IsPhysicsRun == true || m_IsCosmicRun == true || m_IsDebugRun == true)
151
152 B2DEBUG(1, "DQMHistAnalysisTRGEFF: fill histogram");
153
154 for (auto& entry : m_efficiencyList) {
155 const std::string& name = std::get<0>(entry); // Get the histogram name
156 TEfficiency** efficiencyPtr = std::get<1>(entry); // Get the efficiency pointer
157 TCanvas* canvas = std::get<2>(entry); // Get the canvas pointer
158 const std::string& title = std::get<3>(entry); // Get the histogram title
159
160 B2DEBUG(1, "The current histogram name is " << name); // Debug print
161 TH1F* hist = (TH1F*)findHist(name);
162 TH1F* histFtdf = (TH1F*)findHist(name + "_ftdf");
163 if (hist == nullptr || histFtdf == nullptr) {
164 B2WARNING("Histogram for " + name + " or its Ftdf counterpart is not found.");
165 return;
166 }
167
168 // Delete old efficiency if it exists
169 if (*efficiencyPtr != nullptr) {
170 delete *efficiencyPtr;
171 *efficiencyPtr = nullptr;
172 }
173
174 // Check consistency and create a new TEfficiency
175 if (TEfficiency::CheckConsistency(*histFtdf, *hist)) {
176 *efficiencyPtr = new TEfficiency(*histFtdf, *hist);
177 (*efficiencyPtr)->SetTitle(title.c_str());
178
179 // Draw efficiency on canvas and update it
180 canvas->Clear();
181 canvas->cd();
182 (*efficiencyPtr)->Draw();
183 canvas->Modified();
184
185 } else {
186 B2WARNING("Histograms " << histFtdf->GetName() << " and " << hist->GetName() << " are not consistent for efficiency calculation.");
187 canvas->Clear();
188 }
189 }
190
191}
192
194{
195 B2DEBUG(1, "DQMHistAnalysisTRGEFF : endRun called");
196
197 // Loop through m_efficiencyList and process the efficiency histogram
198 for (auto& entry : m_efficiencyList) {
199 const std::string& name = std::get<0>(entry); // Get the histogram name
200 TEfficiency** efficiencyPtr = std::get<1>(entry); // Get the efficiency pointer
201
202 TEfficiency* effHist = *efficiencyPtr;
203
204 if (effHist) {
205 /***********************************************************
206 * rebin the histogram for MonitoringObject *
207 ***********************************************************/
208 TH1F* hist = (TH1F*)effHist->GetTotalHistogram();
209 TH1F* histFtdf = (TH1F*)effHist->GetPassedHistogram();
210
211 Double_t* newBins = nullptr;
212 int nBins = 1;
213
214 if (name.find("TRGEFF/nobha_hie_E_psnecl") != std::string::npos) {
215 newBins = new Double_t[4] {0, 0.6, 1.6, hist->GetXaxis()->GetXmax()}; // Allocate on heap
216 nBins = 3;
217 } else if (name.find("TRGEFF/nobha_stt_P3_psnecl") != std::string::npos) {
218 newBins = new Double_t[4] {0, 0.5, 1, hist->GetXaxis()->GetXmax()};
219 nBins = 3;
220 } else if (name.find("TRGEFF/nobha_fyo_dphi_psnecl") != std::string::npos) {
221 newBins = new Double_t[4] {0, 80, 100, hist->GetXaxis()->GetXmax()};
222 nBins = 3;
223 } else if (name.find("TRGEFF/klmhit_theta_psnecl") != std::string::npos) {
224 newBins = new Double_t[2] {0, hist->GetXaxis()->GetXmax()}; // Assuming barrel is one bin
225 nBins = 1;
226 } else if (name.find("TRGEFF/eklmhit_theta_psnecl") != std::string::npos) {
227 newBins = new Double_t[3] {0, 90, hist->GetXaxis()->GetXmax()}; // Assuming forward and backward are two bins
228 nBins = 2;
229 } else {
230 newBins = new Double_t[2] {0, hist->GetXaxis()->GetXmax()}; // Average of all bins
231 nBins = 1;
232 }
233
234 // Sort the bins if there are more than one
235 if (nBins > 1) {
236 std::sort(newBins, newBins + nBins + 1); // nBins + 1 because we need to sort the edges
237 }
238
239 TEfficiency* efficiencyRebinnedPtr = nullptr;
240
241 // rebin the found histograms
242 TH1F* histRebinned = (TH1F*)hist->Rebin(nBins, (name + "_rebinned").c_str(), newBins);
243 TH1F* histFtdfRebinned = (TH1F*)histFtdf->Rebin(nBins, (name + "_ftdf_rebinned").c_str(), newBins);
244
245 // delete the allocated memory
246 delete[] newBins;
247
248 // Check consistency and create a new TEfficiency for rebinned histograms
249 if (TEfficiency::CheckConsistency(*histFtdfRebinned, *histRebinned)) {
250 efficiencyRebinnedPtr = new TEfficiency(*histFtdfRebinned, *histRebinned);
251
252 // Clean the name: remove "TRGEFF/" prefix and "_psnecl" suffix for the name in m_efficiencyList
253 std::string cleanName = name;
254
255 // Find and erase "TRGEFF/" if it exists
256 size_t prefixPos = cleanName.find("TRGEFF/");
257 if (prefixPos != std::string::npos) {
258 cleanName.erase(prefixPos, std::string("TRGEFF/").length()); // Remove "TRGEFF/"
259 }
260
261 // Find and erase "_psnecl" if it exists
262 size_t suffixPos = cleanName.find("_psnecl");
263 if (suffixPos != std::string::npos) {
264 cleanName.erase(suffixPos, std::string("_psnecl").length()); // Remove "_psnecl"
265 }
266
267 int nbins = efficiencyRebinnedPtr->GetTotalHistogram()->GetNbinsX();
268 for (int i = 1; i <= nbins; i++) {
269 char varName[100];
270 sprintf(varName, "%s_%i", cleanName.c_str(), i);
271 B2DEBUG(1, "The name for MonitoringObject histogram is " << varName << " " << efficiencyRebinnedPtr->GetEfficiency(
272 i) << " " << efficiencyRebinnedPtr->GetEfficiencyErrorUp(i) << " " << efficiencyRebinnedPtr->GetEfficiencyErrorLow(i));
273 m_mon_trgeff->setVariable(varName,
274 efficiencyRebinnedPtr->GetEfficiency(i),
275 efficiencyRebinnedPtr->GetEfficiencyErrorUp(i),
276 efficiencyRebinnedPtr->GetEfficiencyErrorLow(i));
277 }
278
279 if (efficiencyRebinnedPtr != nullptr) {
280 delete efficiencyRebinnedPtr;
281 }
282
283 } else {
284 B2WARNING("Rebinned histograms " << histFtdfRebinned->GetName() << " and " << histRebinned->GetName() <<
285 " are not consistent for efficiency calculation.");
286 }
287 // Delete the rebinned histograms
288 delete histRebinned;
289 delete histFtdfRebinned;
290
291 } else {
292 B2WARNING(std::string("Efficiency histogram is null for ") + name);
293 }
294 }
295
296
297}
298
300{
301 B2DEBUG(1, "terminate called");
302}
303
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)
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
static const std::string & getRunType(void)
Get the Run Type.
TEfficiency * m_nobha_hP3_z_eff
remove the bha_veto, the efficiency of p for z bit
TEfficiency * m_hie_E_eff
the efficiency of phi for hie bit
TCanvas * m_cP3_z_eff
for CDC TRG, the histograms for 3-momentum p with ecl mask bits, p of z bit with ecl mask bits.
std::vector< std::tuple< std::string, TEfficiency **, TCanvas *, std::string > > m_efficiencyList
Combined efficiency list,the histogram, efficiency, Canvas, title
TEfficiency * m_ecltiming_phi_eff
the efficiency of phi for ecltiming bit
void initialize() override final
Initialize the Module.
TEfficiency * m_eklmhit_phi_eff
the efficiency of phi for eklmhit bit
TCanvas * m_c_eklmhit_theta_eff
canvas for TRGEFF efficiency, eklmhit bit
bool m_IsCosmicRun
Run type flag for cosmic runs.
TCanvas * m_cP3_y_eff
for CDC TRG, the histograms for 3-momentum p with ecl mask bits, p of y bit with ecl mask bits.
TEfficiency * m_hPt_eff
the efficiency of Pt for f bit
TCanvas * m_c_klmhit_phi_eff
for KLM TRG, the histograms for the phi of the ecl mask bits, and the phi of klmhit bit with ecl mask...
TCanvas * m_nobha_cPt_eff
remove the bha_veto, Canvas for TRGEFF efficiency, Pt
bool m_IsDebugRun
Run type flag for debug runs.
bool m_IsPhysicsRun
Run type flag for physics runs.
TEfficiency * m_ecltiming_theta_eff
the efficiency of theta for ecltiming bit
bool m_enableAlert
Enable alert by base color of canvases.
TCanvas * m_c_ecltiming_theta_eff
canvas for TRGEFF efficiency, ecltiming bit
TCanvas * m_c_ecltiming_E_eff
for ECL TRG, the histograms for the sum energy E distribution in an event with cdc mask bits,...
TCanvas * m_c_stt_phi_eff
for CDC TRG, the histograms for the phi distribution with ecl mask bits, the phi of stt bit with ecl ...
TEfficiency * m_hP3_y_eff
the efficiency of p for y bit
TEfficiency * m_klmhit_phi_eff
the efficiency of phi for klmhit bit
TCanvas * m_c_eklmhit_phi_eff
for KLM TRG, the histograms for the phi of the ecl mask bits, and the phi of eklmhit bit with ecl mas...
TCanvas * m_c_fyo_dphi_eff
for CDC TRG, the histograms for the largest dphi in an event with ecl mask bits, the largest dphi in ...
TEfficiency * m_nobha_stt_theta_eff
remove the bha_veto, the efficiency of theta for stt bit
void terminate() override final
Termination action.
TEfficiency * m_nobha_hPt_eff
remove the bha_veto, the efficiency of Pt for f bit
TEfficiency * m_stt_P3_eff
the efficiency of p for stt bit
TEfficiency * m_nobha_hie_E_eff
remove the bha_veto, the efficiency of phi for hie bit
TCanvas * m_c_stt_P3_eff
for CDC TRG, the histograms for the largest momentum p distribution in an event of the ecl mask bits,...
void event() override final
Event processor.
TCanvas * m_c_nobha_stt_theta_eff
remove the bha_veto, canvas for TRGEFF efficiency, stt bit
TCanvas * m_c_stt_theta_eff
for CDC TRG, the theta of stt distribution.
TEfficiency * m_stt_phi_eff
the efficiency of phi for stt bit
TEfficiency * m_nobha_stt_phi_eff
remove the bha_veto, the efficiency of phi for stt bit
TCanvas * m_cPt_eff
for CDC TRG, the histograms for momentum pt of the ecl mask bits, the pt of f bit with ecl mask bits.
TCanvas * m_c_ecltiming_phi_eff
canvas for TRGEFF efficiency, ecltiming bit
TCanvas * m_cPhi_eff
for CDC TRG, the histograms for phi of the ecl mask bits, the phi of f bit with ecl mask bits.
TEfficiency * m_klmhit_theta_eff
the efficiency of theta for klmhit bit
TEfficiency * m_eklmhit_theta_eff
the efficiency of theta for eklmhit bit
void endRun() override final
End-of-run action.
TEfficiency * m_hP3_z_eff
the efficiency of p for z bit
TEfficiency * m_hPhi_eff
the efficiency of Phi
TCanvas * m_c_nobha_fyo_dphi_eff
remove the bha_veto, canvas for TRGEFF efficiency, fyo bit
TEfficiency * m_fyo_dphi_eff
the efficiency of dphi for fyo bit
TCanvas * m_c_klmhit_theta_eff
canvas for TRGEFF efficiency, klmhit bit
TCanvas * m_nobha_cP3_z_eff
remove the bha_veto, canvas for TRGEFF efficiency, z bit
TEfficiency * m_stt_theta_eff
the efficiency of theta for stt bit
TCanvas * m_c_hie_E_eff
for ECL TRG, the histograms for the sum energy E distribution in an event within the thetaID range of...
TCanvas * m_c_nobha_stt_P3_eff
remove the bha_veto, canvas for TRGEFF efficiency, stt bit
TCanvas * m_nobha_cP3_y_eff
remove the bha_veto, canvas for TRGEFF efficiency, y bit
TCanvas * m_c_nobha_hie_E_eff
remove the bha_veto, canvas for TRGEFF efficiency, hie bit
Belle2::MonitoringObject * m_mon_trgeff
MonitoringObject for trg.
TEfficiency * m_nobha_fyo_dphi_eff
remove the bha_veto, the efficiency of dphi for fyo bit
TCanvas * m_c_nobha_stt_phi_eff
remove the bha_veto, canvas for TRGEFF efficiency, stt bit
TEfficiency * m_ecltiming_E_eff
the efficiency of phi for ecltiming bit
TEfficiency * m_nobha_stt_P3_eff
remove the bha_veto, the efficiency of p for stt bit
TEfficiency * m_nobha_hP3_y_eff
remove the bha_veto, the efficiency of p for y bit
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
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 addCanvas(TCanvas *canv)
Add Canvas to monitoring object.
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.