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(
"ConfidenceLevel", m_confidence,
"Confidence Level for error bars and alarms", 0.9544);
43 addParam(
"WarnLevel", m_warnlevel,
"Efficiency Warn Level for alarms", 0.92);
44 addParam(
"ErrorLevel", m_errorlevel,
"Efficiency Level for alarms", 0.90);
45 addParam(
"minEntries", m_minEntries,
"minimum number of new entries for last time slot", 1000);
46 B2DEBUG(1,
"DQMHistAnalysisPXDEff: Constructor done.");
49 DQMHistAnalysisPXDEffModule::~DQMHistAnalysisPXDEffModule()
53 if (ca_current_context()) ca_context_destroy();
58 void DQMHistAnalysisPXDEffModule::initialize()
60 B2DEBUG(99,
"DQMHistAnalysisPXDEffModule: initialized.");
62 m_monObj = getMonitoringObject(
"pxd");
67 for (
VxdID& aVxdID : sensors) {
69 if (info.getType() != VXD::SensorInfoBase::PXD)
continue;
70 m_PXDModules.push_back(aVxdID);
72 std::sort(m_PXDModules.begin(), m_PXDModules.end());
79 if (m_PXDModules.size() == 0) {
81 B2WARNING(
"No PXDModules in Geometry found! Use hard-coded setup.");
82 std::vector <string> mod = {
83 "1.1.1",
"1.1.2",
"1.2.1",
"1.2.2",
"1.3.1",
"1.3.2",
"1.4.1",
"1.4.2",
84 "1.5.1",
"1.5.2",
"1.6.1",
"1.6.2",
"1.7.1",
"1.7.2",
"1.8.1",
"1.8.2",
85 "2.4.1",
"2.4.2",
"2.5.1",
"2.5.2"
87 for (
auto& it : mod) m_PXDModules.push_back(
VxdID(it));
97 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
102 for (
VxdID& aPXDModule : m_PXDModules) {
103 TString buff = (std::string)aPXDModule;
104 buff.ReplaceAll(
".",
"_");
107 auto& my = mychid_eff[aPXDModule];
108 SEVCHK(ca_create_channel((m_pvPrefix + buff).Data(), NULL, NULL, 10, &my),
"ca_create_channel failure");
109 B2WARNING(m_pvPrefix + (std::string)aPXDModule);
112 TString histTitle =
"Hit Efficiency on Module " + (std::string)aPXDModule +
";Pixel in U;Pixel in V";
114 m_cEffModules[aPXDModule] =
new TCanvas((m_histogramDirectoryName +
"/c_Eff_").data() + buff);
115 m_hEffModules[aPXDModule] =
new TEfficiency(
"HitEff_" + buff, histTitle,
116 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
121 m_cEffAll =
new TCanvas((m_histogramDirectoryName +
"/c_EffAll").data());
122 m_hEffAll =
new TEfficiency(
"HitEffAll",
"Integrated Efficiency of each module;PXD Module;",
123 m_PXDModules.size(), 0, m_PXDModules.size());
124 m_hEffAll->SetConfidenceLevel(m_confidence);
125 m_hEffAll->Paint(
"AP");
126 m_hEffAllLastTotal = m_hEffAll->GetCopyTotalHisto();
127 m_hEffAllLastPassed = m_hEffAll->GetCopyPassedHisto();
130 auto gr = m_hEffAll->GetPaintedGraph();
133 auto ax = gr->GetXaxis();
135 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
136 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
137 TString ModuleName = (std::string)m_PXDModules[i];
138 ax->SetBinLabel(i + 1, ModuleName);
144 m_cEffAllUpdate =
new TCanvas((m_histogramDirectoryName +
"/c_EffAllUp").data());
145 m_hEffAllUpdate =
new TEfficiency(
"HitEffAllUpdate",
"Integral and last-updated Efficiency per module;PXD Module;",
146 m_PXDModules.size(), 0, m_PXDModules.size());
147 m_hEffAllUpdate->SetConfidenceLevel(m_confidence);
150 auto gr = m_hEffAllUpdate->GetPaintedGraph();
153 auto ax = gr->GetXaxis();
155 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
156 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
157 TString ModuleName = (std::string)m_PXDModules[i];
158 ax->SetBinLabel(i + 1, ModuleName);
165 m_line_warn =
new TLine(0, m_warnlevel, m_PXDModules.size(), m_warnlevel);
166 m_line_error =
new TLine(0, m_errorlevel, m_PXDModules.size(), m_errorlevel);
167 m_line_warn->SetHorizontal(
true);
168 m_line_warn->SetLineColor(kOrange - 3);
169 m_line_warn->SetLineWidth(3);
170 m_line_warn->SetLineStyle(4);
171 m_line_error->SetHorizontal(
true);
172 m_line_error->SetLineColor(kRed + 3);
173 m_line_error->SetLineWidth(3);
174 m_line_error->SetLineStyle(7);
176 m_monObj->addCanvas(m_cEffAll);
177 m_monObj->addCanvas(m_cEffAllUpdate);
182 mychid_status.resize(2);
183 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
184 SEVCHK(ca_create_channel((m_pvPrefix +
"Status").data(), NULL, NULL, 10, &mychid_status[0]),
"ca_create_channel failure");
185 SEVCHK(ca_create_channel((m_pvPrefix +
"Overall").data(), NULL, NULL, 10, &mychid_status[1]),
"ca_create_channel failure");
186 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
189 B2DEBUG(1,
"DQMHistAnalysisPXDEff: initialized.");
193 void DQMHistAnalysisPXDEffModule::beginRun()
195 B2DEBUG(1,
"DQMHistAnalysisPXDEff: beginRun called.");
198 m_cEffAllUpdate->Clear();
201 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
203 m_hEffAll->SetPassedEvents(j, 0);
204 m_hEffAll->SetTotalEvents(j, 0);
205 m_hEffAllUpdate->SetPassedEvents(j, 0);
206 m_hEffAllUpdate->SetTotalEvents(j, 0);
209 m_hEffAllLastTotal->Reset();
210 m_hEffAllLastPassed->Reset();
212 for (
auto single_cmap : m_cEffModules) {
213 if (single_cmap.second) single_cmap.second->Clear();
219 void DQMHistAnalysisPXDEffModule::event()
223 std::map<VxdID, TH1*> mapHits;
224 std::map<VxdID, TH1*> mapMatches;
229 for (
unsigned int i = 1; i <= m_PXDModules.size(); i++) {
230 VxdID& aPXDModule = m_PXDModules[i - 1];
232 TString buff = (std::string)aPXDModule;
233 buff.ReplaceAll(
".",
"_");
236 TString locationHits =
"track_hits_" + buff;
237 if (m_histogramDirectoryName !=
"") {
238 locationHits = m_histogramDirectoryName +
"/" + locationHits;
240 Hits = (TH1*)findHist(locationHits.Data());
241 TString locationMatches =
"matched_cluster_" + buff;
242 if (m_histogramDirectoryName !=
"") {
243 locationMatches = m_histogramDirectoryName +
"/" + locationMatches;
245 Matches = (TH1*)findHist(locationMatches.Data());
248 if (Hits ==
nullptr || Matches ==
nullptr) {
249 B2ERROR(
"Missing histogram for sensor " << aPXDModule);
250 mapHits[aPXDModule] =
nullptr;
251 mapMatches[aPXDModule] =
nullptr;
253 mapHits[aPXDModule] = Hits;
254 mapMatches[aPXDModule] = Matches;
256 if (m_cEffModules[aPXDModule] && m_hEffModules[aPXDModule]) {
257 m_hEffModules[aPXDModule]->SetTotalHistogram(*Hits,
"f");
258 m_hEffModules[aPXDModule]->SetPassedHistogram(*Matches,
"f");
260 m_cEffModules[aPXDModule]->cd();
261 m_hEffModules[aPXDModule]->Draw(
"colz");
262 m_cEffModules[aPXDModule]->Modified();
263 m_cEffModules[aPXDModule]->Update();
269 double stat_data = 0;
270 bool error_flag =
false;
271 bool warn_flag =
false;
274 double imatch = 0.0, ihit = 0.0;
277 std::map <VxdID, bool> updated{};
278 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
279 VxdID& aModule = m_PXDModules[i];
282 if (mapHits[aModule] ==
nullptr || mapMatches[aModule] ==
nullptr) {
283 m_hEffAll->SetPassedEvents(j, 0);
284 m_hEffAll->SetTotalEvents(j, 0);
286 double nmatch = mapMatches[aModule]->Integral();
287 double nhit = mapHits[aModule]->Integral();
288 if (nmatch > 10 && nhit > 10) {
292 double var_e = nmatch / nhit;
293 if (j == 6)
continue;
300 m_hEffAll->SetPassedEvents(j, 0);
301 m_hEffAll->SetTotalEvents(j, nhit);
302 m_hEffAll->SetPassedEvents(j, nmatch);
304 if (nhit < m_minEntries) {
306 m_hEffAllUpdate->SetPassedEvents(j, 0);
307 m_hEffAllUpdate->SetTotalEvents(j, nhit);
308 m_hEffAllUpdate->SetPassedEvents(j, nmatch);
309 m_hEffAllLastTotal->SetBinContent(j, nhit);
310 m_hEffAllLastPassed->SetBinContent(j, nmatch);
311 updated[aModule] =
true;
312 }
else if (nhit - m_hEffAllLastTotal->GetBinContent(j) > m_minEntries) {
313 m_hEffAllUpdate->SetPassedEvents(j, 0);
314 m_hEffAllUpdate->SetTotalEvents(j, nhit - m_hEffAllLastTotal->GetBinContent(j));
315 m_hEffAllUpdate->SetPassedEvents(j, nmatch - m_hEffAllLastPassed->GetBinContent(j));
316 m_hEffAllLastTotal->SetBinContent(j, nhit);
317 m_hEffAllLastPassed->SetBinContent(j, nmatch);
318 updated[aModule] =
true;
321 if (j == 6)
continue;
326 error_flag |= (ihit > 10)
327 && (m_hEffAll->GetEfficiency(j) + m_hEffAll->GetEfficiencyErrorUp(j) < m_errorlevel);
328 warn_flag |= (ihit > 10)
329 && (m_hEffAll->GetEfficiency(j) + m_hEffAll->GetEfficiencyErrorUp(j) < m_warnlevel);
336 m_hEffAll->Paint(
"AP");
340 auto gr = m_hEffAll->GetPaintedGraph();
342 double scale_min = 1.0;
343 for (
int i = 0; i < gr->GetN(); i++) {
344 gr->SetPointEXhigh(i, 0.);
345 gr->SetPointEXlow(i, 0.);
348 gr->GetPoint(i, x, y);
349 gr->SetPoint(i, x - 0.01, y);
350 auto val = y - gr->GetErrorYlow(i);
353 if (scale_min > val) scale_min = val;
356 if (scale_min == 1.0) scale_min = 0.0;
357 if (scale_min > 0.9) scale_min = 0.9;
359 gr->SetMaximum(m_PXDModules.size());
360 auto ay = gr->GetYaxis();
361 if (ay) ay->SetRangeUser(scale_min, 1.0);
362 auto ax = gr->GetXaxis();
364 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
365 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
366 TString ModuleName = (std::string)m_PXDModules[i];
367 ax->SetBinLabel(i + 1, ModuleName);
373 gr->SetMarkerStyle(8);
377 auto tt =
new TLatex(5.5, scale_min,
" 1.3.2 Module is excluded, please ignore");
378 tt->SetTextAngle(90);
379 tt->SetTextAlign(12);
383 m_cEffAll->Pad()->SetFillColor(kGray);
386 m_cEffAll->Pad()->SetFillColor(kRed);
387 }
else if (warn_flag) {
388 m_cEffAll->Pad()->SetFillColor(kYellow);
390 m_cEffAll->Pad()->SetFillColor(kGreen);
395 m_cEffAll->Pad()->SetFrameFillColor(kWhite - 1);
396 m_cEffAll->Pad()->SetFrameFillStyle(1001);
397 m_cEffAll->Pad()->Modified();
398 m_cEffAll->Pad()->Update();
400 m_line_error->Draw();
403 m_cEffAll->Modified();
408 m_cEffAllUpdate->cd();
409 m_hEffAllUpdate->Paint(
"AP");
410 m_cEffAllUpdate->Clear();
411 m_cEffAllUpdate->cd(0);
413 auto gr = m_hEffAllUpdate->GetPaintedGraph();
414 auto gr3 = (TGraphAsymmErrors*) m_hEffAll->GetPaintedGraph()->Clone();
416 for (
int i = 0; i < gr3->GetN(); i++) {
418 gr3->GetPoint(i, x, y);
419 gr3->SetPoint(i, x + 0.2, y);
423 double scale_min = 1.0;
425 for (
int i = 0; i < gr->GetN(); i++) {
426 gr->SetPointEXhigh(i, 0.);
427 gr->SetPointEXlow(i, 0.);
430 gr->GetPoint(i, x, y);
431 gr->SetPoint(i, x - 0.2, y);
432 auto val = y - gr->GetErrorYlow(i);
435 if (scale_min > val) scale_min = val;
438 if (scale_min == 1.0) scale_min = 0.0;
439 if (scale_min > 0.9) scale_min = 0.9;
441 gr->SetMaximum(m_PXDModules.size());
442 auto ay = gr->GetYaxis();
443 if (ay) ay->SetRangeUser(scale_min, 1.0);
444 auto ax = gr->GetXaxis();
446 ax->Set(m_PXDModules.size() , 0, m_PXDModules.size());
447 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
448 TString ModuleName = (std::string)m_PXDModules[i];
449 ax->SetBinLabel(i + 1, ModuleName);
454 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
455 if (updated[m_PXDModules[i]]) {
457 gr->GetPoint(i, x, y);
458 auto& my = mychid_eff[m_PXDModules[i]];
460 SEVCHK(ca_put(DBR_DOUBLE, my, (
void*)&y),
"ca_set failure");
465 gr->SetLineColor(kBlack);
467 gr->SetMarkerStyle(33);
468 }
else scale_min = 0.0;
469 if (gr) gr->Draw(
"AP");
470 if (gr3) gr3->Draw(
"P");
471 auto tt =
new TLatex(5.5, scale_min,
"1.3.2 Module is excluded, please ignore");
472 tt->SetTextSize(0.035);
473 tt->SetTextAngle(90);
474 tt->SetTextAlign(12);
478 m_cEffAllUpdate->Pad()->SetFillColor(kGray);
482 m_cEffAllUpdate->Pad()->SetFillColor(kRed);
484 }
else if (warn_flag) {
485 m_cEffAllUpdate->Pad()->SetFillColor(kYellow);
488 m_cEffAllUpdate->Pad()->SetFillColor(kGreen);
494 m_cEffAllUpdate->Pad()->SetFrameFillColor(kWhite - 1);
495 m_cEffAllUpdate->Pad()->SetFrameFillStyle(1001);
496 m_cEffAllUpdate->Pad()->Modified();
497 m_cEffAllUpdate->Pad()->Update();
499 m_line_error->Draw();
501 m_cEffAllUpdate->Modified();
502 m_cEffAllUpdate->Update();
505 double var_efficiency = ihit > 0 ? imatch / ihit : 0.0;
506 m_monObj->setVariable(
"efficiency", var_efficiency);
507 m_monObj->setVariable(
"nmodules", ieff);
511 SEVCHK(ca_put(DBR_DOUBLE, mychid_status[0], (
void*)&stat_data),
"ca_set failure");
513 if (stat_data != 0) SEVCHK(ca_put(DBR_DOUBLE, mychid_status[1], (
void*)&var_efficiency),
"ca_set failure");
514 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
519 void DQMHistAnalysisPXDEffModule::terminate()
521 B2DEBUG(1,
"DQMHistAnalysisPXDEff: terminate called");
524 for (
auto& m : mychid_status) SEVCHK(ca_clear_channel(m),
"ca_clear_channel failure");
525 for (
auto& m : mychid_eff) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
526 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");