Belle II Software  release-06-02-00
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 DQM histogram analysis of SVD sensors occupancies
11 //-
12 
13 
14 #include <dqm/analysis/modules/DQMHistAnalysisEventT0.h>
15 
16 #include <TROOT.h>
17 #include <TStyle.h>
18 #include <TString.h>
19 #include <TFitResult.h>
20 
21 #include <TMath.h>
22 #include <iostream>
23 
24 using namespace std;
25 using namespace Belle2;
26 
27 //-----------------------------------------------------------------
28 // Register the Module
29 //-----------------------------------------------------------------
30 REG_MODULE(DQMHistAnalysisEventT0)
31 
32 //-----------------------------------------------------------------
33 // Implementation
34 //-----------------------------------------------------------------
35 
38 {
39  //Parameter definition
40  addParam("min_nEntries", m_nEntriesMin, "minimum numeber of entries to process the histogram", m_nEntriesMin);
41  addParam("prefixCanvas", m_prefixCanvas, "prefix to be added to canvas filename when saved as pdf", std::string("c"));
42  addParam("printCanvas", m_printCanvas, "if True prints pdf of the analysis canvas", bool(false));
43 }
44 
45 
46 DQMHistAnalysisEventT0Module::~DQMHistAnalysisEventT0Module() { }
47 
48 void DQMHistAnalysisEventT0Module::initialize()
49 {
50  gROOT->cd();
51 
52  //ECLTRG canvas
53  m_cECLTRG = new TCanvas("EventT0/c_ECLTRGjitter", "ECLTRG jitter", 1200, 400);
54  m_pad1ECLTRG = new TPad("pad1ECLTRG", "pad1 ECLTRG", 0.03, 0.02, 0.33, 0.98);
55  m_pad2ECLTRG = new TPad("pad2ECLTRG", "pad2 ECLTRG", 0.35, 0.02, 0.65, 0.98);
56  m_pad3ECLTRG = new TPad("pad3ECLTRG", "pad3 ECLTRG", 0.67, 0.02, 0.97, 0.98);
57 
58  //CDCTRG canvases
59  m_cCDCTRG = new TCanvas("EventT0/c_CDCTRGjitter", "CDCTRG jitter", 1200, 400);
60  m_pad1CDCTRG = new TPad("pad1CDCTRG", "pad1 CDCTRG", 0.03, 0.02, 0.33, 0.98);
61  m_pad2CDCTRG = new TPad("pad2CDCTRG", "pad2 CDCTRG", 0.35, 0.02, 0.65, 0.98);
62  m_pad3CDCTRG = new TPad("pad3CDCTRG", "pad3 CDCTRG", 0.67, 0.02, 0.97, 0.98);
63 
64  m_monObj = getMonitoringObject("eventT0");
65  m_monObj->addCanvas(m_cECLTRG);
66  m_monObj->addCanvas(m_cCDCTRG);
67 }
68 
69 
70 void DQMHistAnalysisEventT0Module::beginRun()
71 {
72  m_cECLTRG->Clear();
73  m_cCDCTRG->Clear();
74 }
75 
76 void DQMHistAnalysisEventT0Module::endRun()
77 {
78 
79 
80  // --- ECLTRG ---
81 
82  //find TOP EventT0 Hadrons ECLTRG histogram and process it
83  TH1* h = findHist("EventT0DQMdir/m_histEventT0_TOP_hadron_L1_ECLTRG");
84  TString tag = "hadronECLTRG";
85  m_pad1ECLTRG->cd();
86  if (processHistogram(h, tag)) {
87  m_pad1ECLTRG->SetFillColor(0);
88  m_pad1ECLTRG->Modified();
89  m_pad1ECLTRG->Update();
90  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
91  h->Draw();
92  m_pad1ECLTRG->SetFillColor(kGray);
93  }
94 
95  //find TOP EventT0 Bhabhas ECLTRG histogram and process it
96  h = findHist("EventT0DQMdir/m_histEventT0_TOP_bhabha_L1_ECLTRG");
97  tag = "bhabhaECLTRG";
98  m_pad2ECLTRG->cd();
99  if (processHistogram(h, tag)) {
100  m_pad2ECLTRG->SetFillColor(0);
101  m_pad2ECLTRG->Modified();
102  m_pad2ECLTRG->Update();
103  } else {
104  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
105  h->Draw();
106  m_pad2ECLTRG->SetFillColor(kGray);
107  }
108 
109 
110  //find TOP EventT0 Mumus ECLTRG histogram and process it
111  h = findHist("EventT0DQMdir/m_histEventT0_TOP_mumu_L1_ECLTRG");
112  tag = "mumuECLTRG";
113  m_pad3ECLTRG->cd();
114  if (processHistogram(h, tag)) {
115  m_pad3ECLTRG->SetFillColor(0);
116  m_pad3ECLTRG->Modified();
117  m_pad3ECLTRG->Update();
118  } else {
119  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
120  h->Draw();
121  m_pad3ECLTRG->SetFillColor(kGray);
122  }
123 
124  m_cECLTRG->cd();
125  m_pad1ECLTRG->Draw();
126  m_pad2ECLTRG->Draw();
127  m_pad3ECLTRG->Draw();
128 
129  if (m_printCanvas)
130  m_cECLTRG->Print(Form("%s_ECLTRG.pdf", m_prefixCanvas.c_str()));
131 
132 
133  // --- CDCTRG ---
134 
135  //find TOP EventT0 Hadrons CDCTRG histogram and process it
136  h = findHist("EventT0DQMdir/m_histEventT0_TOP_hadron_L1_CDCTRG");
137  tag = "hadronCDCTRG";
138  m_pad1CDCTRG->cd();
139  if (processHistogram(h, tag)) {
140  m_pad1CDCTRG->SetFillColor(0);
141  m_pad1CDCTRG->Modified();
142  m_pad1CDCTRG->Update();
143  m_cCDCTRG->cd();
144  m_pad1CDCTRG->Draw();
145  } else {
146  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
147  h->Draw();
148  m_pad1CDCTRG->SetFillColor(kGray);
149  m_cCDCTRG->cd();
150  m_pad1CDCTRG->Draw();
151  }
152 
153  //find TOP EventT0 Bhabhas CDCTRG histogram and process it
154  h = findHist("EventT0DQMdir/m_histEventT0_TOP_bhabha_L1_CDCTRG");
155  tag = "bhabhaCDCTRG";
156  m_pad2CDCTRG->cd();
157  if (processHistogram(h, tag)) {
158  m_pad2CDCTRG->SetFillColor(0);
159  m_pad2CDCTRG->Modified();
160  m_pad2CDCTRG->Update();
161  m_cCDCTRG->cd();
162  m_pad2CDCTRG->Draw();
163  } else {
164  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
165  h->Draw();
166  m_pad2CDCTRG->SetFillColor(kGray);
167  m_cCDCTRG->cd();
168  m_pad2CDCTRG->Draw();
169  }
170 
171 
172  //find TOP EventT0 Mumus CDCTRG histogram and process it
173  h = findHist("EventT0DQMdir/m_histEventT0_TOP_mumu_L1_CDCTRG");
174  tag = "mumuCDCTRG";
175  m_pad3CDCTRG->cd();
176  if (processHistogram(h, tag)) {
177  m_pad3CDCTRG->SetFillColor(0);
178  m_pad3CDCTRG->Modified();
179  m_pad3CDCTRG->Update();
180  } else {
181  B2WARNING(Form("Histogram TOP EventT0 for %s from EventT0 DQM not processed!", tag.Data()));
182  h->Draw();
183  m_pad3CDCTRG->SetFillColor(kGray);
184  }
185 
186  m_cCDCTRG->cd();
187  m_pad1CDCTRG->Draw();
188  m_pad2CDCTRG->Draw();
189  m_pad3CDCTRG->Draw();
190 
191  if (m_printCanvas)
192  m_cCDCTRG->Print(Form("%s_CDCTRG.pdf", m_prefixCanvas.c_str()));
193 
194 
195 }
196 
197 void DQMHistAnalysisEventT0Module::terminate()
198 {
199 
200  delete m_cECLTRG;
201  delete m_cCDCTRG;
202 
203 }
204 
205 
206 double DQMHistAnalysisEventT0Module::fDoubleGaus(double* x, double* par)
207 {
208  double N = par[0];
209  double frac = par[1];
210  double mean = par[2];
211  double sigma = par[3];
212  double mean2 = par[4];
213  double sigma2 = par[5];
214 
215  return N * frac * TMath::Gaus(x[0], mean, sigma) + N * (1 - frac) * TMath::Gaus(x[0], mean2, sigma2);
216 }
217 
218 bool DQMHistAnalysisEventT0Module::processHistogram(TH1* h, TString tag)
219 {
220 
221  if (h == nullptr) {
222  B2DEBUG(20, "h == nullptr");
223  m_monObj->setVariable(Form("fit_%s", tag.Data()), 0);
224  return false;
225  }
226 
227  int nToFit = h->GetEntries();// - h->GetBinContent(0) - h->GetBinContent(h->GetNbinsX()+1);
228  if (nToFit < m_nEntriesMin) {
229  B2DEBUG(20, "not enough entries");
230  m_monObj->setVariable(Form("fit_%s", tag.Data()), 0);
231  return false;
232  }
233 
234 
235  //scale the histogram
236  h->Scale(1. / h->GetEntries());
237  h->GetXaxis()->SetRangeUser(-50, 50);
238 
239  //define the fitting function
240  TF1 fitf("fit", DQMHistAnalysisEventT0Module::fDoubleGaus, -50, 50, 6);
241  fitf.SetParNames("N", "f_{1}", "#mu_{1}", "#sigma_{1}", "#mu_{2}", "#sigma_{2}");
242  fitf.SetParameters(0.1, 0.8, 0, 5, 0, 15);
243  fitf.SetParLimits(1, 0, 1); //fraction
244  fitf.SetParLimits(3, 0, 100); //sigma1
245  fitf.SetParLimits(5, 0, 100); //sigma2
246 
247  if (h->Fit(&fitf, "SR+") != 0) {
248  B2DEBUG(20, "failed fit");
249  m_monObj->setVariable(Form("fit_%s", tag.Data()), 0);
250  return false;
251  }
252 
253  Double_t par[6];
254  fitf.GetParameters(&par[0]);
255  Double_t parErr[6];
256  for (int i = 0; i < 6; i++)
257  parErr[i] = fitf.GetParError(i) ;
258 
259 
260  //define gaussian components
261  TF1 gauss1("gauss1", "gaus", -100, 100);
262  TF1 gauss2("gauss2", "gaus", -100, 100);
263 
264  gauss1.SetLineColor(kBlue);
265  gauss1.SetLineStyle(kDashed);
266  gauss1.SetParameters(par[0]*par[1], par[2], par[3]);
267 
268  gauss2.SetLineColor(kBlue);
269  gauss2.SetLineStyle(kDashed);
270  gauss2.SetParameters(par[0] * (1 - par[1]), par[4], par[5]);
271 
272  m_monObj->setVariable(Form("fit_%s", tag.Data()), 1);
273  m_monObj->setVariable(Form("N_%s", tag.Data()), h->GetEntries(), TMath::Sqrt(h->GetEntries()));
274  m_monObj->setVariable(Form("f_%s", tag.Data()), par[1], parErr[1]);
275  m_monObj->setVariable(Form("mean1_%s", tag.Data()), par[2], parErr[2]);
276  m_monObj->setVariable(Form("sigma1_%s", tag.Data()), par[3], parErr[3]);
277  m_monObj->setVariable(Form("mean2_%s", tag.Data()), par[4], parErr[4]);
278  m_monObj->setVariable(Form("sigma2_%s", tag.Data()), par[5], parErr[5]);
279 
280  //SETUP gSTYLE - all plots
281  gStyle->SetOptFit(1111);
282 
283  h->DrawClone();
284  fitf.DrawClone("same");
285  gauss1.DrawClone("same");
286  gauss2.DrawClone("same");
287 
288  return true;
289 
290 }
291 
Class definition for the output module of Sequential ROOT I/O.
The base class for the histogram analysis module.
#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.