Belle II Software development
DQMHistAnalysisARICHMonObj.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// Own header.
10#include <dqm/analysis/modules/DQMHistAnalysisARICHMonObj.h>
11
12#include <TF1.h>
13#include <TH1F.h>
14#include <TH3.h>
15#include <TH2.h>
16#include <TLine.h>
17#include <TH2Poly.h>
18#include <TText.h>
19#include <TROOT.h>
20#include <TLegend.h>
21#include <iostream>
22#include <TStyle.h>
23#include <TGaxis.h>
24
25using namespace std;
26using namespace Belle2;
27
28//-----------------------------------------------------------------
29// Register module
30//-----------------------------------------------------------------
31
32REG_MODULE(DQMHistAnalysisARICHMonObj);
33
36{
37 // set module description (e.g. insert text)
38 setDescription("Example module for making MonitoringObject in DQMHistAnalysis module");
40}
41
43{
44 // make monitoring object related to this module (use arich as an example)
45 // if monitoring object already exists this will return pointer to it
47
48 // make canvases to be added to MonitoringObject
49 m_c_main = new TCanvas("arich_main", "main", 1500, 800);
50 m_c_mask = new TCanvas("arich_mask", "mask", 750, 1600);
51 m_c_mirror = new TCanvas("arich_mirror", "mirror", 1000, 1000);
52 m_c_tracks = new TCanvas("arich_tracks", "tracks", 500, 500);
53
54 m_apdHist = new ARICHChannelHist("tmpApdHist", "tmpApdHist", 2);
55 //m_chHist = new ARICHChannelHist("tmpChHist", "tmpChHist", 0); /**<ARICH TObject to draw hit map for each channel*/
56 m_hapdHist = new ARICHChannelHist("tmpHapdHist", "tmpHapdHist", 1);
57
58 // add canvases to MonitoringObject
59 m_monObj->addCanvas(m_c_main);
60 m_monObj->addCanvas(m_c_mask);
61 m_monObj->addCanvas(m_c_mirror);
62 m_monObj->addCanvas(m_c_tracks);
63
64}
65
66
68{
69
70
71 TGaxis::SetMaxDigits(3);
72 gStyle->SetPalette(1);
73 gStyle->SetOptStat(0);
74
75
76 // get existing histograms produced by DQM modules
77 TH1* chHit = findHist("ARICH/chHit");
78 TH1* bits = findHist("ARICH/bits");
79 TH1* hitsPerTrack = findHist("ARICH/hitsPerTrack");
80 TH1* theta = findHist("ARICH/theta");
81 TH2* tracks2D = (TH2*)findHist("ARICH/tracks2D");
82 TH1* hitsPerEvent = findHist("ARICH/hitsPerEvent");
83 TH2* hapdHitPerEvent = (TH2*)findHist("ARICH/hapdHitPerEvent");
84 TH2* thetaPhi = (TH2*)findHist("ARICH/thetaPhi");
85 TH3* mirrorThetaPhi = (TH3*)findHist("ARICH/mirrorThetaPhi");
86 TH1* chDigit = findHist("ARICH/chDigit");
87 TH1* hapdDigit = findHist("ARICH/hapdDigit");
88
89 if (chHit == NULL) {m_monObj->setVariable("comment", "No arich histograms in file"); B2INFO("Histogram named chHit is not found."); return;}
90 if (chHit->GetEntries() == 0) {m_monObj->setVariable("comment", "No arich hits in histograms"); B2INFO("No arich hits in histograms."); return;}
91
92 // set the content of main canvas
93 m_c_main->Clear(); // clear existing content
94 m_c_main->Divide(3, 2);
95 m_c_mirror->Clear(); // clear existing content
96 m_c_mirror->Divide(3, 3);
97 m_c_mask->Clear(); // clear existing content
98 m_c_mask->Divide(2, 4);
99 m_c_tracks->Clear(); // clear existing content
100
101 //Draw 2D hit map of channels and APDs
102 pp1 = new TH2Poly();
103 pp1->SetTitle("Number of hits / APD / event");
104 pp1->SetOption("colz");
105
106 pp2 = new TH2Poly();
107 pp2->SetMaximum(0.1 / 36.);
108 pp2->SetMinimum(0.0001 / 36.);
109 pp2->SetTitle("Number of hits / channel / event");
110
111 pflash = new TH2Poly();
112 pflash->SetTitle("Number of flash (>40 hits) / event");
113
114 int nevt = 0;
115 if (hitsPerEvent) nevt = hitsPerEvent->GetEntries();
116 m_apdHist->fillFromTH1(chHit);
117 // m_chHist->fillFromTH1(chHit);
118 if (nevt) {
119 m_apdHist->Scale(1. / float(nevt));
120 // m_chHist->Scale(1. / float(nevt));
121 }
122
123 double signalHitsPerEvent = 0;
124 double backgroundHitsPerEvent = 0;
125 if (bits and nevt) {
126 double bin0 = bits->GetBinContent(2);
127 double bin1 = bits->GetBinContent(3);
128 double bin2 = bits->GetBinContent(4);
129 double bin3 = bits->GetBinContent(5);
130 signalHitsPerEvent = (bin1 + bin2 - bin0 - bin3) / nevt;
131 backgroundHitsPerEvent = (bin0 + bin3) / nevt;
132 }
133
134 pp1->SetMaximum(0.1);
135 m_apdHist->setPoly(pp1);
136 pp1->SetMinimum(0.0001);
137 pp2->SetMaximum(0.1 / 36.);
138 // m_chHist->setPoly(pp2);
139 // pp2->SetMinimum(0.0001 / 36.);
140
141
142 //TCanvas main
143 m_c_main->cd(1);
144 pp1->Draw("colz");
145 pp1->GetXaxis()->SetTickLength(0);
146 pp1->GetYaxis()->SetTickLength(0);
147 gPad->SetLogz();
148 //m_c_main->Update();
149
150 TH1F* flash = (TH1F*)hapdHitPerEvent->ProjectionX("flash", 40, 144);
151 m_hapdHist->fillFromTH1(flash);
152 if (nevt) m_hapdHist->Scale(1. / float(nevt));
153
154 m_hapdHist->setPoly(pflash);
155 // draw sector lines
156 double rlin = 40;
157 double rlout = 113;
158 for (int isec = 0; isec < 6; isec++) {
159 double x1 = rlin * cos(M_PI / 3.*isec);
160 double x2 = rlout * cos(M_PI / 3.*isec);
161 double y1 = rlin * sin(M_PI / 3.*isec);
162 double y2 = rlout * sin(M_PI / 3.*isec);
163 TLine* line = new TLine(x1, y1, x2, y2);
164 line->Draw();
165 x1 = rlin * cos(M_PI / 3.*isec + M_PI / 6.);
166 y1 = rlin * sin(M_PI / 3.*isec + M_PI / 6.);
167 TText* lab = new TText(x1, y1, TString::Format("S-%d", isec + 1));
168 lab->SetTextAlign(22);
169 lab->SetTextSize(0.03);
170 lab->Draw();
171 }
172
173
174 //TCanvas tracks
175 m_c_tracks->cd();
176 tracks2D->RebinX(4);
177 tracks2D->RebinY(4);
178 double trkevt = nevt > 0 ? tracks2D->GetEntries() / nevt : 0;
179 int ntracks = tracks2D->GetEntries();
180 m_monObj->setVariable("ntracks", ntracks ? ntracks : 0);
181 m_monObj->setVariable("ntracksPerEvent", trkevt ? trkevt : 0);
182 string comment = "";
183 if (ntracks == 0) comment = "No arich tracks in file.";
184 if (theta->GetEntries() == 0) comment.append(" No cherenkov photons available");
185 m_monObj->setVariable("comment", comment);
186
187 tracks2D->SetTitle(TString::Format("Track distribution (avg %f trk/evt)", trkevt));
188 tracks2D->Draw("colz");
189
190
191 if (ntracks) {
192 double sigbkg[8] = {0};
193 //fit two gauses
194 if (theta->GetEntries() == 0) return;
195 TF1* f1 = new TF1("thcFit", "gaus(0)+gaus(3)", 0.2, 0.4);
196 f1->SetParameters(0.8 * theta->GetMaximum(), 0.323, 0.016, 0.2 * theta->GetMaximum(), 0.323, 0.13);
197 f1->FixParameter(5, 0.13);
198 f1->SetParName(0, "C");
199 f1->SetParName(1, "mean");
200 f1->SetParName(2, "sigma");
201 f1->SetParName(3, "p0");
202 f1->SetParName(4, "p1");
203 int status = theta->Fit(f1, "R");
204 double xmin = f1->GetParameter(1) - 2.*f1->GetParameter(2);
205 double xmax = f1->GetParameter(1) + 2.*f1->GetParameter(2);
206 double tmp = f1->GetParameter(3);
207 f1->SetParameter(3, 0);
208 double nphot = f1->Integral(xmin, xmax);
209 f1->SetParameter(3, tmp);
210 tmp = f1->GetParameter(0);
211 f1->SetParameter(0, 0);
212 double nbkg = f1->Integral(xmin, xmax);
213 f1->SetParameter(0, tmp);
214 if (status) return;
215
216 sigbkg[0] = nphot;
217 sigbkg[1] = f1->GetParameter(0) > 0 ? nphot * f1->GetParError(0) / f1->GetParameter(0) : 0.;
218 sigbkg[2] = nbkg;
219 sigbkg[3] = f1->GetParameter(3) > 0 ? nbkg * f1->GetParError(3) / f1->GetParameter(3) : 0.;
220 sigbkg[4] = f1->GetParameter(1);
221 sigbkg[5] = f1->GetParError(1);
222 sigbkg[6] = f1->GetParameter(2);
223 sigbkg[7] = f1->GetParError(2);
224 if (theta->GetBinWidth(1) == 0) return;
225 m_monObj->setVariable("nsig", sigbkg[0] / float(ntracks) / theta->GetBinWidth(1),
226 sigbkg[1] / float(ntracks) / theta->GetBinWidth(1));
227 m_monObj->setVariable("nbgr", sigbkg[2] / float(ntracks) / theta->GetBinWidth(1),
228 sigbkg[3] / float(ntracks) / theta->GetBinWidth(1));
229 m_monObj->setVariable("theta", sigbkg[4], sigbkg[5]);
230 m_monObj->setVariable("sigma", sigbkg[6], sigbkg[7]);
231 std::cout << sigbkg[0] << " " << sigbkg[1] / float(ntracks) / theta->GetBinWidth(1) << std::endl;
232 }
233
234
235 //TCanvas mirror
236 TH1F* thetaCl = (TH1F*)theta->Clone("thetaCl");
237 thetaCl->SetLineColor(16);
238 thetaCl->SetLineWidth(2);
239 thetaCl->SetTitle("");
240 TLegend* leg[9];
241 gStyle->SetOptTitle(0);
242
243 if (mirrorThetaPhi) {
244 for (int i = 1; i < 18 + 1; i++) {
245 TH1F* hmir = (TH1F*)mirrorThetaPhi->ProjectionZ(TString::Format("hmir_%d", i), i, i, 1, 10000);
246 hmir->SetTitle(TString::Format("mirror %d", i));
247 if (hmir->GetEntries() > 0) hmir->Scale(theta->GetEntries() / hmir->GetEntries());
248 hmir->Rebin(2);
249 hmir->SetLineWidth(2);
250 int iplot = (i - 1) / 2;
251 if ((i - 1) % 2 == 0) { m_c_mirror->cd(iplot + 1); thetaCl->Draw("hist"); hmir->SetLineColor(1); hmir->Draw("sames hist"); leg[iplot] = new TLegend(0.1, 0.75, 0.4, 0.9); leg[iplot]->AddEntry(hmir, TString::Format("mirror %d", i));}
252 else {
253 hmir->SetLineColor(2); hmir->Draw("sames hist");
254 leg[iplot]->AddEntry(hmir, TString::Format("mirror %d", i));
255 leg[iplot]->Draw();
256 }
257 }
258 }
259
260 gStyle->SetOptTitle(1);
261
262
263 //chDigit
264 if (chDigit != NULL && nevt) chDigit->Scale(1. / nevt);
265 if (nevt) {
266 chHit->Scale(1. / nevt);
267 flash->Scale(1. / nevt);
268 }
269 int nhot = 0, ndead = 0;
270 TH2F* hotCh = new TH2F("arich_hot", "Number of channels in APD with >0.5% occ.", 42, 0.5, 42.5, 40, 0.5, 40.5);
271 TH2F* hotCh1 = new TH2F("arich_hot1", "Number of channels in APD with >0.5% occ. after mask", 42, 0.5, 42.5, 40, 0.5, 40.5);
272 TH2F* deadCh = new TH2F("arich_dead", "Number of channels in APD with no hits", 42, 0.5, 42.5, 40, 0.5, 40.5);
273 TH2F* falseCh = new TH2F("arich_false", "Number of wrongly masked channels in APD (masked but not dead/hot)", 42, 0.5, 42.5, 40,
274 0.5,
275 40.5);
276 TH1F* occ = new TH1F("arich_occ", "nhits / nevt for all channels; nhits/nevt;# of chn", 500, 0, 0.005);
277
278 int ndeadHapd = 0;
279 if (chDigit != NULL) {
280 double hotlim = 0.005;
281 for (int i = 0; i < chDigit->GetNbinsX(); i++) {
282 int hapd = i / 144 + 1; int chip = (i % 144) / 36 + 1;
283 int binx = (hapd - 1) % 42 + 1; int biny = ((hapd - 1) / 42) * 4 + chip;
284 if (chDigit->GetBinContent(i + 1) > hotlim) { hotCh->Fill(binx, biny); nhot++;}
285 if (chDigit->GetBinContent(i + 1) == 0) {
286 deadCh->Fill(binx, biny);
287 if (hapdDigit->GetBinContent(hapd) != 0) ndead++;
288 }
289 if (chHit->GetBinContent(i + 1) == 0 && chDigit->GetBinContent(i + 1) < hotlim
290 && chDigit->GetBinContent(i + 1) > 0.00002) falseCh->Fill(binx, biny);
291 if (chHit->GetBinContent(i + 1) > hotlim) hotCh1->Fill(binx, biny);
292 occ->Fill(chHit->GetBinContent(i + 1));
293 }
294
295 for (int i = 0; i < hapdDigit->GetNbinsX(); i++) {
296 if (hapdDigit->GetBinContent(i + 1) == 0) ndeadHapd++;
297 }
298 }
299 m_monObj->setVariable("nhot", nhot);
300 m_monObj->setVariable("ndead", ndead);
301 m_monObj->setVariable("ndeadHapd", ndeadHapd);
302
303
304 // TCanvas mask
305 m_c_mask->cd(1);
306 occ->Draw();
307 m_c_mask->cd(2);
308 pflash->Draw("colz");
309 m_c_mask->cd(3);
310 // pp2->Draw("colz");
311 //pp2->GetXaxis()->SetTickLength(0);
312 //pp2->GetYaxis()->SetTickLength(0);
313 gPad->SetLogz();
314 m_c_mask->cd(4);
315 hotCh->Draw("colz text");
316 m_c_mask->cd(5);
317 deadCh->Draw("colz text");
318 m_c_mask->cd(6);
319 hotCh1->Draw("colz text");
320 m_c_mask->cd(7);
321 falseCh->Draw("colz text");
322
323 for (int i = 0; i < 42; i++) {
324 double x1 = i + 0.5 + 1;
325 TLine* line = new TLine(x1, 0.5, x1, 40.5);
326 m_c_mask->cd(5); line->Draw();
327 m_c_mask->cd(6); line->Draw();
328 m_c_mask->cd(7); line->Draw();
329 m_c_mask->cd(4); line->Draw();
330 }
331 for (int i = 0; i < 40; i++) {
332 double y1 = i + 0.5 + 1;
333 TLine* line = new TLine(0.5, y1, 42.5, y1);
334 if ((i + 1) % 4 == 0) line->SetLineColor(2);
335 else line->SetLineColor(15);
336 m_c_mask->cd(5); line->Draw();
337 m_c_mask->cd(6); line->Draw();
338 m_c_mask->cd(7); line->Draw();
339 m_c_mask->cd(4); line->Draw();
340 }
341
342 if (bits) {
343 bits->SetLineWidth(2);
344 bits->SetLineColor(2);
345 bits->SetOption("hist");
346 bits->SetFillStyle(3010);
347 bits->SetFillColor(3);
348 }
349
350 if (hitsPerTrack) {
351 hitsPerTrack->SetLineWidth(2);
352 hitsPerTrack->SetLineColor(2);
353 hitsPerTrack->SetOption("hist");
354 }
355 if (hitsPerEvent) {
356 hitsPerEvent->SetLineWidth(2);
357 hitsPerEvent->SetLineColor(2);
358 hitsPerEvent->SetOption("hist");
359 }
360 //Tcanvas main
361 m_c_main->cd(2);
362 if (bits) { bits->Draw(); bits->GetYaxis()->SetTitleOffset(0.5); }
363 m_c_main->cd(3);
364 if (theta) theta->Draw();
365 m_c_main->cd(4);
366 if (hitsPerTrack) hitsPerTrack->Draw();
367 m_c_main->cd(5);
368 if (hitsPerEvent) hitsPerEvent->Draw();
369 m_c_main->cd(6);
370 if (thetaPhi != NULL) thetaPhi->Draw("colz");
371
372 // set values of monitoring variables (if variable already exists this will change its value, otherwise it will insert new variable)
373 // with error (also asymmetric error can be used as m_monObj->setVariable(name, value, upError, downError))
374 m_monObj->setVariable("hitsPerEvent", hitsPerEvent ? hitsPerEvent->GetMean() : 0, hitsPerEvent ? hitsPerEvent->GetMeanError() : -1);
375
376 m_monObj->setVariable("signalHitsPerEvent", signalHitsPerEvent);
377 m_monObj->setVariable("backgroundHitsPerEvent", backgroundHitsPerEvent);
378
379 // without error
380 m_monObj->setVariable("bitsMean", bits ? bits->GetMean() : 0);
381 B2DEBUG(20, "DQMHistAnalysisARICHMonObj : endRun called");
382}
383
385{
386
387 B2DEBUG(20, "terminate called");
388}
ARICH histogram with HAPD plane 3 options for bin segmentation are available type 0 - one bin per HAP...
void initialize() override final
Initialize the Module.
Belle2::ARICHChannelHist * m_apdHist
ARICH TObject to draw hit map for each APD.
MonitoringObject * m_monObj
MonitoringObject to be produced by this module.
Belle2::ARICHChannelHist * m_hapdHist
ARICH TObject to draw flash map for each hapd.
void terminate() override final
Termination action.
TCanvas * m_c_mask
Canvas with histograms related to channel masking.
TCanvas * m_c_main
Canvas with main run summary histograms.
TCanvas * m_c_mirror
Canvas with histograms related to mirrors.
void endRun() override final
End-of-run action.
TH2Poly * pp2
2D hitmap of number of hits per channel per event
TCanvas * m_c_tracks
Canvas with histograms related to tracks.
TH2Poly * pflash
2D hitmap of number of flash (>40 hits) per event
TH2Poly * pp1
2D hitmap of number of hits per APD per event
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
DQMHistAnalysisModule()
Constructor / Destructor.
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
TH1F * hapd[6]
histogram of hits for each hapd
#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.
STL namespace.