Belle II Software  release-06-01-15
DQMHistAnalysisPXDFits.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 : DQMHistAnalysisPXDFits.cc
10 // Description : DQM module, which fits many PXD histograms and writes out fit parameters in new histograms
11 //-
12 
13 
14 #include <dqm/analysis/modules/DQMHistAnalysisPXDFits.h>
15 #include <TROOT.h>
16 
17 #include <boost/format.hpp>
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 using boost::format;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
27 REG_MODULE(DQMHistAnalysisPXDFits)
28 
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32 
35 {
36  //Parameter definition
37  addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where histograms were placed",
38  std::string("PXDRAW"));
39 // addParam("HistoName", m_histoname, "Name of Histogram (incl dir)", std::string(""));
40  for (auto i = 0, j = 0; i < 64; i++) {
41  auto layer = (((i >> 5) & 0x1) + 1);
42  auto ladder = ((i >> 1) & 0xF);
43  if (ladder == 0) continue; // numbering starts at 1
44  if (layer == 1 && ladder > 8) continue; // 8 inner ladders
45  if (layer == 2 && ladder > 12) continue; // 12 outer ladders
46  m_id_to_inx[i] = j; // i = id , j - index
47  m_inx_to_id[j] = i;
48  j++;
49  if (j == NUM_MODULES) break;
50  }
51  for (auto i = 0; i < NUM_MODULES; i++) {
52  m_hSignal[i] = nullptr;
53  m_hCommon[i] = nullptr;
54  m_hCounts[i] = nullptr;
55  m_cSignal[i] = nullptr;
56  m_cCommon[i] = nullptr;
57  m_cCounts[i] = nullptr;
58  }
59  B2DEBUG(1, "DQMHistAnalysisPXDFits: Constructor done.");
60 }
61 
62 void DQMHistAnalysisPXDFitsModule::initialize()
63 {
64  B2DEBUG(1, "DQMHistAnalysisPXDFits: initialized.");
65 
66  gROOT->cd(); // this seems to be important, or strange things happen
67 
68  TString a;
69 
70  a = "pxdraw/hSignalAll";
71  a.ReplaceAll("/", "_");
72  m_cSignalAll = new TCanvas((m_histogramDirectoryName + "/c_").data() + a);
73  m_hSignalAll = new TH1F(a, a, NUM_MODULES, 0, NUM_MODULES);
74  m_hSignalAll->SetDirectory(0);// dont mess with it, this is MY histogram
75  m_hSignalAll->SetStats(false);
76 
77  a = "pxdraw/hCommonAll";
78  a.ReplaceAll("/", "_");
79  m_cCommonAll = new TCanvas((m_histogramDirectoryName + "/c_").data() + a);
80  m_hCommonAll = new TH1F(a, a, NUM_MODULES, 0, NUM_MODULES);
81  m_hCommonAll->SetDirectory(0);// dont mess with it, this is MY histogram
82  m_hCommonAll->SetStats(false);
83 
84  a = "pxdraw/hCountsAll";
85  a.ReplaceAll("/", "_");
86  m_cCountsAll = new TCanvas((m_histogramDirectoryName + "/c_").data() + a);
87  m_hCountsAll = new TH1F(a, a, NUM_MODULES, 0, NUM_MODULES);
88  m_hCountsAll->SetDirectory(0);// dont mess with it, this is MY histogram
89  m_hCountsAll->SetStats(false);
90 
91  a = "pxdraw/hOccupancyAll";
92  a.ReplaceAll("/", "_");
93  m_cOccupancyAll = new TCanvas((m_histogramDirectoryName + "/c_").data() + a);
94  m_hOccupancyAll = new TH1F(a, a, NUM_MODULES, 0, NUM_MODULES);
95  m_hOccupancyAll->SetDirectory(0);// dont mess with it, this is MY histogram
96  m_hOccupancyAll->SetStats(false);
97 
98  for (auto i = 0; i < NUM_MODULES; i++) {
99  auto id = m_inx_to_id[i];
100  auto layer = (((id >> 5) & 0x1) + 1);
101  auto ladder = ((id >> 1) & 0xF);
102  auto sensor = ((id & 0x1) + 1);
103  string s2 = str(format("_%d.%d.%d") % layer % ladder % sensor);
104 
105  m_hSignalAll->GetXaxis()->SetBinLabel(i + 1, TString(s2));
106  m_hCommonAll->GetXaxis()->SetBinLabel(i + 1, TString(s2));
107  m_hCountsAll->GetXaxis()->SetBinLabel(i + 1, TString(s2));
108  m_hOccupancyAll->GetXaxis()->SetBinLabel(i + 1, TString(s2));
109 
110  a = "pxdraw/hSignal";
111  a.ReplaceAll("/", "_");
112  a += s2;
113 
114  m_cSignal[i] = new TCanvas((m_histogramDirectoryName + "/c_").data() + a);
115  m_hSignal[i] = new TH2F(a, a, 6, 0, 6, 4, 0, 4);
116  m_hSignal[i]->SetDirectory(0);// dont mess with it, this is MY histogram
117  m_hSignal[i]->SetStats(false);
118  m_hSignal[i]->SetMinimum(0);
119  m_hSignal[i]->SetMaximum(64);
120 
121  a = "pxdraw/hCommon";
122  a.ReplaceAll("/", "_");
123  a += s2;
124  m_cCommon[i] = new TCanvas((m_histogramDirectoryName + "/c_").data() + a);
125  m_hCommon[i] = new TH2F(a, a, 6, 0, 6, 4, 0, 4);
126  m_hCommon[i]->SetDirectory(0);// dont mess with it, this is MY histogram
127  m_hCommon[i]->SetStats(false);
128  m_hCommon[i]->SetMinimum(0);
129  m_hCommon[i]->SetMaximum(256);
130 
131  a = "pxdraw/hCounts";
132  a.ReplaceAll("/", "_");
133  a += s2;
134  m_cCounts[i] = new TCanvas((m_histogramDirectoryName + "/c_").data() + a);
135  m_hCounts[i] = new TH2F(a, a, 6, 0, 6, 4, 0, 4);
136  m_hCounts[i]->SetDirectory(0);// dont mess with it, this is MY histogram
137  m_hCounts[i]->SetStats(false);
138  }
139 
140  m_fLandau = new TF1("f_Landau", "landau", 0, 256);
141  m_fLandau->SetParameter(0, 1000);
142  m_fLandau->SetParameter(1, 0);
143  m_fLandau->SetParameter(2, 10);
144  m_fLandau->SetLineColor(4);
145  m_fLandau->SetNpx(256);
146  m_fLandau->SetNumberFitPoints(256);
147 
148  m_fGaus = new TF1("f_Gaus", "gaus", 0, 8096);
149  m_fGaus->SetParameter(0, 1000);
150  m_fGaus->SetParameter(1, 0);
151  m_fGaus->SetParameter(2, 10);
152  m_fGaus->SetLineColor(4);
153  m_fGaus->SetNpx(256);
154  m_fGaus->SetNumberFitPoints(256);
155 }
156 
157 
158 void DQMHistAnalysisPXDFitsModule::beginRun()
159 {
160  B2DEBUG(1, "DQMHistAnalysisPXDFits: beginRun called.");
161 
162  // not much we can do here ... as we have created everything already
163  for (auto i = 0; i < NUM_MODULES; i++) {
164  m_cSignal[i]->Clear();
165  m_cCommon[i]->Clear();
166  m_cCounts[i]->Clear();
167  // no need to Cd and Draw yet
168  }
169 }
170 
171 void DQMHistAnalysisPXDFitsModule::event()
172 {
173 // bool flag = false;
174 
175  m_hSignalAll->Reset(); // dont sum up!!!
176  m_hCommonAll->Reset(); // dont sum up!!!
177  m_hCountsAll->Reset(); // dont sum up!!!
178  m_hOccupancyAll->Reset(); // dont sum up!!!
179 
180  for (auto i = 0; i < NUM_MODULES; i++) {
181  auto id = m_inx_to_id[i];
182  auto layer = (((id >> 5) & 0x1) + 1);
183  auto ladder = ((id >> 1) & 0xF);
184  auto sensor = ((id & 0x1) + 1);
185 
186  m_hSignal[i]->Reset(); // dont sum up!!!
187  m_hCommon[i]->Reset(); // dont sum up!!!
188  m_hCounts[i]->Reset(); // dont sum up!!!
189 
190  for (auto j = 0; j < 6; j++) {
191  for (auto k = 0; k < 4; k++) {
192  //TH1* hh1 = NULL;
193  string s2 = str(format("_%d.%d.%d_%d_%d") % layer % ladder % sensor % j % k);
194 
195  std::string name = "hrawPxdHitsCharge" + s2;
196  TH1* hh1 = findHist(name);
197  if (hh1 == NULL) {
198  hh1 = findHist(m_histogramDirectoryName, name);
199  }
200 
201  if (hh1 != NULL) {
202 // cout << "do da fit " << endl;
203 // m_fLandau->SetParameter(0, 1000);
204 // m_fLandau->SetParameter(1, 0);
205 // m_fLandau->SetParameter(2, 10);
206 // hh1->Fit(m_fLandau, "0");
207 // m_hSignal[i]->Fill(j, k, m_fLandau->GetParameter(1));
208 // cout << m_fLandau->GetParameter(0) << " " << m_fLandau->GetParameter(1) << " " << m_fLandau->GetParameter(2) << endl;
209  m_hSignal[i]->Fill(j, k, hh1->GetMean());
210  m_hSignalAll->Fill(i, hh1->GetMean());
211  } else {
212  B2INFO("Histo " << name << " not found");
213  }
214 
215  name = "hrawPxdHitsCommonMode" + s2;
216  hh1 = findHist(name);
217  if (hh1 == NULL) {
218  hh1 = findHist(m_histogramDirectoryName, name);
219  }
220 
221  if (hh1 != NULL) {
222 // cout << "do da fit " << endl;
223 // m_fGaus->SetParameter(0, 1000);
224 // m_fGaus->SetParameter(1, 10);
225 // m_fGaus->SetParameter(2, 10);
226 // hh1->Fit(m_fGaus, "0");
227 // m_hCommon[i]->Fill(j, k, m_fGaus->GetParameter(1));
228 // cout << m_fGaus->GetParameter(0) << " " << m_fGaus->GetParameter(1) << " " << m_fGaus->GetParameter(2) << endl;
229  m_hCommon[i]->Fill(j, k, hh1->GetMean());
230  m_hCommonAll->Fill(i, hh1->GetMean());
231  } else {
232  B2INFO("Histo " << name << " not found");
233  }
234 
235  name = "hrawPxdCount" + s2;
236  hh1 = findHist(name);
237  if (hh1 == NULL) {
238  hh1 = findHist(m_histogramDirectoryName, name);
239  }
240 
241  if (hh1 != NULL) {
242 // cout << "do da fit " << endl;
243 // m_fGaus->SetParameter(0, 1000);
244 // m_fGaus->SetParameter(1, 100);
245 // m_fGaus->SetParameter(2, 10);
246 // hh1->Fit(m_fGaus, "0");
247 // m_hCounts[i]->Fill(j, k, m_fGaus->GetParameter(1));
248 // cout << m_fGaus->GetParameter(0) << " " << m_fGaus->GetParameter(1) << " " << m_fGaus->GetParameter(2) << endl;
249  m_hCounts[i]->Fill(j, k, hh1->GetMean());
250  m_hCountsAll->Fill(i, hh1->GetMean());
251  m_hOccupancyAll->Fill(i, hh1->GetMean() / (250 * 768 / 24)); // Occupancy in percent
252  } else {
253  B2INFO("Histo " << name << " not found");
254  }
255  }
256  }
257  if (m_cSignal[i]) {
258  m_cSignal[i]->cd();
259  if (m_hSignal[i]) m_hSignal[i]->Draw("colz");
260  m_cSignal[i]->Modified();
261  m_cSignal[i]->Update();
262  }
263  if (m_cCommon[i]) {
264  m_cCommon[i]->cd();
265  if (m_hCommon[i]) m_hCommon[i]->Draw("colz");
266  m_cCommon[i]->Modified();
267  m_cCommon[i]->Update();
268  }
269  if (m_cCounts[i]) {
270  m_cCounts[i]->cd();
271  if (m_hCounts[i]) m_hCounts[i]->Draw("colz");
272  m_cCounts[i]->Modified();
273  m_cCounts[i]->Update();
274  }
275  }
276  if (m_cSignalAll) {
277  m_cSignalAll->cd();
278  if (m_hSignalAll) {
279  m_hSignalAll->Scale(1.0 / 24.0); // need to scale
280  m_hSignalAll->Draw();
281  }
282  m_cSignalAll->Modified();
283  m_cSignalAll->Update();
284  }
285  if (m_cCommonAll) {
286  m_cCommonAll->cd();
287  if (m_hCommonAll) {
288  m_hCommonAll->Scale(1.0 / 24.0); // need to scale
289  m_hCommonAll->Draw();
290  }
291  m_cCommonAll->Modified();
292  m_cCommonAll->Update();
293  }
294  if (m_cCountsAll) {
295  m_cCountsAll->cd();
296  if (m_hCountsAll) {
297  // m_hCountsAll->Scale(1.0/24.0); // dont scale counts, we want to have sum
298  // but we would need to scale if we directly calculate occupancy!
299  m_hCountsAll->Draw();
300  }
301  m_cCountsAll->Modified();
302  m_cCountsAll->Update();
303  }
304  if (m_cOccupancyAll) {
305  m_cOccupancyAll->cd();
306  if (m_hOccupancyAll) {
307  m_hOccupancyAll->Scale(1.0 / 24.0); // need to scale
308  m_hOccupancyAll->Draw();
309  }
310  m_cOccupancyAll->Modified();
311  m_cOccupancyAll->Update();
312  }
313 }
314 
315 void DQMHistAnalysisPXDFitsModule::endRun()
316 {
317  B2DEBUG(1, "DQMHistAnalysisPXDFits : endRun called");
318 }
319 
320 
321 void DQMHistAnalysisPXDFitsModule::terminate()
322 {
323  B2DEBUG(1, "DQMHistAnalysisPXDFits: terminate called");
324 }
325 
The base class for the histogram analysis module.
Class definition for the output module of Sequential ROOT I/O.
#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.