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
44{
45
46 gROOT->cd();
47
48 // canvas for event timing related histograms
50 new TCanvas("TRGECLEventTiming/c_a_EventTimingFraction",
51 "Event timing fraction",
52 300, 300);
54 new TCanvas("TRGECLEventTiming/c_a_EventT0Mean",
55 "EventT0 mean",
56 300, 300);
58 new TCanvas("TRGECLEventTiming/c_a_EventT0Width",
59 "EventT0 width",
60 300, 300);
61
62 // TGraph for fraction of event timing
63 h_EventTimingEnergyFraction = new TGraph();
64 h_EventTimingEnergyFraction->SetTitle("[TRGECL] Fraction of event timing");
65 h_EventTimingEnergyFraction->GetXaxis()->SetTitle("max TC Energy (ADC)");
66 h_EventTimingEnergyFraction->GetYaxis()->SetTitle("N(max TC E > X) / N(all)");
67 h_EventTimingEnergyFraction->SetMarkerStyle(20);
68 h_EventTimingEnergyFraction->SetMarkerSize(0.5);
69 h_EventTimingEnergyFraction->SetMarkerColor(4);
70 h_EventTimingEnergyFraction->SetLineStyle(1);
71 h_EventTimingEnergyFraction->SetLineWidth(1);
72 h_EventTimingEnergyFraction->SetLineColor(4);
73 h_EventTimingEnergyFraction->SetMinimum(0);
74
75 // set EventT0 histogram names
76 s_histNameEventT0 = std::vector<std::string>(15, "");
77 for (int iii = 0; iii < 15; iii++) {
78 std::stringstream ss1, ss2;
79 ss1 << std::setfill('0') << std::setw(3) << std::to_string(10 + 20 * iii);
80 ss2 << std::setfill('0') << std::setw(3) << std::to_string(10 + 20 * (iii + 1));
81 std::string s_EnergyRange = ss1.str() + "to" + ss2.str();
82 s_histNameEventT0[iii] = "TRGECLEventTiming/h_EventT0_MaxTCE_" + s_EnergyRange;
83 }
84
85 // EventT0 mean
86 h_EventT0Mean = new TGraphErrors();
87 h_EventT0Mean->SetTitle("[TRGECL] Event T0 mean");
88 h_EventT0Mean->GetXaxis()->SetTitle("max TC Energy (ADC)");
89 h_EventT0Mean->GetYaxis()->SetTitle("EventT0 mean (ns)");
90 h_EventT0Mean->SetMarkerStyle(20);
91 h_EventT0Mean->SetMarkerSize(0.5);
92 h_EventT0Mean->SetMarkerColor(4);
93 h_EventT0Mean->SetLineStyle(1);
94 h_EventT0Mean->SetLineWidth(1);
95 h_EventT0Mean->SetLineColor(4);
96
97 // EventT0 width
98 h_EventT0Width = new TGraphErrors();
99 h_EventT0Width->SetTitle("[TRGECL] Event T0 width");
100 h_EventT0Width->GetXaxis()->SetTitle("max TC Energy (ADC)");
101 h_EventT0Width->GetYaxis()->SetTitle("EventT0 width (ns)");
102 h_EventT0Width->SetMarkerStyle(20);
103 h_EventT0Width->SetMarkerSize(0.5);
104 h_EventT0Width->SetMarkerColor(4);
105 h_EventT0Width->SetLineStyle(1);
106 h_EventT0Width->SetLineWidth(1);
107 h_EventT0Width->SetLineColor(4);
108 h_EventT0Width->SetMinimum(0);
109
110}
111
113{
114 c_TCEFraction->Clear();
115 c_EventT0Mean->Clear();
116 c_EventT0Width->Clear();
117}
118
120{
121}
122
124{
125
126 auto hhh = (TH1F*) findHist("TRGECLEventTiming/h_MaxTCE");
127 if (hhh != nullptr) {
128 // calculate fraction of event timing with max TC E threshold
129 int n_bin = hhh->GetNbinsX();
130 float n_entry_all = (float) hhh->GetEffectiveEntries();
131 float n_entry_bin_sum[140] = {0};
132 float ratio[140] = {0};
133 for (int iii = 0; iii < n_bin; iii++) {
134 for (int jjj = iii; jjj < n_bin; jjj++) {
135 n_entry_bin_sum[iii] += (float) hhh->GetBinContent(jjj + 1);
136 }
137 ratio[iii] = n_entry_bin_sum[iii] / n_entry_all;
138 }
139 // fill value to TGraph
140 for (int iii = 0; iii <= 30; iii++) {
141 h_EventTimingEnergyFraction->SetPoint(iii, iii * 10, ratio[iii]);
142 }
143 c_TCEFraction->cd();
144 c_TCEFraction->Clear();
145 h_EventTimingEnergyFraction->Draw("AP");
146 c_TCEFraction->Modified();
147 c_TCEFraction->Update();
149 }
150
151 // EventT0 mean canvas
152 c_EventT0Mean->cd();
153 c_EventT0Mean->Clear();
154
155 // set TGraphErrors for EventT0 mean and width
159
160 // EventT0 mean
161 h_EventT0Mean->Draw("AP");
162 c_EventT0Mean->Modified();
163 c_EventT0Mean->Update();
165
166 // EventT0 width canvas
167 c_EventT0Width->cd();
168 c_EventT0Width->Clear();
169
170 // EventT0 width
171 h_EventT0Width->Draw("AP");
172 c_EventT0Width->Modified();
173 c_EventT0Width->Update();
175
176
177}
178
180{
181 delete c_TCEFraction;
182 delete c_EventT0Mean;
183 delete c_EventT0Width;
184 delete h_EventT0Mean;
185 delete h_EventT0Width;
186}
187
188double DQMHistAnalysisTRGECLModule::fGaus(double* x, double* par)
189{
190 double yield = par[0];
191 double mean = par[1];
192 double sigma = par[2];
193 return yield * TMath::Gaus(x[0], mean, sigma);
194}
195
196void DQMHistAnalysisTRGECLModule::getEventT0(std::vector<std::string> s_HistName,
197 TGraphErrors* h_tge_mean,
198 TGraphErrors* h_tge_width)
199{
200
201 // loop for fits on 15 sets of EventT0
202 for (int iii = 0; iii < 15; iii++) {
203
204 TH1* hhh = findHist(s_HistName[iii]);
205
206 if (hhh != nullptr) {
207
208 // fit 6 parameters (yield, yieled err, mean, mean err, sigma, sigma err)
209 std::vector<double> par_fit(6, 0.0);
210
211 // check the number of entry in histogram to fit
212 int nToFit = hhh->GetEffectiveEntries();
213 if (nToFit > m_MinEntryForFit &&
214 nToFit > 200) {
215
216 // perform fit on EventT0 and get peak position and width
217 fitEventT0(hhh, par_fit);
218
219 }
220
221 // set mean parameter to TGraphErrors
222 h_tge_mean->SetPoint(iii, (iii + 1) * 20, par_fit[2]);
223 h_tge_mean->SetPointError(iii, 10, par_fit[3]);
224 // set width parameter to TGraphErrors
225 h_tge_width->SetPoint(iii, (iii + 1) * 20, par_fit[4]);
226 h_tge_width->SetPointError(iii, 10, par_fit[5]);
227
228 }
229 }
230}
231
233 std::vector<double>& fit_par)
234{
235
236 // initial parameters to fit on EventT0 from histogram statistics
237 float v_mean = hist->GetMean();
238 float v_rms = hist->GetRMS();
239 float v_norm = hist->GetEffectiveEntries() / v_rms;
240 float x_min = v_mean - 3 * v_rms;
241 float x_max = v_mean + 3 * v_rms;
242
243 // Gaussian function for fit on EventT0
244 TF1* f1 = new TF1("f1", DQMHistAnalysisTRGECLModule::fGaus,
245 x_min,
246 x_max,
247 3);
248 // set initial parameters of Gaussian
249 f1->SetParameters(v_norm, v_mean, v_rms);
250
251 // perform fit
252 hist->Fit("f1", "Q", "", x_min, x_max);
253
254 //
255 if (hist->GetFunction("f1") == NULL) {
256 B2DEBUG(20, "Fit failed");
257 return;
258 }
259
260 //
261 if (f1->GetParameter(2) <= 0) {
262 B2DEBUG(20, "Fit failed");
263 return;
264 }
265
266 // get fit parameters
267 fit_par[0] = f1->GetParameter(0);
268 fit_par[1] = f1->GetParError(0);
269 fit_par[2] = f1->GetParameter(1);
270 fit_par[3] = f1->GetParError(1);
271 fit_par[4] = f1->GetParameter(2);
272 fit_par[5] = f1->GetParError(2);
273
274 // delete fit function
275 delete f1;
276}
The base class for the histogram analysis module.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
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: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.