Belle II Software development
DQMHistAnalysisCDCEpics.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#include <dqm/analysis/modules/DQMHistAnalysisCDCEpics.h>
10#include <cdc/geometry/CDCGeometryPar.h>
11
12using namespace std;
13using namespace Belle2;
14
15//-----------------------------------------------------------------
16// Register module
17//-----------------------------------------------------------------
18REG_MODULE(DQMHistAnalysisCDCEpics);
19
22{
23 addParam("HistDirectory", m_name_dir, "CDC Dir of DQM Histogram", std::string("CDC"));
24 addParam("RefDirectory", m_name_refdir, "Reference histogram dir", std::string("ref/CDC/default"));
25 addParam("PvPrefix", m_name_pvpfx, "PV Prefix and Name", std::string("CDC:"));
26 addParam("RefFilePhi", m_fname_refphi, "Reference histogram file name", std::string("CDCDQM_PhiRef.root"));
27 addParam("HistLayerADC", m_hname_ladc, "Layer ADC Histogram Name", std::string("hADCLayer"));
28 addParam("HistBoardADC", m_hname_badc, "Board ADC Histogram Name", std::string("hADCBoard"));
29 addParam("HistBoardTDC", m_hname_btdc, "Board TDC Histogram Name", std::string("hTDC"));
30 addParam("HistPhiIndex", m_hname_idxphi, "Phi Index Histogram Name", std::string("hPhiIndex"));
31 addParam("HistPhiEff", m_hname_effphi, "Phi Eff Histogram Name", std::string("hPhiEff"));
32 addParam("HistHitsPhi", m_hname_hitsphi, "Phi Hits Histogram Name", std::string("hPhiNCDC"));
33 addParam("MinPhiDiffFrac", m_minphibinsfrac, "Minimum bin percentage for phi diff comparison", 0.05);
34 addParam("MinEvt", m_minevt, "Min events for intra-run point", 1000);
35 addParam("HistTrackingWireEff", m_histoTrackingWireEff, "Wire Eff Histogram Name", std::string("hTrackingWireEff"));
36 addParam("DoTH2PolyTrackingWireEff", m_doTH2PolyTrackingWireEff,
37 "If true, creates TH2Poly instead of TH2F for TrackingWireEff Histos", m_doTH2PolyTrackingWireEff);
38 addParam("FirstEffBoundary", m_firstEffBoundary, "The first boundary of the efficiency range", m_firstEffBoundary);
39 addParam("SecondEffBoundary", m_secondEffBoundary, "The second boundary of the efficiency range", m_secondEffBoundary);
40 for (int i = 0; i < 300; i++) {
41 m_hists_bADC[i] = nullptr;
42 m_hists_bTDC[i] = nullptr;
43 //layer
44 if (i < 56)m_hists_lADC[i] = nullptr;
45 }
46
47 B2DEBUG(20, "DQMHistAnalysisCDCEpics: Constructor done.");
48}
49
53
55{
56
57 gROOT->cd();
58 c_histmd_ladc = new TCanvas("CDC/c_histmd_ladc", "c_histmd_ladc", 500, 400);
59 m_histmd_ladc = new TH1F("CDC/histmd_ladc", "m_histmd_ladc", 56, 0, 56);
60 m_histmd_ladc->SetTitle("ADC Medians vs Layers (SL-lines); CDC Layer index; ADC medians");
61
62 c_hist_adc = new TCanvas("CDC/c_hist_adc", "c_hist_adc", 500, 400);
63 m_hist_adc = new TH1F("CDC/hist_adc", "m_hist_adc", 300, 0, 300);
64 m_hist_adc->SetTitle("ADC Medians; CDC board index; ADC medians");
65
66 c_hist_tdc = new TCanvas("CDC/c_hist_tdc", "c_hist_tdc", 500, 400);
67 m_hist_tdc = new TH1F("CDC/hist_tdc", "m_hist_tdc", 300, 0, 300);
68 m_hist_tdc->SetTitle("TDC Medians; CDC board index; TDC medians");
69
70 //array of various phi histograms
71 for (int ic = 0; ic < 8; ic++) {
72 c_hist_skimphi[ic] = new TCanvas(Form("CDC/c_hist_skimphi_c%d", ic), Form("hist_skimphi_c%d", ic), 500, 400);
73 }
74
75 c_hist_crphi = new TCanvas("CDC/c_hist_crphi", "c_hist_crphi", 500, 400);
76 c_hist_hitsphi = new TCanvas("CDC/c_hist_hitsphi", "c_hist_hitsphi", 500, 400);
77
78 //CR alarm reference
79 if (m_fname_refphi != "") {
80 m_fileRefPhi = TFile::Open(m_fname_refphi.data(), "READ");
81 if (m_fileRefPhi && m_fileRefPhi->IsOpen()) {
82 B2INFO("DQMHistAnalysisCDCEpics: reference (" << m_fname_refphi << ") found OK");
83 m_histref_phiindex = (TH2F*)m_fileRefPhi->Get((m_name_refdir + "/hPhiIndex").data());
84 if (!m_histref_phiindex)B2INFO("\t .. but (histogram) not found");
85 else B2INFO("\t ..and (cdcdqm_phiref) also exist");
86 }
87 }
88
89 m_lines.clear();
90 m_lines.reserve(kNumLayers);
91 for (unsigned il = 0; il < kNumLayers; ++il) {
92 int bin = il + 1;
93 auto* line = new TLine(bin, 0, bin, 1.0);
94 line->SetLineStyle(2);
95 if (bin >= 8 && bin < 14)line->SetLineColor(kRed); // U-type
96 else if (bin >= 20 && bin < 26)line->SetLineColor(kGreen); // V-type
97 else if (bin >= 32 && bin < 38)line->SetLineColor(kRed); // U-type
98 else if (bin >= 44 && bin < 50)line->SetLineColor(kGreen); // v-type
99 else line->SetLineColor(kGray); // A-type
100 m_lines.push_back(line);
101 }
102
103 c_hist_effphi = new TCanvas("CDC/c_hist_effphi", "c_hist_effphi", 500, 400);
104 m_hist_effphi = new TH1D("CDC/hist_effphi", "m_hist_effphi", 360, -180.0, 180.0);
105
106 c_hist_attach_eff[0] = new TCanvas("CDC/c_hist_attached_wires", "c_hist_attached_wires", 403, 400);
107 c_hist_attach_eff[1] = new TCanvas("CDC/c_hist_expected_wires", "c_hist_expected_wires", 403, 400);
108 c_hist_attach_eff[2] = new TCanvas("CDC/c_hist_attach_eff", "c_hist_attach_eff", 403, 400);
109 c_hist_attach_eff[3] = new TCanvas("CDC/c_hist_attach_eff_1d", "c_hist_attach_eff_1d", 403, 400);
111 m_hist_attach_eff_Poly[0] = createEffiTH2Poly("CDC/hist_attachedWires",
112 "hist_attachedWires (backplate view);X [cm];Y [cm]; Track / bin");
113 m_hist_attach_eff_Poly[0]->GetYaxis()->SetTitleOffset(1.4);
114 m_hist_attach_eff_Poly[0]->SetDirectory(gDirectory);
115 m_hist_attach_eff_Poly[1] = (TH2Poly*)m_hist_attach_eff_Poly[0]->Clone();
116 m_hist_attach_eff_Poly[1]->SetNameTitle("CDC/hist_expectedWires", "hist_expectedWires (backplate view);X [cm];Y [cm]; Track / bin");
117 m_hist_attach_eff_Poly[1]->SetDirectory(gDirectory);
118 m_hist_attach_eff_Poly[2] = (TH2Poly*)m_hist_attach_eff_Poly[0]->Clone();
119 m_hist_attach_eff_Poly[2]->SetNameTitle("CDC/hist_wireAttachEff", "hist_wireAttachEff (backplate view);X [cm];Y [cm]; Efficiency");
120 m_hist_attach_eff_Poly[2]->SetDirectory(gDirectory);
121 } else {
123 int nSLayers = cdcgeo.getNumberOfSenseLayers();
124 double maxLayerR = cdcgeo.senseWireR(nSLayers - 1);
125 m_hist_attach_eff[0] = new TH2F("CDC/hist_attachedWires", "hist_attachedWires (backplate view);X [cm];Y [cm]; Track / bin",
126 nSLayers * 6, -maxLayerR * 1.02, maxLayerR * 1.02,
127 nSLayers * 6, -maxLayerR * 1.02, maxLayerR * 1.02);
128 m_hist_attach_eff[0]->GetYaxis()->SetTitleOffset(1.4);
129 m_hist_attach_eff[1] = (TH2F*)m_hist_attach_eff[0]->Clone();
130 m_hist_attach_eff[1]->SetNameTitle("CDC/hist_expectedWires", "hist_expectedWires (backplate view);X [cm];Y [cm]; Track / bin");
131 m_hist_attach_eff[2] = (TH2F*)m_hist_attach_eff[0]->Clone();
132 m_hist_attach_eff[2]->SetNameTitle("CDC/hist_wireAttachEff", "hist_wireAttachEff (backplate view);X [cm];Y [cm]; Efficiency");
133 }
134 m_hist_wire_attach_eff_1d = new TH1F("CDC/hist_wire_attach_eff_1d", "hist_wire_attach_eff_1d;Wire Efficiency;Wire / bin",
135 208, -0.02, 1.02);
136 m_hist_wire_attach_eff_1d->GetYaxis()->SetTitleOffset(1.4);
137
139 addDeltaPar(m_name_dir, m_hname_ladc, HistDelta::c_Entries, m_minevt, 1);
140
142 addDeltaPar(m_name_dir, m_hname_badc, HistDelta::c_Entries, m_minevt, 1);
143
145 addDeltaPar(m_name_dir, m_hname_btdc, HistDelta::c_Entries, m_minevt, 1);
146
148 addDeltaPar(m_name_dir, m_hname_idxphi, HistDelta::c_Entries, m_minevt, 1);
149
151 addDeltaPar(m_name_dir, m_hname_effphi, HistDelta::c_Entries, m_minevt, 1);
152
154 addDeltaPar(m_name_dir, m_hname_hitsphi, HistDelta::c_Entries, m_minevt, 1);
155
157 addDeltaPar(m_name_dir, m_histoTrackingWireEff, HistDelta::c_Events, m_minevt, 1);
158
159
160 m_line_ladc_sl01 = new TLine(0, m_minadc_sl01, 47, m_minadc_sl01);
161 m_line_ladc_sl01->SetLineColor(kBlue);
162 m_line_ladc_sl01->SetLineWidth(2);
163
164 m_line_hadc_sl01 = new TLine(0, m_maxadc_sl01, 47, m_maxadc_sl01);
165 m_line_hadc_sl01->SetLineColor(kBlue);
166 m_line_hadc_sl01->SetLineWidth(2);
167
168 m_line_ltdc_sl01 = new TLine(0, m_mintdc_sl01, 47, m_mintdc_sl01);
169 m_line_ltdc_sl01->SetLineColor(kBlue);
170 m_line_ltdc_sl01->SetLineWidth(2);
171
172 m_line_htdc_sl01 = new TLine(0, m_maxtdc_sl01, 47, m_maxtdc_sl01);
173 m_line_htdc_sl01->SetLineColor(kBlue);
174 m_line_htdc_sl01->SetLineWidth(2);
175
176 m_line_ladc_sl28 = new TLine(48, m_minadc_sl28, 300, m_minadc_sl28);
177 m_line_ladc_sl28->SetLineColor(kRed);
178 m_line_ladc_sl28->SetLineWidth(2);
179
180 m_line_hadc_sl28 = new TLine(48, m_maxadc_sl28, 300, m_maxadc_sl28);
181 m_line_hadc_sl28->SetLineColor(kRed);
182 m_line_hadc_sl28->SetLineWidth(2);
183
184 m_line_ltdc_sl28 = new TLine(48, m_mintdc_sl28, 300, m_mintdc_sl28);
185 m_line_ltdc_sl28->SetLineColor(kRed);
186 m_line_ltdc_sl28->SetLineWidth(2);
187
188 m_line_htdc_sl28 = new TLine(48, m_maxtdc_sl28, 300, m_maxtdc_sl28);
189 m_line_htdc_sl28->SetLineColor(kRed);
190 m_line_htdc_sl28->SetLineWidth(2);
191
192 registerEpicsPV(m_name_pvpfx + "cdcboards_wadc", "adcboards");
193 registerEpicsPV(m_name_pvpfx + "cdcboards_wtdc", "tdcboards");
194
195 registerEpicsPV(m_name_pvpfx + "adc_median_window_sl10", "adcmedianwindow_sl01");
196 registerEpicsPV(m_name_pvpfx + "tdc_median_window_sl10", "tdcmedianwindow_sl01");
197 registerEpicsPV(m_name_pvpfx + "adc_median_window_sl28", "adcmedianwindow_sl28");
198 registerEpicsPV(m_name_pvpfx + "tdc_median_window_sl28", "tdcmedianwindow_sl28");
199
200 registerEpicsPV(m_name_pvpfx + "phi_compare_window", "phicomparewindow");
201
203
204 B2DEBUG(20, "DQMHistAnalysisCDCEpics: initialized.");
205}
206
208{
209 double unused = 0;
210 requestLimitsFromEpicsPVs("adcmedianwindow_sl01", unused, m_minadc_sl01, m_maxadc_sl01, unused);
211 requestLimitsFromEpicsPVs("tdcmedianwindow_sl01", unused, m_mintdc_sl01, m_maxtdc_sl01, unused);
212 requestLimitsFromEpicsPVs("adcmedianwindow_sl28", unused, m_minadc_sl28, m_maxadc_sl28, unused);
213 requestLimitsFromEpicsPVs("tdcmedianwindow_sl28", unused, m_mintdc_sl28, m_maxtdc_sl28, unused);
214 requestLimitsFromEpicsPVs("phicomparewindow", m_phialarm, m_phiwarn, unused, unused);
215
216 //in case if something is wrong in config file (for S0-1 and S2-8)
217 //SL 0 and 1 is with different HV thershold
218
219 if (std::isnan(m_minadc_sl01)) m_minadc_sl01 = 20.0;
220 if (std::isnan(m_maxadc_sl01)) m_maxadc_sl01 = 40.0;
221 if (std::isnan(m_mintdc_sl01)) m_mintdc_sl01 = 4700.0;
222 if (std::isnan(m_maxtdc_sl01)) m_maxtdc_sl01 = 5200.0;
223
224 if (std::isnan(m_minadc_sl28)) m_minadc_sl28 = 60.0;
225 if (std::isnan(m_maxadc_sl28)) m_maxadc_sl28 = 130.0;
226 if (std::isnan(m_mintdc_sl28)) m_mintdc_sl28 = 4500.0;
227 if (std::isnan(m_maxtdc_sl28)) m_maxtdc_sl28 = 5000.0;
228
229 if (std::isnan(m_phiwarn)) m_phiwarn = 0.05;
230 if (std::isnan(m_phialarm)) m_phialarm = 0.15;
231
240
249
250 B2DEBUG(20, "DQMHistAnalysisCDCEpics: beginRun run called");
251}
252
254{
255 //1. get adc median vs layer numbers
256 auto m_delta_ladc = (TH2F*)getDelta(m_name_dir, m_hname_ladc, 0, true);
257 if (m_delta_ladc) {
258 m_histmd_ladc->Reset();
259 for (unsigned il = 0; il < kNumLayers; ++il) {
260 if (m_hists_lADC[il]) delete m_hists_lADC[il];
261 m_hists_lADC[il] = m_delta_ladc->ProjectionY(Form("histmd_adc_layer%d", il + 1), il + 1, il + 1, "");
262 m_hists_lADC[il]->SetTitle(Form("histmd_adc_layer%d", il));
263 float md_ladc = getHistMedian(m_hists_lADC[il]);
264 if (!std::isfinite(md_ladc) || md_ladc < 0) md_ladc = 0;
265 m_histmd_ladc->SetBinContent(il + 1, md_ladc);
266 }
267 // Draw canvas
268 c_histmd_ladc->Clear();
269 c_histmd_ladc->cd();
270 double y_max = m_histmd_ladc->GetMaximum();
271 if (!std::isfinite(y_max) || y_max <= 0 || y_max > 1e3)y_max = 1;
272 m_histmd_ladc->SetFillColor(kYellow);
273 m_histmd_ladc->SetMinimum(0);
274 m_histmd_ladc->SetMaximum(y_max * 1.20);
275 m_histmd_ladc->Draw("hist");
276 for (auto* line : m_lines) {
277 line->SetY2(y_max * 1.20);
278 line->Draw("same");
279 }
280 c_histmd_ladc->Update();
282 }
283
284 //2. get adc medians vs board ID
285 auto m_delta_adc = (TH2F*)getDelta(m_name_dir, m_hname_badc, 0, true); //true=only if updated
286 if (m_delta_adc) {
287 m_hist_adc->Reset();
288 int cadcgood = 0;
289 int cadcbad = 0;
290 double sumadcgood = 0;
291 for (unsigned ic = 0; ic < kNumBoards; ++ic) {
292 if (ic == 0) continue; //299 boards only
293 if (m_hists_bADC[ic]) delete m_hists_bADC[ic];
294 m_hists_bADC[ic] = m_delta_adc->ProjectionY(Form("histmd_tdc_board%d", ic + 1), ic + 1, ic + 1, "");
295 m_hists_bADC[ic]->SetTitle(Form("histmd_adc_board%d", ic));
296 float md_adc = getHistMedian(m_hists_bADC[ic]);
297 m_hist_adc->SetBinContent(ic + 1, md_adc);
298 float minadc = (ic < 48) ? m_minadc_sl01 : m_minadc_sl28;
299 float maxadc = (ic < 48) ? m_maxadc_sl01 : m_maxadc_sl28;
300 if (md_adc >= minadc && md_adc <= maxadc) {
301 sumadcgood = sumadcgood + md_adc;
302 cadcgood++;
303 } else cadcbad++;
304 }
305 double adcfrac = cadcgood / 2.99; // (100.0/299) in %
306 setEpicsPV("adcboards", adcfrac);
307 // Draw canvas
308 c_hist_adc->Clear();
309 c_hist_adc->cd();
310 if (cadcgood > 0)sumadcgood = sumadcgood * 1.0 / cadcgood;
311 getHistStyle(m_hist_adc, "adc", sumadcgood);
312 m_hist_adc->SetTitle(Form("ADC Medians: Bad board count = %d (%0.01f%%)", cadcbad - 1, 100.0 - adcfrac));
313 m_hist_adc->Draw("");
314 m_line_ladc_sl01->Draw("same");
315 m_line_hadc_sl01->Draw("same");
316 m_line_ladc_sl28->Draw("same");
317 m_line_hadc_sl28->Draw("same");
318 c_hist_adc->Update();
320 }
321
322 //3. get tdc medians vs board ID
323 auto m_delta_tdc = (TH2F*)getDelta(m_name_dir, m_hname_btdc, 0, true);
324 if (m_delta_tdc) {
325 m_hist_tdc->Reset();
326 int ctdcgood = 0;
327 int ctdcbad = 0;
328 double sumtdcgood = 0;
329 for (unsigned ic = 0; ic < kNumBoards; ++ic) {
330 if (ic == 0) continue; //299 boards only
331 if (m_hists_bTDC[ic]) delete m_hists_bTDC[ic];
332 m_hists_bTDC[ic] = m_delta_tdc->ProjectionY(Form("histmd_tdc_board%d", ic + 1), ic + 1, ic + 1, "");
333 m_hists_bTDC[ic]->SetTitle(Form("histmd_tdc_board%d", ic));
334 float md_tdc = getHistMedian(m_hists_bTDC[ic]);
335 m_hist_tdc->SetBinContent(ic + 1, md_tdc);
336 float mintdc = (ic <= 48) ? m_mintdc_sl01 : m_mintdc_sl28;
337 float maxtdc = (ic <= 48) ? m_maxtdc_sl01 : m_maxtdc_sl28;
338 if (md_tdc >= mintdc && md_tdc <= maxtdc) {
339 ctdcgood++;
340 sumtdcgood = sumtdcgood + md_tdc;
341 } else ctdcbad++;
342 }
343 double tdcfrac = ctdcgood / 2.99;
344 setEpicsPV("tdcboards", tdcfrac);
345 c_hist_tdc->Clear();
346 c_hist_tdc->cd();
347 if (ctdcgood > 0)sumtdcgood = sumtdcgood * 1.0 / ctdcgood;
348 getHistStyle(m_hist_tdc, "tdc", sumtdcgood);
349 m_hist_tdc->SetTitle(Form("TDC Medians: Bad board count = %d (%0.01f%%)", ctdcbad - 1, 100.0 - tdcfrac));
350 m_hist_tdc->Draw("");
351 m_line_ltdc_sl01->Draw("same");
352 m_line_htdc_sl01->Draw("same");
353 m_line_ltdc_sl28->Draw("same");
354 m_line_htdc_sl28->Draw("same");
355 c_hist_tdc->Update();
357 }
358
359 //get phi plots for various options
360 auto m_delta_skimphi = (TH2F*)getDelta(m_name_dir, m_hname_idxphi, 0, true); //true=only if updated
361 if (m_delta_skimphi) {
362 TString sip[2] = {"OffIP", "IP"};
363 TString sname[4] = {"all", "bhabha", "hadron", "mumutrk"};
364 for (int j = 0; j < 2; j++) { //ip selections
365 for (int i = 0; i < 4; i++) { //skim selections
366 int k = 4 * j + i; //0 to 7
367 TString hname = TString::Format("histphi_%s_%sevt", sip[j].Data(), sname[i].Data());
368 m_hist_skimphi[k] = m_delta_skimphi->ProjectionX(hname, k + 1, k + 1, "");
369 m_hist_skimphi[k]->SetTitle(TString::Format("cdc-track #phi (%s, %s-events);#phi;entries", sip[j].Data(), sname[i].Data()));
370 if (k < 4)m_hist_skimphi[k]->SetFillColor(kGray);
371 else m_hist_skimphi[k]->SetFillColor(kCyan);
372 c_hist_skimphi[k]->Clear();
373 c_hist_skimphi[k]->cd();
374 gPad->SetGridx(1);
375 gPad->SetGridy(1);
376 m_hist_skimphi[k]->Draw("hist");
377 }
378 }
379 }
380
381 //for CR shifter IP + all hadrons including alarm system
382 if (m_delta_skimphi) {
383 c_hist_crphi->Clear();
384 bool isFew = false, isAlarm = false, isWarn = false;
385 m_hist_crphi = m_delta_skimphi->ProjectionX("histphi_ip_hadrons", 7, 7, "");
386 m_hist_crphi->SetTitle("cdc-track #phi (IP + hadrons);cdc-track #phi;norm entries");
387 if (m_hist_crphi) {
388 double maxnow = m_hist_crphi->Integral();
389 if (maxnow > 0)m_hist_crphi->Scale(1.0 / maxnow);
390 if (maxnow < 10000) {
391 isFew = true;
392 } else {
393 if (m_histref_phiindex) {
394 m_hist_refphi = m_histref_phiindex->ProjectionX("histphi_ip_hadronsref", 7, 7, "");
395 double nbinref = m_hist_refphi->GetNbinsX();
396 double nbinnow = m_hist_crphi->GetNbinsX();
397 if (nbinref == nbinnow) { //same bins
398 double maxref = m_hist_refphi->Integral();
399 if (maxref > 0) {
400 m_hist_refphi->Scale(1.0 / maxref);
401 int warnCount = 0;
402 int alarmCount = 0;
403 for (int iphi = 0; iphi < nbinnow; iphi++) {
404 double icnow = m_hist_crphi->GetBinContent(iphi + 1);
405 double icref = m_hist_refphi->GetBinContent(iphi + 1);
406 double phidiff = 0;
407 if (icref > 0) phidiff = fabs(icnow - icref) / icref;
408 if (phidiff > m_phiwarn) warnCount++;
409 if (phidiff > m_phialarm) alarmCount++;
410 }
411 // difference threshold
412 int minBins = m_minphibinsfrac * nbinnow;
413 if (warnCount >= minBins) isWarn = true;
414 if (alarmCount >= minBins) isAlarm = true;
415 double warnFrac = 100.0 * warnCount / nbinnow;
416 double alarmFrac = 100.0 * alarmCount / nbinnow;
417 m_hist_crphi->SetTitle(
418 Form("%s [warn bins %.1f%%, alarm bins %.1f%% | crit: %.1f%% bins]",
419 m_hist_crphi->GetTitle(),
420 warnFrac,
421 alarmFrac,
422 100.0 * m_minphibinsfrac)
423 );
424 }
425 }
426 }
427 }
428 }
429 c_hist_crphi->cd();
430 gPad->SetGridx(1);
431 gPad->SetGridy(1);
432 if (!m_histref_phiindex)m_hist_crphi->SetTitle(Form("%s (no ref file)", m_hist_crphi->GetTitle()));
433 m_hist_crphi->Draw("hist");
435 else if (isAlarm)colorizeCanvas(c_hist_crphi, c_StatusError);
438 c_hist_crphi->Update();
440 }
441
442 //get tracking efficiency
443 auto m_delta_effphi = (TH2F*)getDelta(m_name_dir, m_hname_effphi, 0, true); //true=only if updated
444 if (m_delta_effphi) {
445 c_hist_effphi->Clear();
446 double eff = -1;
447 const int all_phibins = m_delta_effphi->GetNbinsX();
448 const int all_hitbins = m_delta_effphi->GetNbinsY();
449 const int thr_hitbin = m_delta_effphi->GetYaxis()->FindBin(20);//min hits bin
450 for (int iphi = 0; iphi < all_phibins; iphi++) {
451 TH1D* temp = (TH1D*)m_delta_effphi->ProjectionY(Form("hhits_bin_%d", iphi + 1), iphi + 1, iphi + 1, "");
452 Double_t num = temp->Integral(thr_hitbin, all_hitbins);
453 Double_t den = temp->Integral();
454 if (den > 0)eff = num * 100.0 / den;
455 m_hist_effphi->SetBinContent(iphi + 1, eff);
456 m_hist_effphi->SetBinError(iphi + 1, 0);
457 delete temp;
458 }
459 m_hist_effphi->GetYaxis()->SetRangeUser(80.0, 110.0); //per efficiency
460 m_hist_effphi->SetTitle("CDC track efficiency(cdchits>20/all); cdc-track #phi; tracking efficiency");
461 c_hist_effphi->cd();
462 gPad->SetGridx();
463 gPad->SetGridy();
464 m_hist_effphi->SetFillColor(kCyan);
465 m_hist_effphi->Draw("hist");
466 c_hist_effphi->Update();
468 }
469
470 //get cdc hits vs phi
471 auto m_delta_hitphi = (TH2F*)getDelta(m_name_dir, m_hname_hitsphi, 0, true); //true=only if updated
472 if (m_delta_hitphi) {
473 c_hist_hitsphi->Clear();
474 m_delta_hitphi->SetTitle("CDC track #phi vs cdchits; cdc-track #phi; nCDCHits");
475 c_hist_hitsphi->cd();
476 gPad->SetLogz();
477 m_delta_hitphi->Draw("COLZ");
478 c_hist_hitsphi->Update();
480 }
481
482 // get wire efficiency
483 double meanWireAttachProb = 0;
484 double fracWiresWithLowAttachProb = 0;
485 double fracWiresWithHighAttachProb = 0;
486 gStyle->SetNumberContours(100);
487 auto m_delta_efflay = (TH2F*)getDelta(m_name_dir, m_histoTrackingWireEff, 0, true); //true=only if updated
488 if (m_delta_efflay) {
489 for (int ij = 0; ij < 4; ij++) c_hist_attach_eff[ij]->Clear();
491 int nEffiValues = 0;
492 for (int ij = 1; ij <= m_delta_efflay->GetNbinsX(); ij++) {
493 int halfYbin = m_delta_efflay->GetNbinsY() / 2;
494 for (int jk = 0; jk < halfYbin; jk++) {
495 if (m_delta_efflay->GetBinContent(ij, jk + 1) == 0) continue;
496 double binEffi = m_delta_efflay->GetBinContent(ij, jk + halfYbin + 1) / m_delta_efflay->GetBinContent(ij, jk + 1);
497 m_hist_wire_attach_eff_1d->Fill(binEffi);
498 meanWireAttachProb += binEffi;
499 nEffiValues++;
500 }
501 }
502 if (nEffiValues) meanWireAttachProb /= nEffiValues;
505 else
507 TLatex latex;
508 latex.SetTextSize(0.025);
509 for (int ij = 0; ij < 3; ij++) {
510 c_hist_attach_eff[ij]->cd();
512 m_hist_attach_eff_Poly[ij]->SetStats(0);
513 m_hist_attach_eff_Poly[ij]->Draw("COLZ");
514 } else {
515 m_hist_attach_eff[ij]->SetStats(0);
516 m_hist_attach_eff[ij]->Draw("COLZ");
517 int isl = 0;
518 TEllipse* el[9];
519 for (int ilay = 0; ilay < 56; ilay++) {
520 int rmdr = int(abs(ilay - 2) % 6);
521 if ((rmdr == 0 && ilay > 2) || ilay == 55) {
522 isl++;
523 el[isl] = new TEllipse(0, 0, m_lbinEdges[ilay], m_lbinEdges[ilay]);
524 el[isl]->SetLineColor(kRed);
525 el[isl]->SetLineWidth(2);
526 el[isl]->SetFillStyle(0);
527 el[isl]->Draw("same");
528 }
529 }
530 }
531 if (ij == 2)
532 latex.DrawLatexNDC(0.12, 0.87, TString::Format("mean = %.3f%%", meanWireAttachProb * 100.0));
533 }
534 c_hist_attach_eff[3]->cd();
535 if (nEffiValues) {
536 int firstBoundaryBin = m_hist_wire_attach_eff_1d->GetXaxis()->FindBin(m_firstEffBoundary) - 1;
537 fracWiresWithLowAttachProb = m_hist_wire_attach_eff_1d->Integral(1, firstBoundaryBin) / nEffiValues;
538 int secondBoundaryBin = m_hist_wire_attach_eff_1d->GetXaxis()->FindBin(m_secondEffBoundary) - 1;
539 fracWiresWithHighAttachProb = m_hist_wire_attach_eff_1d->Integral(secondBoundaryBin + 1,
540 m_hist_wire_attach_eff_1d->GetNbinsX()) / nEffiValues;
541 m_hist_wire_attach_eff_1d->SetStats(0);
543 latex.DrawLatexNDC(0.15, 0.87, TString::Format("%06.3f%% wire : eff < %.2f",
544 fracWiresWithLowAttachProb * 100,
546 latex.DrawLatexNDC(0.15, 0.84, TString::Format("%06.3f%% wire : %.2f < eff < %.2f",
547 (1. - fracWiresWithHighAttachProb - fracWiresWithLowAttachProb) * 100,
549 latex.DrawLatexNDC(0.15, 0.81, TString::Format("%06.3f%% wire : %.2f < eff",
550 fracWiresWithHighAttachProb * 100,
552 }
553 for (int ij = 0; ij < 4; ij++) {
554 c_hist_attach_eff[ij]->Update();
556 }
557 }
558
559 m_monObj->setVariable("meanWireAttachProb", meanWireAttachProb);
560 m_monObj->setVariable("fracWiresWithLowAttachProb", fracWiresWithLowAttachProb);
561 m_monObj->setVariable("fracWiresWithHighAttachProb", fracWiresWithHighAttachProb);
562
563 B2DEBUG(20, "DQMHistAnalysisCDCEpics: end event");
564}
565
566//------------------------------------
568{
569 B2DEBUG(20, "DQMHistAnalysisCDCEpics: end run");
570}
571
572
573//------------------------------------
575{
576 for (auto* line : m_lines) delete line;
577 m_lines.clear();
578 B2DEBUG(20, "DQMHistAnalysisCDCEpics: terminate called");
579}
580
581
582//------------------------------------
584{
585
586 if (!h) return 0.0;
587 TH1D* hist = (TH1D*)h->Clone();
588 hist->SetBinContent(1, 0.0); // Exclude 0-th bin
589 float median = 0.0;
590 if (hist->Integral(1, hist->GetNbinsX()) > 0) {
591 double quantiles[1];
592 double probSums[1] = {0.5};
593 hist->GetQuantiles(1, quantiles, probSums);
594 if (std::isfinite(quantiles[0]))median = quantiles[0];
595 }
596 delete hist;
597 return median;
598}
599
600
601void DQMHistAnalysisCDCEpicsModule::fillEffiTH2(TH2F* hist, TH2F* attached, TH2F* expected, TH2F* efficiency)
602{
604 int nSLayers = cdcgeo.getNumberOfSenseLayers();
605
606 // Array to hold bin edges, with nSLayers + 1 edges needed for nSLayers bins
607 std::vector<double> binEdges(nSLayers + 1);
608 // Calculate r bin edges
609 double firstR = cdcgeo.senseWireR(0);
610 double secondR = cdcgeo.senseWireR(1);
611 binEdges[0] = firstR - (secondR - firstR) / 2;
612 m_lbinEdges[0] = firstR;
613 for (int lay = 1; lay < nSLayers; lay++) {
614 double prevR = cdcgeo.senseWireR(lay - 1);
615 double currentR = cdcgeo.senseWireR(lay);
616 binEdges[lay] = (prevR + currentR) / 2;
617 m_lbinEdges[lay] = currentR;
618 }
619 double lastR = cdcgeo.senseWireR(nSLayers - 1);
620 double secondLastR = cdcgeo.senseWireR(nSLayers - 2);
621 binEdges[nSLayers] = lastR + (lastR - secondLastR) / 2;
622 // convenient histogram to get layer number
623 TH1F layerHist("layerHist", "Layer Histogram", nSLayers, binEdges.data());
624
625 for (int binx = 1; binx <= efficiency->GetNbinsX(); binx++) {
626 for (int biny = 1; biny <= efficiency->GetNbinsY(); biny++) {
627 double bincenterx = efficiency->GetXaxis()->GetBinCenter(binx);
628 double bincentery = efficiency->GetYaxis()->GetBinCenter(biny);
629 double r = TMath::Sqrt(bincenterx * bincenterx + bincentery * bincentery);
630 double phi = TMath::ATan2(bincentery, bincenterx);
631 if (phi < 0) phi += 2 * TMath::Pi();
632
633 int layerBin = layerHist.FindBin(r); // Get the bin corresponding to r
634 if (layerBin < 1 || layerBin > nSLayers) continue;
635 int layerExpected = layerBin - 1;
636
637 int nWires = cdcgeo.nWiresInLayer(layerExpected);
638 double offset = cdcgeo.offset(layerExpected);
639 int wireExpected = phi * nWires / (2 * TMath::Pi()) - offset + 0.5;
640 if (wireExpected < 0) wireExpected += nWires;
641 if (wireExpected >= nWires) wireExpected -= nWires;
642
643 int expBin = hist->GetYaxis()->FindBin(layerExpected);
644 int obsBin = expBin + nSLayers;
645 expected->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, expBin));
646 attached->SetBinContent(binx, biny, hist->GetBinContent(wireExpected + 1, obsBin));
647 }
648 }
649 efficiency->Divide(attached, expected);
650}
651
652TH2Poly* DQMHistAnalysisCDCEpicsModule::createEffiTH2Poly(const TString& name, const TString& title)
653{
655 int nSLayers = cdcgeo.getNumberOfSenseLayers();
656 double maxLayerR = cdcgeo.senseWireR(nSLayers - 1);
657 TH2Poly* hist = new TH2Poly(name, title, -maxLayerR * 1.02, maxLayerR * 1.02, -maxLayerR * 1.02, maxLayerR * 1.02);
658 for (int lay = 0; lay < nSLayers; lay++) {
659 int nWires = cdcgeo.nWiresInLayer(lay);
660 double offset = cdcgeo.offset(lay);
661 double layerR = cdcgeo.senseWireR(lay);
662 double r_inner = 0;
663 double r_outer = 0;
664 if (lay == 0) {
665 r_inner = layerR - (cdcgeo.senseWireR(1) - cdcgeo.senseWireR(0)) / 2;
666 r_outer = layerR + (cdcgeo.senseWireR(1) - cdcgeo.senseWireR(0)) / 2;
667 } else if (lay == nSLayers - 1) {
668 r_inner = layerR - (cdcgeo.senseWireR(lay) - cdcgeo.senseWireR(lay - 1)) / 2;
669 r_outer = layerR + (cdcgeo.senseWireR(lay) - cdcgeo.senseWireR(lay - 1)) / 2;
670 } else {
671 r_inner = layerR - (cdcgeo.senseWireR(lay) - cdcgeo.senseWireR(lay - 1)) / 2;
672 r_outer = layerR + (cdcgeo.senseWireR(lay + 1) - cdcgeo.senseWireR(lay)) / 2;
673 }
674 for (int wire = 0; wire < nWires; wire++) {
675 double phi_inner = (wire - 0.5 + offset) * 2 * TMath::Pi() / nWires;
676 double phi_outer = (wire + 0.5 + offset) * 2 * TMath::Pi() / nWires;
677 // Calculate the four corners of the bin
678 double x0 = r_inner * TMath::Cos(phi_inner);
679 double y0 = r_inner * TMath::Sin(phi_inner);
680 double x1 = r_outer * TMath::Cos(phi_inner);
681 double y1 = r_outer * TMath::Sin(phi_inner);
682 double x2 = r_outer * TMath::Cos(phi_outer);
683 double y2 = r_outer * TMath::Sin(phi_outer);
684 double x3 = r_inner * TMath::Cos(phi_outer);
685 double y3 = r_inner * TMath::Sin(phi_outer);
686 double xx[] = {x0, x1, x2, x3};
687 double yy[] = {y0, y1, y2, y3};
688 hist->AddBin(4, xx, yy);
689 }
690 }
691 return hist;
692}
693
694void DQMHistAnalysisCDCEpicsModule::fillEffiTH2Poly(TH2F* hist, TH2Poly* attached, TH2Poly* expected, TH2Poly* efficiency)
695{
696 attached->Reset("ICES");
697 expected->Reset("ICES");
699 int nSLayers = cdcgeo.getNumberOfSenseLayers();
700 for (int lay = 0; lay < nSLayers; lay++) {
701 int nWires = cdcgeo.nWiresInLayer(lay);
702 double layerR = cdcgeo.senseWireR(lay);
703 double offset = cdcgeo.offset(lay);
704 int expBin = hist->GetYaxis()->FindBin(lay);
705 int obsBin = expBin + nSLayers;
706 // fill the bins for this layer
707 for (int wire = 0; wire < nWires; wire++) {
708 double phi = (wire + offset) * 2 * TMath::Pi() / nWires;
709 double fillX = layerR * TMath::Cos(phi);
710 double fillY = layerR * TMath::Sin(phi);
711 attached->Fill(fillX, fillY, hist->GetBinContent(wire + 1, obsBin));
712 expected->Fill(fillX, fillY, hist->GetBinContent(wire + 1, expBin));
713 }
714 }
715 efficiency->Divide(attached, expected);
716}
The Class for CDC Geometry Parameters.
double offset(int layerID) const
Return wire offset in phi direction at endplate.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
ushort getNumberOfSenseLayers() const
Get the number of sense layers.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
TCanvas * c_hist_adc
canvas for adc board median
TCanvas * c_hist_skimphi[8]
canvas for various phi distribution
TLine * m_line_ltdc_sl28
line for lower TDC window for SL2-8
double m_maxtdc_sl28
max tdc median threshold accepted for SL2-8
void initialize() override final
Initialize the Module.
TCanvas * c_histmd_ladc
canvas for adc layer median
double m_secondEffBoundary
The second boundary of the efficiency range.
int m_minevt
min events for single intra-run point
TCanvas * c_hist_effphi
canvas for tracking efficiency
std::string m_hname_idxphi
Phi Inedx histogram names.
void fillEffiTH2Poly(TH2F *hist, TH2Poly *attached, TH2Poly *expected, TH2Poly *efficiency)
Populate the efficiency histograms.
TH1D * m_hists_bADC[kNumBoards]
ADC histograms with track associated hits for each board (0-299)
double m_mintdc_sl01
min tdc median threshold accepted for SL0-1
TH2Poly * createEffiTH2Poly(const TString &name, const TString &title)
Convenient function to create a TH2Poly based on CDC geometry.
double m_maxadc_sl28
max adc median threshold accepted for SL2-8
std::string m_hname_hitsphi
Phi Hits histogram names.
double m_phiwarn
5% warn thershold for phi differences
TLine * m_line_ladc_sl01
line for lower ADC window for SL0-1
std::string m_histoTrackingWireEff
Wire Eff histogram names.
TFile * m_fileRefPhi
reference histogram file point
double m_mintdc_sl28
min tdc median threshold accepted for SL2-8
double m_phialarm
15% alarm thershold for phi differences
TLine * m_line_ltdc_sl01
line for lower TDC window for SL0-1
std::string m_hname_effphi
Phi Eff histogram names.
double m_maxadc_sl01
max adc median threshold accepted for SL0-1
TLine * m_line_hadc_sl01
line for higher ADC window for SL0-1
double m_lbinEdges[kNumLayers+1]
vector for radius edge 56
void getHistStyle(TH1F *&htemp, std::string label, double max) const
get histogram styles
MonitoringObject * m_monObj
monitoring object
TCanvas * c_hist_crphi
canvas for control shifter phi
double m_minadc_sl28
min adc median threshold accepted for SL2-8
TLine * m_line_htdc_sl01
line for higher TDC window for SL0-1
std::string m_fname_refphi
reference file of phi histogram
void terminate() override final
Termination action.
void event() override final
intra-run actions (EPICC PVs).
std::vector< TLine * > m_lines
number of CDC layer lines
TCanvas * c_hist_tdc
canvas for tdc board median
std::string m_hname_ladc
Layer ADC histogram names.
TH1D * m_hists_lADC[kNumLayers]
ADC histograms with track associated hits for each board (0-299)
bool m_doTH2PolyTrackingWireEff
If true, creates TH2Poly instead of TH2F for TrackingWireEff Histos.
TCanvas * c_hist_hitsphi
expert canvas for hits vs phi
double m_minphibinsfrac
min phi diff fraction for alarms
TCanvas * c_hist_attach_eff[4]
canvas for layer efficiency
double m_firstEffBoundary
The first boundary of the efficiency range.
double m_maxtdc_sl01
max tdc median threshold accepted for SL0-1
std::string m_name_refdir
reference histogram dir
void endRun() override final
End-of-run action.
void beginRun() override final
Called when entering a new run.
TLine * m_line_htdc_sl28
line for higher TDC window for SL2-8
TH1D * m_hists_bTDC[kNumBoards]
TDC histograms with track associated hits for each board (0-299)
double m_minadc_sl01
min adc median threshold accepted for SL0-1
TLine * m_line_hadc_sl28
line for higher ADC window for SL2-8
float getHistMedian(TH1D *h) const
Get median of given histogram.
TLine * m_line_ladc_sl28
line for lower ADC window for SL2-8
std::string m_hname_btdc
Board TDC histogram names.
std::string m_hname_badc
Board ADC histogram names.
void fillEffiTH2(TH2F *hist, TH2F *attached, TH2F *expected, TH2F *efficiency)
Populate the efficiency histograms.
static bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
int registerEpicsPV(const std::string &pvname, const std::string &keyname="")
EPICS related Functions.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static void colorizeCanvas(TCanvas *canvas, EStatus status)
Helper function for Canvas colorization.
static void UpdateCanvas(const std::string &name, bool updated=true)
Mark canvas as updated (or not)
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
DQMHistAnalysisModule()
Constructor / Destructor.
@ c_StatusTooFew
Not enough entries/event to judge.
@ c_StatusError
Analysis result: Severe issue found.
@ c_StatusWarning
Analysis result: Warning, there may be minor issues.
@ c_StatusGood
Analysis result: Good.
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
constexpr unsigned kNumLayers
const CDC numbers for layers, boards and super layers
constexpr unsigned kNumBoards
Total number of CDC Boards.
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.
STL namespace.