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,
"Whether to update EPICS PVs.",
false);
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;
379 m_hEffAll->SetPassedEvents(j, 0);
380 m_hEffAll->SetTotalEvents(j, nhit);
381 m_hEffAll->SetPassedEvents(j, nmatch);
383 if (nhit < m_minEntries) {
385 m_hEffAllUpdate->SetPassedEvents(j, 0);
386 m_hEffAllUpdate->SetTotalEvents(j, nhit);
387 m_hEffAllUpdate->SetPassedEvents(j, nmatch);
388 m_hEffAllLastTotal->SetBinContent(j, nhit);
389 m_hEffAllLastPassed->SetBinContent(j, nmatch);
390 updated[aModule] =
true;
391 }
else if (nhit - m_hEffAllLastTotal->GetBinContent(j) > m_minEntries) {
392 m_hEffAllUpdate->SetPassedEvents(j, 0);
393 m_hEffAllUpdate->SetTotalEvents(j, nhit - m_hEffAllLastTotal->GetBinContent(j));
394 m_hEffAllUpdate->SetPassedEvents(j, nmatch - m_hEffAllLastPassed->GetBinContent(j));
395 m_hEffAllLastTotal->SetBinContent(j, nhit);
396 m_hEffAllLastPassed->SetBinContent(j, nmatch);
397 updated[aModule] =
true;
406 error_flag |= (m_hEffAll->GetEfficiency(j) + m_hEffAll->GetEfficiencyErrorUp(j) <
407 m_errorlevelmod[aModule]);
408 warn_flag |= (m_hEffAll->GetEfficiency(j) + m_hEffAll->GetEfficiencyErrorUp(j) <
409 m_warnlevelmod[aModule]);
411 error_flag |= (m_hEffAllUpdate->GetEfficiency(j) + m_hEffAllUpdate->GetEfficiencyErrorUp(j) <
412 m_errorlevelmod[aModule]);
413 warn_flag |= (m_hEffAllUpdate->GetEfficiency(j) + m_hEffAllUpdate->GetEfficiencyErrorUp(j) <
414 m_warnlevelmod[aModule]);
423 m_hEffAll->Paint(
"AP");
427 auto gr = m_hEffAll->GetPaintedGraph();
429 double scale_min = 1.0;
430 for (
int i = 0; i < gr->GetN(); i++) {
431 gr->SetPointEXhigh(i, 0.);
432 gr->SetPointEXlow(i, 0.);
435 gr->GetPoint(i, x, y);
436 gr->SetPoint(i, x - 0.01, y);
437 auto val = y - gr->GetErrorYlow(i);
440 if (scale_min > val) scale_min = val;
442 if (scale_min == 1.0) scale_min = 0.0;
443 if (scale_min > 0.9) scale_min = 0.9;
445 gr->SetMaximum(m_PXDModules.size());
446 auto ay = gr->GetYaxis();
447 if (ay) ay->SetRangeUser(scale_min, 1.0);
448 auto ax = gr->GetXaxis();
450 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
451 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
452 TString ModuleName = (std::string)m_PXDModules[i];
453 ax->SetBinLabel(i + 1, ModuleName);
459 gr->SetMarkerStyle(8);
470 m_cEffAll->Pad()->SetFillColor(kGray);
473 m_cEffAll->Pad()->SetFillColor(kRed);
474 }
else if (warn_flag) {
475 m_cEffAll->Pad()->SetFillColor(kYellow);
477 m_cEffAll->Pad()->SetFillColor(kGreen);
482 m_cEffAll->Pad()->SetFrameFillColor(kWhite - 1);
483 m_cEffAll->Pad()->SetFrameFillStyle(1001);
484 m_cEffAll->Pad()->Modified();
485 m_cEffAll->Pad()->Update();
486 m_hWarnLine->Draw(
"same,hist");
487 m_hErrorLine->Draw(
"same,hist");
490 m_cEffAll->Modified();
495 m_cEffAllUpdate->cd();
496 m_hEffAllUpdate->Paint(
"AP");
497 m_cEffAllUpdate->Clear();
498 m_cEffAllUpdate->cd(0);
500 auto gr = m_hEffAllUpdate->GetPaintedGraph();
501 auto gr3 = (TGraphAsymmErrors*) m_hEffAll->GetPaintedGraph()->Clone();
503 for (
int i = 0; i < gr3->GetN(); i++) {
505 gr3->GetPoint(i, x, y);
506 gr3->SetPoint(i, x + 0.2, y);
510 double scale_min = 1.0;
512 for (
int i = 0; i < gr->GetN(); i++) {
513 gr->SetPointEXhigh(i, 0.);
514 gr->SetPointEXlow(i, 0.);
517 gr->GetPoint(i, x, y);
518 gr->SetPoint(i, x - 0.2, y);
519 auto val = y - gr->GetErrorYlow(i);
522 if (scale_min > val) scale_min = val;
524 if (scale_min == 1.0) scale_min = 0.0;
525 if (scale_min > 0.9) scale_min = 0.9;
527 gr->SetMaximum(m_PXDModules.size());
528 auto ay = gr->GetYaxis();
529 if (ay) ay->SetRangeUser(scale_min, 1.0);
530 auto ax = gr->GetXaxis();
532 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
533 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
534 TString ModuleName = (std::string)m_PXDModules[i];
535 ax->SetBinLabel(i + 1, ModuleName);
539 if (m_useEpics && !m_useEpicsRO) {
540 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
541 if (updated[m_PXDModules[i]]) {
543 gr->GetPoint(i, x, y);
544 auto& my = mychid_eff[m_PXDModules[i]];
546 SEVCHK(ca_put(DBR_DOUBLE, my, (
void*)&y),
"ca_set failure");
551 gr->SetLineColor(kBlack);
553 gr->SetMarkerStyle(33);
554 }
else scale_min = 0.0;
555 if (gr) gr->Draw(
"AP");
556 if (gr3) gr3->Draw(
"P");
565 m_cEffAllUpdate->Pad()->SetFillColor(kGray);
569 m_cEffAllUpdate->Pad()->SetFillColor(kRed);
571 }
else if (warn_flag) {
572 m_cEffAllUpdate->Pad()->SetFillColor(kYellow);
575 m_cEffAllUpdate->Pad()->SetFillColor(kGreen);
581 m_cEffAllUpdate->Pad()->SetFrameFillColor(kWhite - 1);
582 m_cEffAllUpdate->Pad()->SetFrameFillStyle(1001);
583 m_cEffAllUpdate->Pad()->Modified();
584 m_cEffAllUpdate->Pad()->Update();
585 m_hWarnLine->Draw(
"same,hist");
586 m_hErrorLine->Draw(
"same,hist");
588 m_cEffAllUpdate->Modified();
589 m_cEffAllUpdate->Update();
592 double var_efficiency = ihit > 0 ? imatch / ihit : 0.0;
593 m_monObj->setVariable(
"efficiency", var_efficiency);
594 m_monObj->setVariable(
"nmodules", ieff);
597 if (m_useEpics && !m_useEpicsRO) {
598 SEVCHK(ca_put(DBR_DOUBLE, mychid_status[0], (
void*)&stat_data),
"ca_set failure");
600 if (stat_data != 0) SEVCHK(ca_put(DBR_DOUBLE, mychid_status[1], (
void*)&var_efficiency),
"ca_set failure");
601 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
606 void DQMHistAnalysisPXDEffModule::terminate()
608 B2DEBUG(1,
"DQMHistAnalysisPXDEff: terminate called");
611 for (
auto& m : mychid_status) SEVCHK(ca_clear_channel(m),
"ca_clear_channel failure");
612 for (
auto& m : mychid_eff) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
613 for (
auto& m : mychid_low) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
614 for (
auto& m : mychid_lolo) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
615 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.