14 #include <dqm/analysis/modules/DQMHistAnalysisPXDCM.h>
17 #include <vxd/geometry/GeoCache.h>
37 addParam(
"histogramDirectoryName", m_histogramDirectoryName,
"Name of Histogram dir", std::string(
"PXDCM"));
38 addParam(
"PVPrefix", m_pvPrefix,
"PV Prefix", std::string(
"DQM:PXD:CommonMode:"));
39 addParam(
"useEpics", m_useEpics,
"useEpics",
true);
40 addParam(
"minEntries", m_minEntries,
"minimum number of new entries for last time slot", 10000);
42 addParam(
"warnMeanAdhoc", m_warnMeanAdhoc,
"warn level for peak position", 2.0);
43 addParam(
"errorMeanAdhoc", m_errorMeanAdhoc,
"error level for peak position", 3.0);
44 addParam(
"warnOutsideAdhoc", m_warnOutsideAdhoc,
"warn level for outside fraction", 1e-5);
45 addParam(
"errorOutsideAdhoc", m_errorOutsideAdhoc,
"error level for outside fraction", 1e-4);
46 addParam(
"upperLineAdhoc", m_upperLineAdhoc,
"upper threshold and line for outside fraction", 17);
48 addParam(
"warnMeanFull", m_warnMeanFull,
"warn level for peak position", 2.0);
49 addParam(
"errorMeanFull", m_errorMeanFull,
"error level for peak position", 3.0);
50 addParam(
"warnOutsideFull", m_warnOutsideFull,
"warn level for outside fraction", 1e-5);
51 addParam(
"errorOutsideFull", m_errorOutsideFull,
"error level for outside fraction", 1e-4);
52 addParam(
"upperLineFull", m_upperLineFull,
"upper threshold and line for outside fraction", 17);
53 B2DEBUG(99,
"DQMHistAnalysisPXDCM: Constructor done.");
56 DQMHistAnalysisPXDCMModule::~DQMHistAnalysisPXDCMModule()
60 if (ca_current_context()) ca_context_destroy();
65 void DQMHistAnalysisPXDCMModule::initialize()
67 m_monObj = getMonitoringObject(
"pxd");
72 for (
VxdID& aVxdID : sensors) {
74 if (info.getType() != VXD::SensorInfoBase::PXD)
continue;
75 m_PXDModules.push_back(aVxdID);
77 std::sort(m_PXDModules.begin(), m_PXDModules.end());
81 m_cCommonMode =
new TCanvas((m_histogramDirectoryName +
"/c_CommonMode").data());
82 m_cCommonModeDelta =
new TCanvas((m_histogramDirectoryName +
"/c_CommonModeDelta").data());
84 m_hCommonMode =
new TH2D(
"hPXDCommonMode",
"PXD CommonMode; Module; CommonMode", m_PXDModules.size(), 0, m_PXDModules.size(), 63, 0,
86 m_hCommonMode->SetDirectory(0);
87 m_hCommonMode->SetStats(
false);
88 m_hCommonModeDelta =
new TH2D(
"hPXDCommonModeAdhoc",
"PXD CommonMode Adhoc; Module; CommonMode", m_PXDModules.size(), 0,
89 m_PXDModules.size(), 63, 0, 63);
90 m_hCommonModeDelta->SetDirectory(0);
91 m_hCommonModeDelta->SetStats(
false);
92 m_hCommonModeOld =
new TH2D(
"hPXDCommonModeOld",
"PXD CommonMode Old; Module; CommonMode", m_PXDModules.size(), 0,
95 m_hCommonModeOld->SetDirectory(0);
96 m_hCommonModeOld->SetStats(
false);
98 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
99 TString ModuleName = (std::string)m_PXDModules[i];
100 m_hCommonMode->GetXaxis()->SetBinLabel(i + 1, ModuleName);
101 m_hCommonModeDelta->GetXaxis()->SetBinLabel(i + 1, ModuleName);
102 m_hCommonModeOld->GetXaxis()->SetBinLabel(i + 1, ModuleName);
105 m_hCommonMode->Draw(
"colz");
106 m_hCommonModeDelta->Draw(
"colz");
107 m_hCommonModeOld->Draw(
"colz");
109 m_monObj->addCanvas(m_cCommonMode);
112 m_line1 =
new TLine(0, 10, m_PXDModules.size(), 10);
113 m_lineA =
new TLine(0, m_upperLineAdhoc, m_PXDModules.size(), m_upperLineAdhoc);
114 m_lineF =
new TLine(0, m_upperLineFull, m_PXDModules.size(), m_upperLineFull);
115 m_line1->SetHorizontal(
true);
116 m_line1->SetLineColor(3);
117 m_line1->SetLineWidth(3);
118 m_lineA->SetHorizontal(
true);
119 m_lineA->SetLineColor(1);
120 m_lineA->SetLineWidth(3);
121 m_lineF->SetHorizontal(
true);
122 m_lineF->SetLineColor(1);
123 m_lineF->SetLineWidth(3);
128 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
130 SEVCHK(ca_create_channel((m_pvPrefix +
"Outside").data(), NULL, NULL, 10, &mychid[0]),
"ca_create_channel failure");
131 SEVCHK(ca_create_channel((m_pvPrefix +
"Status").data(), NULL, NULL, 10, &mychid[1]),
"ca_create_channel failure");
132 SEVCHK(ca_create_channel((m_pvPrefix +
"CM63").data(), NULL, NULL, 10, &mychid[2]),
"ca_create_channel failure");
133 SEVCHK(ca_create_channel((m_pvPrefix +
"Status_Adhoc").data(), NULL, NULL, 10, &mychid[3]),
"ca_create_channel failure");
135 for (
VxdID& aPXDModule : m_PXDModules) {
136 TString buff = (std::string)aPXDModule;
137 buff.ReplaceAll(
".",
"_");
138 auto& my = mychid_mean[aPXDModule];
139 SEVCHK(ca_create_channel((m_pvPrefix +
"Mean:" + buff).Data(), NULL, NULL, 10, &my),
"ca_create_channel failure");
141 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
144 B2DEBUG(99,
"DQMHistAnalysisPXDCM: initialized.");
147 void DQMHistAnalysisPXDCMModule::beginRun()
149 B2DEBUG(99,
"DQMHistAnalysisPXDCM: beginRun called.");
151 m_cCommonMode->Clear();
152 m_cCommonModeDelta->Clear();
153 m_cCommonMode->SetLogz();
154 m_cCommonModeDelta->SetLogz();
157 m_hCommonMode->Reset();
158 m_hCommonModeDelta->Reset();
159 m_hCommonModeOld->Reset();
162 void DQMHistAnalysisPXDCMModule::event()
164 double all_outside = 0.0, all = 0.0;
166 bool error_full_flag =
false;
167 bool warn_full_flag =
false;
168 bool error_adhoc_flag =
false;
169 bool warn_adhoc_flag =
false;
170 bool anyupdate =
false;
171 if (!m_cCommonMode)
return;
172 m_hCommonMode->Reset();
174 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
175 std::string name =
"PXDDAQCM2_" + (std::string)m_PXDModules[i ];
178 TH1* hh1 = findHist(name);
180 hh1 = findHist(m_histogramDirectoryName, name);
183 double current_full = 0.0;
184 double outside_full = 0.0;
186 auto nevent = hh1->GetBinContent(0);
187 double scale = nevent - m_hCommonModeOld->GetBinContent(i + 1, 0);
188 bool update = scale > m_minEntries ;
190 if (update) m_hCommonModeOld->SetBinContent(i + 1, 0, nevent);
191 if (scale > 0) scale = 1.0 / scale;
193 for (
int bin = 1; bin <= 63; bin++) {
195 v = hh1->GetBinContent(bin);
196 m_hCommonMode->SetBinContent(i + 1, bin, v);
198 if (nevent < m_minEntries) {
199 m_hCommonModeDelta->SetBinContent(i + 1, bin, v * scale);
201 auto old = m_hCommonModeOld->GetBinContent(i + 1, bin);
202 m_hCommonModeDelta->SetBinContent(i + 1, bin, (v - old)*scale);
203 m_hCommonModeOld->SetBinContent(i + 1, bin, v);
209 outside_full += hh1->Integral(m_upperLineFull + 1, 63);
212 all_outside += outside_full;
214 double dhpc = hh1->GetBinContent(64);
216 if (current_full > 1) {
217 error_full_flag |= (outside_full / current_full > m_errorOutsideFull);
218 warn_full_flag |= (outside_full / current_full > m_warnOutsideFull);
222 Double_t mean_adhoc = 0.;
223 Double_t entries_adhoc = 0.;
224 Double_t outside_adhoc = 0.;
227 for (
int cm_y = 0; cm_y < m_upperLineAdhoc; cm_y++) {
228 auto v = m_hCommonModeDelta->GetBinContent(m_hCommonModeDelta->GetBin(i + 1, cm_y + 1));
230 mean_adhoc += v * (cm_y + 1);
233 for (
int cm_y = m_upperLineAdhoc; cm_y < 64; cm_y++) {
234 auto v = m_hCommonModeDelta->GetBinContent(m_hCommonModeDelta->GetBin(i + 1, cm_y + 1));
238 if (entries_adhoc > 0) {
239 mean_adhoc /= entries_adhoc;
241 warn_adhoc_flag |= scale < 1e-3 && (fabs(10.0 - mean_adhoc) > m_warnMeanAdhoc || outside_adhoc > m_warnOutsideAdhoc);
242 error_adhoc_flag |= scale < 1e-3 && (fabs(10.0 - mean_adhoc) > m_errorMeanAdhoc || outside_adhoc > m_errorOutsideAdhoc);
243 m_monObj->setVariable((
"cm_" + (std::string)m_PXDModules[i]).c_str(), mean_adhoc);
246 auto my = mychid_mean[m_PXDModules[i]];
248 if (my) SEVCHK(ca_put(DBR_DOUBLE, my, (
void*)&mean_adhoc),
"ca_set failure");
261 m_cCommonMode->Pad()->SetFillColor(kGray);
265 if (all_outside / all > m_errorOutsideFull || error_full_flag) {
266 m_cCommonMode->Pad()->SetFillColor(kRed);
268 }
else if (all_outside / all > m_warnOutsideFull || warn_full_flag) {
269 m_cCommonMode->Pad()->SetFillColor(kYellow);
271 }
else if (all_outside == 0. ) {
272 m_cCommonMode->Pad()->SetFillColor(kGreen);
275 m_cCommonMode->Pad()->SetFillColor(kWhite);
281 m_hCommonMode->Draw(
"colz");
286 auto tt =
new TLatex(5.5, 3,
"1.3.2 Module is excluded, please ignore");
287 tt->SetTextAngle(90);
288 tt->SetTextAlign(12);
291 m_cCommonMode->Modified();
292 m_cCommonMode->Update();
296 int status_adhoc = 0;
297 m_cCommonModeDelta->cd();
301 m_cCommonModeDelta->Pad()->SetFillColor(kGray);
305 if (error_adhoc_flag) {
306 m_cCommonModeDelta->Pad()->SetFillColor(kRed);
308 }
else if (warn_adhoc_flag) {
309 m_cCommonModeDelta->Pad()->SetFillColor(kYellow);
312 m_cCommonModeDelta->Pad()->SetFillColor(kGreen);
320 if (m_useEpics && anyupdate) SEVCHK(ca_put(DBR_INT, mychid[3], (
void*)&status_adhoc),
"ca_set failure");
322 if (m_hCommonModeDelta) {
323 m_hCommonModeDelta->Draw(
"colz");
328 auto tt =
new TLatex(5.5, 3,
"1.3.2 Module is excluded, please ignore");
329 tt->SetTextAngle(90);
330 tt->SetTextAlign(12);
333 m_cCommonModeDelta->Modified();
334 m_cCommonModeDelta->Update();
339 double data = all > 0 ? (all_outside / all) : 0;
340 double data2 = all > 0 ? (all_cm / all) : 0;
341 SEVCHK(ca_put(DBR_DOUBLE, mychid[0], (
void*)&data),
"ca_set failure");
342 SEVCHK(ca_put(DBR_INT, mychid[1], (
void*)&status),
"ca_set failure");
343 SEVCHK(ca_put(DBR_DOUBLE, mychid[2], (
void*)&data2),
"ca_set failure");
344 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
349 void DQMHistAnalysisPXDCMModule::terminate()
351 B2DEBUG(99,
"DQMHistAnalysisPXDCM: terminate called");
355 for (
auto m : mychid) SEVCHK(ca_clear_channel(m),
"ca_clear_channel failure");
356 for (
auto& m : mychid_mean) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
357 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
The base class for the histogram analysis module.
DQM Histogram Analysis for PXD Common Modes.
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.
Class to uniquely identify a any structure of the PXD and SVD.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.