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,
"useEpics",
true);
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");
236 auto tt =
new TLatex(5.5, 0,
" 1.3.2 Module is excluded, please ignore");
237 tt->SetTextAngle(90);
238 tt->SetTextAlign(12);
245 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
246 TCanvas* canvas = m_cChargeMod[m_PXDModules[i]];
247 if (canvas ==
nullptr)
continue;
249 std::string name =
"PXD_Track_Cluster_Charge_" + (std::string)m_PXDModules[i];
250 std::replace(name.begin(), name.end(),
'.',
'_');
255 TH1* hh1 = findHist(m_histogramDirectoryName, name);
258 if (hh1->GetEntries() > 50) {
260 auto hdata =
new RooDataHist(hh1->GetName(), hh1->GetTitle(), *m_x, (
const TH1*) hh1);
261 auto plot = m_x->frame(RooFit::Title(hh1->GetTitle()));
262 model->fitTo(*hdata, RooFit::Range(
"signal"));
264 model->paramOn(plot, RooFit::Format(
"NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.6, 0.9, 0.9));
265 hdata->plotOn(plot, RooFit::LineColor(kBlue));
266 model->plotOn(plot, RooFit::LineColor(kRed), RooFit::Range(
"signal"), RooFit::NormRange(
"signal"));
278 int p = m_gCharge->GetN();
279 m_gCharge->SetPoint(p, i + 0.49, ml->getValV());
280 m_gCharge->SetPointError(p, 0.1, ml->getError());
281 m_monObj->setVariable((
"trackcharge_" + (std::string)m_PXDModules[i]).c_str(), ml->getValV(), ml->getError());
284 TH1* hist2 = GetHisto(
"ref/" + m_histogramDirectoryName +
"/" + name);
288 hist2->SetLineStyle(3);
289 hist2->SetLineColor(kBlack);
304 TH1* h = (TH1*)hist2->Clone();
305 if (abs(hist2->GetEntries()) > 0) h->Scale(hh1->GetEntries() / hist2->GetEntries());
308 h->Draw(
"same,hist");
312 canvas->Pad()->SetFrameFillColor(10);
314 if (hh1->GetEntries() < 100) {
316 canvas->Pad()->SetFillColor(kGray);
318 canvas->Pad()->SetFillColor(kGreen);
321 canvas->Pad()->SetFillColor(kWhite);
328 if (hh1->GetEntries() >= 1000) enough =
true;
333 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
335 VxdID& aVxdID = m_PXDModules[i];
337 if (m_hChargeModASIC2d[aVxdID]) m_hChargeModASIC2d[aVxdID]->Reset();
338 if (m_cChargeModASIC2d[aVxdID]) m_cChargeModASIC2d[aVxdID]->Clear();
340 for (
int s = 1; s <= 6; s++) {
341 for (
int d = 1; d <= 4; d++) {
342 std::string name =
"PXD_Track_Cluster_Charge_" + (std::string)m_PXDModules[i] + Form(
"_sw%d_dcd%d", s, d);
343 std::replace(name.begin(), name.end(),
'.',
'_');
345 if (m_cChargeModASIC[aVxdID][s - 1][d - 1]) {
346 m_cChargeModASIC[aVxdID][s - 1][d - 1]->Clear();
347 m_cChargeModASIC[aVxdID][s - 1][d - 1]->cd();
350 TH1* hh1 = findHist(m_histogramDirectoryName, name);
353 if (hh1->GetEntries() > 50) {
354 auto hdata =
new RooDataHist(hh1->GetName(), hh1->GetTitle(), *m_x, (
const TH1*) hh1);
355 auto plot = m_x->frame(RooFit::Title(hh1->GetTitle()));
356 model->fitTo(*hdata, RooFit::Range(
"signal"));
358 if (m_cChargeModASIC[aVxdID][s - 1][d - 1]) {
359 model->paramOn(plot, RooFit::Format(
"NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.6, 0.9, 0.9));
360 hdata->plotOn(plot, RooFit::LineColor(kBlue));
361 model->plotOn(plot, RooFit::LineColor(kRed), RooFit::Range(
"signal"), RooFit::NormRange(
"signal"));
368 if (m_hChargeModASIC2d[aVxdID]) {
369 if (mpv > 0.0) m_hChargeModASIC2d[aVxdID]->Fill(s, d, mpv);
376 if (m_hChargeModASIC2d[aVxdID] && m_cChargeModASIC2d[aVxdID]) {
377 m_cChargeModASIC2d[aVxdID]->cd();
378 m_hChargeModASIC2d[aVxdID]->Draw(
"colz");
384 m_gCharge->SetMinimum(0);
385 m_gCharge->SetMaximum(70);
386 auto ax = m_gCharge->GetXaxis();
388 ax->Set(m_PXDModules.size(), 0, m_PXDModules.size());
389 for (
unsigned int i = 0; i < m_PXDModules.size(); i++) {
390 TString ModuleName = (std::string)m_PXDModules[i];
391 ax->SetBinLabel(i + 1, ModuleName);
393 }
else B2ERROR(
"no axis");
395 m_gCharge->SetLineColor(4);
396 m_gCharge->SetLineWidth(2);
397 m_gCharge->SetMarkerStyle(8);
398 m_gCharge->Draw(
"AP");
400 auto tt =
new TLatex(5.5, 0,
" 1.3.2 Module is excluded, please ignore");
401 tt->SetTextAngle(90);
402 tt->SetTextAlign(12);
406 m_cCharge->Modified();
411 if (m_gCharge && enough) {
413 m_gCharge->Fit(m_fMean,
"R");
414 double mean = m_gCharge->GetMean(2);
415 double maxi = mean + 15;
416 double mini = mean - 15;
417 m_line_up->SetY1(maxi);
418 m_line_up->SetY2(maxi);
419 m_line_mean->SetY1(mean);
420 m_line_mean->SetY2(mean);
421 m_line_low->SetY1(mini);
422 m_line_low->SetY2(mini);
425 diff = m_gCharge->GetRMS(2);
431 m_monObj->setVariable(
"trackcharge", mean, diff);
436 SEVCHK(ca_put(DBR_DOUBLE, mychid[0], (
void*)&data),
"ca_set failure");
437 SEVCHK(ca_put(DBR_DOUBLE, mychid[1], (
void*)&diff),
"ca_set failure");
445 m_cCharge->Pad()->SetFillColor(kGray);
449 if (fabs(data - 30.) > 20. || diff > 12) {
450 m_cCharge->Pad()->SetFillColor(kRed);
452 }
else if (fabs(data - 30) > 15. || diff > 8) {
453 m_cCharge->Pad()->SetFillColor(kYellow);
456 m_cCharge->Pad()->SetFillColor(kGreen);
467 SEVCHK(ca_put(DBR_INT, mychid[2], (
void*)&status),
"ca_set failure");
468 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
474 void DQMHistAnalysisPXDTrackChargeModule::endRun()
476 B2DEBUG(99,
"DQMHistAnalysisPXDTrackCharge : endRun called");
480 void DQMHistAnalysisPXDTrackChargeModule::terminate()
482 B2DEBUG(99,
"DQMHistAnalysisPXDTrackCharge: terminate called");
486 for (
auto m : mychid) SEVCHK(ca_clear_channel(m),
"ca_clear_channel failure");
487 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
490 if (m_refFile)
delete m_refFile;
494 TH1* DQMHistAnalysisPXDTrackChargeModule::GetHisto(TString histoname)
501 B2DEBUG(20,
"findHisto failed " << histoname <<
" not in memfile");
504 if (m_refFile && m_refFile->IsOpen()) {
505 TDirectory* d = m_refFile;
506 TString myl = histoname;
510 while (myl.Tokenize(tok, from,
"/")) {
514 if (myl.Tokenize(dummy, f,
"/")) {
515 auto e = d->GetDirectory(tok);
517 B2DEBUG(20,
"Cd Dir " << tok <<
" from " << d->GetPath());
520 B2DEBUG(20,
"cd failed " << tok <<
" from " << d->GetPath());
526 TObject* obj = d->FindObject(tok);
528 if (obj->IsA()->InheritsFrom(
"TH1")) {
529 B2DEBUG(20,
"Histo " << histoname <<
" found in ref file");
532 B2DEBUG(20,
"Histo " << histoname <<
" found in ref file but wrong type");
536 TIter next(d->GetListOfKeys());
538 while ((key = (TKey*)next())) {
539 TObject* obj2 = key->ReadObj() ;
540 if (obj2->InheritsFrom(
"TH1")) {
541 if (obj2->GetName() == tok) {
543 B2DEBUG(20,
"Histo " << histoname <<
" found as key -> readobj");
548 if (hh1 == NULL) B2DEBUG(20,
"Histo " << histoname <<
" NOT found in ref file " << tok);
553 B2DEBUG(20,
"Histo " << histoname <<
" not in memfile or ref file");
555 TDirectory* d = gROOT;
556 TString myl = histoname;
559 while (myl.Tokenize(tok, from,
"/")) {
563 if (myl.Tokenize(dummy, f,
"/")) {
564 auto e = d->GetDirectory(tok);
566 B2DEBUG(20,
"Cd Dir " << tok);
568 }
else B2DEBUG(20,
"cd failed " << tok);
574 TObject* obj = d->FindObject(tok);
576 if (obj->IsA()->InheritsFrom(
"TH1")) {
577 B2DEBUG(20,
"Histo " << histoname <<
" found in mem");
581 B2DEBUG(20,
"Histo " << histoname <<
" NOT found in mem");
587 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.