Belle II Software  release-08-00-10
DQMHistAnalysisEventT0.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 : DQMHistAnalysisEventT0.cc
10 // Description : module for trigger jitter/EventT0 DQM histogram analysis
11 //-
12 
13 
14 #include <dqm/analysis/modules/DQMHistAnalysisEventT0.h>
15 
16 #include <TROOT.h>
17 #include <TStyle.h>
18 #include <TF1.h>
19 #include <TMath.h>
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
27 REG_MODULE(DQMHistAnalysisEventT0);
28 
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32 
33 DQMHistAnalysisEventT0Module::DQMHistAnalysisEventT0Module()
35 {
36  setDescription("Determining and processing EventT0s from different subdetector (TOP and SVD for now) for different L1 trigger sources (ECL and CDC for now) to estimate trigger jitter information.");
37 
38  //Parameter definition
39  addParam("min_nEntries", m_nEntriesMin, "Minimum number of entries to process the histogram.", m_nEntriesMin);
40  addParam("prefixCanvas", m_prefixCanvas, "Prefix to be added to canvas filename when saved as pdf.", std::string("c"));
41  addParam("printCanvas", m_printCanvas, "If true, prints pdf of the analysis canvas.", bool(false));
42 }
43 
44 
46 
48 {
49  gROOT->cd();
50 
51  //ECLTRG canvas
52  m_cTOPTimeForECLTRG = new TCanvas("EventT0/c_TOPTimeECLTRGjitter", "ECLTRG jitter based on TOP time", 1200, 400);
53  m_topPad1ECLTRG = new TPad("topPad1ECLTRG", "TOP pad1 ECLTRG", 0.03, 0.02, 0.33, 0.98);
54  m_topPad2ECLTRG = new TPad("topPad2ECLTRG", "TOP pad2 ECLTRG", 0.35, 0.02, 0.65, 0.98);
55  m_topPad3ECLTRG = new TPad("topPad3ECLTRG", "TOP pad3 ECLTRG", 0.67, 0.02, 0.97, 0.98);
56 
57  //CDCTRG canvases
58  m_cTOPTimeForCDCTRG = new TCanvas("EventT0/c_TOPTimeCDCTRGjitter", "CDCTRG jitter based on TOP time", 1200, 400);
59  m_topPad1CDCTRG = new TPad("topPad1CDCTRG", "TOP pad1 CDCTRG", 0.03, 0.02, 0.33, 0.98);
60  m_topPad2CDCTRG = new TPad("topPad2CDCTRG", "TOP pad2 CDCTRG", 0.35, 0.02, 0.65, 0.98);
61  m_topPad3CDCTRG = new TPad("topPad3CDCTRG", "TOP pad3 CDCTRG", 0.67, 0.02, 0.97, 0.98);
62 
63  //SVD canvases
64  //ECLTRG canvas
65  m_cSVDTimeForECLTRG = new TCanvas("EventT0/c_SVDTimeECLTRGjitter", "ECLTRG jitter based on SVD time", 1200, 400);
66  m_svdPad1ECLTRG = new TPad("svdPad1ECLTRG", "SVD pad1 ECLTRG", 0.03, 0.02, 0.33, 0.98);
67  m_svdPad2ECLTRG = new TPad("svdPad2ECLTRG", "SVD pad2 ECLTRG", 0.35, 0.02, 0.65, 0.98);
68  m_svdPad3ECLTRG = new TPad("svdPad3ECLTRG", "SVD pad3 ECLTRG", 0.67, 0.02, 0.97, 0.98);
69 
70  // CDC TRG canvas
71  m_cSVDTimeForCDCTRG = new TCanvas("EventT0/c_SVDTimeCDCTRGjitter", "CDCTRG jitter based on SVD time", 1200, 400);
72  m_svdPad1CDCTRG = new TPad("svdPad1CDCTRG", "SVD pad1 CDCTRG", 0.03, 0.02, 0.33, 0.98);
73  m_svdPad2CDCTRG = new TPad("svdPad2CDCTRG", "SVD pad2 CDCTRG", 0.35, 0.02, 0.65, 0.98);
74  m_svdPad3CDCTRG = new TPad("svdPad3CDCTRG", "SVD pad3 CDCTRG", 0.67, 0.02, 0.97, 0.98);
75 
76  m_monObj = getMonitoringObject("eventT0");
81 }
82 
83 
85 {
86  m_cTOPTimeForECLTRG->Clear();
87  m_cTOPTimeForCDCTRG->Clear();
88  m_cSVDTimeForECLTRG->Clear();
89  m_cSVDTimeForCDCTRG->Clear();
90 }
91 
93 {
94  // --- TOP EventT0 plots for ECLTRG ---
95 
96  // find TOP EventT0 Hadrons ECLTRG histogram and process it
97  TH1* h = findHist("EventT0DQMdir/m_histEventT0_TOP_hadron_L1_ECLTRG");
98  TString tag = "hadronECLTRG";
99  m_topPad1ECLTRG->cd();
100  if (processHistogram(h, tag)) {
101  m_topPad1ECLTRG->SetFillColor(0);
102  m_topPad1ECLTRG->Modified();
103  m_topPad1ECLTRG->Update();
104  } else {
105  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
106  h->Draw();
107  m_topPad1ECLTRG->SetFillColor(kGray);
108  }
109 
110  // find TOP EventT0 Bhabhas ECLTRG histogram and process it
111  h = findHist("EventT0DQMdir/m_histEventT0_TOP_bhabha_L1_ECLTRG");
112  tag = "bhabhaECLTRG";
113  m_topPad2ECLTRG->cd();
114  if (processHistogram(h, tag)) {
115  m_topPad2ECLTRG->SetFillColor(0);
116  m_topPad2ECLTRG->Modified();
117  m_topPad2ECLTRG->Update();
118  } else {
119  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
120  h->Draw();
121  m_topPad2ECLTRG->SetFillColor(kGray);
122  }
123 
124  // find TOP EventT0 Mumus ECLTRG histogram and process it
125  h = findHist("EventT0DQMdir/m_histEventT0_TOP_mumu_L1_ECLTRG");
126  tag = "mumuECLTRG";
127  m_topPad3ECLTRG->cd();
128  if (processHistogram(h, tag)) {
129  m_topPad3ECLTRG->SetFillColor(0);
130  m_topPad3ECLTRG->Modified();
131  m_topPad3ECLTRG->Update();
132  } else {
133  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
134  h->Draw();
135  m_topPad3ECLTRG->SetFillColor(kGray);
136  }
137 
138  m_cTOPTimeForECLTRG->cd();
139  m_topPad1ECLTRG->Draw();
140  m_topPad2ECLTRG->Draw();
141  m_topPad3ECLTRG->Draw();
142 
143  if (m_printCanvas)
144  m_cTOPTimeForECLTRG->Print(Form("%s_ECLTRG.pdf", m_prefixCanvas.c_str()));
145 
146 
147  // --- TOP EventT0 plots for CDCTRG ---
148 
149  // find TOP EventT0 Hadrons CDCTRG histogram and process it
150  h = findHist("EventT0DQMdir/m_histEventT0_TOP_hadron_L1_CDCTRG");
151  tag = "hadronCDCTRG";
152  m_topPad1CDCTRG->cd();
153  if (processHistogram(h, tag)) {
154  m_topPad1CDCTRG->SetFillColor(0);
155  m_topPad1CDCTRG->Modified();
156  m_topPad1CDCTRG->Update();
157  m_cTOPTimeForCDCTRG->cd();
158  m_topPad1CDCTRG->Draw();
159  } else {
160  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
161  h->Draw();
162  m_topPad1CDCTRG->SetFillColor(kGray);
163  m_cTOPTimeForCDCTRG->cd();
164  m_topPad1CDCTRG->Draw();
165  }
166 
167  // find TOP EventT0 Bhabhas CDCTRG histogram and process it
168  h = findHist("EventT0DQMdir/m_histEventT0_TOP_bhabha_L1_CDCTRG");
169  tag = "bhabhaCDCTRG";
170  m_topPad2CDCTRG->cd();
171  if (processHistogram(h, tag)) {
172  m_topPad2CDCTRG->SetFillColor(0);
173  m_topPad2CDCTRG->Modified();
174  m_topPad2CDCTRG->Update();
175  m_cTOPTimeForCDCTRG->cd();
176  m_topPad2CDCTRG->Draw();
177  } else {
178  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
179  h->Draw();
180  m_topPad2CDCTRG->SetFillColor(kGray);
181  m_cTOPTimeForCDCTRG->cd();
182  m_topPad2CDCTRG->Draw();
183  }
184 
185  // find TOP EventT0 Mumus CDCTRG histogram and process it
186  h = findHist("EventT0DQMdir/m_histEventT0_TOP_mumu_L1_CDCTRG");
187  tag = "mumuCDCTRG";
188  m_topPad3CDCTRG->cd();
189  if (processHistogram(h, tag)) {
190  m_topPad3CDCTRG->SetFillColor(0);
191  m_topPad3CDCTRG->Modified();
192  m_topPad3CDCTRG->Update();
193  } else {
194  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
195  h->Draw();
196  m_topPad3CDCTRG->SetFillColor(kGray);
197  }
198 
199  m_cTOPTimeForCDCTRG->cd();
200  m_topPad1CDCTRG->Draw();
201  m_topPad2CDCTRG->Draw();
202  m_topPad3CDCTRG->Draw();
203 
204  if (m_printCanvas)
205  m_cTOPTimeForCDCTRG->Print(Form("%s_CDCTRG.pdf", m_prefixCanvas.c_str()));
206 
207 
208 
209  // --- SVD EventT0 plots for ECLTRG ---
210 
211  // find SVD EventT0 Hadrons ECLTRG histogram and process it
212  h = findHist("EventT0DQMdir/m_histEventT0_SVD_hadron_L1_ECLTRG");
213  tag = "hadronECLTRG";
214  m_svdPad1ECLTRG->cd();
215  if (processHistogram(h, tag)) {
216  m_svdPad1ECLTRG->SetFillColor(0);
217  m_svdPad1ECLTRG->Modified();
218  m_svdPad1ECLTRG->Update();
219  } else {
220  B2WARNING(Form("Histogram SVD EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
221  h->Draw();
222  m_svdPad1ECLTRG->SetFillColor(kGray);
223  }
224 
225  // find SVD EventT0 Bhabhas ECLTRG histogram and process it
226  h = findHist("EventT0DQMdir/m_histEventT0_SVD_bhabha_L1_ECLTRG");
227  tag = "bhabhaECLTRG";
228  m_svdPad2ECLTRG->cd();
229  if (processHistogram(h, tag)) {
230  m_svdPad2ECLTRG->SetFillColor(0);
231  m_svdPad2ECLTRG->Modified();
232  m_svdPad2ECLTRG->Update();
233  } else {
234  B2WARNING(Form("Histogram SVD EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
235  h->Draw();
236  m_svdPad2ECLTRG->SetFillColor(kGray);
237  }
238 
239  // find SVD EventT0 Mumus ECLTRG histogram and process it
240  h = findHist("EventT0DQMdir/m_histEventT0_SVD_mumu_L1_ECLTRG");
241  tag = "mumuECLTRG";
242  m_svdPad3ECLTRG->cd();
243  if (processHistogram(h, tag)) {
244  m_svdPad3ECLTRG->SetFillColor(0);
245  m_svdPad3ECLTRG->Modified();
246  m_svdPad3ECLTRG->Update();
247  } else {
248  B2WARNING(Form("Histogram SVD EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
249  h->Draw();
250  m_svdPad3ECLTRG->SetFillColor(kGray);
251  }
252 
253  m_cSVDTimeForECLTRG->cd();
254  m_svdPad1ECLTRG->Draw();
255  m_svdPad2ECLTRG->Draw();
256  m_svdPad3ECLTRG->Draw();
257 
258  if (m_printCanvas)
259  m_cSVDTimeForECLTRG->Print(Form("%s_SVDECLTRG.pdf", m_prefixCanvas.c_str()));
260 
261 
262  // --- SVD EventT0 plots for CDCTRG ---
263 
264  // find SVD EventT0 Hadrons CDCTRG histogram and process it
265  h = findHist("EventT0DQMdir/m_histEventT0_SVD_hadron_L1_CDCTRG");
266  tag = "hadronCDCTRG";
267  m_svdPad1CDCTRG->cd();
268  if (processHistogram(h, tag)) {
269  m_svdPad1CDCTRG->SetFillColor(0);
270  m_svdPad1CDCTRG->Modified();
271  m_svdPad1CDCTRG->Update();
272  m_cSVDTimeForCDCTRG->cd();
273  m_svdPad1CDCTRG->Draw();
274  } else {
275  B2WARNING(Form("Histogram SVD EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
276  h->Draw();
277  m_svdPad1CDCTRG->SetFillColor(kGray);
278  m_cSVDTimeForCDCTRG->cd();
279  m_svdPad1CDCTRG->Draw();
280  }
281 
282  // find SVD EventT0 Bhabhas CDCTRG histogram and process it
283  h = findHist("EventT0DQMdir/m_histEventT0_SVD_bhabha_L1_CDCTRG");
284  tag = "bhabhaCDCTRG";
285  m_svdPad2CDCTRG->cd();
286  if (processHistogram(h, tag)) {
287  m_svdPad2CDCTRG->SetFillColor(0);
288  m_svdPad2CDCTRG->Modified();
289  m_svdPad2CDCTRG->Update();
290  m_cSVDTimeForCDCTRG->cd();
291  m_svdPad2CDCTRG->Draw();
292  } else {
293  B2WARNING(Form("Histogram SVD EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
294  h->Draw();
295  m_svdPad2CDCTRG->SetFillColor(kGray);
296  m_cSVDTimeForCDCTRG->cd();
297  m_svdPad2CDCTRG->Draw();
298  }
299 
300 
301  // find SVD EventT0 Mumus CDCTRG histogram and process it
302  h = findHist("EventT0DQMdir/m_histEventT0_SVD_mumu_L1_CDCTRG");
303  tag = "mumuCDCTRG";
304  m_svdPad3CDCTRG->cd();
305  if (processHistogram(h, tag)) {
306  m_svdPad3CDCTRG->SetFillColor(0);
307  m_svdPad3CDCTRG->Modified();
308  m_svdPad3CDCTRG->Update();
309  } else {
310  B2WARNING(Form("Histogram SVD EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
311  h->Draw();
312  m_svdPad3CDCTRG->SetFillColor(kGray);
313  }
314 
315  m_cSVDTimeForCDCTRG->cd();
316  m_svdPad1CDCTRG->Draw();
317  m_svdPad2CDCTRG->Draw();
318  m_svdPad3CDCTRG->Draw();
319 
320  if (m_printCanvas)
321  m_cSVDTimeForCDCTRG->Print(Form("%s_SVDCDCTRG.pdf", m_prefixCanvas.c_str()));
322 
323 }
324 
326 {
327 
328  delete m_cTOPTimeForECLTRG;
329  delete m_cTOPTimeForCDCTRG;
330  delete m_cSVDTimeForECLTRG;
331  delete m_cSVDTimeForCDCTRG;
332 
333 }
334 
335 double DQMHistAnalysisEventT0Module::fDoubleGaus(double* x, double* par)
336 {
337  double N = par[0];
338  double frac = par[1];
339  double mean = par[2];
340  double sigma = par[3];
341  double mean2 = par[4];
342  double sigma2 = par[5];
343 
344  return N * frac * TMath::Gaus(x[0], mean, sigma) + N * (1 - frac) * TMath::Gaus(x[0], mean2, sigma2);
345 }
346 
348 {
349 
350  if (h == nullptr) {
351  B2DEBUG(20, "h == nullptr");
352  m_monObj->setVariable(Form("fit_%s", tag.Data()), 0);
353  return false;
354  }
355 
356  // The default value for the EventT0 value is -1000, but bins start at -100, so we might mostly fill the underflow bin if
357  // EventT0 for a detector is not present. And also the nominal EventT0 might be too big or too small. Only use the content
358  // of the actually useful bins to decide whether or not to fit the histogram.
359  auto nValidEntries = h->GetEntries() - h->GetBinContent(0) - h->GetBinContent(h->GetNbinsX() + 1);
360  if (static_cast<uint>(nValidEntries) < m_nEntriesMin) {
361  B2DEBUG(20, "not enough entries");
362  m_monObj->setVariable(Form("fit_%s", tag.Data()), 0);
363  return false;
364  }
365 
366 
367  //scale the histogram only with content of valid bins, ignore over and underflow bins
368  h->Scale(1. / nValidEntries);
369  h->GetXaxis()->SetRangeUser(-50, 50);
370 
371  //define the fitting function
372  TF1 fitf("fit", DQMHistAnalysisEventT0Module::fDoubleGaus, -50, 50, 6);
373  fitf.SetParNames("N", "f_{1}", "#mu_{1}", "#sigma_{1}", "#mu_{2}", "#sigma_{2}");
374  fitf.SetParameters(0.1, 0.8, 0, 5, 0, 15);
375  fitf.SetParLimits(1, 0, 1); //fraction
376  fitf.SetParLimits(3, 0, 100); //sigma1
377  fitf.SetParLimits(5, 0, 100); //sigma2
378 
379  if (h->Fit(&fitf, "SR+") != 0) {
380  B2DEBUG(20, "failed fit");
381  m_monObj->setVariable(Form("fit_%s", tag.Data()), 0);
382  return false;
383  }
384 
385  Double_t par[6];
386  fitf.GetParameters(&par[0]);
387  Double_t parErr[6];
388  for (int i = 0; i < 6; i++)
389  parErr[i] = fitf.GetParError(i) ;
390 
391 
392  //define gaussian components
393  TF1 gauss1("gauss1", "gaus", -100, 100);
394  TF1 gauss2("gauss2", "gaus", -100, 100);
395 
396  gauss1.SetLineColor(kBlue);
397  gauss1.SetLineStyle(kDashed);
398  gauss1.SetParameters(par[0]*par[1], par[2], par[3]);
399 
400  gauss2.SetLineColor(kRed);
401  gauss2.SetLineStyle(kDashed);
402  gauss2.SetParameters(par[0] * (1 - par[1]), par[4], par[5]);
403 
404  m_monObj->setVariable(Form("fit_%s", tag.Data()), 1);
405  m_monObj->setVariable(Form("N_%s", tag.Data()), nValidEntries, TMath::Sqrt(nValidEntries));
406  m_monObj->setVariable(Form("f_%s", tag.Data()), par[1], parErr[1]);
407  m_monObj->setVariable(Form("mean1_%s", tag.Data()), par[2], parErr[2]);
408  m_monObj->setVariable(Form("sigma1_%s", tag.Data()), par[3], parErr[3]);
409  m_monObj->setVariable(Form("mean2_%s", tag.Data()), par[4], parErr[4]);
410  m_monObj->setVariable(Form("sigma2_%s", tag.Data()), par[5], parErr[5]);
411 
412  //SETUP gSTYLE - all plots
413  gStyle->SetOptFit(1111);
414 
415  h->DrawClone();
416  fitf.DrawClone("same");
417  gauss1.DrawClone("same");
418  gauss2.DrawClone("same");
419 
420  return true;
421 
422 }
423 
TCanvas * m_cTOPTimeForECLTRG
TOP EventT0 for ECLTRG plots canvas.
TCanvas * m_cSVDTimeForECLTRG
SVD EventT0 for ECLTRG plots canvas.
void initialize() override final
create TCanvas and MonitoringObject
static double fDoubleGaus(double *x, double *par)
double gaussian fitting function for the jitter distribution
TPad * m_svdPad1CDCTRG
pad for SVD time CDCTRG hadrons
TPad * m_svdPad3CDCTRG
pad for SVD time CDCTRG mumu
std::string m_prefixCanvas
prefix to be added to canvas name when saved as pdf
TPad * m_svdPad2ECLTRG
pad for SVD time ECLTRG bhabhas
MonitoringObject * m_monObj
MonitoringObject to be produced by this module.
void terminate() override final
delete pointers
bool m_printCanvas
if true print the pdf of the canvases
TPad * m_svdPad2CDCTRG
pad for SVD time CDCTRG bhabhas
TPad * m_topPad1CDCTRG
pad for TOP time CDCTRG hadrons
uint m_nEntriesMin
minimum number of entries to process the histogram
void endRun() override final
fit the histograms
TPad * m_topPad3CDCTRG
pad for TOP time CDCTRG mumu
TPad * m_svdPad1ECLTRG
pad for SVD time ECLTRG hadrons
bool processHistogram(TH1 *h, TString tag)
process the EventT0 distribution fitting with two gaussians filling the MonitoringObject
void beginRun() override final
clear TCanvas
TPad * m_topPad2CDCTRG
pad for TOP time CDCTRG bhabhas
TPad * m_topPad3ECLTRG
pad for TOP time ECLTRG mumu
TPad * m_topPad2ECLTRG
pad for TOP time ECLTRG bhabhas
TCanvas * m_cTOPTimeForCDCTRG
TOP EventT0 for CDCTRG plots canvas.
TCanvas * m_cSVDTimeForCDCTRG
SVD EventT0 for CDCTRG plots canvas.
TPad * m_topPad1ECLTRG
pad for TOP time ECLTRG hadrons
TPad * m_svdPad3ECLTRG
pad for SVD time ECLTRG mumu
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).
static MonitoringObject * getMonitoringObject(const std::string &histname)
Get MonitoringObject with given name (new object is created if non-existing)
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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.