43 B2INFO(
"Preparing dE/dx calibration for CDC dE/dx run gain");
54 int run = 0, runtemp = 0;
56 ttree->SetBranchAddress(
"dedx", &dedx);
57 ttree->SetBranchAddress(
"run", &run);
62 for (
int i = 0; i < ttree->GetEntries(); ++i) {
64 if (dedx <= 0)
continue;
66 hDedxAbs->Fill(dedx * ExistingRG);
71 if (hDedx->Integral() < 1000) {
72 B2INFO(
"Not enough data for run (" << runtemp <<
") so far only " << hDedx->Integral() <<
" therefore adding next run");
73 fsrun += Form(
"%d_", runtemp);
79 B2INFO(
"Total track for this run: " << runtemp <<
" = " << hDedx->Integral());
80 fsrun += Form(
"%d", runtemp);
81 hDedx->SetName(Form(
"%s_%s", hDedx->GetName(),
fsrun.Data()));
82 hDedxAbs->SetName(Form(
"%s_%s", hDedxAbs->GetName(),
fsrun.Data()));
85 double RGabs_Mean = 1.0;
87 if (status !=
"FitOK") {
88 hDedxAbs->SetTitle(Form(
"dE/dx abs, Run %s (%s)",
fsrun.Data(), status.Data()));
90 RGabs_Mean = hDedxAbs->GetFunction(
"gaus")->GetParameter(1);
91 double RGabs_MeanErr = hDedxAbs->GetFunction(
"gaus")->GetParError(1);
92 double RGabs_Sigma = hDedxAbs->GetFunction(
"gaus")->GetParameter(2);
93 hDedxAbs->SetTitle(Form(
"dE/dx abs, Run %s (%s), #mu_{fit}: %0.04f#pm%0.04f,, #sigma_{fit}: %0.04f",
fsrun.Data(), status.Data(),
94 RGabs_Mean, RGabs_MeanErr, RGabs_Sigma));
98 double RGrel_Mean = 1.0, RGrel_MeanErr = -99.0, RGrel_Sigma = -99.0;
100 if (status !=
"FitOK") {
101 RGrel_Mean = hDedx->GetMean();
102 hDedx->SetTitle(Form(
"dE/dx abs, Run %s (%s)",
fsrun.Data(), status.Data()));
104 RGrel_Mean = hDedx->GetFunction(
"gaus")->GetParameter(1);
105 RGrel_MeanErr = hDedx->GetFunction(
"gaus")->GetParError(1);
106 RGrel_Sigma = hDedx->GetFunction(
"gaus")->GetParameter(2);
107 hDedx->SetTitle(Form(
"dE/dx rel, Run %s (%s), #mu_{fit}: %0.04f#pm%0.04f,, #sigma_{fit}: %0.04f",
fsrun.Data(), status.Data(),
108 RGrel_Mean, RGrel_MeanErr, RGrel_Sigma));
111 if (RGrel_Mean <= 0.0)RGrel_Mean = 1.0;
116 std::ofstream fileRGout;
117 fileRGout.open(Form(
"fRG_Constants_%s.txt",
fsrun.Data()));
118 fileRGout << expRun.second <<
" " << ExistingRG <<
" " << RGrel_Mean <<
" " << RGrel_MeanErr <<
" " << RGrel_Sigma <<
"\n";
121 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1000, 500);
122 ctmp->SetBatch(kTRUE);
126 hDedx->SetFillColorAlpha(kYellow, 0.30);
129 TLine* tl =
new TLine();
130 tl->SetLineColor(kRed);
131 tl->SetX1(RGrel_Mean); tl->SetX2(RGrel_Mean);
132 tl->SetY1(0); tl->SetY2(hDedx->GetMaximum());
133 tl->DrawClone(
"same");
136 hDedxAbs->SetFillColorAlpha(kBlue, 0.10);
137 hDedxAbs->DrawCopy(
"");
139 TLine* tlAbs =
new TLine();
140 tlAbs->SetLineColor(kRed);
141 tlAbs->SetX1(RGabs_Mean); tlAbs->SetX2(RGabs_Mean);
142 tlAbs->SetY1(0); tlAbs->SetY2(hDedxAbs->GetMaximum());
143 tlAbs->DrawClone(
"same");
145 ctmp->Print(Form(
"cdcdedx_rungain_fits_%s_%s.pdf",
fsrun.Data(), status.Data()));
147 TCanvas* cstats =
new TCanvas(
"cstats",
"cstats", 1000, 500);
148 cstats->SetBatch(kTRUE);
149 cstats->Divide(2, 1);
152 if (hestats)hestats->DrawCopy(
"");
155 if (htstats)htstats->DrawCopy(
"");
156 cstats->Print(Form(
"cdcdedx_rungain_stats_%s.pdf",
fsrun.Data()));
164 B2INFO(
"Saving new rung for (Exp, Run) : (" << expRun.first <<
"," << expRun.second <<
")");
194 double histmean = temphist->GetMean();
195 double histrms = temphist->GetRMS();
196 temphist->GetXaxis()->SetRangeUser(histmean - 5.0 * histrms, histmean + 5.0 * histrms);
198 int fs = temphist->Fit(
"gaus",
"Q0");
200 B2INFO(Form(
"\tFit (round 1) for hist (%s) failed (status = %d)", temphist->GetName(), fs));
201 status =
"FitFailed";
204 double mean = temphist->GetFunction(
"gaus")->GetParameter(1);
205 double width = temphist->GetFunction(
"gaus")->GetParameter(2);
206 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
207 fs = temphist->Fit(
"gaus",
"QR",
"", mean -
fSigLim * width, mean +
fSigLim * width);
209 B2INFO(Form(
"\tFit (round 2) for hist (%s) failed (status = %d)", temphist->GetName(), fs));
210 status =
"FitFailed";
213 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
214 B2INFO(Form(
"\tFit for hist (%s) successful (status = %d)", temphist->GetName(), fs));
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...