14 #include <dqm/analysis/modules/DQMHistAnalysisPXDTrackCharge.h>
19 #include <vxd/geometry/GeoCache.h>
22 #include <RooDataHist.h>
23 #include <RooAbsPdf.h>
45 addParam(
"histogramDirectoryName", m_histogramDirectoryName,
"Name of Histogram dir", std::string(
"PXDER"));
46 addParam(
"RangeLow", m_rangeLow,
"Lower border for fit", 20.);
47 addParam(
"RangeHigh", m_rangeHigh,
"High border for fit", 80.);
50 addParam(
"PVPrefix", m_pvPrefix,
"PV Prefix", std::string(
"DQM:PXD:TrackCharge:"));
51 addParam(
"useEpics", m_useEpics,
"Whether to update EPICS PVs.",
false);
52 addParam(
"RefHistoFile", m_refFileName,
"Reference histrogram file name", std::string(
"refHisto.root"));
53 addParam(
"ColorAlert", m_color,
"Whether to show the color alert",
true);
55 B2DEBUG(99,
"DQMHistAnalysisPXDTrackCharge: Constructor done.");
58 DQMHistAnalysisPXDTrackChargeModule::~DQMHistAnalysisPXDTrackChargeModule()
62 if (ca_current_context()) ca_context_destroy();
67 void DQMHistAnalysisPXDTrackChargeModule::initialize()
69 B2DEBUG(99,
"DQMHistAnalysisPXDTrackCharge: initialized.");
72 if (m_refFileName !=
"") {
73 m_refFile =
new TFile(m_refFileName.data());
76 m_monObj = getMonitoringObject(
"pxd");
79 m_rfws =
new RooWorkspace(
"w");
80 m_rfws->factory(
"Landau::landau(x[0,100],ml[20,10,50],sl[5,1,30])");
81 m_rfws->factory(
"Gaussian::gauss(x,mg[0],sg[2,0.1,10])");
82 m_rfws->factory(
"FCONV::lxg(x,landau,gauss)");
84 m_x = m_rfws->var(
"x");
85 m_x->setRange(
"signal", m_rangeLow, m_rangeHigh);
89 for (
VxdID& aVxdID : sensors) {
91 if (info.getType() != VXD::SensorInfoBase::PXD)
continue;
92 m_PXDModules.push_back(aVxdID);
94 std::string name =
"PXD_Track_Cluster_Charge_" + (std::string)aVxdID;
95 std::replace(name.begin(), name.end(),
'.',
'_');
96 m_cChargeMod[aVxdID] =
new TCanvas((m_histogramDirectoryName +
"/c_Fit_" + name).data());
97 if (aVxdID ==
VxdID(
"1.5.1")) {
98 for (
int s = 0; s < 6; s++) {
99 for (
int d = 0; d < 4; d++) {
100 m_cChargeModASIC[aVxdID][s][d] =
new TCanvas((m_histogramDirectoryName +
"/c_Fit_" + name + Form(
"_s%d_d%d", s + 1, d + 1)).data());
103 m_hChargeModASIC2d[aVxdID] =
new TH2F((
"hPXD_TCChargeMPV_" + name).data(),
104 (
"PXD TCCharge MPV " + name +
";Switcher;DCD;MPV").data(),
105 6, 0.5, 6.5, 4, 0.5, 4.5);
106 m_cChargeModASIC2d[aVxdID] =
new TCanvas((m_histogramDirectoryName +
"/c_TCCharge_MPV_" + name).data());
109 std::sort(m_PXDModules.begin(), m_PXDModules.end());
113 m_cTrackedClusters =
new TCanvas((m_histogramDirectoryName +
"/c_TrackedClusters").data());
114 m_hTrackedClusters =
new TH1F(
"hPXDTrackedClusters",
"PXD Tracked Clusters/Event;Module", 40, 0, 40);
115 m_hTrackedClusters->Draw();
116 auto ax = m_hTrackedClusters->GetXaxis();
118 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
119 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
120 TString ModuleName = (std::string)m_PXDModules[i];
121 ax->SetBinLabel(i + 1, ModuleName);
123 }
else B2ERROR(
"no axis");
125 m_cCharge =
new TCanvas((m_histogramDirectoryName +
"/c_TrackCharge").data());
126 m_monObj->addCanvas(m_cCharge);
128 m_gCharge =
new TGraphErrors();
129 m_gCharge->SetName(
"Track_Cluster_Charge");
130 m_gCharge->SetTitle(
"Track Cluster Charge");
133 m_line_up =
new TLine(0, 10, m_PXDModules.size(), 10);
134 m_line_mean =
new TLine(0, 16, m_PXDModules.size(), 16);
135 m_line_low =
new TLine(0, 3, m_PXDModules.size(), 3);
136 m_line_up->SetHorizontal(
true);
137 m_line_up->SetLineColor(kMagenta);
138 m_line_up->SetLineWidth(3);
139 m_line_up->SetLineStyle(7);
140 m_line_mean->SetHorizontal(
true);
141 m_line_mean->SetLineColor(kGreen);
142 m_line_mean->SetLineWidth(3);
143 m_line_mean->SetLineStyle(4);
144 m_line_low->SetHorizontal(
true);
145 m_line_low->SetLineColor(kMagenta);
146 m_line_low->SetLineWidth(3);
147 m_line_low->SetLineStyle(7);
149 m_fMean =
new TF1(
"f_Mean",
"pol0", 0, m_PXDModules.size());
150 m_fMean->SetParameter(0, 50);
151 m_fMean->SetLineColor(kYellow);
152 m_fMean->SetLineWidth(3);
153 m_fMean->SetLineStyle(7);
154 m_fMean->SetNpx(m_PXDModules.size());
155 m_fMean->SetNumberFitPoints(m_PXDModules.size());
159 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
161 SEVCHK(ca_create_channel((m_pvPrefix +
"Mean").data(), NULL, NULL, 10, &mychid[0]),
"ca_create_channel failure");
162 SEVCHK(ca_create_channel((m_pvPrefix +
"Diff").data(), NULL, NULL, 10, &mychid[1]),
"ca_create_channel failure");
163 SEVCHK(ca_create_channel((m_pvPrefix +
"Status").data(), NULL, NULL, 10, &mychid[2]),
"ca_create_channel failure");
164 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
170 void DQMHistAnalysisPXDTrackChargeModule::beginRun()
172 B2DEBUG(99,
"DQMHistAnalysisPXDTrackCharge: beginRun called.");
177 void DQMHistAnalysisPXDTrackChargeModule::event()
179 if (!m_cCharge)
return;
181 gStyle->SetOptStat(0);
182 gStyle->SetStatStyle(1);
183 gStyle->SetOptDate(22);
189 auto model = m_rfws->pdf(
"lxg");
191 auto ml = m_rfws->var(
"ml");
197 m_cTrackedClusters->Clear();
198 m_cTrackedClusters->cd();
199 m_hTrackedClusters->Reset();
201 std::string name =
"Tracked_Clusters";
202 TH1* hh2 = findHist(m_histogramDirectoryName,
"PXD_Tracked_Clusters");
204 auto scale = hh2->GetBinContent(0);
207 for (
int i = 0; i < 64; i++) {
208 auto layer = (((i >> 5) & 0x1) + 1);
209 auto ladder = ((i >> 1) & 0xF);
210 auto sensor = ((i & 0x1) + 1);
215 m_hTrackedClusters->SetBinContent(j, hh2->GetBinContent(i + 1) / scale);
220 m_hTrackedClusters->SetName(name.data());
221 m_hTrackedClusters->SetTitle(
"Tracked Clusters/Event");
222 m_hTrackedClusters->SetFillColor(kWhite);
223 m_hTrackedClusters->SetStats(kFALSE);
224 m_hTrackedClusters->SetLineStyle(1);
225 m_hTrackedClusters->SetLineColor(kBlue);
226 m_hTrackedClusters->Draw(
"hist");
228 TH1* href2 = GetHisto(
"ref/" + m_histogramDirectoryName +
"/" + name);
231 href2->SetLineStyle(3);
232 href2->SetLineColor(kBlack);
233 href2->Draw(
"same,hist");
246 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
247 TCanvas* canvas = m_cChargeMod[m_PXDModules[i]];
248 if (canvas ==
nullptr)
continue;
250 std::string name =
"PXD_Track_Cluster_Charge_" + (std::string)m_PXDModules[i];
251 std::replace(name.begin(), name.end(),
'.',
'_');
256 TH1* hh1 = findHist(m_histogramDirectoryName, name);
259 if (hh1->GetEntries() > 50) {
261 auto hdata =
new RooDataHist(hh1->GetName(), hh1->GetTitle(), *m_x, (
const TH1*) hh1);
262 auto plot = m_x->frame(RooFit::Title(hh1->GetTitle()));
263 model->fitTo(*hdata, RooFit::Range(
"signal"));
265 model->paramOn(plot, RooFit::Format(
"NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.6, 0.9, 0.9));
266 hdata->plotOn(plot, RooFit::LineColor(kBlue));
267 model->plotOn(plot, RooFit::LineColor(kRed), RooFit::Range(
"signal"), RooFit::NormRange(
"signal"));
279 int p = m_gCharge->GetN();
280 m_gCharge->SetPoint(p, i + 0.49, ml->getValV());
281 m_gCharge->SetPointError(p, 0.1, ml->getError());
282 m_monObj->setVariable((
"trackcharge_" + (std::string)m_PXDModules[i]).c_str(), ml->getValV(), ml->getError());
285 TH1* hist2 = GetHisto(
"ref/" + m_histogramDirectoryName +
"/" + name);
289 hist2->SetLineStyle(3);
290 hist2->SetLineColor(kBlack);
305 TH1* h = (TH1*)hist2->Clone();
306 if (abs(hist2->GetEntries()) > 0) h->Scale(hh1->GetEntries() / hist2->GetEntries());
309 h->Draw(
"same,hist");
313 canvas->Pad()->SetFrameFillColor(10);
315 if (hh1->GetEntries() < 100) {
317 canvas->Pad()->SetFillColor(kGray);
319 canvas->Pad()->SetFillColor(kGreen);
322 canvas->Pad()->SetFillColor(kWhite);
329 if (hh1->GetEntries() >= 1000) enough =
true;
334 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
336 VxdID& aVxdID = m_PXDModules[i];
338 if (m_hChargeModASIC2d[aVxdID]) m_hChargeModASIC2d[aVxdID]->Reset();
339 if (m_cChargeModASIC2d[aVxdID]) m_cChargeModASIC2d[aVxdID]->Clear();
341 for (
int s = 1; s <= 6; s++) {
342 for (
int d = 1; d <= 4; d++) {
343 std::string name =
"PXD_Track_Cluster_Charge_" + (std::string)m_PXDModules[i] + Form(
"_sw%d_dcd%d", s, d);
344 std::replace(name.begin(), name.end(),
'.',
'_');
346 if (m_cChargeModASIC[aVxdID][s - 1][d - 1]) {
347 m_cChargeModASIC[aVxdID][s - 1][d - 1]->Clear();
348 m_cChargeModASIC[aVxdID][s - 1][d - 1]->cd();
351 TH1* hh1 = findHist(m_histogramDirectoryName, name);
354 if (hh1->GetEntries() > 50) {
355 auto hdata =
new RooDataHist(hh1->GetName(), hh1->GetTitle(), *m_x, (
const TH1*) hh1);
356 auto plot = m_x->frame(RooFit::Title(hh1->GetTitle()));
357 model->fitTo(*hdata, RooFit::Range(
"signal"));
359 if (m_cChargeModASIC[aVxdID][s - 1][d - 1]) {
360 model->paramOn(plot, RooFit::Format(
"NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.6, 0.9, 0.9));
361 hdata->plotOn(plot, RooFit::LineColor(kBlue));
362 model->plotOn(plot, RooFit::LineColor(kRed), RooFit::Range(
"signal"), RooFit::NormRange(
"signal"));
369 if (m_hChargeModASIC2d[aVxdID]) {
370 if (mpv > 0.0) m_hChargeModASIC2d[aVxdID]->Fill(s, d, mpv);
377 if (m_hChargeModASIC2d[aVxdID] && m_cChargeModASIC2d[aVxdID]) {
378 m_cChargeModASIC2d[aVxdID]->cd();
379 m_hChargeModASIC2d[aVxdID]->Draw(
"colz");
385 m_gCharge->SetMinimum(0);
386 m_gCharge->SetMaximum(70);
387 auto ax = m_gCharge->GetXaxis();
389 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
390 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
391 TString ModuleName = (std::string)m_PXDModules[i];
392 ax->SetBinLabel(i + 1, ModuleName);
394 }
else B2ERROR(
"no axis");
396 m_gCharge->SetLineColor(4);
397 m_gCharge->SetLineWidth(2);
398 m_gCharge->SetMarkerStyle(8);
399 m_gCharge->Draw(
"AP");
408 m_cCharge->Modified();
413 if (m_gCharge && enough) {
415 m_gCharge->Fit(m_fMean,
"R");
416 double mean = m_gCharge->GetMean(2);
417 double maxi = mean + 15;
418 double mini = mean - 15;
419 m_line_up->SetY1(maxi);
420 m_line_up->SetY2(maxi);
421 m_line_mean->SetY1(mean);
422 m_line_mean->SetY2(mean);
423 m_line_low->SetY1(mini);
424 m_line_low->SetY2(mini);
427 diff = m_gCharge->GetRMS(2);
433 m_monObj->setVariable(
"trackcharge", mean, diff);
438 SEVCHK(ca_put(DBR_DOUBLE, mychid[0], (
void*)&data),
"ca_set failure");
439 SEVCHK(ca_put(DBR_DOUBLE, mychid[1], (
void*)&diff),
"ca_set failure");
447 m_cCharge->Pad()->SetFillColor(kGray);
451 if (fabs(data - 30.) > 20. || diff > 12) {
452 m_cCharge->Pad()->SetFillColor(kRed);
454 }
else if (fabs(data - 30) > 15. || diff > 8) {
455 m_cCharge->Pad()->SetFillColor(kYellow);
458 m_cCharge->Pad()->SetFillColor(kGreen);
469 SEVCHK(ca_put(DBR_INT, mychid[2], (
void*)&status),
"ca_set failure");
470 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
476 void DQMHistAnalysisPXDTrackChargeModule::endRun()
478 B2DEBUG(99,
"DQMHistAnalysisPXDTrackCharge : endRun called");
482 void DQMHistAnalysisPXDTrackChargeModule::terminate()
484 B2DEBUG(99,
"DQMHistAnalysisPXDTrackCharge: terminate called");
488 for (
auto m : mychid) SEVCHK(ca_clear_channel(m),
"ca_clear_channel failure");
489 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
492 if (m_refFile)
delete m_refFile;
496 TH1* DQMHistAnalysisPXDTrackChargeModule::GetHisto(TString histoname)
503 B2DEBUG(20,
"findHisto failed " << histoname <<
" not in memfile");
506 if (m_refFile && m_refFile->IsOpen()) {
507 TDirectory* d = m_refFile;
508 TString myl = histoname;
512 while (myl.Tokenize(tok, from,
"/")) {
516 if (myl.Tokenize(dummy, f,
"/")) {
517 auto e = d->GetDirectory(tok);
519 B2DEBUG(20,
"Cd Dir " << tok <<
" from " << d->GetPath());
522 B2DEBUG(20,
"cd failed " << tok <<
" from " << d->GetPath());
528 TObject* obj = d->FindObject(tok);
530 if (obj->IsA()->InheritsFrom(
"TH1")) {
531 B2DEBUG(20,
"Histo " << histoname <<
" found in ref file");
534 B2DEBUG(20,
"Histo " << histoname <<
" found in ref file but wrong type");
538 TIter next(d->GetListOfKeys());
540 while ((key = (TKey*)next())) {
541 TObject* obj2 = key->ReadObj() ;
542 if (obj2->InheritsFrom(
"TH1")) {
543 if (obj2->GetName() == tok) {
545 B2DEBUG(20,
"Histo " << histoname <<
" found as key -> readobj");
550 if (hh1 == NULL) B2DEBUG(20,
"Histo " << histoname <<
" NOT found in ref file " << tok);
555 B2DEBUG(20,
"Histo " << histoname <<
" not in memfile or ref file");
557 TDirectory* d = gROOT;
558 TString myl = histoname;
561 while (myl.Tokenize(tok, from,
"/")) {
565 if (myl.Tokenize(dummy, f,
"/")) {
566 auto e = d->GetDirectory(tok);
568 B2DEBUG(20,
"Cd Dir " << tok);
570 }
else B2DEBUG(20,
"cd failed " << tok);
576 TObject* obj = d->FindObject(tok);
578 if (obj->IsA()->InheritsFrom(
"TH1")) {
579 B2DEBUG(20,
"Histo " << histoname <<
" found in mem");
583 B2DEBUG(20,
"Histo " << histoname <<
" NOT found in mem");
589 B2DEBUG(20,
"Histo " << histoname <<
" not found");
The base class for the histogram analysis module.
DQM Histogram Analysis for PXD Cluster Charge.
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.
static GeoCache & getInstance()
Return a reference to the singleton instance.
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.