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->GetEvent(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;
122 double dedx_new = dedxnosat;
124 if (correct) dedx_new = had.
D2I(costh, had.
I2D(costh, 1.0) * dedxnosat);
126 hdedx_bgcosth[bgBin][cosBin]->Fill(dedx_new);
127 hdedxvscosth_bg[bgBin]->Fill(uncosth, dedx_new);
141 setPars(outfile, hdedx_bgcosth, pdg.data());
145 plotDist(hdedx_bgcosth, Form(
"fits_dedx_inbg_%s", suffix.data()), pdg.data());
146 plotDist(hdedxvscosth_bg, Form(
"dist_dedx_vscos_scat_%s", suffix.data()), pdg.data());
150 hdedxvscosth_bg.clear();
151 hdedx_bgcosth.clear();
161 std::string title = Form(
"%s_%s_%d", pdg.data(), svar.data(), j);
162 double dedxMax = 4.0;
163 int cosbins = int(50 * dedxMax);
165 dedxMax = 2.0; cosbins = int(100 * dedxMax);
167 if (pdg ==
"proton") dedxMax = 20.0;
168 if (svar.substr(0, svar.find(
"_")) ==
"dedx")
169 htemp.push_back(
new TH1F(title.data(), title.data(), cosbins, 0, dedxMax));
171 htemp.push_back(
new TH1F(title.data(), title.data(), cosbins, -30, 30));
177void HadronPrep::plotDist(std::map<
int, std::vector<TH1F*>>& hist,
const std::string& sname,
const std::string& pdg)
180 TCanvas ctmp(Form(
"cdcdedx_%s_%s", sname.data(), pdg.data()),
"", 1200, 1200);
182 ctmp.SetBatch(kTRUE);
184 std::stringstream psname;
185 psname << Form(
"plots/HadronSat/%s_%s.pdf[", sname.data(), pdg.data());
186 ctmp.Print(psname.str().c_str());
188 psname << Form(
"plots/HadronSat/%s_%s.pdf", sname.data(), pdg.data());
190 for (
int i = 0 ; i <
m_bgBins; ++i) {
192 hist[i][j]->SetFillColor(kYellow - 9);
198 if (j + 1 ==
m_cosBins) ctmp.Print(psname.str().c_str());
199 }
else if ((j + 1) % 4 == 0 || (j + 1 ==
m_cosBins)) {
200 ctmp.Print(psname.str().c_str());
206 psname << Form(
"plots/HadronSat/%s_%s.pdf]", sname.data(), pdg.data());
207 ctmp.Print(psname.str().c_str());
214 TCanvas ctmp(Form(
"cdcdedx_%s_%s", sname.data(), pdg.data()),
"", 1200, 1200);
216 ctmp.SetBatch(kTRUE);
218 std::stringstream psname;
219 psname << Form(
"plots/HadronSat/%s_%s.pdf[", sname.data(), pdg.data());
220 ctmp.Print(psname.str().c_str());
222 psname << Form(
"plots/HadronSat/%s_%s.pdf", sname.data(), pdg.data());
225 if (pdg ==
"kaon")dmax = 3.5;
226 else if (pdg ==
"proton")dmax = 15.5;
228 for (
int i = 0 ; i <
m_bgBins; ++i) {
230 double frombg =
m_bgMin + i * bgstep;
231 double tobg = frombg + bgstep;
233 hist[i]->SetTitle(Form(
"%s, pF=(%0.02f,%0.02f)", hist[i]->GetTitle(), frombg, tobg));
234 hist[i]->GetYaxis()->SetRangeUser(-0.5, dmax);
235 hist[i]->DrawCopy(
"colz");
236 if ((i + 1) % 4 == 0 || (i + 1) ==
m_bgBins) {
237 ctmp.Print(psname.str().c_str());
242 psname << Form(
"plots/HadronSat/%s_%s.pdf]", sname.data(), pdg.data());
243 ctmp.Print(psname.str().c_str());
247void HadronPrep::setPars(TFile*& outfile, std::map<
int, std::vector<TH1F*>>& hdedx_bgcosth,
const std::string& pdg)
250 TTree* satTree =
new TTree(Form(
"%s", pdg.data()),
"dE/dx means and errors");
259 satTree->Branch(
"bg", &satbg,
"bg/D");
260 satTree->Branch(
"costh", &satcosth,
"costh/D");
263 satTree->Branch(
"dedx", &satdedx,
"dedx/D");
264 satTree->Branch(
"dedxerr", &satdedxerr,
"dedxerr/D");
265 satTree->Branch(
"dedxwidth", &satdedxwidth,
"dedxwidth/D");
268 satTree->Branch(
"bg_avg", &satbg_avg,
"bg_avg/D");
269 satTree->Branch(
"costh_avg", &satcosth_avg,
"costh_avg/D");
274 for (
int i = 0; i <
m_bgBins; ++i) {
278 satbg =
m_bgMin + 0.5 * bgstep + i * bgstep;
279 satcosth =
m_cosMin + 0.5 * cosstep + j * cosstep;
287 prep.
fit(hdedx_bgcosth[i][j], pdg.data());
288 satdedx =
m_means[i][j] = hdedx_bgcosth[i][j]->GetFunction(
"gaus")->GetParameter(1);
289 satdedxerr =
m_errors[i][j] = hdedx_bgcosth[i][j]->GetFunction(
"gaus")->GetParError(1);
290 satdedxwidth = hdedx_bgcosth[i][j]->GetFunction(
"gaus")->GetParameter(2);
311 cbcenters[j] =
m_cosMin + 0.5 * cosstep + j * cosstep;
316 TCanvas ctmp6(Form(
"cdcdedx_costh_%s_%s", sname.data(), pdg.data()),
"", 500, 500);
319 TH1F base(
"base",
"bla-bla", 25, 0, 1.0);
320 base.SetTitle(Form(
"%s: dE/dx fit means vs. cos(#theta);cos(#theta);dE/dx-fit mean", pdg.data()));
321 base.GetXaxis()->SetTitleOffset(1.2);
324 if (pdg ==
"proton") margin = 0.95;
331 TLegend legend(0.75, 0.75, 0.95, 0.9);
333 std::vector<TGraphErrors*> gdedx_costh(
m_bgBins);
335 legend.SetBorderSize(0);
337 for (
int i = 0; i <
m_bgBins; ++i) {
345 gdedx_costh[i] =
new TGraphErrors(
m_cosBins, cbcenters.data(), mean_d.data(), cberrors.data(), error_d.data());
347 gdedx_costh[i]->SetMarkerSize(0.9);
348 gdedx_costh[i]->SetMarkerColor(50 + i * 3);
349 gdedx_costh[i]->SetLineColor(i + 1);
350 gdedx_costh[i]->SetLineWidth(1);
351 gdedx_costh[i]->Draw(
"same");
352 legend.AddEntry(gdedx_costh[i], Form(
"bg = (%0.03f - %0.03f)",
m_bgMin + i * bgstep,
m_bgMin + (i + 1) * bgstep),
"lep");
357 std::stringstream psname;
359 psname << Form(
"plots/HadronSat/gr_dedx_vscosth_%s_%s.pdf", sname.data(), pdg.data());
360 ctmp6.SaveAs(psname.str().c_str());
363 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.
double getParticleMass(const std::string &particle)
function to get the particle mass
void fit(TH1F *&hist, const std::string &pdg)
function to fit the histograms
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.