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, and corresponding canvases
111 {"TRGEFF/hPt_psnecl", &m_hPt_eff, m_cPt_eff},
112 {"TRGEFF/hPhi_psnecl", &m_hPhi_eff, m_cPhi_eff},
113 {"TRGEFF/nobha_hPt_psnecl", &m_nobha_hPt_eff, m_nobha_cPt_eff},
114 {"TRGEFF/hP3_z_psnecl", &m_hP3_z_eff, m_cP3_z_eff},
115 {"TRGEFF/hP3_y_psnecl", &m_hP3_y_eff, m_cP3_y_eff},
116 {"TRGEFF/nobha_hP3_z_psnecl", &m_nobha_hP3_z_eff, m_nobha_cP3_z_eff},
117 {"TRGEFF/nobha_hP3_y_psnecl", &m_nobha_hP3_y_eff, m_nobha_cP3_y_eff},
118 {"TRGEFF/fyo_dphi_psnecl", &m_fyo_dphi_eff, m_c_fyo_dphi_eff},
119 {"TRGEFF/nobha_fyo_dphi_psnecl", &m_nobha_fyo_dphi_eff, m_c_nobha_fyo_dphi_eff},
120 {"TRGEFF/stt_phi_psnecl", &m_stt_phi_eff, m_c_stt_phi_eff},
121 {"TRGEFF/stt_P3_psnecl", &m_stt_P3_eff, m_c_stt_P3_eff},
122 {"TRGEFF/stt_theta_psnecl", &m_stt_theta_eff, m_c_stt_theta_eff},
123 {"TRGEFF/nobha_stt_phi_psnecl", &m_nobha_stt_phi_eff, m_c_nobha_stt_phi_eff},
124 {"TRGEFF/nobha_stt_P3_psnecl", &m_nobha_stt_P3_eff, m_c_nobha_stt_P3_eff},
125 {"TRGEFF/nobha_stt_theta_psnecl", &m_nobha_stt_theta_eff, m_c_nobha_stt_theta_eff},
126 {"TRGEFF/hie_E_psnecl", &m_hie_E_eff, m_c_hie_E_eff},
127 {"TRGEFF/nobha_hie_E_psnecl", &m_nobha_hie_E_eff, m_c_nobha_hie_E_eff},
128 {"TRGEFF/ecltiming_E_psnecl", &m_ecltiming_E_eff, m_c_ecltiming_E_eff},
129 {"TRGEFF/ecltiming_theta_psnecl", &m_ecltiming_theta_eff, m_c_ecltiming_theta_eff},
130 {"TRGEFF/ecltiming_phi_psnecl", &m_ecltiming_phi_eff, m_c_ecltiming_phi_eff},
131 {"TRGEFF/klmhit_phi_psnecl", &m_klmhit_phi_eff, m_c_klmhit_phi_eff},
132 {"TRGEFF/klmhit_theta_psnecl", &m_klmhit_theta_eff, m_c_klmhit_theta_eff},
133 {"TRGEFF/eklmhit_phi_psnecl", &m_eklmhit_phi_eff, m_c_eklmhit_phi_eff},
134 {"TRGEFF/eklmhit_theta_psnecl", &m_eklmhit_theta_eff, m_c_eklmhit_theta_eff}
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
159 B2DEBUG(1, "The current histogram name is " << name); // Debug print
160 TH1F* hist = (TH1F*)findHist(name);
161 TH1F* histFtdf = (TH1F*)findHist(name + "_ftdf");
162 if (hist == nullptr || histFtdf == nullptr) {
163 B2WARNING("Histogram for " + name + " or its Ftdf counterpart is not found.");
164 return;
165 }
166
167 // Delete old efficiency if it exists
168 if (*efficiencyPtr != nullptr) {
169 delete *efficiencyPtr;
170 *efficiencyPtr = nullptr;
171 }
172
173 // Check consistency and create a new TEfficiency
174 if (TEfficiency::CheckConsistency(*histFtdf, *hist)) {
175 *efficiencyPtr = new TEfficiency(*histFtdf, *hist);
176 } else {
177 B2WARNING("Histograms " << histFtdf->GetName() << " and " << hist->GetName() << " are not consistent for efficiency calculation.");
178 }
179
180 // Draw efficiency on canvas and update it
181 canvas->Clear();
182 canvas->cd();
183 (*efficiencyPtr)->Draw();
184 canvas->Modified();
185 }
186
187}
188
190{
191 B2DEBUG(1, "DQMHistAnalysisTRGEFF : endRun called");
192
193 // Loop through m_efficiencyList and process the efficiency histogram
194 for (auto& entry : m_efficiencyList) {
195 const std::string& name = std::get<0>(entry); // Get the histogram name
196 TEfficiency** efficiencyPtr = std::get<1>(entry); // Get the efficiency pointer
197
198 TEfficiency* effHist = *efficiencyPtr;
199
200 if (effHist) {
201 /***********************************************************
202 * rebin the histogram for MonitoringObject *
203 ***********************************************************/
204 TH1F* hist = (TH1F*)effHist->GetTotalHistogram();
205 TH1F* histFtdf = (TH1F*)effHist->GetPassedHistogram();
206
207 Double_t* newBins = nullptr;
208 int nBins = 1;
209
210 if (name.find("TRGEFF/nobha_hie_E_psnecl") != std::string::npos) {
211 newBins = new Double_t[4] {0, 0.6, 1.6, hist->GetXaxis()->GetXmax()}; // Allocate on heap
212 nBins = 3;
213 } else if (name.find("TRGEFF/nobha_stt_P3_psnecl") != std::string::npos) {
214 newBins = new Double_t[4] {0, 0.5, 1, hist->GetXaxis()->GetXmax()};
215 nBins = 3;
216 } else if (name.find("TRGEFF/nobha_fyo_dphi_psnecl") != std::string::npos) {
217 newBins = new Double_t[4] {0, 80, 100, hist->GetXaxis()->GetXmax()};
218 nBins = 3;
219 } else if (name.find("TRGEFF/klmhit_theta_psnecl") != std::string::npos) {
220 newBins = new Double_t[2] {0, hist->GetXaxis()->GetXmax()}; // Assuming barrel is one bin
221 nBins = 1;
222 } else if (name.find("TRGEFF/eklmhit_theta_psnecl") != std::string::npos) {
223 newBins = new Double_t[3] {0, 90, hist->GetXaxis()->GetXmax()}; // Assuming forward and backward are two bins
224 nBins = 2;
225 } else {
226 newBins = new Double_t[2] {0, hist->GetXaxis()->GetXmax()}; // Average of all bins
227 nBins = 1;
228 }
229
230 // Sort the bins if there are more than one
231 if (nBins > 1) {
232 std::sort(newBins, newBins + nBins + 1); // nBins + 1 because we need to sort the edges
233 }
234
235 TEfficiency* efficiencyRebinnedPtr = nullptr;
236
237 // rebin the found histograms
238 TH1F* histRebinned = (TH1F*)hist->Rebin(nBins, (name + "_rebinned").c_str(), newBins);
239 TH1F* histFtdfRebinned = (TH1F*)histFtdf->Rebin(nBins, (name + "_ftdf_rebinned").c_str(), newBins);
240
241 // delete the allocated memory
242 delete[] newBins;
243
244 // Check consistency and create a new TEfficiency for rebinned histograms
245 if (TEfficiency::CheckConsistency(*histFtdfRebinned, *histRebinned)) {
246 efficiencyRebinnedPtr = new TEfficiency(*histFtdfRebinned, *histRebinned);
247 } else {
248 B2WARNING("Rebinned histograms " << histFtdfRebinned->GetName() << " and " << histRebinned->GetName() <<
249 " are not consistent for efficiency calculation.");
250 }
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 // Delete the rebinned histograms
284 delete histRebinned;
285 delete histFtdfRebinned;
286
287 } else {
288 B2WARNING(std::string("Efficiency histogram is null for ") + name);
289 }
290 }
291
292
293}
294
296{
297 B2DEBUG(1, "terminate called");
298}
299
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.
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 ...
std::vector< std::tuple< std::string, TEfficiency **, TCanvas * > > m_efficiencyList
Combined efficiency list,the histogram, efficiency and Canvas
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.