9 #include <dqm/analysis/modules/DQMHistAnalysisPXDEff.h>
12 #include <TGraphAsymmErrors.h>
13 #include <vxd/geometry/GeoCache.h>
35 addParam(
"binsU", m_u_bins,
"histogram bins in u direction, needs to be the same as in PXDDQMEfficiency",
int(4));
36 addParam(
"binsV", m_v_bins,
"histogram bins in v direction, needs to be the same as in PXDDQMEfficiency",
int(6));
37 addParam(
"histogramDirectoryName", m_histogramDirectoryName,
"Name of the directory where histograms were placed",
38 std::string(
"PXDEFF"));
39 addParam(
"singleHists", m_singleHists,
"Also plot one efficiency histogram per module",
bool(
false));
40 addParam(
"PVPrefix", m_pvPrefix,
"PV Prefix", std::string(
"DQM:PXD:Eff:"));
41 addParam(
"useEpics", m_useEpics,
"useEpics",
true);
42 addParam(
"useEpicsRO", m_useEpicsRO,
"useEpics ReadOnly",
false);
43 addParam(
"ConfidenceLevel", m_confidence,
"Confidence Level for error bars and alarms", 0.9544);
44 addParam(
"WarnLevel", m_warnlevel,
"Efficiency Warn Level for alarms", 0.92);
45 addParam(
"ErrorLevel", m_errorlevel,
"Efficiency Level for alarms", 0.90);
46 addParam(
"perModuleAlarm", m_perModuleAlarm,
"Alarm level per module",
true);
47 addParam(
"alarmAdhoc", m_alarmAdhoc,
"Generate Alarm from adhoc values",
true);
48 addParam(
"minEntries", m_minEntries,
"minimum number of new entries for last time slot", 1000);
49 B2DEBUG(1,
"DQMHistAnalysisPXDEff: Constructor done.");
52 DQMHistAnalysisPXDEffModule::~DQMHistAnalysisPXDEffModule()
56 if (ca_current_context()) ca_context_destroy();
61 void DQMHistAnalysisPXDEffModule::initialize()
63 B2DEBUG(99,
"DQMHistAnalysisPXDEffModule: initialized.");
65 m_monObj = getMonitoringObject(
"pxd");
70 for (
VxdID& aVxdID : sensors) {
72 if (info.getType() != VXD::SensorInfoBase::PXD)
continue;
73 m_PXDModules.push_back(aVxdID);
75 std::sort(m_PXDModules.begin(), m_PXDModules.end());
82 if (m_PXDModules.size() == 0) {
84 B2WARNING(
"No PXDModules in Geometry found! Use hard-coded setup.");
85 std::vector <string> mod = {
86 "1.1.1",
"1.1.2",
"1.2.1",
"1.2.2",
"1.3.1",
"1.3.2",
"1.4.1",
"1.4.2",
87 "1.5.1",
"1.5.2",
"1.6.1",
"1.6.2",
"1.7.1",
"1.7.2",
"1.8.1",
"1.8.2",
88 "2.4.1",
"2.4.2",
"2.5.1",
"2.5.2"
90 for (
auto& it : mod) m_PXDModules.push_back(
VxdID(it));
99 m_useEpics |= m_useEpicsRO;
101 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
106 for (
VxdID& aPXDModule : m_PXDModules) {
107 TString buff = (std::string)aPXDModule;
108 buff.ReplaceAll(
".",
"_");
111 auto& my = mychid_eff[aPXDModule];
112 SEVCHK(ca_create_channel((m_pvPrefix + buff).Data(), NULL, NULL, 10, &my),
"ca_create_channel failure");
113 B2WARNING(m_pvPrefix + (std::string)aPXDModule);
116 TString histTitle =
"PXD Hit Efficiency on Module " + (std::string)aPXDModule +
";Pixel in U;Pixel in V";
118 m_cEffModules[aPXDModule] =
new TCanvas((m_histogramDirectoryName +
"/c_Eff_").data() + buff);
119 m_hEffModules[aPXDModule] =
new TEfficiency(
"ePXDHitEff_" + buff, histTitle,
120 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
124 m_hErrorLine =
new TH1F(
"hPXDErrorlimit",
"Error Limit", m_PXDModules.size(), 0, m_PXDModules.size());
125 m_hWarnLine =
new TH1F(
"hPXDWarnlimit",
"Warn Limit", m_PXDModules.size(), 0, m_PXDModules.size());
126 for (
int i = 0; i < (int)m_PXDModules.size(); i++) {
127 m_hErrorLine->SetBinContent(i + 1, m_errorlevel);
128 m_hWarnLine->SetBinContent(i + 1, m_warnlevel);
130 m_hWarnLine->SetLineColor(kOrange - 3);
131 m_hWarnLine->SetLineWidth(3);
132 m_hWarnLine->SetLineStyle(4);
133 m_hErrorLine->SetLineColor(kRed + 3);
134 m_hErrorLine->SetLineWidth(3);
135 m_hErrorLine->SetLineStyle(7);
138 m_cEffAll =
new TCanvas((m_histogramDirectoryName +
"/c_EffAll").data());
139 m_hEffAll =
new TEfficiency(
"ePXDHitEffAll",
"PXD Integrated Efficiency of each module;PXD Module;",
140 m_PXDModules.size(), 0, m_PXDModules.size());
141 m_hEffAll->SetConfidenceLevel(m_confidence);
142 m_hEffAll->Paint(
"AP");
143 m_hEffAllLastTotal = m_hEffAll->GetCopyTotalHisto();
144 m_hEffAllLastPassed = m_hEffAll->GetCopyPassedHisto();
147 auto gr = m_hEffAll->GetPaintedGraph();
150 auto ax = gr->GetXaxis();
152 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
153 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
154 TString ModuleName = (std::string)m_PXDModules[i];
155 ax->SetBinLabel(i + 1, ModuleName);
161 m_cEffAllUpdate =
new TCanvas((m_histogramDirectoryName +
"/c_EffAllUp").data());
162 m_hEffAllUpdate =
new TEfficiency(
"ePXDHitEffAllUpdate",
"PXD Integral and last-updated Efficiency per module;PXD Module;",
163 m_PXDModules.size(), 0, m_PXDModules.size());
164 m_hEffAllUpdate->SetConfidenceLevel(m_confidence);
167 auto gr = m_hEffAllUpdate->GetPaintedGraph();
170 auto ax = gr->GetXaxis();
172 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
173 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
174 TString ModuleName = (std::string)m_PXDModules[i];
175 ax->SetBinLabel(i + 1, ModuleName);
181 m_monObj->addCanvas(m_cEffAll);
182 m_monObj->addCanvas(m_cEffAllUpdate);
187 mychid_status.resize(2);
188 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
189 SEVCHK(ca_create_channel((m_pvPrefix +
"Status").data(), NULL, NULL, 10, &mychid_status[0]),
"ca_create_channel failure");
190 SEVCHK(ca_create_channel((m_pvPrefix +
"Overall").data(), NULL, NULL, 10, &mychid_status[1]),
"ca_create_channel failure");
191 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
194 B2DEBUG(1,
"DQMHistAnalysisPXDEff: initialized.");
198 void DQMHistAnalysisPXDEffModule::beginRun()
200 B2DEBUG(1,
"DQMHistAnalysisPXDEff: beginRun called.");
203 m_cEffAllUpdate->Clear();
206 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
208 m_hEffAll->SetPassedEvents(j, 0);
209 m_hEffAll->SetTotalEvents(j, 0);
210 m_hEffAllUpdate->SetPassedEvents(j, 0);
211 m_hEffAllUpdate->SetTotalEvents(j, 0);
213 m_warnlevelmod[m_PXDModules[i]] = m_warnlevel;
214 m_errorlevelmod[m_PXDModules[i]] = m_errorlevel;
220 struct dbr_ctrl_double tPvData;
221 auto r = ca_get(DBR_CTRL_DOUBLE, mychid_eff[m_PXDModules[i]], &tPvData);
222 if (r == ECA_NORMAL) r = ca_pend_io(5.0);
223 if (r == ECA_NORMAL) {
224 if (!std::isnan(tPvData.lower_alarm_limit)
225 && tPvData.lower_alarm_limit > 0.0) {
226 m_hErrorLine->SetBinContent(i + 1, tPvData.lower_alarm_limit);
227 if (m_perModuleAlarm) m_errorlevelmod[m_PXDModules[i]] = tPvData.lower_alarm_limit;
229 if (!std::isnan(tPvData.lower_warning_limit)
230 && tPvData.lower_warning_limit > 0.0) {
231 m_hWarnLine->SetBinContent(i + 1, tPvData.lower_warning_limit);
232 if (m_perModuleAlarm) m_warnlevelmod[m_PXDModules[i]] = tPvData.lower_warning_limit;
235 SEVCHK(r,
"ca_get or ca_pend_io failure");
242 m_hEffAllLastTotal->Reset();
243 m_hEffAllLastPassed->Reset();
245 for (
auto single_cmap : m_cEffModules) {
246 if (single_cmap.second) single_cmap.second->Clear();
252 void DQMHistAnalysisPXDEffModule::event()
256 std::map<VxdID, TH1*> mapHits;
257 std::map<VxdID, TH1*> mapMatches;
262 for (
unsigned int i = 1; i <= m_PXDModules.size(); i++) {
263 VxdID& aPXDModule = m_PXDModules[i - 1];
265 TString buff = (std::string)aPXDModule;
266 buff.ReplaceAll(
".",
"_");
269 TString locationHits =
"track_hits_" + buff;
270 if (m_histogramDirectoryName !=
"") {
271 locationHits = m_histogramDirectoryName +
"/" + locationHits;
273 Hits = (TH1*)findHist(locationHits.Data());
274 TString locationMatches =
"matched_cluster_" + buff;
275 if (m_histogramDirectoryName !=
"") {
276 locationMatches = m_histogramDirectoryName +
"/" + locationMatches;
278 Matches = (TH1*)findHist(locationMatches.Data());
281 if (Hits ==
nullptr || Matches ==
nullptr) {
282 B2ERROR(
"Missing histogram for sensor " << aPXDModule);
283 mapHits[aPXDModule] =
nullptr;
284 mapMatches[aPXDModule] =
nullptr;
286 mapHits[aPXDModule] = Hits;
287 mapMatches[aPXDModule] = Matches;
289 if (m_cEffModules[aPXDModule] && m_hEffModules[aPXDModule]) {
290 m_hEffModules[aPXDModule]->SetTotalHistogram(*Hits,
"f");
291 m_hEffModules[aPXDModule]->SetPassedHistogram(*Matches,
"f");
293 m_cEffModules[aPXDModule]->cd();
294 m_hEffModules[aPXDModule]->Draw(
"colz");
295 m_cEffModules[aPXDModule]->Modified();
296 m_cEffModules[aPXDModule]->Update();
302 double stat_data = 0;
303 bool error_flag =
false;
304 bool warn_flag =
false;
307 double imatch = 0.0, ihit = 0.0;
310 std::map <VxdID, bool> updated{};
311 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
312 VxdID& aModule = m_PXDModules[i];
315 if (mapHits[aModule] ==
nullptr || mapMatches[aModule] ==
nullptr) {
316 m_hEffAll->SetPassedEvents(j, 0);
317 m_hEffAll->SetTotalEvents(j, 0);
319 double nmatch = mapMatches[aModule]->Integral();
320 double nhit = mapHits[aModule]->Integral();
321 if (nmatch > 10 && nhit > 10) {
325 double var_e = nmatch / nhit;
326 if (j == 6)
continue;
333 m_hEffAll->SetPassedEvents(j, 0);
334 m_hEffAll->SetTotalEvents(j, nhit);
335 m_hEffAll->SetPassedEvents(j, nmatch);
337 if (nhit < m_minEntries) {
339 m_hEffAllUpdate->SetPassedEvents(j, 0);
340 m_hEffAllUpdate->SetTotalEvents(j, nhit);
341 m_hEffAllUpdate->SetPassedEvents(j, nmatch);
342 m_hEffAllLastTotal->SetBinContent(j, nhit);
343 m_hEffAllLastPassed->SetBinContent(j, nmatch);
344 updated[aModule] =
true;
345 }
else if (nhit - m_hEffAllLastTotal->GetBinContent(j) > m_minEntries) {
346 m_hEffAllUpdate->SetPassedEvents(j, 0);
347 m_hEffAllUpdate->SetTotalEvents(j, nhit - m_hEffAllLastTotal->GetBinContent(j));
348 m_hEffAllUpdate->SetPassedEvents(j, nmatch - m_hEffAllLastPassed->GetBinContent(j));
349 m_hEffAllLastTotal->SetBinContent(j, nhit);
350 m_hEffAllLastPassed->SetBinContent(j, nmatch);
351 updated[aModule] =
true;
354 if (j == 6)
continue;
360 error_flag |= (m_hEffAll->GetEfficiency(j) + m_hEffAll->GetEfficiencyErrorUp(j) <
361 m_errorlevelmod[aModule]);
362 warn_flag |= (m_hEffAll->GetEfficiency(j) + m_hEffAll->GetEfficiencyErrorUp(j) <
363 m_warnlevelmod[aModule]);
365 error_flag |= (m_hEffAllUpdate->GetEfficiency(j) + m_hEffAllUpdate->GetEfficiencyErrorUp(j) <
366 m_errorlevelmod[aModule]);
367 warn_flag |= (m_hEffAllUpdate->GetEfficiency(j) + m_hEffAllUpdate->GetEfficiencyErrorUp(j) <
368 m_warnlevelmod[aModule]);
377 m_hEffAll->Paint(
"AP");
381 auto gr = m_hEffAll->GetPaintedGraph();
383 double scale_min = 1.0;
384 for (
int i = 0; i < gr->GetN(); i++) {
385 gr->SetPointEXhigh(i, 0.);
386 gr->SetPointEXlow(i, 0.);
389 gr->GetPoint(i, x, y);
390 gr->SetPoint(i, x - 0.01, y);
391 auto val = y - gr->GetErrorYlow(i);
394 if (scale_min > val) scale_min = val;
397 if (scale_min == 1.0) scale_min = 0.0;
398 if (scale_min > 0.9) scale_min = 0.9;
400 gr->SetMaximum(m_PXDModules.size());
401 auto ay = gr->GetYaxis();
402 if (ay) ay->SetRangeUser(scale_min, 1.0);
403 auto ax = gr->GetXaxis();
405 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
406 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
407 TString ModuleName = (std::string)m_PXDModules[i];
408 ax->SetBinLabel(i + 1, ModuleName);
414 gr->SetMarkerStyle(8);
418 auto tt =
new TLatex(5.5, scale_min,
" 1.3.2 Module is excluded, please ignore");
419 tt->SetTextAngle(90);
420 tt->SetTextAlign(12);
424 m_cEffAll->Pad()->SetFillColor(kGray);
427 m_cEffAll->Pad()->SetFillColor(kRed);
428 }
else if (warn_flag) {
429 m_cEffAll->Pad()->SetFillColor(kYellow);
431 m_cEffAll->Pad()->SetFillColor(kGreen);
436 m_cEffAll->Pad()->SetFrameFillColor(kWhite - 1);
437 m_cEffAll->Pad()->SetFrameFillStyle(1001);
438 m_cEffAll->Pad()->Modified();
439 m_cEffAll->Pad()->Update();
440 m_hWarnLine->Draw(
"same,hist");
441 m_hErrorLine->Draw(
"same,hist");
444 m_cEffAll->Modified();
449 m_cEffAllUpdate->cd();
450 m_hEffAllUpdate->Paint(
"AP");
451 m_cEffAllUpdate->Clear();
452 m_cEffAllUpdate->cd(0);
454 auto gr = m_hEffAllUpdate->GetPaintedGraph();
455 auto gr3 = (TGraphAsymmErrors*) m_hEffAll->GetPaintedGraph()->Clone();
457 for (
int i = 0; i < gr3->GetN(); i++) {
459 gr3->GetPoint(i, x, y);
460 gr3->SetPoint(i, x + 0.2, y);
464 double scale_min = 1.0;
466 for (
int i = 0; i < gr->GetN(); i++) {
467 gr->SetPointEXhigh(i, 0.);
468 gr->SetPointEXlow(i, 0.);
471 gr->GetPoint(i, x, y);
472 gr->SetPoint(i, x - 0.2, y);
473 auto val = y - gr->GetErrorYlow(i);
476 if (scale_min > val) scale_min = val;
479 if (scale_min == 1.0) scale_min = 0.0;
480 if (scale_min > 0.9) scale_min = 0.9;
482 gr->SetMaximum(m_PXDModules.size());
483 auto ay = gr->GetYaxis();
484 if (ay) ay->SetRangeUser(scale_min, 1.0);
485 auto ax = gr->GetXaxis();
487 ax->Set(m_PXDModules.size() , 0, m_PXDModules.size());
488 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
489 TString ModuleName = (std::string)m_PXDModules[i];
490 ax->SetBinLabel(i + 1, ModuleName);
494 if (m_useEpics && !m_useEpicsRO) {
495 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
496 if (updated[m_PXDModules[i]]) {
498 gr->GetPoint(i, x, y);
499 auto& my = mychid_eff[m_PXDModules[i]];
501 SEVCHK(ca_put(DBR_DOUBLE, my, (
void*)&y),
"ca_set failure");
506 gr->SetLineColor(kBlack);
508 gr->SetMarkerStyle(33);
509 }
else scale_min = 0.0;
510 if (gr) gr->Draw(
"AP");
511 if (gr3) gr3->Draw(
"P");
512 auto tt =
new TLatex(5.5, scale_min,
" 1.3.2 Module is excluded, please ignore");
513 tt->SetTextSize(0.035);
514 tt->SetTextAngle(90);
515 tt->SetTextAlign(12);
519 m_cEffAllUpdate->Pad()->SetFillColor(kGray);
523 m_cEffAllUpdate->Pad()->SetFillColor(kRed);
525 }
else if (warn_flag) {
526 m_cEffAllUpdate->Pad()->SetFillColor(kYellow);
529 m_cEffAllUpdate->Pad()->SetFillColor(kGreen);
535 m_cEffAllUpdate->Pad()->SetFrameFillColor(kWhite - 1);
536 m_cEffAllUpdate->Pad()->SetFrameFillStyle(1001);
537 m_cEffAllUpdate->Pad()->Modified();
538 m_cEffAllUpdate->Pad()->Update();
539 m_hWarnLine->Draw(
"same,hist");
540 m_hErrorLine->Draw(
"same,hist");
542 m_cEffAllUpdate->Modified();
543 m_cEffAllUpdate->Update();
546 double var_efficiency = ihit > 0 ? imatch / ihit : 0.0;
547 m_monObj->setVariable(
"efficiency", var_efficiency);
548 m_monObj->setVariable(
"nmodules", ieff);
551 if (m_useEpics && !m_useEpicsRO) {
552 SEVCHK(ca_put(DBR_DOUBLE, mychid_status[0], (
void*)&stat_data),
"ca_set failure");
554 if (stat_data != 0) SEVCHK(ca_put(DBR_DOUBLE, mychid_status[1], (
void*)&var_efficiency),
"ca_set failure");
555 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
560 void DQMHistAnalysisPXDEffModule::terminate()
562 B2DEBUG(1,
"DQMHistAnalysisPXDEff: terminate called");
565 for (
auto& m : mychid_status) SEVCHK(ca_clear_channel(m),
"ca_clear_channel failure");
566 for (
auto& m : mychid_eff) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
567 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");