42 B2INFO(
"Preparing dE/dx calibration for CDC dE/dx run gain");
53 int run = 0, runtemp = 0;
55 ttree->SetBranchAddress(
"dedx", &dedx);
56 ttree->SetBranchAddress(
"run", &run);
61 for (
int i = 0; i < ttree->GetEntries(); ++i) {
63 if (dedx <= 0)
continue;
65 hDedxAbs->Fill(dedx * ExistingRG);
70 if (hDedx->Integral() < 1000) {
71 B2INFO(
"Not enough data for run (" << runtemp <<
") so far only " << hDedx->Integral() <<
" therefore adding next run");
72 fsrun += Form(
"%d_", runtemp);
78 B2INFO(
"Total track for this run: " << runtemp <<
" = " << hDedx->Integral());
79 fsrun += Form(
"%d", runtemp);
80 hDedx->SetName(Form(
"%s_%s", hDedx->GetName(),
fsrun.Data()));
81 hDedxAbs->SetName(Form(
"%s_%s", hDedxAbs->GetName(),
fsrun.Data()));
84 double RGabs_Mean = 1.0;
86 if (status !=
"FitOK") {
87 hDedxAbs->SetTitle(Form(
"dE/dx abs, Run %s (%s)",
fsrun.Data(), status.Data()));
89 RGabs_Mean = hDedxAbs->GetFunction(
"gaus")->GetParameter(1);
90 double RGabs_MeanErr = hDedxAbs->GetFunction(
"gaus")->GetParError(1);
91 double RGabs_Sigma = hDedxAbs->GetFunction(
"gaus")->GetParameter(2);
92 hDedxAbs->SetTitle(Form(
"dE/dx abs, Run %s (%s), #mu_{fit}: %0.04f#pm%0.04f,, #sigma_{fit}: %0.04f",
fsrun.Data(), status.Data(),
93 RGabs_Mean, RGabs_MeanErr, RGabs_Sigma));
97 double RGrel_Mean = 1.0, RGrel_MeanErr = -99.0, RGrel_Sigma = -99.0;
99 if (status !=
"FitOK") {
100 RGrel_Mean = hDedx->GetMean();
101 hDedx->SetTitle(Form(
"dE/dx abs, Run %s (%s)",
fsrun.Data(), status.Data()));
103 RGrel_Mean = hDedx->GetFunction(
"gaus")->GetParameter(1);
104 RGrel_MeanErr = hDedx->GetFunction(
"gaus")->GetParError(1);
105 RGrel_Sigma = hDedx->GetFunction(
"gaus")->GetParameter(2);
106 hDedx->SetTitle(Form(
"dE/dx rel, Run %s (%s), #mu_{fit}: %0.04f#pm%0.04f,, #sigma_{fit}: %0.04f",
fsrun.Data(), status.Data(),
107 RGrel_Mean, RGrel_MeanErr, RGrel_Sigma));
110 if (RGrel_Mean <= 0.0)RGrel_Mean = 1.0;
115 std::ofstream fileRGout;
116 fileRGout.open(Form(
"fRG_Constants_%s.txt",
fsrun.Data()));
117 fileRGout << expRun.second <<
" " << ExistingRG <<
" " << RGrel_Mean <<
" " << RGrel_MeanErr <<
" " << RGrel_Sigma <<
"\n";
120 TCanvas* ctmp =
new TCanvas(
"tmp",
"tmp", 1000, 500);
121 ctmp->SetBatch(kTRUE);
125 hDedx->SetFillColorAlpha(kYellow, 0.30);
128 TLine* tl =
new TLine();
129 tl->SetLineColor(kRed);
130 tl->SetX1(RGrel_Mean); tl->SetX2(RGrel_Mean);
131 tl->SetY1(0); tl->SetY2(hDedx->GetMaximum());
132 tl->DrawClone(
"same");
135 hDedxAbs->SetFillColorAlpha(kBlue, 0.10);
136 hDedxAbs->DrawCopy(
"");
138 TLine* tlAbs =
new TLine();
139 tlAbs->SetLineColor(kRed);
140 tlAbs->SetX1(RGabs_Mean); tlAbs->SetX2(RGabs_Mean);
141 tlAbs->SetY1(0); tlAbs->SetY2(hDedxAbs->GetMaximum());
142 tlAbs->DrawClone(
"same");
144 ctmp->Print(Form(
"cdcdedx_rungain_fits_%s_%s.pdf",
fsrun.Data(), status.Data()));
146 TCanvas* cstats =
new TCanvas(
"cstats",
"cstats", 1000, 500);
147 cstats->SetBatch(kTRUE);
148 cstats->Divide(2, 1);
151 if (hestats)hestats->DrawCopy(
"");
154 if (htstats)htstats->DrawCopy(
"");
155 cstats->Print(Form(
"cdcdedx_rungain_stats_%s.pdf",
fsrun.Data()));
163 B2INFO(
"Saving new rung for (Exp, Run) : (" << expRun.first <<
"," << expRun.second <<
")");
193 double histmean = temphist->GetMean();
194 double histrms = temphist->GetRMS();
195 temphist->GetXaxis()->SetRangeUser(histmean - 5.0 * histrms, histmean + 5.0 * histrms);
197 int fs = temphist->Fit(
"gaus",
"Q0");
199 B2INFO(Form(
"\tFit (round 1) for hist (%s) failed (status = %d)", temphist->GetName(), fs));
200 status =
"FitFailed";
203 double mean = temphist->GetFunction(
"gaus")->GetParameter(1);
204 double width = temphist->GetFunction(
"gaus")->GetParameter(2);
205 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
206 fs = temphist->Fit(
"gaus",
"QR",
"", mean -
fSigLim * width, mean +
fSigLim * width);
208 B2INFO(Form(
"\tFit (round 2) for hist (%s) failed (status = %d)", temphist->GetName(), fs));
209 status =
"FitFailed";
212 temphist->GetXaxis()->SetRangeUser(mean - 5.0 * width, mean + 5.0 * width);
213 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...