9#include <cdc/calibration/CDCdEdx/CDCDedxValidationAlgorithm.h>
10#include <cdc/calibration/CDCdEdx/CDCDedxWireGainAlgorithm.h>
12#include <cdc/dbobjects/CDCDedxWireGain.h>
13#include <cdc/dbobjects/CDCDedxCosineCor.h>
14#include <cdc/dbobjects/CDCDedx1DCell.h>
15#include <cdc/dbobjects/CDCDedxRunGain.h>
16#include <cdc/dbobjects/CDCDedxBadWires.h>
17#include <framework/database/IntervalOfValidity.h>
19#include <framework/database/Database.h>
20#include <framework/database/DBStore.h>
21#include <framework/database/Configuration.h>
67 std::vector<std::string> subdirs = {
"run",
"costh",
"mom",
"wire",
"injection",
"oneD"};
68 for (
const auto& dir : subdirs) {
69 gSystem->Exec(Form(
"mkdir -p plots/%s", dir.c_str()));
99 if (cruns == 0) B2INFO(
"start exp " << expRun.first <<
" and run " << expRun.second <<
"");
104 int estart = erStart.first;
105 int rstart = erStart.second;
110 else m_suffix = Form(
"e%d_r%d", estart, rstart);
118 double dedx, costh, p, injtime = 0.0, injring = 1.0;
121 std::vector<double>* dedxhit = 0, *enta = 0;
122 std::vector<int>* layer = 0;
124 ttree->SetBranchAddress(
"dedx", &dedx);
125 ttree->SetBranchAddress(
"p", &p);
126 ttree->SetBranchAddress(
"costh", &costh);
127 ttree->SetBranchAddress(
"charge", &charge);
128 ttree->SetBranchAddress(
"injtime", &injtime);
129 ttree->SetBranchAddress(
"injring", &injring);
130 ttree->SetBranchAddress(
"dedxhit", &dedxhit);
131 ttree->SetBranchAddress(
"entaRS", &enta);
132 ttree->SetBranchAddress(
"layer", &layer);
134 std::vector<double> vtlocaledges;
136 m_tbins = vtlocaledges.size() - 1;
139 std::array<std::array<std::vector<TH1D*>, 2>, 13> hdedx_mom;
140 std::array<std::vector<TH1D*>, 2> hdedx_mom_peaks, hdedx_inj, hdedx_inj_nocor, hdedx_oned;
144 const double momBinW = (4.0 -
m_momMin) / 4;
146 std::string scos[13] = {
"acos",
"cos#theta > 0.0",
"cos#theta < 0.0",
"cos#theta <= -0.8",
147 "cos#theta > -0.8 and cos#theta <= -0.6",
148 "cos#theta > -0.6 and cos#theta <= -0.4",
"cos#theta > -0.4 and cos#theta <= -0.2",
149 "cos#theta > -0.2 and cos#theta <= 0",
"cos#theta > 0 and cos#theta <= 0.2",
150 "cos#theta > 0.2 and cos#theta <= 0.4",
"cos#theta > 0.4 and cos#theta <= 0.6",
151 "cos#theta > 0.6 and cos#theta <= 0.8",
"cos#theta > 0.8"
153 std::string stype[2] = {
"posi",
"elec"};
154 std::string sLayer[2] = {
"IL",
"OL"};
157 for (
int ic = 0; ic < 13; ic++) {
158 for (
int it = 0; it < 2; ++it) {
160 defineHisto(hdedx_mom[ic][it],
"mom", Form(
"%d_%s", ic, stype[it].data()));
165 for (
unsigned int ir = 0; ir < 2; ir++) {
167 hdedx_inj_nocor[ir].resize(
m_tbins);
168 hdedx_mom_peaks[ir].resize(4);
169 hdedx_oned[ir].resize(
m_eaBin);
173 defineHisto(hdedx_mom_peaks[ir],
"mom_peaks", Form(
"%s", stype[ir].data()));
174 defineHisto(hdedx_oned[ir],
"oned", Form(
"%s", sLayer[ir].data()));
178 double icos[3] = {0, -1, -1};
182 for (
int i = 0; i < ttree->GetEntries(); ++i) {
186 if (dedx <= 0 || injtime < 0 || injring < 0)
continue;
189 int binIndex =
static_cast<int>((abs(p) -
m_momMin) / momBinWidth);
193 icos[1] = (costh > 0) ? 1 : 2;
194 icos[2] = int((costh + 1.0) / 0.2) + 3;
195 if (icos[2] < 3) icos[2] = 3;
196 if (icos[2] > 12) icos[2] = 12;
199 chgtype = (charge > 0) ? 0 : 1;
202 if (binIndex >= 0 && binIndex <
m_momBins) {
203 hdedx_mom[icos[0]][chgtype][binIndex]->Fill(dedx);
204 hdedx_mom[icos[1]][chgtype][binIndex]->Fill(dedx);
205 hdedx_mom[icos[2]][chgtype][binIndex]->Fill(dedx);
212 int wr = (injring > 0.5) ? 1 : 0;
214 double timeGain =
m_DBInjectTime->getCorrection(
"mean", injring, injtime);
217 unsigned int tb = htimes->GetXaxis()->FindBin(injtime);
218 tb = std::min(tb,
static_cast<unsigned int>(
m_tbins)) - 1;
221 htimes->Fill(injtime);
222 hdedx_inj[wr][tb]->Fill(dedx);
223 hdedx_inj_nocor[wr][tb]->Fill(dedx * timeGain);
226 int binI =
static_cast<int>((abs(p) -
m_momMin) / momBinW);
227 if (binI >= 0 && binI < 4) {
228 hdedx_mom_peaks[chgtype][binI]->Fill(dedx);
232 for (
unsigned int j = 0; j < dedxhit->size(); ++j) {
233 if (dedxhit->at(j) == 0)
continue;
235 double entaval = enta->at(j);
236 int ibin = std::floor((entaval -
m_eaMin) / eaBW);
237 if (ibin < 0 || ibin >=
m_eaBin)
continue;
239 int mL = (layer->at(j) < 8) ? 0 : 1;
240 hdedx_oned[mL][ibin]->Fill(dedxhit->at(j));
245 for (
int ic = 0; ic < 13; ic++) {
246 for (
int it = 0; it < 2; ++it) {
247 printCanvas(hdedx_mom[ic][it], Form(
"plots/mom/dedx_vs_mom_%d_%s_%s", ic, stype[it].data(),
m_suffix.data()),
"mom");
250 for (
int it = 0; it < 2; ++it) {
252 printCanvas(hdedx_inj_nocor[it], Form(
"plots/injection/dedx_vs_inj_nocor_%s_%s",
m_sring[it].data(),
m_suffix.data()),
"inj");
253 printCanvas(hdedx_oned[it], Form(
"plots/oneD/dedx_vs_1D_%s_%s", sLayer[it].data(),
m_suffix.data()),
"oned");
267 std::vector<int>* wire = 0;
268 ttree->SetBranchAddress(
"wire", &wire);
270 std::vector<double>* dedxhit = 0;
271 ttree->SetBranchAddress(
"dedxhit", &dedxhit);
273 ttree->SetBranchAddress(
"dedx", &dedx);
274 ttree->SetBranchAddress(
"run", &run);
275 ttree->SetBranchAddress(
"charge", &charge);
276 ttree->SetBranchAddress(
"costh", &costh);
278 std::map<int, TH1D*> hdedx_run;
279 std::array<std::vector<TH1D*>, 3> hdedx_cos;
280 std::array<std::vector<TH1D*>, 2> hdedx_cos_peaks;
281 std::vector<TH1D*> hdedxhit(c_nSenseWires);
286 std::string stype[3] = {
"all",
"posi",
"elec"};
288 for (
int it = 0; it < 3; ++it) {
293 for (
int ir = 0; ir < 2; ir++) {
294 hdedx_cos_peaks[ir].resize(4);
295 defineHisto(hdedx_cos_peaks[ir],
"cos_peaks", Form(
"%s", stype[ir + 1].data()));
301 for (
int i = 0; i < ttree->GetEntries(); ++i) {
303 if (dedx <= 0)
continue;
306 if (hdedx_run.find(run) == hdedx_run.end()) {
307 std::string histName = Form(
"hist_dedx_run_%d", run);
308 std::string histTitle = Form(
"dE/dx Histogram for Run %d", run);
313 hdedx_run[run]->Fill(dedx);
316 int binIndex =
static_cast<int>((costh -
m_cosMin) / cosBinWidth);
317 if (binIndex >= 0 && binIndex <
m_cosBins) {
318 hdedx_cos[0][binIndex]->Fill(dedx);
321 hdedx_cos[1][binIndex]->Fill(dedx);
323 hdedx_cos[2][binIndex]->Fill(dedx);
327 for (
unsigned int j = 0; j < wire->size(); ++j) {
328 int jwire = wire->at(j);
329 double jhitdedx = dedxhit->at(j);
330 hdedxhit[jwire]->Fill(jhitdedx);
334 int binI =
static_cast<int>((costh -
m_cosMin) / cosBinW);
335 if (binI >= 0 && binI < 4) {
337 hdedx_cos_peaks[0][binI]->Fill(dedx);
339 hdedx_cos_peaks[1][binI]->Fill(dedx);
344 printCanvas(hdedx_cos[0], Form(
"plots/costh/dedx_vs_cos_all_%s",
m_suffix.data()),
"costh");
345 printCanvas(hdedx_cos[1], Form(
"plots/costh/dedx_vs_cos_positrons_%s",
m_suffix.data()),
"costh");
346 printCanvas(hdedx_cos[2], Form(
"plots/costh/dedx_vs_cos_electrons_%s",
m_suffix.data()),
"costh");
355 double xmin = 0.0, xmax = 0.0;
356 double binWidth = 0.0;
360 }
else if (var ==
"oned") {
362 }
else if (var ==
"costh") {
364 }
else if (var ==
"inj") {
366 }
else if (var ==
"mom_peaks") {
367 xbins = 4; xmin =
m_momMin; xmax = 4.0;
368 }
else if (var ==
"cos_peaks") {
374 if (var ==
"costh" || var ==
"mom" || var ==
"mom_peaks" || var ==
"cos_peaks" || var ==
"oned") {
375 binWidth = (xmax - xmin) / xbins;
378 for (
int ic = 0; ic < xbins; ic++) {
379 std::string title = Form(
"dedxhit-dist, wire:%d", ic);
380 std::string name = Form(
"hdedx_%s_%s_%d",
m_suffix.data(), var.data(), ic);
382 if (var ==
"costh" || var ==
"mom" || var ==
"mom_peaks" || var ==
"cos_peaks" || var ==
"oned") {
383 double min = ic * binWidth + xmin;
384 double max = min + binWidth;
385 title = Form(
"%s: (%0.02f, %0.02f) %s", var.data(), min, max, stype.data());
386 name = Form(
"hdedx_%s_%s_%s_%d",
m_suffix.data(), var.data(), stype.data(), ic);
387 }
else if (var ==
"inj") {
389 title = Form(
"%s, time(%s)", stype.data(), label.data());
390 name = Form(
"h%s_%s_%s_t%d", var.data(),
m_suffix.data(), stype.data(), ic);
393 htemp[ic]->SetTitle(Form(
"%s;dedx;entries", title.data()));
404 }
else if (svar ==
"costh") {
407 B2FATAL(
"wrong input");
409 double binWidth = (xmax - xmin) / xbins;
412 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1200, 1200);
416 std::stringstream psname;
417 psname << Form(
"%s.pdf[", namesfx.data());
418 ctmp->Print(psname.str().c_str());
420 psname << Form(
"%s.pdf", namesfx.data());
423 for (
int i = 0; i < xbins; ++i) {
427 double emean, emeanErr, esigma, esigmaErr;
428 double pmean, pmeanErr, psigma, psigmaErr;
430 fit(htemp[0][i], emean, emeanErr, esigma, esigmaErr);
431 fit(htemp[1][i], pmean, pmeanErr, psigma, psigmaErr);
433 double min = i * binWidth + xmin;
434 double max = min + binWidth;
436 TPaveText pt(0.6, 0.63, 0.85, 0.89,
"NBNDC");
439 pt.AddText(Form(
"#mu_{fit}: %0.03f#pm%0.03f", emean, emeanErr));
440 pt.AddText(Form(
"#sigma_{fit}: %0.03f#pm%0.03f", esigma, esigmaErr));
443 pt.AddText(Form(
"#mu_{fit}: %0.03f#pm%0.03f", pmean, pmeanErr));
444 pt.AddText(Form(
"#sigma_{fit}: %0.03f#pm%0.03f", psigma, psigmaErr));
446 htemp[0][i]->SetStats(0);
447 htemp[1][i]->SetStats(0);
448 htemp[0][i]->SetFillColor(0);
449 htemp[1][i]->SetFillColor(0);
450 htemp[0][i]->SetLineColor(8);
451 htemp[1][i]->SetLineColor(9);
452 htemp[0][i]->SetTitle(Form(
"%s: (%0.02f, %0.02f)", svar.data(), min, max));
453 if (htemp[0][i]->GetEntries() > 0)
454 htemp[0][i]->Scale(1.0 / htemp[0][i]->GetEntries());
455 if (htemp[1][i]->GetEntries() > 0)
456 htemp[1][i]->Scale(1.0 / htemp[1][i]->GetEntries());
458 if (htemp[1][i]->GetMaximum() > htemp[0][i]->GetMaximum())
459 htemp[0][i]->SetMaximum(htemp[1][i]->GetMaximum());
461 htemp[0][i]->DrawCopy(
"HIST");
462 htemp[1][i]->DrawCopy(
"same HIST");
463 pt.DrawClone(
"same");
465 TLegend* lego =
new TLegend(0.15, 0.67, 0.3, 0.8);
466 lego->AddEntry(htemp[0][i],
"e+",
"l");
467 lego->AddEntry(htemp[1][i],
"e-",
"l");
470 if ((i + 1) % 4 == 0 || i == xbins - 1) {
471 ctmp->SetBatch(kTRUE);
472 ctmp->Print(psname.str().c_str());
473 if ((i + 1) % 4 == 0) ctmp->Clear(
"D");
478 psname << Form(
"%s.pdf]", namesfx.data());
479 ctmp->Print(psname.str().c_str());
487 double xmin = 0.0, xmax = 0.0;
491 }
else if (svar ==
"oned") {
493 }
else if (svar ==
"costh") {
495 }
else if (svar ==
"inj") {
497 }
else if (svar ==
"mom_peaks") {
498 xbins = 4; xmin =
m_momMin; xmax = 4.0;
500 B2FATAL(
"wrong input");
504 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1200, 1200);
508 std::stringstream psname;
509 psname << Form(
"%s.pdf[", namesfx.data());
510 ctmp->Print(psname.str().c_str());
512 psname << Form(
"%s.pdf", namesfx.data());
514 std::ofstream outFile;
515 outFile.open(Form(
"%s.txt", namesfx.data()));
519 for (
int i = 0; i < xbins; ++i) {
521 ctmp->cd(i % 16 + 1);
522 TPaveText pt(0.6, 0.73, 0.85, 0.89,
"NBNDC");
525 if (svar ==
"oned") {
526 unsigned int minbin, maxbin;
528 htemp[i]->SetTitle(Form(
"dedxhit-dist, entabin: %d ;%d;%d", i, minbin, maxbin));
532 const double binWidth = (xmax - xmin) / xbins;
533 double binCenter = xmin + (i + 0.5) * binWidth;
535 outFile << binCenter <<
" " << dedxmean << std::endl;
537 double mean, meanErr, sigma, sigmaErr;
538 fit(htemp[i], mean, meanErr, sigma, sigmaErr);
540 if (svar ==
"mom" || svar ==
"costh" || svar ==
"mom_peaks") {
541 const double binWidth = (xmax - xmin) / xbins;
542 double binCenter = xmin + (i + 0.5) * binWidth;
544 outFile << binCenter <<
" " << mean <<
" " << meanErr <<
" " << sigma <<
" " << sigmaErr << std::endl;
547 outFile << i <<
" " << label <<
" " << mean <<
" " << meanErr <<
" " << sigma <<
" " << sigmaErr << std::endl;
550 pt.AddText(Form(
"#mu_{fit}: %0.03f#pm%0.03f", mean, meanErr));
551 pt.AddText(Form(
"#sigma_{fit}: %0.03f#pm%0.03f", sigma, sigmaErr));
553 htemp[i]->SetStats(0);
554 htemp[i]->DrawCopy(
"");
555 pt.DrawClone(
"same");
557 if ((i + 1) % 16 == 0 || ((i + 1) == xbins)) {
558 ctmp->SetBatch(kTRUE);
559 ctmp->Print(psname.str().c_str());
566 psname << Form(
"%s.pdf]", namesfx.data());
567 ctmp->Print(psname.str().c_str());
577 std::string status =
"";
579 if (hist->Integral() > 100)
582 if (status !=
"fitOK") {
583 hist->SetFillColor(kOrange);
584 mean = 0.0, meanErr = 0.0, sigma = 0.0, sigmaErr = 0.0;
586 mean = hist->GetFunction(
"gaus")->GetParameter(1);
587 meanErr = hist->GetFunction(
"gaus")->GetParError(1);
588 sigma = hist->GetFunction(
"gaus")->GetParameter(2);
589 sigmaErr = hist->GetFunction(
"gaus")->GetParError(2);
590 hist->SetFillColor(kYellow);
597 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1200, 1200);
601 std::stringstream psname;
602 psname << Form(
"%s.pdf[", namesfx.data());
603 ctmp->Print(psname.str().c_str());
605 psname << Form(
"%s.pdf", namesfx.data());
607 std::ofstream outFile;
608 outFile.open(Form(
"%s.txt", namesfx.data()));
612 for (
const auto& entry : htemp) {
613 int run = entry.first;
614 TH1D* hist = entry.second;
616 ctmp->cd(irun % 16 + 1);
618 TPaveText pt(0.6, 0.73, 0.85, 0.89,
"NBNDC");
621 double mean, meanErr, sigma, sigmaErr;
622 fit(hist, mean, meanErr, sigma, sigmaErr);
624 outFile << run <<
" " << mean <<
" " << meanErr <<
" " << sigma <<
" " << sigmaErr << std::endl;
626 pt.AddText(Form(
"#mu_{fit}: %0.03f#pm%0.03f", mean, meanErr));
627 pt.AddText(Form(
"#sigma_{fit}: %0.03f#pm%0.03f", sigma, sigmaErr));
631 pt.DrawClone(
"same");
633 if ((irun + 1) % 16 == 0 || irun ==
int(htemp.size() - 1)) {
634 ctmp->SetBatch(kTRUE);
635 ctmp->Print(psname.str().c_str());
641 ctmp->Print(psname.str().c_str());
643 psname << Form(
"%s.pdf]", namesfx.data());
644 ctmp->Print(psname.str().c_str());
654 double histmean = temphist->GetMean();
655 double histrms = temphist->GetRMS();
656 temphist->GetXaxis()->SetRangeUser(histmean - 5.0 * histrms, histmean + 5.0 * histrms);
658 int fs = temphist->Fit(
"gaus",
"Q0");
660 B2INFO(Form(
"\tFit (round 1) for hist (%s) failed (status = %d)", temphist->GetName(), fs));
661 status =
"fitFailed";
664 double mean = temphist->GetFunction(
"gaus")->GetParameter(1);
665 double width = temphist->GetFunction(
"gaus")->GetParameter(2);
666 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
667 fs = temphist->Fit(
"gaus",
"QR",
"", mean -
m_sigmaR * width, mean +
m_sigmaR * width);
669 B2INFO(Form(
"\tFit (round 2) for hist (%s) failed (status = %d)", temphist->GetName(), fs));
670 status =
"fitFailed";
673 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
674 B2INFO(Form(
"\tFit for hist (%s) successful (status = %d)", temphist->GetName(), fs));
683 std::vector<double> vdedx_means;
684 std::vector<double> layermean(c_maxNSenseLayers);
685 std::vector<double> lgmean(c_maxNSenseLayers);
687 std::ofstream outFile, outFileLayer, outFileAvg, outFilebdwire;
688 outFile.open(Form(
"plots/wire/dedx_mean_gwire_%s.txt",
m_suffix.data()));
689 outFilebdwire.open(Form(
"plots/wire/dedx_mean_badwire_%s.txt",
m_suffix.data()));
690 outFileLayer.open(Form(
"plots/wire/dedx_mean_layer_%s.txt",
m_suffix.data()));
691 outFileAvg.open(Form(
"plots/wire/dedx_mean_layer_avg_%s.txt",
m_suffix.data()));
693 int activelayers = 0;
694 double layeravg = 0.0;
702 for (
unsigned int il = 0; il < c_maxNSenseLayers; ++il) {
704 int activewires = 0, goodwires = 0;
708 for (
unsigned int iw = 0; iw < cdcgeo.
nWiresInLayer(il); ++iw) {
711 unsigned int minbin, maxbin;
713 hdedxhit[jwire]->SetTitle(Form(
"dedxhit-dist, wire: %d ;%d;%d", jwire, minbin, maxbin));
716 vdedx_means.push_back(dedxmean);
718 if (Badwire->getBadWireStatus(jwire) == kTRUE)
719 outFilebdwire << jwire <<
" " << dedxmean << std::endl;
721 outFile << jwire <<
" " << dedxmean << std::endl;
723 if (vdedx_means.at(jwire) > 0) {
724 layermean[il] += vdedx_means.at(jwire);
726 if (Badwire->getBadWireStatus(jwire) != kTRUE) {
727 lgmean[il] += vdedx_means.at(jwire);
733 if (activewires > 0) layermean[il] /= activewires;
734 else layermean[il] = 1.0;
736 if (goodwires > 0) lgmean[il] /= goodwires;
737 else lgmean[il] = 1.0;
739 outFileLayer << il <<
" " << layermean[il] <<
" " << lgmean[il] << std::endl;
742 if (il >= 8 && layermean[il] > 0) {
743 layeravg += layermean[il];
749 if (activelayers > 0) layeravg /= activelayers;
750 outFileAvg << layeravg << std::endl;
753 outFilebdwire.close();
754 outFileLayer.close();
760 const std::vector<double>& vdedx_mean)
762 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 900, 900);
765 std::stringstream psname;
766 psname << Form(
"%s.pdf[", namesfx.data());
767 ctmp->Print(psname.str().c_str());
769 psname << Form(
"%s.pdf", namesfx.data());
771 for (
unsigned int ip = 0; ip < c_nwireCDC; ip++) {
772 int minbin = std::stoi(temp[ip]->GetXaxis()->GetTitle());
773 int maxbin = std::stoi(temp[ip]->GetYaxis()->GetTitle());
774 temp[ip]->SetFillColor(kYellow - 9);
775 temp[ip]->SetTitle(Form(
"%s, #mu_{trunc} %0.03f;dedxhit;entries", temp[ip]->GetTitle(), vdedx_mean.at(ip)));
777 ctmp->cd(ip % 16 + 1);
779 temp[ip]->DrawCopy(
"hist");
780 TH1D* hdedxhitC = (TH1D*)temp[ip]->Clone(Form(
"%sC", temp[ip]->GetName()));
781 hdedxhitC->GetXaxis()->SetRange(minbin, maxbin);
782 hdedxhitC->SetFillColor(kAzure + 1);
783 hdedxhitC->DrawCopy(
"same histo");
785 if ((ip + 1) % 16 == 0) {
786 ctmp->SetBatch(kTRUE);
787 ctmp->Print(psname.str().c_str());
796 psname << Form(
"%s.pdf]", namesfx.data());
797 ctmp->Print(psname.str().c_str());
804 for (
int ib = 0; ib < 69; ib++) {
805 fixedges[ib] = ib * 0.5 * 1e3;
806 if (ib > 40 && ib <= 60) fixedges[ib] = fixedges[ib - 1] + 1.0 * 1e3;
807 else if (ib > 60 && ib <= 64) fixedges[ib] = fixedges[ib - 1] + 10.0 * 1e3;
808 else if (ib > 64 && ib <= 65) fixedges[ib] = fixedges[ib - 1] + 420.0 * 1e3;
809 else if (ib > 65 && ib <= 66) fixedges[ib] = fixedges[ib - 1] + 500.0 * 1e3;
810 else if (ib > 66) fixedges[ib] = fixedges[ib - 1] + 2e6;
811 vtlocaledges.push_back(fixedges[ib]);
819 TCanvas cstats(
"cstats",
"cstats", 800, 400);
820 cstats.SetBatch(kTRUE);
826 hestats->SetName(Form(
"hestats_%s",
m_suffix.data()));
827 hestats->SetStats(0);
828 hestats->DrawCopy(
"");
834 htstats->SetName(Form(
"htstats_%s",
m_suffix.data()));
835 htstats->SetStats(0);
836 htstats->DrawCopy(
"");
839 cstats.Print(Form(
"cdcdedx_stats_%s.pdf",
m_suffix.data()));
850 dbConfiguration.overrideGlobalTags();
851 dbConfiguration.setGlobalTags({
"online"});
857 B2FATAL(
"Setting both testing payload and Global Tag or setting no one of them.");
877 std::vector<double> wiregain;
878 std::vector<double> layermean(c_maxNSenseLayers);
881 if (!DBWireGains.
isValid()) B2FATAL(
"Wire gain data are not valid.");
886 for (
unsigned int il = 0; il < c_maxNSenseLayers; ++il) {
891 for (
unsigned int iw = 0; iw < cdcgeo.
nWiresInLayer(il); ++iw) {
894 wiregain.push_back(DBWireGains->getWireGain(jwire));
896 if (wiregain.at(jwire) > 0) {
897 layermean[il] += wiregain.at(jwire);
902 if (activewires > 0) layermean[il] /= activewires;
903 else layermean[il] = 1.0;
907 return { wiregain, layermean };
915 std::vector<double> cosgain, cos;
918 if (!DBCosineCor.
isValid()) B2FATAL(
"Cosine gain data are not valid.");
920 unsigned int nCosBins = DBCosineCor->getSize();
922 for (
unsigned int il = 0; il < nCosBins; ++il) {
923 double costh = -1.0 + (il + 0.5) * 2.0 / nCosBins;
925 cosgain.push_back(DBCosineCor->getMean(il));
926 cos.push_back(costh);
930 return {cosgain, cos};
938 std::vector<double> inner1D, outer1D, Enta;
941 if (!DBOneDCell.
isValid()) B2FATAL(
"OneD cell gain data are not valid.");
943 for (
int i = 0; i < 2; i++) {
945 unsigned int nBins = DBOneDCell->getNBins(i);
946 double binSize = TMath::Pi() / nBins;
948 for (
unsigned int nbin = 0; nbin < nBins; nbin++) {
950 double enta = (-1 * TMath::Pi() / 2.0) + binSize * nbin;
952 Enta.push_back(enta);
953 inner1D.push_back(DBOneDCell->getMean(0, nbin));
955 outer1D.push_back(DBOneDCell->getMean(17, nbin));
959 return {inner1D, outer1D, Enta};
969 if (!RunGain.
isValid()) B2FATAL(
"Run gain data are not valid.");
970 double gain = RunGain->getRunGain();
void bhabhaValidation()
Validate dE/dx using bhabha sample (vs run, cosine)
double m_eaMax
upper edge of entrance angle
double m_momMin
min range of momentum
void resetDatabase()
Clear current DB pointers and state.
void wireGain(std::vector< TH1D * > &hdedxhit)
Validate wire gain data using dE/dx histograms.
void printCanvasdEdx(std::array< std::vector< TH1D * >, 2 > &htemp, std::string namesfx, std::string svar)
Draw dE/dx histograms for momentum and cosine bins.
void printCanvasRun(std::map< int, TH1D * > &htemp, std::string namesfx)
Draw dE/dx per run histogram canvas.
int m_cosBins
bins for cosine
void radeeValidation()
Validate dE/dx using radee sample (vs momentum, injection time)
double m_sigmaR
fit dedx dist in sigma range
void setTextCosmetics(TPaveText pt, Color_t color)
Set text cosmetics for TPaveText.
WireGainData getwiregain(int experiment, int run)
Retrieve wire gain data from DB.
void getExpRunInfo()
function to get extract calibration run/exp
double m_cosMax
max range of cosine
OnedData getonedgain(int experiment, int run)
Retrieve 1D gain data from DB.
double * m_tedges
internal time array (copy of vtlocaledges)
std::string m_GlobalTagName
Global Tag name.
void DatabaseIN(int experiment, int run)
Load database payload for given run.
void defineTimeBins(std::vector< double > &vtlocaledges)
Set bin edges for injection time.
std::array< std::string, 2 > m_sring
injection ring name
CosGainData getcosgain(int experiment, int run)
Retrieve cosine gain data from DB.
void printCanvasWire(std::vector< TH1D * > temp, std::string namesfx, const std::vector< double > &vdedx_mean)
Plot dE/dx vs wire number.
std::string m_testingPayloadName
Testing payload location.
std::string m_suffix
suffix string to separate plots
int m_momBins
bins for momentum
int m_dedxBins
bins for dedx histogram
DBObjPtr< CDCGeometry > m_cdcGeo
Geometry of CDC.
double m_momMax
max range of momentum
CDCDedxValidationAlgorithm()
Constructor: Sets the description, the properties and the parameters of the algorithm.
double getrungain(int experiment, int run)
Retrieve run gain data from DB.
void fitGaussianWRange(TH1D *&temphist, std::string &status)
Perform Gaussian fit with range on a histogram.
double m_cosMin
min range of cosine
void plotEventStats()
Plot summary statistics of selected events.
virtual EResult calibrate() override
Main calibration method.
void printCanvas(std::vector< TH1D * > &htemp, std::string namesfx, std::string svar)
Draw dE/dx histograms across bins.
double m_dedxMax
max range of dedx
DBObjPtr< CDCDedxInjectionTime > m_DBInjectTime
Injection time DB object.
StoreObjPtr< EventMetaData > m_EventMetaData
Event metadata.
double m_dedxMin
min range of dedx
unsigned int m_tbins
internal time bins
void defineHisto(std::vector< TH1D * > &htemp, std::string var, std::string stype)
Define dE/dx histograms for plotting.
std::string getTimeBinLabel(const double &tedges, const int &it)
Get time bin label string.
void fit(TH1D *&hist, double &mean, double &meanErr, double &sigma, double &sigmaErr)
Perform full Gaussian fit and extract parameters.
double m_eaMin
lower edge of entrance angle
A calibration algorithm for CDC dE/dx wire gains.
void getTruncatedBins(TH1D *hdedxhit, unsigned int &binlow, unsigned int &binhigh)
function to get bins of truncation from histogram
double getTruncationMean(TH1D *hdedxhit, int binlow, int binhigh)
function to get mean of truncation from histogram
The Class for CDC Geometry Parameters.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
static void updateDBObjPtrs(const unsigned int event, const int run, const int experiment)
Updates any DBObjPtrs by calling update(event) for DBStore.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing objects in the database.
Singleton class to cache database objects.
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
std::shared_ptr< T > getObjectPtr(const std::string &name, const std::vector< Calibration::ExpRun > &requestedRuns)
Get calibration data object by name and list of runs, the Merge function will be called to generate t...
void reset(bool keepEntries=false)
Invalidate all payloads.
static Database & Instance()
Instance of a singleton Database.
static DBStore & Instance()
Instance of a singleton DBStore.
void updateEvent()
Updates all intra-run dependent objects.
void update()
Updates all objects that are outside their interval of validity.
static void reset(bool keepConfig=false)
Reset the database instance.
Abstract base class for different kinds of events.
Container for cosine gain data.
Container for 1D gain data.
Container for wire gain data.