Belle II Software development
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 <format>
18
19using namespace Belle2;
20
21//-----------------------------------------------------------------
22// Register the Module
23//-----------------------------------------------------------------
24REG_MODULE(DQMHistAnalysisPXDFits);
25
26//-----------------------------------------------------------------
27// Implementation
28//-----------------------------------------------------------------
29
32{
33 // This module CAN NOT be run in parallel!
34 setDescription("DQM Analysis for PXD Raw");
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
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 std::string s2 = std::format("_{}.{}.{}", 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
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
172{
173 m_hSignalAll->Reset(); // dont sum up!!!
174 m_hCommonAll->Reset(); // dont sum up!!!
175 m_hCountsAll->Reset(); // dont sum up!!!
176 m_hOccupancyAll->Reset(); // dont sum up!!!
177
178 for (auto i = 0; i < NUM_MODULES; i++) {
179 auto id = m_inx_to_id[i];
180 auto layer = (((id >> 5) & 0x1) + 1);
181 auto ladder = ((id >> 1) & 0xF);
182 auto sensor = ((id & 0x1) + 1);
183
184 m_hSignal[i]->Reset(); // dont sum up!!!
185 m_hCommon[i]->Reset(); // dont sum up!!!
186 m_hCounts[i]->Reset(); // dont sum up!!!
187
188 for (auto j = 0; j < 6; j++) {
189 for (auto k = 0; k < 4; k++) {
190 std::string s2 = std::format("_{}.{}.{}_{}_{}", layer, ladder, sensor, j, k);
191 {
192 std::string name = "hrawPxdHitsCharge" + s2;
193 if (auto hh1 = findHist(m_histogramDirectoryName, name); hh1 != nullptr) {
194// m_fLandau->SetParameter(0, 1000);
195// m_fLandau->SetParameter(1, 0);
196// m_fLandau->SetParameter(2, 10);
197// hh1->Fit(m_fLandau, "0");
198// m_hSignal[i]->Fill(j, k, m_fLandau->GetParameter(1));
199// cout << m_fLandau->GetParameter(0) << " " << m_fLandau->GetParameter(1) << " " << m_fLandau->GetParameter(2) << endl;
200 m_hSignal[i]->Fill(j, k, hh1->GetMean());
201 m_hSignalAll->Fill(i, hh1->GetMean());
202 } else {
203 B2INFO("Histo " << name << " not found");
204 }
205 }
206 {
207 std::string name = "hrawPxdHitsCommonMode" + s2;
208 if (auto hh1 = findHist(m_histogramDirectoryName, name); hh1 != nullptr) {
209// m_fGaus->SetParameter(0, 1000);
210// m_fGaus->SetParameter(1, 10);
211// m_fGaus->SetParameter(2, 10);
212// hh1->Fit(m_fGaus, "0");
213// m_hCommon[i]->Fill(j, k, m_fGaus->GetParameter(1));
214// cout << m_fGaus->GetParameter(0) << " " << m_fGaus->GetParameter(1) << " " << m_fGaus->GetParameter(2) << endl;
215 m_hCommon[i]->Fill(j, k, hh1->GetMean());
216 m_hCommonAll->Fill(i, hh1->GetMean());
217 } else {
218 B2INFO("Histo " << name << " not found");
219 }
220 }
221 {
222 std::string name = "hrawPxdCount" + s2;
223 if (auto hh1 = findHist(m_histogramDirectoryName, name); hh1 != nullptr) {
224// m_fGaus->SetParameter(0, 1000);
225// m_fGaus->SetParameter(1, 100);
226// m_fGaus->SetParameter(2, 10);
227// hh1->Fit(m_fGaus, "0");
228// m_hCounts[i]->Fill(j, k, m_fGaus->GetParameter(1));
229// cout << m_fGaus->GetParameter(0) << " " << m_fGaus->GetParameter(1) << " " << m_fGaus->GetParameter(2) << endl;
230 m_hCounts[i]->Fill(j, k, hh1->GetMean());
231 m_hCountsAll->Fill(i, hh1->GetMean());
232 m_hOccupancyAll->Fill(i, hh1->GetMean() / (250 * 768 / 24)); // Occupancy in percent
233 } else {
234 B2INFO("Histo " << name << " not found");
235 }
236 }
237
238 }
239 }
240 if (m_cSignal[i]) {
241 m_cSignal[i]->cd();
242 if (m_hSignal[i]) m_hSignal[i]->Draw("colz");
243 m_cSignal[i]->Modified();
244 m_cSignal[i]->Update();
245 }
246 if (m_cCommon[i]) {
247 m_cCommon[i]->cd();
248 if (m_hCommon[i]) m_hCommon[i]->Draw("colz");
249 m_cCommon[i]->Modified();
250 m_cCommon[i]->Update();
251 }
252 if (m_cCounts[i]) {
253 m_cCounts[i]->cd();
254 if (m_hCounts[i]) m_hCounts[i]->Draw("colz");
255 m_cCounts[i]->Modified();
256 m_cCounts[i]->Update();
257 }
258 }
259 if (m_cSignalAll) {
260 m_cSignalAll->cd();
261 if (m_hSignalAll) {
262 m_hSignalAll->Scale(1.0 / 24.0); // need to scale
263 m_hSignalAll->Draw();
264 }
265 m_cSignalAll->Modified();
266 m_cSignalAll->Update();
267 }
268 if (m_cCommonAll) {
269 m_cCommonAll->cd();
270 if (m_hCommonAll) {
271 m_hCommonAll->Scale(1.0 / 24.0); // need to scale
272 m_hCommonAll->Draw();
273 }
274 m_cCommonAll->Modified();
275 m_cCommonAll->Update();
276 }
277 if (m_cCountsAll) {
278 m_cCountsAll->cd();
279 if (m_hCountsAll) {
280 // m_hCountsAll->Scale(1.0/24.0); // dont scale counts, we want to have sum
281 // but we would need to scale if we directly calculate occupancy!
282 m_hCountsAll->Draw();
283 }
284 m_cCountsAll->Modified();
285 m_cCountsAll->Update();
286 }
287 if (m_cOccupancyAll) {
288 m_cOccupancyAll->cd();
289 if (m_hOccupancyAll) {
290 m_hOccupancyAll->Scale(1.0 / 24.0); // need to scale
291 m_hOccupancyAll->Draw();
292 }
293 m_cOccupancyAll->Modified();
294 m_cOccupancyAll->Update();
295 }
296}
DQMHistAnalysisModule()
Constructor / Destructor.
static TH1 * findHist(const std::string &dirname, const std::string &histname="", bool onlyIfUpdated=false)
Find histogram.
TH2F * m_hSignal[NUM_MODULES]
2D Signal Histograms
TH2F * m_hCommon[NUM_MODULES]
2D Common Histograms
void initialize() override final
Initializer.
TCanvas * m_cSignal[NUM_MODULES]
2D Signal Canvases
TCanvas * m_cOccupancyAll
All Occupancy Canvas.
TCanvas * m_cCommon[NUM_MODULES]
2D Common Canvases
TH1F * m_hOccupancyAll
All Occupancy Histogram.
std::map< int, int > m_inx_to_id
maps from index to VXDid
void event() override final
This method is called for each event.
std::string m_histogramDirectoryName
Histogram doirectory.
std::map< int, int > m_id_to_inx
maps from VXDid to index
void beginRun() override final
Called when entering a new run.
TH2F * m_hCounts[NUM_MODULES]
2D Counts Histograms
TCanvas * m_cCounts[NUM_MODULES]
2D Counts Canvases
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.