Belle II Software development
DQMHistAnalysisTRGECL.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 : DQMHistAnalysisTRGECL.cc
10// Description : DQM analysis for ECL trigger
11//
12#include <dqm/analysis/modules/DQMHistAnalysisTRGECL.h>
13#include <TROOT.h>
14#include <TStyle.h>
15#include <TString.h>
16#include <TFitResult.h>
17#include <TMath.h>
18#include <TF1.h>
19#include <iomanip>
20#include <iostream>
21
22using namespace Belle2;
23//-----------------------------------------------------------------
24// Register the Module
25//-----------------------------------------------------------------
26REG_MODULE(DQMHistAnalysisTRGECL);
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
32{
33 setDescription("Module for DQM histogram analysis of ECL trigger Event T0 DQM histograms");
34
35 addParam("MinEntryForFit",
37 "set minimum number of entries for fit (default=200)",
39}
40
42{
43
44 gROOT->cd();
45
46 // canvas for event timing related histograms
48 new TCanvas("TRGECLEventTiming/c_a_EventTimingFraction",
49 "Event timing fraction",
50 300, 300);
52 new TCanvas("TRGECLEventTiming/c_a_EventT0Mean",
53 "EventT0 mean",
54 300, 300);
56 new TCanvas("TRGECLEventTiming/c_a_EventT0Width",
57 "EventT0 width",
58 300, 300);
59
60 // TGraph for fraction of event timing
61 h_EventTimingEnergyFraction = new TGraph();
62 h_EventTimingEnergyFraction->SetTitle("[TRGECL] Fraction of event timing");
63 h_EventTimingEnergyFraction->GetXaxis()->SetTitle("max TC Energy (ADC)");
64 h_EventTimingEnergyFraction->GetYaxis()->SetTitle("N(max TC E > X) / N(all)");
65 h_EventTimingEnergyFraction->SetMarkerStyle(20);
66 h_EventTimingEnergyFraction->SetMarkerSize(0.5);
67 h_EventTimingEnergyFraction->SetMarkerColor(4);
68 h_EventTimingEnergyFraction->SetLineStyle(1);
69 h_EventTimingEnergyFraction->SetLineWidth(1);
70 h_EventTimingEnergyFraction->SetLineColor(4);
71 h_EventTimingEnergyFraction->SetMinimum(0);
72
73 // set EventT0 histogram names
74 s_histNameEventT0 = std::vector<std::string>(15, "");
75 for (int iii = 0; iii < 15; iii++) {
76 std::stringstream ss1, ss2;
77 ss1 << std::setfill('0') << std::setw(3) << std::to_string(10 + 20 * iii);
78 ss2 << std::setfill('0') << std::setw(3) << std::to_string(10 + 20 * (iii + 1));
79 std::string s_EnergyRange = ss1.str() + "to" + ss2.str();
80 s_histNameEventT0[iii] = "TRGECLEventTiming/h_EventT0_MaxTCE_" + s_EnergyRange;
81 }
82
83 // EventT0 mean
84 h_EventT0Mean = new TGraphErrors();
85 h_EventT0Mean->SetTitle("[TRGECL] Event T0 mean");
86 h_EventT0Mean->GetXaxis()->SetTitle("max TC Energy (ADC)");
87 h_EventT0Mean->GetYaxis()->SetTitle("EventT0 mean (ns)");
88 h_EventT0Mean->SetMarkerStyle(20);
89 h_EventT0Mean->SetMarkerSize(0.5);
90 h_EventT0Mean->SetMarkerColor(4);
91 h_EventT0Mean->SetLineStyle(1);
92 h_EventT0Mean->SetLineWidth(1);
93 h_EventT0Mean->SetLineColor(4);
94
95 // EventT0 width
96 h_EventT0Width = new TGraphErrors();
97 h_EventT0Width->SetTitle("[TRGECL] Event T0 width");
98 h_EventT0Width->GetXaxis()->SetTitle("max TC Energy (ADC)");
99 h_EventT0Width->GetYaxis()->SetTitle("EventT0 width (ns)");
100 h_EventT0Width->SetMarkerStyle(20);
101 h_EventT0Width->SetMarkerSize(0.5);
102 h_EventT0Width->SetMarkerColor(4);
103 h_EventT0Width->SetLineStyle(1);
104 h_EventT0Width->SetLineWidth(1);
105 h_EventT0Width->SetLineColor(4);
106 h_EventT0Width->SetMinimum(0);
107
108}
109
111{
112 c_TCEFraction->Clear();
113 c_EventT0Mean->Clear();
114 c_EventT0Width->Clear();
115}
116
120
122{
123
124 auto hhh = (TH1F*) findHist("TRGECLEventTiming/h_MaxTCE");
125 if (hhh != nullptr) {
126 // calculate fraction of event timing with max TC E threshold
127 int n_bin = hhh->GetNbinsX();
128 float n_entry_all = (float) hhh->GetEffectiveEntries();
129 float n_entry_bin_sum[140] = {0};
130 float ratio[140] = {0};
131 for (int iii = 0; iii < n_bin; iii++) {
132 for (int jjj = iii; jjj < n_bin; jjj++) {
133 n_entry_bin_sum[iii] += (float) hhh->GetBinContent(jjj + 1);
134 }
135 ratio[iii] = n_entry_bin_sum[iii] / n_entry_all;
136 }
137 // fill value to TGraph
138 for (int iii = 0; iii <= 30; iii++) {
139 h_EventTimingEnergyFraction->SetPoint(iii, iii * 10, ratio[iii]);
140 }
141 c_TCEFraction->cd();
142 c_TCEFraction->Clear();
143 h_EventTimingEnergyFraction->Draw("AP");
144 c_TCEFraction->Modified();
145 c_TCEFraction->Update();
147 }
148
149 // EventT0 mean canvas
150 c_EventT0Mean->cd();
151 c_EventT0Mean->Clear();
152
153 // set TGraphErrors for EventT0 mean and width
157
158 // EventT0 mean
159 h_EventT0Mean->Draw("AP");
160 c_EventT0Mean->Modified();
161 c_EventT0Mean->Update();
163
164 // EventT0 width canvas
165 c_EventT0Width->cd();
166 c_EventT0Width->Clear();
167
168 // EventT0 width
169 h_EventT0Width->Draw("AP");
170 c_EventT0Width->Modified();
171 c_EventT0Width->Update();
173
174
175}
176
178{
179 delete c_TCEFraction;
180 delete c_EventT0Mean;
181 delete c_EventT0Width;
182 delete h_EventT0Mean;
183 delete h_EventT0Width;
184}
185
186double DQMHistAnalysisTRGECLModule::fGaus(double* x, double* par)
187{
188 double yield = par[0];
189 double mean = par[1];
190 double sigma = par[2];
191 return yield * TMath::Gaus(x[0], mean, sigma);
192}
193
194void DQMHistAnalysisTRGECLModule::getEventT0(std::vector<std::string> s_HistName,
195 TGraphErrors* h_tge_mean,
196 TGraphErrors* h_tge_width)
197{
198
199 // loop for fits on 15 sets of EventT0
200 for (int iii = 0; iii < 15; iii++) {
201
202 TH1* hhh = findHist(s_HistName[iii]);
203
204 if (hhh != nullptr) {
205
206 // fit 6 parameters (yield, yieled err, mean, mean err, sigma, sigma err)
207 std::vector<double> par_fit(6, 0.0);
208
209 // check the number of entry in histogram to fit
210 int nToFit = hhh->GetEffectiveEntries();
211 if (nToFit > m_MinEntryForFit &&
212 nToFit > 200) {
213
214 // perform fit on EventT0 and get peak position and width
215 fitEventT0(hhh, par_fit);
216
217 }
218
219 // set mean parameter to TGraphErrors
220 h_tge_mean->SetPoint(iii, (iii + 1) * 20, par_fit[2]);
221 h_tge_mean->SetPointError(iii, 10, par_fit[3]);
222 // set width parameter to TGraphErrors
223 h_tge_width->SetPoint(iii, (iii + 1) * 20, par_fit[4]);
224 h_tge_width->SetPointError(iii, 10, par_fit[5]);
225
226 }
227 }
228}
229
231 std::vector<double>& fit_par)
232{
233
234 // initial parameters to fit on EventT0 from histogram statistics
235 float v_mean = hist->GetMean();
236 float v_rms = hist->GetRMS();
237 float v_norm = hist->GetEffectiveEntries() / v_rms;
238 float x_min = v_mean - 3 * v_rms;
239 float x_max = v_mean + 3 * v_rms;
240
241 // Gaussian function for fit on EventT0
242 TF1* f1 = new TF1("f1", DQMHistAnalysisTRGECLModule::fGaus,
243 x_min,
244 x_max,
245 3);
246 // set initial parameters of Gaussian
247 f1->SetParameters(v_norm, v_mean, v_rms);
248
249 // perform fit
250 hist->Fit("f1", "Q", "", x_min, x_max);
251
252 //
253 if (hist->GetFunction("f1") == NULL) {
254 B2DEBUG(20, "Fit failed");
255 return;
256 }
257
258 //
259 if (f1->GetParameter(2) <= 0) {
260 B2DEBUG(20, "Fit failed");
261 return;
262 }
263
264 // get fit parameters
265 fit_par[0] = f1->GetParameter(0);
266 fit_par[1] = f1->GetParError(0);
267 fit_par[2] = f1->GetParameter(1);
268 fit_par[3] = f1->GetParError(1);
269 fit_par[4] = f1->GetParameter(2);
270 fit_par[5] = f1->GetParError(2);
271
272 // delete fit function
273 delete f1;
274}
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
static void UpdateCanvas(const std::string &name, bool updated=true)
Mark canvas as updated (or not)
DQMHistAnalysisModule()
Constructor / Destructor.
TGraph * h_EventTimingEnergyFraction
fraction of event timing with different max TC selection
static double fGaus(double *x, double *par)
single Gaussian function
void initialize() override final
initialization
TGraphErrors * h_EventT0Width
graph of EventT0 width
void fitEventT0(TH1 *hist, std::vector< double > &)
fit on EventT0 histogram
TGraphErrors * h_EventT0Mean
graph of EventT0 mean
TCanvas * c_EventT0Width
canvas for EventT0 width
void terminate() override final
delete pointers
void event() override final
event function
TCanvas * c_TCEFraction
canvas for fraction of event timing with different max TC selection
int m_MinEntryForFit
minimum entry in EventT0 histogram to fit
void beginRun() override final
begin run
TCanvas * c_EventT0Mean
canvas for EventT0 mean
std::vector< std::string > s_histNameEventT0
name of EventT0 histograms
void getEventT0(std::vector< std::string >, TGraphErrors *, TGraphErrors *)
get EventT0 mean and width
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.