14 #include <dqm/analysis/modules/DQMHistAnalysisPXDEff.h>
17 #include <TGraphAsymmErrors.h>
18 #include <vxd/geometry/GeoCache.h>
40 addParam(
"binsU", m_u_bins,
"histogram bins in u direction, needs to be the same as in PXDDQMEfficiency",
int(16));
41 addParam(
"binsV", m_v_bins,
"histogram bins in v direction, needs to be the same as in PXDDQMEfficiency",
int(48));
42 addParam(
"histogramDirectoryName", m_histogramDirectoryName,
"Name of the directory where histograms were placed",
43 std::string(
"PXDEFF"));
44 addParam(
"PVPrefix", m_pvPrefix,
"PV Prefix", std::string(
"DQM:PXD:Eff:"));
45 addParam(
"useEpics", m_useEpics,
"useEpics",
true);
46 addParam(
"useEpicsRO", m_useEpicsRO,
"useEpics ReadOnly",
false);
47 addParam(
"ConfidenceLevel", m_confidence,
"Confidence Level for error bars and alarms", 0.9544);
48 addParam(
"WarnLevel", m_warnlevel,
"Efficiency Warn Level for alarms", 0.92);
49 addParam(
"ErrorLevel", m_errorlevel,
"Efficiency Level for alarms", 0.90);
50 addParam(
"perModuleAlarm", m_perModuleAlarm,
"Alarm level per module",
true);
51 addParam(
"alarmAdhoc", m_alarmAdhoc,
"Generate Alarm from adhoc values",
true);
52 addParam(
"minEntries", m_minEntries,
"minimum number of new entries for last time slot", 1000);
53 B2DEBUG(1,
"DQMHistAnalysisPXDEff: Constructor done.");
56 DQMHistAnalysisPXDEffModule::~DQMHistAnalysisPXDEffModule()
60 if (ca_current_context()) ca_context_destroy();
65 void DQMHistAnalysisPXDEffModule::initialize()
67 B2DEBUG(99,
"DQMHistAnalysisPXDEffModule: initialized.");
69 m_monObj = getMonitoringObject(
"pxd");
74 for (
VxdID& aVxdID : sensors) {
76 if (info.getType() != VXD::SensorInfoBase::PXD)
continue;
77 m_PXDModules.push_back(aVxdID);
79 std::sort(m_PXDModules.begin(), m_PXDModules.end());
86 if (m_PXDModules.size() == 0) {
88 B2WARNING(
"No PXDModules in Geometry found! Use hard-coded setup.");
89 std::vector <string> mod = {
90 "1.1.1",
"1.1.2",
"1.2.1",
"1.2.2",
"1.3.1",
"1.3.2",
"1.4.1",
"1.4.2",
91 "1.5.1",
"1.5.2",
"1.6.1",
"1.6.2",
"1.7.1",
"1.7.2",
"1.8.1",
"1.8.2",
92 "2.4.1",
"2.4.2",
"2.5.1",
"2.5.2"
94 for (
auto& it : mod) m_PXDModules.push_back(
VxdID(it));
103 m_useEpics |= m_useEpicsRO;
105 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
109 for (
VxdID& aPXDModule : m_PXDModules) {
110 TString buff = (std::string)aPXDModule;
111 buff.ReplaceAll(
".",
"_");
114 B2INFO(
"Connect PVs for " + m_pvPrefix + (std::string)aPXDModule);
115 SEVCHK(ca_create_channel((m_pvPrefix + buff).Data(), NULL, NULL, 10, &mychid_eff[aPXDModule]),
"ca_create_channel failure");
116 SEVCHK(ca_create_channel((m_pvPrefix + buff +
".LOW").Data(), NULL, NULL, 10, &mychid_low[aPXDModule]),
117 "ca_create_channel failure");
118 SEVCHK(ca_create_channel((m_pvPrefix + buff +
".LOLO").Data(), NULL, NULL, 10, &mychid_lolo[aPXDModule]),
119 "ca_create_channel failure");
122 TString histTitle =
"PXD Hit Efficiency on Module " + (std::string)aPXDModule +
";Pixel in U;Pixel in V";
123 m_cEffModules[aPXDModule] =
new TCanvas((m_histogramDirectoryName +
"/c_Eff_").data() + buff);
124 m_hEffModules[aPXDModule] =
new TEfficiency(
"ePXDHitEff_" + buff, histTitle,
125 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
128 m_cInnerMap =
new TCanvas((m_histogramDirectoryName +
"/c_InnerMap").data());
129 m_cOuterMap =
new TCanvas((m_histogramDirectoryName +
"/c_OuterMap").data());
130 m_hInnerMap =
new TH2F(
"hEffInnerMap",
"hEffInnerMap", m_u_bins * 8, 0, m_u_bins * 8, m_v_bins * 2, 0, m_v_bins * 2);
131 m_hOuterMap =
new TH2F(
"hEffOuterMap",
"hEffOuterMap", m_u_bins * 12, 0, m_u_bins * 12, m_v_bins * 2, 0, m_v_bins * 2);
133 m_hErrorLine =
new TH1F(
"hPXDErrorlimit",
"Error Limit", m_PXDModules.size(), 0, m_PXDModules.size());
134 m_hWarnLine =
new TH1F(
"hPXDWarnlimit",
"Warn Limit", m_PXDModules.size(), 0, m_PXDModules.size());
135 for (
int i = 0; i < (int)m_PXDModules.size(); i++) {
136 m_hErrorLine->SetBinContent(i + 1, m_errorlevel);
137 m_hWarnLine->SetBinContent(i + 1, m_warnlevel);
139 m_hWarnLine->SetLineColor(kOrange - 3);
140 m_hWarnLine->SetLineWidth(3);
141 m_hWarnLine->SetLineStyle(4);
142 m_hErrorLine->SetLineColor(kRed + 3);
143 m_hErrorLine->SetLineWidth(3);
144 m_hErrorLine->SetLineStyle(7);
147 m_cEffAll =
new TCanvas((m_histogramDirectoryName +
"/c_EffAll").data());
148 m_hEffAll =
new TEfficiency(
"ePXDHitEffAll",
"PXD Integrated Efficiency of each module;PXD Module;",
149 m_PXDModules.size(), 0, m_PXDModules.size());
150 m_hEffAll->SetConfidenceLevel(m_confidence);
151 m_hEffAll->Paint(
"AP");
152 m_hEffAllLastTotal = m_hEffAll->GetCopyTotalHisto();
153 m_hEffAllLastPassed = m_hEffAll->GetCopyPassedHisto();
156 auto gr = m_hEffAll->GetPaintedGraph();
159 auto ax = gr->GetXaxis();
161 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
162 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
163 TString ModuleName = (std::string)m_PXDModules[i];
164 ax->SetBinLabel(i + 1, ModuleName);
170 m_cEffAllUpdate =
new TCanvas((m_histogramDirectoryName +
"/c_EffAllUp").data());
171 m_hEffAllUpdate =
new TEfficiency(
"ePXDHitEffAllUpdate",
"PXD Integral and last-updated Efficiency per module;PXD Module;",
172 m_PXDModules.size(), 0, m_PXDModules.size());
173 m_hEffAllUpdate->SetConfidenceLevel(m_confidence);
176 auto gr = m_hEffAllUpdate->GetPaintedGraph();
179 auto ax = gr->GetXaxis();
181 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
182 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
183 TString ModuleName = (std::string)m_PXDModules[i];
184 ax->SetBinLabel(i + 1, ModuleName);
190 m_monObj->addCanvas(m_cEffAll);
191 m_monObj->addCanvas(m_cEffAllUpdate);
196 mychid_status.resize(2);
197 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
198 SEVCHK(ca_create_channel((m_pvPrefix +
"Status").data(), NULL, NULL, 10, &mychid_status[0]),
"ca_create_channel failure");
199 SEVCHK(ca_create_channel((m_pvPrefix +
"Overall").data(), NULL, NULL, 10, &mychid_status[1]),
"ca_create_channel failure");
200 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
203 B2DEBUG(1,
"DQMHistAnalysisPXDEff: initialized.");
207 void DQMHistAnalysisPXDEffModule::beginRun()
209 B2DEBUG(1,
"DQMHistAnalysisPXDEff: beginRun called.");
212 m_cEffAllUpdate->Clear();
215 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
217 m_hEffAll->SetPassedEvents(j, 0);
218 m_hEffAll->SetTotalEvents(j, 0);
219 m_hEffAllUpdate->SetPassedEvents(j, 0);
220 m_hEffAllUpdate->SetTotalEvents(j, 0);
222 m_warnlevelmod[m_PXDModules[i]] = m_warnlevel;
223 m_errorlevelmod[m_PXDModules[i]] = m_errorlevel;
229 dbr_double_t tPvData;
230 auto r = ca_get(DBR_DOUBLE, mychid_lolo[m_PXDModules[i]], &tPvData);
231 if (r == ECA_NORMAL) r = ca_pend_io(5.0);
232 if (r == ECA_NORMAL) {
233 if (!std::isnan(tPvData)
235 m_hErrorLine->SetBinContent(i + 1, tPvData);
236 if (m_perModuleAlarm) m_errorlevelmod[m_PXDModules[i]] = tPvData;
239 SEVCHK(r,
"ca_get or ca_pend_io failure");
241 r = ca_get(DBR_DOUBLE, mychid_low[m_PXDModules[i]], &tPvData);
242 if (r == ECA_NORMAL) r = ca_pend_io(5.0);
243 if (r == ECA_NORMAL) {
244 if (!std::isnan(tPvData)
246 m_hWarnLine->SetBinContent(i + 1, tPvData);
247 if (m_perModuleAlarm) m_warnlevelmod[m_PXDModules[i]] = tPvData;
250 SEVCHK(r,
"ca_get or ca_pend_io failure");
257 m_hEffAllLastTotal->Reset();
258 m_hEffAllLastPassed->Reset();
260 for (
auto single_cmap : m_cEffModules) {
261 if (single_cmap.second) single_cmap.second->Clear();
267 void DQMHistAnalysisPXDEffModule::event()
272 m_hInnerMap->Reset();
273 m_hOuterMap->Reset();
275 for (
unsigned int i = 1; i <= m_PXDModules.size(); i++) {
276 VxdID& aPXDModule = m_PXDModules[i - 1];
278 TString buff = (std::string)aPXDModule;
279 buff.ReplaceAll(
".",
"_");
282 TString locationHits =
"track_hits_" + buff;
283 if (m_histogramDirectoryName !=
"") {
284 locationHits = m_histogramDirectoryName +
"/" + locationHits;
286 Hits = (TH1*)findHist(locationHits.Data());
287 TString locationMatches =
"matched_cluster_" + buff;
288 if (m_histogramDirectoryName !=
"") {
289 locationMatches = m_histogramDirectoryName +
"/" + locationMatches;
291 Matches = (TH1*)findHist(locationMatches.Data());
294 if (Hits ==
nullptr || Matches ==
nullptr) {
295 B2ERROR(
"Missing histogram for sensor " << aPXDModule);
297 if (m_cEffModules[aPXDModule] && m_hEffModules[aPXDModule]) {
298 m_hEffModules[aPXDModule]->SetTotalHistogram(*Hits,
"f");
299 m_hEffModules[aPXDModule]->SetPassedHistogram(*Matches,
"f");
301 m_cEffModules[aPXDModule]->cd();
302 m_hEffModules[aPXDModule]->Paint(
"colz");
303 m_cEffModules[aPXDModule]->Modified();
304 m_cEffModules[aPXDModule]->Update();
306 auto h = m_hEffModules[aPXDModule]->GetPaintedHistogram();
307 int s = (2 - aPXDModule.getSensorNumber()) * m_v_bins;
308 int l = (aPXDModule.getLadderNumber() - 1) * m_u_bins;
309 if (m_hInnerMap && aPXDModule.getLayerNumber() == 1) {
310 for (
int u = 0; u < m_u_bins; u++) {
311 for (
int v = 0; v < m_v_bins; v++) {
312 auto b = h->GetBin(u + 1, v + 1);
313 m_hInnerMap->Fill(u + l, v + s, h->GetBinContent(b));
317 if (m_hOuterMap && aPXDModule.getLayerNumber() == 2) {
318 for (
int u = 0; u < m_u_bins; u++) {
319 for (
int v = 0; v < m_v_bins; v++) {
320 auto b = h->GetBin(u + 1, v + 1);
321 m_hOuterMap->Fill(u + l, v + s, h->GetBinContent(b));
330 m_hInnerMap->Draw(
"colz");
331 m_cInnerMap->Modified();
332 m_cInnerMap->Update();
334 m_hOuterMap->Draw(
"colz");
335 m_cOuterMap->Modified();
336 m_cOuterMap->Update();
341 TString locationHits =
"PXD_Eff_combined";
342 if (m_histogramDirectoryName !=
"") {
343 locationHits = m_histogramDirectoryName +
"/" + locationHits;
345 TH1* Combined = (TH1*)findHist(locationHits.Data());
347 double stat_data = 0;
348 bool error_flag =
false;
349 bool warn_flag =
false;
352 double imatch = 0.0, ihit = 0.0;
355 std::map <VxdID, bool> updated{};
356 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
359 if (Combined ==
nullptr) {
360 m_hEffAll->SetPassedEvents(j, 0);
361 m_hEffAll->SetTotalEvents(j, 0);
363 VxdID& aModule = m_PXDModules[i];
364 double nmatch = Combined->GetBinContent(i * 2 + 2);
365 double nhit = Combined->GetBinContent(i * 2 + 1);
366 if (nmatch > 10 && nhit > 10) {
370 double var_e = nmatch / nhit;
371 if (j == 6)
continue;
378 m_hEffAll->SetPassedEvents(j, 0);
379 m_hEffAll->SetTotalEvents(j, nhit);
380 m_hEffAll->SetPassedEvents(j, nmatch);
382 if (nhit < m_minEntries) {
384 m_hEffAllUpdate->SetPassedEvents(j, 0);
385 m_hEffAllUpdate->SetTotalEvents(j, nhit);
386 m_hEffAllUpdate->SetPassedEvents(j, nmatch);
387 m_hEffAllLastTotal->SetBinContent(j, nhit);
388 m_hEffAllLastPassed->SetBinContent(j, nmatch);
389 updated[aModule] =
true;
390 }
else if (nhit - m_hEffAllLastTotal->GetBinContent(j) > m_minEntries) {
391 m_hEffAllUpdate->SetPassedEvents(j, 0);
392 m_hEffAllUpdate->SetTotalEvents(j, nhit - m_hEffAllLastTotal->GetBinContent(j));
393 m_hEffAllUpdate->SetPassedEvents(j, nmatch - m_hEffAllLastPassed->GetBinContent(j));
394 m_hEffAllLastTotal->SetBinContent(j, nhit);
395 m_hEffAllLastPassed->SetBinContent(j, nmatch);
396 updated[aModule] =
true;
399 if (j == 6)
continue;
404 error_flag |= (m_hEffAll->GetEfficiency(j) + m_hEffAll->GetEfficiencyErrorUp(j) <
405 m_errorlevelmod[aModule]);
406 warn_flag |= (m_hEffAll->GetEfficiency(j) + m_hEffAll->GetEfficiencyErrorUp(j) <
407 m_warnlevelmod[aModule]);
409 error_flag |= (m_hEffAllUpdate->GetEfficiency(j) + m_hEffAllUpdate->GetEfficiencyErrorUp(j) <
410 m_errorlevelmod[aModule]);
411 warn_flag |= (m_hEffAllUpdate->GetEfficiency(j) + m_hEffAllUpdate->GetEfficiencyErrorUp(j) <
412 m_warnlevelmod[aModule]);
421 m_hEffAll->Paint(
"AP");
425 auto gr = m_hEffAll->GetPaintedGraph();
427 double scale_min = 1.0;
428 for (
int i = 0; i < gr->GetN(); i++) {
429 gr->SetPointEXhigh(i, 0.);
430 gr->SetPointEXlow(i, 0.);
433 gr->GetPoint(i, x, y);
434 gr->SetPoint(i, x - 0.01, y);
435 auto val = y - gr->GetErrorYlow(i);
438 if (scale_min > val) scale_min = val;
441 if (scale_min == 1.0) scale_min = 0.0;
442 if (scale_min > 0.9) scale_min = 0.9;
444 gr->SetMaximum(m_PXDModules.size());
445 auto ay = gr->GetYaxis();
446 if (ay) ay->SetRangeUser(scale_min, 1.0);
447 auto ax = gr->GetXaxis();
449 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
450 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
451 TString ModuleName = (std::string)m_PXDModules[i];
452 ax->SetBinLabel(i + 1, ModuleName);
458 gr->SetMarkerStyle(8);
462 auto tt =
new TLatex(5.5, scale_min,
" 1.3.2 Module is excluded, please ignore");
463 tt->SetTextAngle(90);
464 tt->SetTextAlign(12);
468 m_cEffAll->Pad()->SetFillColor(kGray);
471 m_cEffAll->Pad()->SetFillColor(kRed);
472 }
else if (warn_flag) {
473 m_cEffAll->Pad()->SetFillColor(kYellow);
475 m_cEffAll->Pad()->SetFillColor(kGreen);
480 m_cEffAll->Pad()->SetFrameFillColor(kWhite - 1);
481 m_cEffAll->Pad()->SetFrameFillStyle(1001);
482 m_cEffAll->Pad()->Modified();
483 m_cEffAll->Pad()->Update();
484 m_hWarnLine->Draw(
"same,hist");
485 m_hErrorLine->Draw(
"same,hist");
488 m_cEffAll->Modified();
493 m_cEffAllUpdate->cd();
494 m_hEffAllUpdate->Paint(
"AP");
495 m_cEffAllUpdate->Clear();
496 m_cEffAllUpdate->cd(0);
498 auto gr = m_hEffAllUpdate->GetPaintedGraph();
499 auto gr3 = (TGraphAsymmErrors*) m_hEffAll->GetPaintedGraph()->Clone();
501 for (
int i = 0; i < gr3->GetN(); i++) {
503 gr3->GetPoint(i, x, y);
504 gr3->SetPoint(i, x + 0.2, y);
508 double scale_min = 1.0;
510 for (
int i = 0; i < gr->GetN(); i++) {
511 gr->SetPointEXhigh(i, 0.);
512 gr->SetPointEXlow(i, 0.);
515 gr->GetPoint(i, x, y);
516 gr->SetPoint(i, x - 0.2, y);
517 auto val = y - gr->GetErrorYlow(i);
520 if (scale_min > val) scale_min = val;
523 if (scale_min == 1.0) scale_min = 0.0;
524 if (scale_min > 0.9) scale_min = 0.9;
526 gr->SetMaximum(m_PXDModules.size());
527 auto ay = gr->GetYaxis();
528 if (ay) ay->SetRangeUser(scale_min, 1.0);
529 auto ax = gr->GetXaxis();
531 ax->Set(m_PXDModules.size() , 0, m_PXDModules.size());
532 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
533 TString ModuleName = (std::string)m_PXDModules[i];
534 ax->SetBinLabel(i + 1, ModuleName);
538 if (m_useEpics && !m_useEpicsRO) {
539 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
540 if (updated[m_PXDModules[i]]) {
542 gr->GetPoint(i, x, y);
543 auto& my = mychid_eff[m_PXDModules[i]];
545 SEVCHK(ca_put(DBR_DOUBLE, my, (
void*)&y),
"ca_set failure");
550 gr->SetLineColor(kBlack);
552 gr->SetMarkerStyle(33);
553 }
else scale_min = 0.0;
554 if (gr) gr->Draw(
"AP");
555 if (gr3) gr3->Draw(
"P");
556 auto tt =
new TLatex(5.5, scale_min,
" 1.3.2 Module is excluded, please ignore");
557 tt->SetTextSize(0.035);
558 tt->SetTextAngle(90);
559 tt->SetTextAlign(12);
563 m_cEffAllUpdate->Pad()->SetFillColor(kGray);
567 m_cEffAllUpdate->Pad()->SetFillColor(kRed);
569 }
else if (warn_flag) {
570 m_cEffAllUpdate->Pad()->SetFillColor(kYellow);
573 m_cEffAllUpdate->Pad()->SetFillColor(kGreen);
579 m_cEffAllUpdate->Pad()->SetFrameFillColor(kWhite - 1);
580 m_cEffAllUpdate->Pad()->SetFrameFillStyle(1001);
581 m_cEffAllUpdate->Pad()->Modified();
582 m_cEffAllUpdate->Pad()->Update();
583 m_hWarnLine->Draw(
"same,hist");
584 m_hErrorLine->Draw(
"same,hist");
586 m_cEffAllUpdate->Modified();
587 m_cEffAllUpdate->Update();
590 double var_efficiency = ihit > 0 ? imatch / ihit : 0.0;
591 m_monObj->setVariable(
"efficiency", var_efficiency);
592 m_monObj->setVariable(
"nmodules", ieff);
595 if (m_useEpics && !m_useEpicsRO) {
596 SEVCHK(ca_put(DBR_DOUBLE, mychid_status[0], (
void*)&stat_data),
"ca_set failure");
598 if (stat_data != 0) SEVCHK(ca_put(DBR_DOUBLE, mychid_status[1], (
void*)&var_efficiency),
"ca_set failure");
599 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
604 void DQMHistAnalysisPXDEffModule::terminate()
606 B2DEBUG(1,
"DQMHistAnalysisPXDEff: terminate called");
609 for (
auto& m : mychid_status) SEVCHK(ca_clear_channel(m),
"ca_clear_channel failure");
610 for (
auto& m : mychid_eff) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
611 for (
auto& m : mychid_low) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
612 for (
auto& m : mychid_lolo) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
613 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
The base class for the histogram analysis module.
DQM Histogram Analysis for PXD Efficiency.
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
const std::vector< VxdID > getListOfSensors() const
Get list of all sensors.
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Base class to provide Sensor Information for PXD and SVD.
int getVCells() const
Return number of pixel/strips in v direction.
int getUCells() const
Return number of pixel/strips in u direction.
Class to uniquely identify a any structure of the PXD and SVD.
baseType getSensorNumber() const
Get the sensor id.
baseType getLadderNumber() const
Get the ladder id.
baseType getLayerNumber() const
Get the layer id.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.