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);
138 std::array<std::array<std::vector<TH1D*>, 2>, 13> hdedx_mom;
139 std::array<std::vector<TH1D*>, 2> hdedx_mom_peaks, hdedx_inj, hdedx_inj_nocor;
140 std::array<std::vector<TH1D*>, 3> hdedx_oned;
145 const double momBinW = (4.0 -
m_momMin) / 4;
147 std::string scos[13] = {
"acos",
"cos#theta > 0.0",
"cos#theta < 0.0",
"cos#theta <= -0.8",
148 "cos#theta > -0.8 and cos#theta <= -0.6",
149 "cos#theta > -0.6 and cos#theta <= -0.4",
"cos#theta > -0.4 and cos#theta <= -0.2",
150 "cos#theta > -0.2 and cos#theta <= 0",
"cos#theta > 0 and cos#theta <= 0.2",
151 "cos#theta > 0.2 and cos#theta <= 0.4",
"cos#theta > 0.4 and cos#theta <= 0.6",
152 "cos#theta > 0.6 and cos#theta <= 0.8",
"cos#theta > 0.8"
154 std::string stype[2] = {
"posi",
"elec"};
155 std::string sLayer[3] = {
"SL0",
"SL1",
"SL2-8"};
158 for (
int ic = 0; ic < 13; ic++) {
159 for (
int it = 0; it < 2; ++it) {
161 defineHisto(hdedx_mom[ic][it],
"mom", Form(
"%d_%s", ic, stype[it].data()));
166 for (
unsigned int ir = 0; ir < 2; ir++) {
168 hdedx_inj_nocor[ir].resize(
m_tbins);
169 hdedx_mom_peaks[ir].resize(4);
173 defineHisto(hdedx_mom_peaks[ir],
"mom_peaks", Form(
"%s", stype[ir].data()));
177 for (
unsigned int ir = 0; ir < 3; ir++) {
178 hdedx_oned[ir].resize(
m_eaBin);
179 defineHisto(hdedx_oned[ir],
"oned", Form(
"%s", sLayer[ir].data()));
183 double icos[3] = {0, -1, -1};
187 for (
int i = 0; i < ttree->GetEntries(); ++i) {
191 if (dedx <= 0 || injtime < 0 || injring < 0)
continue;
194 int binIndex =
static_cast<int>((abs(p) -
m_momMin) / momBinWidth);
198 icos[1] = (costh > 0) ? 1 : 2;
199 icos[2] = int((costh + 1.0) / 0.2) + 3;
200 if (icos[2] < 3) icos[2] = 3;
201 if (icos[2] > 12) icos[2] = 12;
204 chgtype = (charge > 0) ? 0 : 1;
207 if (binIndex >= 0 && binIndex <
m_momBins) {
208 hdedx_mom[icos[0]][chgtype][binIndex]->Fill(dedx);
209 hdedx_mom[icos[1]][chgtype][binIndex]->Fill(dedx);
210 hdedx_mom[icos[2]][chgtype][binIndex]->Fill(dedx);
217 int wr = (injring > 0.5) ? 1 : 0;
219 double timeGain =
m_DBInjectTime->getCorrection(
"mean", injring, injtime);
222 unsigned int tb = htimes->GetXaxis()->FindBin(injtime);
223 tb = std::min(tb,
static_cast<unsigned int>(
m_tbins)) - 1;
226 htimes->Fill(injtime);
227 hdedx_inj[wr][tb]->Fill(dedx);
228 hdedx_inj_nocor[wr][tb]->Fill(dedx * timeGain);
231 int binI =
static_cast<int>((abs(p) -
m_momMin) / momBinW);
232 if (binI >= 0 && binI < 4) {
233 hdedx_mom_peaks[chgtype][binI]->Fill(dedx);
237 for (
unsigned int j = 0; j < dedxhit->size(); ++j) {
238 if (dedxhit->at(j) == 0)
continue;
240 double entaval = enta->at(j);
241 int ibin = std::floor((entaval -
m_eaMin) / eaBW);
242 if (ibin < 0 || ibin >=
m_eaBin)
continue;
244 int lay = layer->at(j);
245 int mL = (lay < 8) ? 0 : ((lay < 14) ? 1 : 2);
246 hdedx_oned[mL][ibin]->Fill(dedxhit->at(j));
251 for (
int ic = 0; ic < 13; ic++) {
252 for (
int it = 0; it < 2; ++it) {
253 printCanvas(hdedx_mom[ic][it], Form(
"plots/mom/dedx_vs_mom_%d_%s_%s", ic, stype[it].data(),
m_suffix.data()),
"mom");
256 for (
int it = 0; it < 2; ++it) {
258 printCanvas(hdedx_inj_nocor[it], Form(
"plots/injection/dedx_vs_inj_nocor_%s_%s",
m_sring[it].data(),
m_suffix.data()),
"inj");
260 for (
int it = 0; it < 3; ++it)
261 printCanvas(hdedx_oned[it], Form(
"plots/oneD/dedx_vs_1D_%s_%s", sLayer[it].data(),
m_suffix.data()),
"oned");
274 std::vector<int>* wire = 0;
275 ttree->SetBranchAddress(
"wire", &wire);
277 std::vector<double>* dedxhit = 0;
278 ttree->SetBranchAddress(
"dedxhit", &dedxhit);
280 ttree->SetBranchAddress(
"dedx", &dedx);
281 ttree->SetBranchAddress(
"run", &run);
282 ttree->SetBranchAddress(
"charge", &charge);
283 ttree->SetBranchAddress(
"costh", &costh);
285 std::map<int, TH1D*> hdedx_run;
286 std::array<std::vector<TH1D*>, 3> hdedx_cos;
287 std::array<std::vector<TH1D*>, 2> hdedx_cos_peaks;
288 std::vector<TH1D*> hdedxhit(c_nSenseWires);
293 std::string stype[3] = {
"all",
"posi",
"elec"};
295 for (
int it = 0; it < 3; ++it) {
300 for (
int ir = 0; ir < 2; ir++) {
301 hdedx_cos_peaks[ir].resize(4);
302 defineHisto(hdedx_cos_peaks[ir],
"cos_peaks", Form(
"%s", stype[ir + 1].data()));
308 for (
int i = 0; i < ttree->GetEntries(); ++i) {
310 if (dedx <= 0)
continue;
313 if (hdedx_run.find(run) == hdedx_run.end()) {
314 std::string histName = Form(
"hist_dedx_run_%d", run);
315 std::string histTitle = Form(
"dE/dx Histogram for Run %d", run);
320 hdedx_run[run]->Fill(dedx);
323 int binIndex =
static_cast<int>((costh -
m_cosMin) / cosBinWidth);
324 if (binIndex >= 0 && binIndex <
m_cosBins) {
325 hdedx_cos[0][binIndex]->Fill(dedx);
328 hdedx_cos[1][binIndex]->Fill(dedx);
330 hdedx_cos[2][binIndex]->Fill(dedx);
334 for (
unsigned int j = 0; j < wire->size(); ++j) {
335 int jwire = wire->at(j);
336 double jhitdedx = dedxhit->at(j);
337 hdedxhit[jwire]->Fill(jhitdedx);
341 int binI =
static_cast<int>((costh -
m_cosMin) / cosBinW);
342 if (binI >= 0 && binI < 4) {
344 hdedx_cos_peaks[0][binI]->Fill(dedx);
346 hdedx_cos_peaks[1][binI]->Fill(dedx);
351 printCanvas(hdedx_cos[0], Form(
"plots/costh/dedx_vs_cos_all_%s",
m_suffix.data()),
"costh");
352 printCanvas(hdedx_cos[1], Form(
"plots/costh/dedx_vs_cos_positrons_%s",
m_suffix.data()),
"costh");
353 printCanvas(hdedx_cos[2], Form(
"plots/costh/dedx_vs_cos_electrons_%s",
m_suffix.data()),
"costh");
362 double xmin = 0.0, xmax = 0.0;
363 double binWidth = 0.0;
368 }
else if (var ==
"oned") {
370 }
else if (var ==
"costh") {
372 }
else if (var ==
"inj") {
374 }
else if (var ==
"mom_peaks") {
375 xbins = 4; xmin =
m_momMin; xmax = 4.0;
376 }
else if (var ==
"cos_peaks") {
379 xbins = c_nSenseWires; dedxbins = 250;
382 if (var ==
"costh" || var ==
"mom" || var ==
"mom_peaks" || var ==
"cos_peaks" || var ==
"oned") {
383 binWidth = (xmax - xmin) / xbins;
386 for (
int ic = 0; ic < xbins; ic++) {
387 std::string title = Form(
"dedxhit-dist, wire:%d", ic);
388 std::string name = Form(
"hdedx_%s_%s_%d",
m_suffix.data(), var.data(), ic);
390 if (var ==
"costh" || var ==
"mom" || var ==
"mom_peaks" || var ==
"cos_peaks" || var ==
"oned") {
391 double min = ic * binWidth + xmin;
392 double max = min + binWidth;
393 title = Form(
"%s: (%0.02f, %0.02f) %s", var.data(), min, max, stype.data());
394 name = Form(
"hdedx_%s_%s_%s_%d",
m_suffix.data(), var.data(), stype.data(), ic);
395 }
else if (var ==
"inj") {
397 title = Form(
"%s, time(%s)", stype.data(), label.data());
398 name = Form(
"h%s_%s_%s_t%d", var.data(),
m_suffix.data(), stype.data(), ic);
401 htemp[ic]->SetTitle(Form(
"%s;dedx;entries", title.data()));
406 const std::string& svar)
409 double xmin = 0., xmax = 0.;
413 }
else if (svar ==
"costh") {
416 B2FATAL(
"wrong input");
418 double binWidth = (xmax - xmin) / xbins;
421 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1200, 1200);
425 std::stringstream psname;
426 psname << Form(
"%s.pdf[", namesfx.data());
427 ctmp->Print(psname.str().c_str());
429 psname << Form(
"%s.pdf", namesfx.data());
432 for (
int i = 0; i < xbins; ++i) {
436 double emean, emeanErr, esigma, esigmaErr;
437 double pmean, pmeanErr, psigma, psigmaErr;
439 fit(htemp[0][i], emean, emeanErr, esigma, esigmaErr);
440 fit(htemp[1][i], pmean, pmeanErr, psigma, psigmaErr);
442 double min = i * binWidth + xmin;
443 double max = min + binWidth;
445 TPaveText pt(0.6, 0.63, 0.85, 0.89,
"NBNDC");
448 pt.AddText(Form(
"#mu_{fit}: %0.03f#pm%0.03f", emean, emeanErr));
449 pt.AddText(Form(
"#sigma_{fit}: %0.03f#pm%0.03f", esigma, esigmaErr));
452 pt.AddText(Form(
"#mu_{fit}: %0.03f#pm%0.03f", pmean, pmeanErr));
453 pt.AddText(Form(
"#sigma_{fit}: %0.03f#pm%0.03f", psigma, psigmaErr));
455 htemp[0][i]->SetStats(0);
456 htemp[1][i]->SetStats(0);
457 htemp[0][i]->SetFillColor(0);
458 htemp[1][i]->SetFillColor(0);
459 htemp[0][i]->SetLineColor(8);
460 htemp[1][i]->SetLineColor(9);
461 htemp[0][i]->SetTitle(Form(
"%s: (%0.02f, %0.02f)", svar.data(), min, max));
462 if (htemp[0][i]->GetEntries() > 0)
463 htemp[0][i]->Scale(1.0 / htemp[0][i]->GetEntries());
464 if (htemp[1][i]->GetEntries() > 0)
465 htemp[1][i]->Scale(1.0 / htemp[1][i]->GetEntries());
467 if (htemp[1][i]->GetMaximum() > htemp[0][i]->GetMaximum())
468 htemp[0][i]->SetMaximum(htemp[1][i]->GetMaximum());
470 htemp[0][i]->DrawCopy(
"HIST");
471 htemp[1][i]->DrawCopy(
"same HIST");
472 pt.DrawClone(
"same");
474 TLegend* lego =
new TLegend(0.15, 0.67, 0.3, 0.8);
475 lego->AddEntry(htemp[0][i],
"e+",
"l");
476 lego->AddEntry(htemp[1][i],
"e-",
"l");
479 if ((i + 1) % 4 == 0 || i == xbins - 1) {
480 ctmp->SetBatch(kTRUE);
481 ctmp->Print(psname.str().c_str());
482 if ((i + 1) % 4 == 0) ctmp->Clear(
"D");
487 psname << Form(
"%s.pdf]", namesfx.data());
488 ctmp->Print(psname.str().c_str());
496 double xmin = 0.0, xmax = 0.0;
500 }
else if (svar ==
"oned") {
502 }
else if (svar ==
"costh") {
504 }
else if (svar ==
"inj") {
506 }
else if (svar ==
"mom_peaks") {
507 xbins = 4; xmin =
m_momMin; xmax = 4.0;
509 B2FATAL(
"wrong input");
513 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1200, 1200);
517 std::stringstream psname;
518 psname << Form(
"%s.pdf[", namesfx.data());
519 ctmp->Print(psname.str().c_str());
521 psname << Form(
"%s.pdf", namesfx.data());
523 std::ofstream outFile;
524 outFile.open(Form(
"%s.txt", namesfx.data()));
528 for (
int i = 0; i < xbins; ++i) {
530 ctmp->cd(i % 16 + 1);
531 TPaveText pt(0.6, 0.73, 0.85, 0.89,
"NBNDC");
534 if (svar ==
"oned") {
535 unsigned int minbin, maxbin;
537 htemp[i]->SetTitle(Form(
"dedxhit-dist, entabin: %d ;%d;%d", i, minbin, maxbin));
541 const double binWidth = (xmax - xmin) / xbins;
542 double binCenter = xmin + (i + 0.5) * binWidth;
544 outFile << binCenter <<
" " << dedxmean << std::endl;
546 double mean, meanErr, sigma, sigmaErr;
547 fit(htemp[i], mean, meanErr, sigma, sigmaErr);
549 if (svar ==
"mom" || svar ==
"costh" || svar ==
"mom_peaks") {
550 const double binWidth = (xmax - xmin) / xbins;
551 double binCenter = xmin + (i + 0.5) * binWidth;
553 outFile << binCenter <<
" " << mean <<
" " << meanErr <<
" " << sigma <<
" " << sigmaErr << std::endl;
556 outFile << i <<
" " << label <<
" " << mean <<
" " << meanErr <<
" " << sigma <<
" " << sigmaErr << std::endl;
559 pt.AddText(Form(
"#mu_{fit}: %0.03f#pm%0.03f", mean, meanErr));
560 pt.AddText(Form(
"#sigma_{fit}: %0.03f#pm%0.03f", sigma, sigmaErr));
562 htemp[i]->SetStats(0);
563 htemp[i]->DrawCopy(
"");
564 pt.DrawClone(
"same");
566 if ((i + 1) % 16 == 0 || ((i + 1) == xbins)) {
567 ctmp->SetBatch(kTRUE);
568 ctmp->Print(psname.str().c_str());
575 psname << Form(
"%s.pdf]", namesfx.data());
576 ctmp->Print(psname.str().c_str());
586 std::string status =
"";
588 if (hist->Integral() > 100)
591 if (status !=
"fitOK") {
592 hist->SetFillColor(kOrange);
593 mean = 0.0, meanErr = 0.0, sigma = 0.0, sigmaErr = 0.0;
595 mean = hist->GetFunction(
"gaus")->GetParameter(1);
596 meanErr = hist->GetFunction(
"gaus")->GetParError(1);
597 sigma = hist->GetFunction(
"gaus")->GetParameter(2);
598 sigmaErr = hist->GetFunction(
"gaus")->GetParError(2);
599 hist->SetFillColor(kYellow);
606 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1200, 1200);
610 std::stringstream psname;
611 psname << Form(
"%s.pdf[", namesfx.data());
612 ctmp->Print(psname.str().c_str());
614 psname << Form(
"%s.pdf", namesfx.data());
616 std::ofstream outFile;
617 outFile.open(Form(
"%s.txt", namesfx.data()));
621 for (
const auto& entry : htemp) {
622 int run = entry.first;
623 TH1D* hist = entry.second;
625 ctmp->cd(irun % 16 + 1);
627 TPaveText pt(0.6, 0.73, 0.85, 0.89,
"NBNDC");
630 double mean, meanErr, sigma, sigmaErr;
631 fit(hist, mean, meanErr, sigma, sigmaErr);
633 outFile << run <<
" " << mean <<
" " << meanErr <<
" " << sigma <<
" " << sigmaErr << std::endl;
635 pt.AddText(Form(
"#mu_{fit}: %0.03f#pm%0.03f", mean, meanErr));
636 pt.AddText(Form(
"#sigma_{fit}: %0.03f#pm%0.03f", sigma, sigmaErr));
640 pt.DrawClone(
"same");
642 if ((irun + 1) % 16 == 0 || irun ==
int(htemp.size() - 1)) {
643 ctmp->SetBatch(kTRUE);
644 ctmp->Print(psname.str().c_str());
650 ctmp->Print(psname.str().c_str());
652 psname << Form(
"%s.pdf]", namesfx.data());
653 ctmp->Print(psname.str().c_str());
663 double histmean = temphist->GetMean();
664 double histrms = temphist->GetRMS();
665 temphist->GetXaxis()->SetRangeUser(histmean - 5.0 * histrms, histmean + 5.0 * histrms);
667 int fs = temphist->Fit(
"gaus",
"Q0");
669 B2INFO(Form(
"\tFit (round 1) for hist (%s) failed (status = %d)", temphist->GetName(), fs));
670 status =
"fitFailed";
673 double mean = temphist->GetFunction(
"gaus")->GetParameter(1);
674 double width = temphist->GetFunction(
"gaus")->GetParameter(2);
675 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
676 fs = temphist->Fit(
"gaus",
"QR",
"", mean -
m_sigmaR * width, mean +
m_sigmaR * width);
678 B2INFO(Form(
"\tFit (round 2) for hist (%s) failed (status = %d)", temphist->GetName(), fs));
679 status =
"fitFailed";
682 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
683 B2INFO(Form(
"\tFit for hist (%s) successful (status = %d)", temphist->GetName(), fs));
692 std::vector<double> vdedx_means;
693 std::vector<double> layermean(c_maxNSenseLayers);
694 std::vector<double> lgmean(c_maxNSenseLayers);
696 std::ofstream outFile, outFileLayer, outFileAvg, outFilebdwire;
697 outFile.open(Form(
"plots/wire/dedx_mean_gwire_%s.txt",
m_suffix.data()));
698 outFilebdwire.open(Form(
"plots/wire/dedx_mean_badwire_%s.txt",
m_suffix.data()));
699 outFileLayer.open(Form(
"plots/wire/dedx_mean_layer_%s.txt",
m_suffix.data()));
700 outFileAvg.open(Form(
"plots/wire/dedx_mean_layer_avg_%s.txt",
m_suffix.data()));
702 int activelayers = 0;
703 double layeravg = 0.0;
711 for (
unsigned int il = 0; il < c_maxNSenseLayers; ++il) {
713 int activewires = 0, goodwires = 0;
717 for (
unsigned int iw = 0; iw < cdcgeo.
nWiresInLayer(il); ++iw) {
720 unsigned int minbin, maxbin;
722 hdedxhit[jwire]->SetTitle(Form(
"dedxhit-dist, wire: %d ;%d;%d", jwire, minbin, maxbin));
725 vdedx_means.push_back(dedxmean);
727 if (Badwire->getBadWireStatus(jwire) == kTRUE)
728 outFilebdwire << jwire <<
" " << dedxmean << std::endl;
730 outFile << jwire <<
" " << dedxmean << std::endl;
732 if (vdedx_means.at(jwire) > 0) {
733 layermean[il] += vdedx_means.at(jwire);
735 if (Badwire->getBadWireStatus(jwire) != kTRUE) {
736 lgmean[il] += vdedx_means.at(jwire);
742 if (activewires > 0) layermean[il] /= activewires;
743 else layermean[il] = 1.0;
745 if (goodwires > 0) lgmean[il] /= goodwires;
746 else lgmean[il] = 1.0;
748 outFileLayer << il <<
" " << layermean[il] <<
" " << lgmean[il] << std::endl;
751 if (il >= 8 && layermean[il] > 0) {
752 layeravg += layermean[il];
758 if (activelayers > 0) layeravg /= activelayers;
759 outFileAvg << layeravg << std::endl;
762 outFilebdwire.close();
763 outFileLayer.close();
769 const std::vector<double>& vdedx_mean)
771 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 900, 900);
774 std::stringstream psname;
775 psname << Form(
"%s.pdf[", namesfx.data());
776 ctmp->Print(psname.str().c_str());
778 psname << Form(
"%s.pdf", namesfx.data());
780 for (
unsigned int ip = 0; ip < c_nwireCDC; ip++) {
781 int minbin = std::stoi(temp[ip]->GetXaxis()->GetTitle());
782 int maxbin = std::stoi(temp[ip]->GetYaxis()->GetTitle());
783 temp[ip]->SetFillColor(kYellow - 9);
784 temp[ip]->SetTitle(Form(
"%s, #mu_{trunc} %0.03f;dedxhit;entries", temp[ip]->GetTitle(), vdedx_mean.at(ip)));
786 ctmp->cd(ip % 16 + 1);
788 temp[ip]->DrawCopy(
"hist");
789 TH1D* hdedxhitC =
static_cast<TH1D*
>(temp[ip]->Clone(Form(
"%sC", temp[ip]->GetName())));
790 hdedxhitC->GetXaxis()->SetRange(minbin, maxbin);
791 hdedxhitC->SetFillColor(kAzure + 1);
792 hdedxhitC->DrawCopy(
"same histo");
794 if ((ip + 1) % 16 == 0) {
795 ctmp->SetBatch(kTRUE);
796 ctmp->Print(psname.str().c_str());
805 psname << Form(
"%s.pdf]", namesfx.data());
806 ctmp->Print(psname.str().c_str());
813 for (
int ib = 0; ib < 69; ib++) {
814 fixedges[ib] = ib * 0.5 * 1e3;
815 if (ib > 40 && ib <= 60) fixedges[ib] = fixedges[ib - 1] + 1.0 * 1e3;
816 else if (ib > 60 && ib <= 64) fixedges[ib] = fixedges[ib - 1] + 10.0 * 1e3;
817 else if (ib > 64 && ib <= 65) fixedges[ib] = fixedges[ib - 1] + 420.0 * 1e3;
818 else if (ib > 65 && ib <= 66) fixedges[ib] = fixedges[ib - 1] + 500.0 * 1e3;
819 else if (ib > 66) fixedges[ib] = fixedges[ib - 1] + 2e6;
820 vtlocaledges.push_back(fixedges[ib]);
828 TCanvas cstats(
"cstats",
"cstats", 800, 400);
829 cstats.SetBatch(kTRUE);
835 hestats->SetName(Form(
"hestats_%s",
m_suffix.data()));
836 hestats->SetStats(0);
837 hestats->DrawCopy(
"");
843 htstats->SetName(Form(
"htstats_%s",
m_suffix.data()));
844 htstats->SetStats(0);
845 htstats->DrawCopy(
"");
848 cstats.Print(Form(
"cdcdedx_stats_%s.pdf",
m_suffix.data()));
855 dbConfiguration.overrideGlobalTags();
856 dbConfiguration.setGlobalTags({
"online"});
863 B2FATAL(
"Setting both testing payload and Global Tag or setting no one of them.");
892 std::vector<double> wiregain;
893 std::vector<double> layermean(c_maxNSenseLayers);
896 if (!DBWireGains.
isValid()) B2FATAL(
"Wire gain data are not valid.");
901 for (
unsigned int il = 0; il < c_maxNSenseLayers; ++il) {
906 for (
unsigned int iw = 0; iw < cdcgeo.
nWiresInLayer(il); ++iw) {
909 wiregain.push_back(DBWireGains->getWireGain(jwire));
911 if (wiregain.at(jwire) > 0) {
912 layermean[il] += wiregain.at(jwire);
917 if (activewires > 0) layermean[il] /= activewires;
918 else layermean[il] = 1.0;
922 return { wiregain, layermean };
930 std::array<std::vector<double>, 3> cosgain;
931 std::vector<double> cos;
935 B2FATAL(
"Cosine gain data are not valid.");
939 const std::array<unsigned int, 3> layerIndex = {1, 9, 17};
941 for (
int igroup = 0; igroup < 3; ++igroup) {
942 unsigned int nCosBins = DBCosineCor->getSize(layerIndex[igroup]);
944 for (
unsigned int ibin = 0; ibin < nCosBins; ++ibin) {
946 double costh = -1.0 + (ibin + 0.5) * 2.0 / nCosBins;
950 cos.push_back(costh);
953 cosgain[igroup].push_back(DBCosineCor->getMean(layerIndex[igroup], ibin));
958 return {cosgain, cos};
966 std::array<std::vector<double>, 3> oneDcorr;
967 std::vector<double> enta;
971 B2FATAL(
"OneD cell gain data are not valid.");
975 const std::array<unsigned int, 3> layerIndex = {1, 9, 17};
977 for (
int igroup = 0; igroup < 3; igroup++) {
979 unsigned int nBins = DBOneDCell->getNBins(layerIndex[igroup]);
980 double binSize = TMath::Pi() / nBins;
982 for (
unsigned int nbin = 0; nbin < nBins; nbin++) {
984 double eta = (-1.0 * TMath::Pi() / 2.0) + binSize * nbin;
990 oneDcorr[igroup].push_back(DBOneDCell->getMean(layerIndex[igroup], nbin));
995 return {oneDcorr, enta};
1004 if (!RunGain.
isValid()) B2FATAL(
"Run gain data are not valid.");
1005 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
static void resetDatabase()
Clear current DB pointers and state.
static void setTextCosmetics(TPaveText pt, Color_t color)
Set text cosmetics for TPaveText.
void wireGain(std::vector< TH1D * > &hdedxhit)
Validate wire gain data using dE/dx histograms.
void printCanvas(std::vector< TH1D * > &htemp, const std::string &namesfx, const std::string &svar)
Draw dE/dx histograms across bins.
std::vector< double > m_vtlocaledges
internal time vector
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
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 (points into m_vtlocaledges)
std::string m_GlobalTagName
Global Tag name.
void DatabaseIN(int experiment, int run)
Load database payload for given run.
static 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.
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 printCanvasRun(const std::map< int, TH1D * > &htemp, const std::string &namesfx)
Draw dE/dx per run histogram canvas.
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 printCanvasdEdx(std::array< std::vector< TH1D * >, 2 > &htemp, const std::string &namesfx, const std::string &svar)
Draw dE/dx histograms for momentum and cosine bins.
double m_dedxMax
max range of dedx
static void printCanvasWire(std::vector< TH1D * > temp, const std::string &namesfx, const std::vector< double > &vdedx_mean)
Plot dE/dx vs wire number.
DBObjPtr< CDCDedxInjectionTime > m_DBInjectTime
Injection time DB object.
double m_dedxMin
min range of dedx
unsigned int m_tbins
internal time bins
void defineHisto(std::vector< TH1D * > &htemp, const std::string &var, const 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
static 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.
Type-safe access to single objects in the data store.
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.