9#include <cdc/calibration/CDCdEdx/HadronPrep.h>
23HadronPrep::HadronPrep(
int bgbins,
double lowerbg,
double upperbg,
int cosbins,
double lowercos,
double uppercos,
double cut)
35 const std::string& pdg,
bool ismakePlots,
bool correct)
38 std::map<int, std::vector<TH1F*>> hdedx_bgcosth;
39 std::vector<TH2F*> hdedxvscosth_bg;
44 std::string title = Form(
"%s_dedxvscos_bg_%d", pdg.data(), i);
45 hdedxvscosth_bg.push_back(
new TH2F(title.data(), Form(
"%s;costh;dEdx", title.data()),
46 440, -1.1, 1.1, 2600, -1.0, 25));
48 defineHisto(hdedx_bgcosth[i], Form(
"dedx_bg_%d_cos", i), pdg.data());
75 hadron->SetBranchAddress(
"dedxnosat", &dedxnosat);
76 hadron->SetBranchAddress(
"p", &p);
77 hadron->SetBranchAddress(
"costh", &costh);
78 hadron->SetBranchAddress(
"timereso", &timereso);
79 hadron->SetBranchAddress(
"nhits", &nhit);
83 if (mass == 0.0) B2FATAL(
"Mass of particle " << pdg.data() <<
" is zero");
88 std::string infile =
"sat-pars.fit.txt";
89 std::ifstream parfile(infile);
91 if (!parfile.fail()) {
92 B2INFO(
"new parameters are using");
95 B2INFO(
"default parameters are using");
100 for (
unsigned int index = 0; index < hadron->GetEntries(); ++index) {
102 hadron->GetEntry(index);
107 double uncosth = costh;
111 if (nhit < 0 || nhit > 100)
continue;
112 if (dedxnosat <= 0)
continue;
113 if (costh != costh)
continue;
114 if (bg <= m_bgMin || bg >=
m_bgMax)
continue;
115 if (costh <= m_cosMin || costh >=
m_cosMax)
continue;
117 if (pdg ==
"proton")
if ((dedxnosat - 0.45) * abs(p) * abs(p) <
m_cut)
continue;
120 bgBin = std::max(0, std::min(bgBin,
m_bgBins - 1));
123 cosBin = std::max(0, std::min(cosBin,
m_cosBins - 1));
125 double dedx_new = dedxnosat;
127 if (correct) dedx_new = had.
D2I(costh, had.
I2D(costh, 1.0) * dedxnosat);
129 hdedx_bgcosth[bgBin][cosBin]->Fill(dedx_new);
130 hdedxvscosth_bg[bgBin]->Fill(uncosth, dedx_new);
144 setPars(outfile, hdedx_bgcosth, pdg.data());
148 plotDist(hdedx_bgcosth, Form(
"fits_dedx_inbg_%s", suffix.data()), pdg.data());
149 plotDist(hdedxvscosth_bg, Form(
"dist_dedx_vscos_scat_%s", suffix.data()), pdg.data());
153 hdedxvscosth_bg.clear();
154 hdedx_bgcosth.clear();
164 std::string title = Form(
"%s_%s_%d", pdg.data(), svar.data(), j);
165 double dedxMax = 4.0;
166 int cosbins = int(50 * dedxMax);
168 dedxMax = 2.0; cosbins = int(100 * dedxMax);
170 if (pdg ==
"proton") dedxMax = 20.0;
171 if (svar.substr(0, svar.find(
"_")) ==
"dedx")
172 htemp.push_back(
new TH1F(title.data(), title.data(), cosbins, 0, dedxMax));
174 htemp.push_back(
new TH1F(title.data(), title.data(), cosbins, -30, 30));
180void HadronPrep::plotDist(std::map<
int, std::vector<TH1F*>>& hist,
const std::string& sname,
const std::string& pdg)
183 TCanvas ctmp(Form(
"cdcdedx_%s_%s", sname.data(), pdg.data()),
"", 1200, 1200);
185 ctmp.SetBatch(kTRUE);
187 std::stringstream psname;
188 psname << Form(
"plots/HadronSat/%s_%s.pdf[", sname.data(), pdg.data());
189 ctmp.Print(psname.str().c_str());
191 psname << Form(
"plots/HadronSat/%s_%s.pdf", sname.data(), pdg.data());
193 for (
int i = 0 ; i <
m_bgBins; ++i) {
195 hist[i][j]->SetFillColor(kYellow - 9);
201 if (j + 1 ==
m_cosBins) ctmp.Print(psname.str().c_str());
202 }
else if ((j + 1) % 4 == 0 || (j + 1 ==
m_cosBins)) {
203 ctmp.Print(psname.str().c_str());
209 psname << Form(
"plots/HadronSat/%s_%s.pdf]", sname.data(), pdg.data());
210 ctmp.Print(psname.str().c_str());
217 TCanvas ctmp(Form(
"cdcdedx_%s_%s", sname.data(), pdg.data()),
"", 1200, 1200);
219 ctmp.SetBatch(kTRUE);
221 std::stringstream psname;
222 psname << Form(
"plots/HadronSat/%s_%s.pdf[", sname.data(), pdg.data());
223 ctmp.Print(psname.str().c_str());
225 psname << Form(
"plots/HadronSat/%s_%s.pdf", sname.data(), pdg.data());
228 if (pdg ==
"kaon")dmax = 3.5;
229 else if (pdg ==
"proton")dmax = 15.5;
231 for (
int i = 0 ; i <
m_bgBins; ++i) {
233 double frombg =
m_bgMin + i * bgstep;
234 double tobg = frombg + bgstep;
236 hist[i]->SetTitle(Form(
"%s, pF=(%0.02f,%0.02f)", hist[i]->GetTitle(), frombg, tobg));
237 hist[i]->GetYaxis()->SetRangeUser(-0.5, dmax);
238 hist[i]->DrawCopy(
"colz");
239 if ((i + 1) % 4 == 0 || (i + 1) ==
m_bgBins) {
240 ctmp.Print(psname.str().c_str());
245 psname << Form(
"plots/HadronSat/%s_%s.pdf]", sname.data(), pdg.data());
246 ctmp.Print(psname.str().c_str());
250void HadronPrep::setPars(TFile*& outfile, std::map<
int, std::vector<TH1F*>>& hdedx_bgcosth,
const std::string& pdg)
253 TTree* satTree =
new TTree(Form(
"%s", pdg.data()),
"dE/dx means and errors");
262 satTree->Branch(
"bg", &satbg,
"bg/D");
263 satTree->Branch(
"costh", &satcosth,
"costh/D");
266 satTree->Branch(
"dedx", &satdedx,
"dedx/D");
267 satTree->Branch(
"dedxerr", &satdedxerr,
"dedxerr/D");
268 satTree->Branch(
"dedxwidth", &satdedxwidth,
"dedxwidth/D");
271 satTree->Branch(
"bg_avg", &satbg_avg,
"bg_avg/D");
272 satTree->Branch(
"costh_avg", &satcosth_avg,
"costh_avg/D");
277 for (
int i = 0; i <
m_bgBins; ++i) {
281 satbg =
m_bgMin + 0.5 * bgstep + i * bgstep;
282 satcosth =
m_cosMin + 0.5 * cosstep + j * cosstep;
288 satbg_avg = satcosth_avg = 0.0;
295 prep.
fit(hdedx_bgcosth[i][j], pdg.data(), stats);
297 satdedx =
m_means[i][j] = hdedx_bgcosth[i][j]->GetFunction(
"gaus")->GetParameter(1);
298 satdedxerr =
m_errors[i][j] = hdedx_bgcosth[i][j]->GetFunction(
"gaus")->GetParError(1);
299 satdedxwidth = hdedx_bgcosth[i][j]->GetFunction(
"gaus")->GetParameter(2);
300 }
else { satdedx = 0.0; satdedxerr = 0.0; satdedxwidth = 0.0;}
322 cbcenters[j] =
m_cosMin + 0.5 * cosstep + j * cosstep;
327 TCanvas ctmp6(Form(
"cdcdedx_costh_%s_%s", sname.data(), pdg.data()),
"", 500, 500);
330 TH1F base(
"base",
"bla-bla", 25, 0, 1.0);
331 base.SetTitle(Form(
"%s: dE/dx fit means vs. cos(#theta);cos(#theta);dE/dx-fit mean", pdg.data()));
332 base.GetXaxis()->SetTitleOffset(1.2);
335 if (pdg ==
"proton") margin = 0.95;
342 TLegend legend(0.75, 0.75, 0.95, 0.9);
344 std::vector<TGraphErrors*> gdedx_costh(
m_bgBins);
346 legend.SetBorderSize(0);
348 for (
int i = 0; i <
m_bgBins; ++i) {
356 gdedx_costh[i] =
new TGraphErrors(
m_cosBins, cbcenters.data(), mean_d.data(), cberrors.data(), error_d.data());
358 gdedx_costh[i]->SetMarkerSize(0.9);
359 gdedx_costh[i]->SetMarkerColor(50 + i * 3);
360 gdedx_costh[i]->SetLineColor(i + 1);
361 gdedx_costh[i]->SetLineWidth(1);
362 gdedx_costh[i]->Draw(
"same");
363 legend.AddEntry(gdedx_costh[i], Form(
"bg = (%0.03f - %0.03f)",
m_bgMin + i * bgstep,
m_bgMin + (i + 1) * bgstep),
"lep");
368 std::stringstream psname;
370 psname << Form(
"plots/HadronSat/gr_dedx_vscosth_%s_%s.pdf", sname.data(), pdg.data());
371 ctmp6.SaveAs(psname.str().c_str());
374 delete gdedx_costh[i];
Class to hold the hadron saturation functions.
double I2D(double cosTheta, double I) const
hadron saturation parameterization part 2
double D2I(double cosTheta, double D) const
hadron saturation parameterization part 1
void setParameters()
set the parameters
Class to prepare sample for fitting in beta gamma bins.
void fit(TH1F *&hist, const std::string &pdg, gstatus &status)
function to fit the histograms
double getParticleMass(const std::string &particle)
function to get the particle mass
void prepareSample(std::shared_ptr< TTree > hadron, TFile *&outfile, const std::string &suffix, const std::string &pdg, bool ismakePlots, bool correct)
function to prepare sample for monitoring plots, bg curve fitting and sigma vs ionz fitting
double m_dedxmax
variables to set maximum dedx mean
int m_cosBins
bins for dedx histogram
std::map< int, std::vector< double > > m_errors
error variable
double m_cosMax
max range of dedx
std::map< int, std::vector< int > > m_sumsize
variables for size
HadronPrep()
Constructor: Sets the description, the properties and the parameters of the algorithm.
double m_dedxmin
variables to set minimum dedx mean
void plotDist(std::map< int, std::vector< TH1F * > > &hist, const std::string &sname, const std::string &pdg)
function to plot the map of histograms
int m_bgBins
bins for dedx histogram
void setPars(TFile *&outfile, std::map< int, std::vector< TH1F * > > &hdedx_bgcosth, const std::string &pdg)
function to fill the parameters like mean and reso in the tree
double m_bgMax
max range of dedx
void plotGraph(const std::string &sname, const std::string &pdg)
function to make graph dedx vs cos in different bg bins
void defineHisto(std::vector< TH1F * > &htemp, const std::string &title, const std::string &pdg)
function to define histograms
double m_bgMin
min range of dedx
double m_cosMin
min range of dedx
double m_cut
cut to clean protons
void clear()
function to clear the variables
std::map< int, std::vector< double > > m_means
mean variable
std::map< int, std::vector< double > > m_sumbg
variables to add bg values
std::map< int, std::vector< double > > m_sumcos
variables to add cos values
Abstract base class for different kinds of events.