10 #include <dqm/analysis/modules/DQMHistAnalysisPXDCM.h>
13 #include <vxd/geometry/GeoCache.h>
33 addParam(
"histogramDirectoryName", m_histogramDirectoryName,
"Name of Histogram dir", std::string(
"PXDCM"));
34 addParam(
"PVPrefix", m_pvPrefix,
"PV Prefix", std::string(
"DQM:PXD:CommonMode:"));
35 addParam(
"useEpics", m_useEpics,
"useEpics",
true);
36 addParam(
"minEntries", m_minEntries,
"minimum number of new entries for last time slot", 10000);
38 addParam(
"warnMeanAdhoc", m_warnMeanAdhoc,
"warn level for peak position", 2.0);
39 addParam(
"errorMeanAdhoc", m_errorMeanAdhoc,
"error level for peak position", 3.0);
40 addParam(
"warnOutsideAdhoc", m_warnOutsideAdhoc,
"warn level for outside fraction", 1e-5);
41 addParam(
"errorOutsideAdhoc", m_errorOutsideAdhoc,
"error level for outside fraction", 1e-4);
42 addParam(
"upperLineAdhoc", m_upperLineAdhoc,
"upper threshold and line for outside fraction", 17);
44 addParam(
"warnMeanFull", m_warnMeanFull,
"warn level for peak position", 2.0);
45 addParam(
"errorMeanFull", m_errorMeanFull,
"error level for peak position", 3.0);
46 addParam(
"warnOutsideFull", m_warnOutsideFull,
"warn level for outside fraction", 1e-5);
47 addParam(
"errorOutsideFull", m_errorOutsideFull,
"error level for outside fraction", 1e-4);
48 addParam(
"upperLineFull", m_upperLineFull,
"upper threshold and line for outside fraction", 17);
49 B2DEBUG(99,
"DQMHistAnalysisPXDCM: Constructor done.");
52 DQMHistAnalysisPXDCMModule::~DQMHistAnalysisPXDCMModule()
56 if (ca_current_context()) ca_context_destroy();
61 void DQMHistAnalysisPXDCMModule::initialize()
63 m_monObj = getMonitoringObject(
"pxd");
68 for (
VxdID& aVxdID : sensors) {
70 if (info.getType() != VXD::SensorInfoBase::PXD)
continue;
71 m_PXDModules.push_back(aVxdID);
73 std::sort(m_PXDModules.begin(), m_PXDModules.end());
77 m_cCommonMode =
new TCanvas((m_histogramDirectoryName +
"/c_CommonMode").data());
78 m_cCommonModeDelta =
new TCanvas((m_histogramDirectoryName +
"/c_CommonModeDelta").data());
80 m_hCommonMode =
new TH2D(
"hPXDCommonMode",
"PXD CommonMode; Module; CommonMode", m_PXDModules.size(), 0, m_PXDModules.size(), 63, 0,
82 m_hCommonMode->SetDirectory(0);
83 m_hCommonMode->SetStats(
false);
84 m_hCommonModeDelta =
new TH2D(
"hPXDCommonModeAdhoc",
"PXD CommonMode Adhoc; Module; CommonMode", m_PXDModules.size(), 0,
85 m_PXDModules.size(), 63, 0, 63);
86 m_hCommonModeDelta->SetDirectory(0);
87 m_hCommonModeDelta->SetStats(
false);
88 m_hCommonModeOld =
new TH2D(
"hPXDCommonModeOld",
"PXD CommonMode Old; Module; CommonMode", m_PXDModules.size(), 0,
91 m_hCommonModeOld->SetDirectory(0);
92 m_hCommonModeOld->SetStats(
false);
94 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
95 TString ModuleName = (std::string)m_PXDModules[i];
96 m_hCommonMode->GetXaxis()->SetBinLabel(i + 1, ModuleName);
97 m_hCommonModeDelta->GetXaxis()->SetBinLabel(i + 1, ModuleName);
98 m_hCommonModeOld->GetXaxis()->SetBinLabel(i + 1, ModuleName);
101 m_hCommonMode->Draw(
"colz");
102 m_hCommonModeDelta->Draw(
"colz");
103 m_hCommonModeOld->Draw(
"colz");
105 m_monObj->addCanvas(m_cCommonMode);
108 m_line1 =
new TLine(0, 10, m_PXDModules.size(), 10);
109 m_lineA =
new TLine(0, m_upperLineAdhoc, m_PXDModules.size(), m_upperLineAdhoc);
110 m_lineF =
new TLine(0, m_upperLineFull, m_PXDModules.size(), m_upperLineFull);
111 m_line1->SetHorizontal(
true);
112 m_line1->SetLineColor(3);
113 m_line1->SetLineWidth(3);
114 m_lineA->SetHorizontal(
true);
115 m_lineA->SetLineColor(1);
116 m_lineA->SetLineWidth(3);
117 m_lineF->SetHorizontal(
true);
118 m_lineF->SetLineColor(1);
119 m_lineF->SetLineWidth(3);
124 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
126 SEVCHK(ca_create_channel((m_pvPrefix +
"Outside").data(), NULL, NULL, 10, &mychid[0]),
"ca_create_channel failure");
127 SEVCHK(ca_create_channel((m_pvPrefix +
"Status").data(), NULL, NULL, 10, &mychid[1]),
"ca_create_channel failure");
128 SEVCHK(ca_create_channel((m_pvPrefix +
"CM63").data(), NULL, NULL, 10, &mychid[2]),
"ca_create_channel failure");
129 SEVCHK(ca_create_channel((m_pvPrefix +
"Status_Adhoc").data(), NULL, NULL, 10, &mychid[3]),
"ca_create_channel failure");
131 for (
VxdID& aPXDModule : m_PXDModules) {
132 TString buff = (std::string)aPXDModule;
133 buff.ReplaceAll(
".",
"_");
134 auto& my = mychid_mean[aPXDModule];
135 SEVCHK(ca_create_channel((m_pvPrefix +
"Mean:" + buff).Data(), NULL, NULL, 10, &my),
"ca_create_channel failure");
137 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
140 B2DEBUG(99,
"DQMHistAnalysisPXDCM: initialized.");
143 void DQMHistAnalysisPXDCMModule::beginRun()
145 B2DEBUG(99,
"DQMHistAnalysisPXDCM: beginRun called.");
147 m_cCommonMode->Clear();
148 m_cCommonModeDelta->Clear();
149 m_cCommonMode->SetLogz();
150 m_cCommonModeDelta->SetLogz();
153 m_hCommonMode->Reset();
154 m_hCommonModeDelta->Reset();
155 m_hCommonModeOld->Reset();
158 void DQMHistAnalysisPXDCMModule::event()
160 double all_outside = 0.0, all = 0.0;
162 bool error_full_flag =
false;
163 bool warn_full_flag =
false;
164 bool error_adhoc_flag =
false;
165 bool warn_adhoc_flag =
false;
166 bool anyupdate =
false;
167 if (!m_cCommonMode)
return;
168 m_hCommonMode->Reset();
170 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
171 std::string name =
"PXDDAQCM2_" + (std::string)m_PXDModules[i ];
174 TH1* hh1 = findHist(name);
176 hh1 = findHist(m_histogramDirectoryName, name);
179 double current_full = 0.0;
180 double outside_full = 0.0;
182 auto nevent = hh1->GetBinContent(0);
183 double scale = nevent - m_hCommonModeOld->GetBinContent(i + 1, 0);
184 bool update = scale > m_minEntries ;
186 if (update) m_hCommonModeOld->SetBinContent(i + 1, 0, nevent);
187 if (scale > 0) scale = 1.0 / scale;
189 for (
int bin = 1; bin <= 63; bin++) {
191 v = hh1->GetBinContent(bin);
192 m_hCommonMode->SetBinContent(i + 1, bin, v);
194 if (nevent < m_minEntries) {
195 m_hCommonModeDelta->SetBinContent(i + 1, bin, v * scale);
197 auto old = m_hCommonModeOld->GetBinContent(i + 1, bin);
198 m_hCommonModeDelta->SetBinContent(i + 1, bin, (v - old)*scale);
199 m_hCommonModeOld->SetBinContent(i + 1, bin, v);
205 outside_full += hh1->Integral(m_upperLineFull + 1, 63);
208 all_outside += outside_full;
210 double dhpc = hh1->GetBinContent(64);
212 if (current_full > 1) {
213 error_full_flag |= (outside_full / current_full > m_errorOutsideFull);
214 warn_full_flag |= (outside_full / current_full > m_warnOutsideFull);
218 Double_t mean_adhoc = 0.;
219 Double_t entries_adhoc = 0.;
220 Double_t outside_adhoc = 0.;
223 for (
int cm_y = 0; cm_y < m_upperLineAdhoc; cm_y++) {
224 auto v = m_hCommonModeDelta->GetBinContent(m_hCommonModeDelta->GetBin(i + 1, cm_y + 1));
226 mean_adhoc += v * (cm_y + 1);
229 for (
int cm_y = m_upperLineAdhoc; cm_y < 64; cm_y++) {
230 auto v = m_hCommonModeDelta->GetBinContent(m_hCommonModeDelta->GetBin(i + 1, cm_y + 1));
234 if (entries_adhoc > 0) {
235 mean_adhoc /= entries_adhoc;
237 warn_adhoc_flag |= scale < 1e-3 && (fabs(10.0 - mean_adhoc) > m_warnMeanAdhoc || outside_adhoc > m_warnOutsideAdhoc);
238 error_adhoc_flag |= scale < 1e-3 && (fabs(10.0 - mean_adhoc) > m_errorMeanAdhoc || outside_adhoc > m_errorOutsideAdhoc);
239 m_monObj->setVariable((
"cm_" + (std::string)m_PXDModules[i]).c_str(), mean_adhoc);
242 auto my = mychid_mean[m_PXDModules[i]];
244 if (my) SEVCHK(ca_put(DBR_DOUBLE, my, (
void*)&mean_adhoc),
"ca_set failure");
257 m_cCommonMode->Pad()->SetFillColor(kGray);
261 if (all_outside / all > m_errorOutsideFull || error_full_flag) {
262 m_cCommonMode->Pad()->SetFillColor(kRed);
264 }
else if (all_outside / all > m_warnOutsideFull || warn_full_flag) {
265 m_cCommonMode->Pad()->SetFillColor(kYellow);
267 }
else if (all_outside == 0. ) {
268 m_cCommonMode->Pad()->SetFillColor(kGreen);
271 m_cCommonMode->Pad()->SetFillColor(kWhite);
277 m_hCommonMode->Draw(
"colz");
282 auto tt =
new TLatex(5.5, 3,
"1.3.2 Module is excluded, please ignore");
283 tt->SetTextAngle(90);
284 tt->SetTextAlign(12);
287 m_cCommonMode->Modified();
288 m_cCommonMode->Update();
292 int status_adhoc = 0;
293 m_cCommonModeDelta->cd();
297 m_cCommonModeDelta->Pad()->SetFillColor(kGray);
301 if (error_adhoc_flag) {
302 m_cCommonModeDelta->Pad()->SetFillColor(kRed);
304 }
else if (warn_adhoc_flag) {
305 m_cCommonModeDelta->Pad()->SetFillColor(kYellow);
308 m_cCommonModeDelta->Pad()->SetFillColor(kGreen);
316 if (m_useEpics && anyupdate) SEVCHK(ca_put(DBR_INT, mychid[3], (
void*)&status_adhoc),
"ca_set failure");
318 if (m_hCommonModeDelta) {
319 m_hCommonModeDelta->Draw(
"colz");
324 auto tt =
new TLatex(5.5, 3,
"1.3.2 Module is excluded, please ignore");
325 tt->SetTextAngle(90);
326 tt->SetTextAlign(12);
329 m_cCommonModeDelta->Modified();
330 m_cCommonModeDelta->Update();
335 double data = all > 0 ? (all_outside / all) : 0;
336 double data2 = all > 0 ? (all_cm / all) : 0;
337 SEVCHK(ca_put(DBR_DOUBLE, mychid[0], (
void*)&data),
"ca_set failure");
338 SEVCHK(ca_put(DBR_INT, mychid[1], (
void*)&status),
"ca_set failure");
339 SEVCHK(ca_put(DBR_DOUBLE, mychid[2], (
void*)&data2),
"ca_set failure");
340 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
345 void DQMHistAnalysisPXDCMModule::terminate()
347 B2DEBUG(99,
"DQMHistAnalysisPXDCM: terminate called");
351 for (
auto m : mychid) SEVCHK(ca_clear_channel(m),
"ca_clear_channel failure");
352 for (
auto& m : mychid_mean) SEVCHK(ca_clear_channel(m.second),
"ca_clear_channel failure");
353 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");