1#include "KVMultiGaussIsotopeFit.h"
10KVMultiGaussIsotopeFit::KVMultiGaussIsotopeFit(
int z,
int Ngauss,
double PID_min,
double PID_max,
const KVNumberList& alist, std::vector<double> pidlist)
14 PIDmin{PID_min}, PIDmax{PID_max},
15 Alist{alist.GetArray()},
19 FixParameter(0, Niso);
20 SetParLimits(fit_param_index::bkg_cst, -1.e+5, 1e+5);
21 SetParameter(fit_param_index::bkg_cst, 4.);
22 SetParName(fit_param_index::bkg_cst,
"Norm");
23 SetParLimits(fit_param_index::bkg_slp, -10, 0);
24 SetParameter(fit_param_index::bkg_slp, -0.2);
25 SetParName(fit_param_index::bkg_slp,
"Bkg. slope");
26 SetParName(fit_param_index::gauss_wid,
"Sigma");
27 SetParLimits(fit_param_index::gauss_wid, min_sigma, max_sigma);
28 SetParameter(fit_param_index::gauss_wid, 0.1);
31 for (
int ig = 1; ig <= Niso; ++ig) {
32 SetParName(get_gauss_norm_index(ig),
Form(
"Norm. A=%d", Alist[ig - 1]));
33 SetParLimits(get_gauss_norm_index(ig), 1.e-3, 1.e+06);
34 SetParameter(get_gauss_norm_index(ig), 1.);
35 SetParName(get_mass_index(ig, Niso),
Form(
"A_%d", ig));
36 FixParameter(get_mass_index(ig, Niso), Alist[ig - 1]);
38#if ROOT_VERSION_CODE >= ROOT_VERSION(6,24,0)
39 pid_vs_a.
AddPoint(Alist[ig - 1], PIDlist[ig - 1]);
41 pid_vs_a.
SetPoint(pid_vs_a.
GetN(), Alist[ig - 1], PIDlist[ig - 1]);
47 centroidFit.SetParLimits(0, -50, 50);
48 centroidFit.SetParameter(0, 0);
49 centroidFit.SetParLimits(1, 1.e-2, 5.);
50 centroidFit.SetParameter(1, 1.e-1);
51 centroidFit.SetParLimits(2, -2.e-2, 1.);
52 centroidFit.SetParameter(2, 1.e-3);
53 pid_vs_a.
Fit(¢roidFit,
"N");
55 for (
int i = 0; i < 3; ++i) {
56 FixParameter(fit_param_index::pidvsA_a0 + i, centroidFit.GetParameter(i));
57 SetParName(fit_param_index::pidvsA_a0 + i,
Form(
"PIDvsA_a%d", i));
72KVMultiGaussIsotopeFit::KVMultiGaussIsotopeFit(
int z,
int Ngauss,
double PID_min,
double PID_max,
73 const KVNumberList& alist,
double bkg_cst,
double bkg_slp,
74 double gaus_wid,
double pidvsa_a0,
double pidvsa_a1,
double pidvsa_a2)
78 PIDmin{PID_min}, PIDmax{PID_max},
79 Alist{alist.GetArray()}
85 SetParameter(0, Niso);
86 SetParameter(fit_param_index::bkg_cst, bkg_cst);
87 SetParameter(fit_param_index::bkg_slp, bkg_slp);
88 SetParameter(fit_param_index::gauss_wid, gaus_wid);
89 SetParameter(fit_param_index::pidvsA_a0, pidvsa_a0);
90 SetParameter(fit_param_index::pidvsA_a1, pidvsa_a1);
91 SetParameter(fit_param_index::pidvsA_a2, pidvsa_a2);
93 SetParName(fit_param_index::bkg_cst,
"Norm");
94 SetParName(fit_param_index::bkg_slp,
"Bkg. slope");
95 SetParName(fit_param_index::gauss_wid,
"Sigma");
97 for (
int ig = 1; ig <= Niso; ++ig) {
98 SetParName(get_gauss_norm_index(ig),
Form(
"Norm. A=%d", Alist[ig - 1]));
99 SetParName(get_mass_index(ig, Niso),
Form(
"A_%d", ig));
100 FixParameter(get_mass_index(ig, Niso), Alist[ig - 1]);
102 for (
int i = 0; i < 3; ++i)
103 SetParName(fit_param_index::pidvsA_a0 + i,
Form(
"PIDvsA_a%d", i));
115KVMultiGaussIsotopeFit::KVMultiGaussIsotopeFit(
int Z,
const KVNameValueList& fitparams)
117 fitparams.GetDoubleValue(
"PIDmax"), fitparams.GetStringValue(
"Alist"),
118 fitparams.GetDoubleValue(
"Bkg_cst"), fitparams.GetDoubleValue(
"Bkg_slp"),
119 fitparams.GetDoubleValue(
"GausWid"),
120 fitparams.GetDoubleValue(
"PIDvsA_a0"),
121 fitparams.GetDoubleValue(
"PIDvsA_a1"),
122 fitparams.GetDoubleValue(
"PIDvsA_a2"))
125 for (
int ig = 1; ig <= fitparams.
GetIntValue(
"Ng"); ++ig)
134void KVMultiGaussIsotopeFit::UnDraw(
TVirtualPad* pad)
const
138 auto old_fit = pad->
FindObject(get_name_of_multifit(Z));
139 if (old_fit)
delete old_fit;
140 for (
auto a : Alist) {
141 UnDrawGaussian(Z, a, pad);
150void KVMultiGaussIsotopeFit::DrawFitWithGaussians(
Option_t* opt)
const
156 TF1 fgaus(
"fgaus",
"gausn", PIDmin, PIDmax);
160 for (
auto& a : Alist) {
161 fgaus.SetParameters(GetGaussianNorm(ig), GetCentroid(ig), GetGaussianWidth(ig));
164 fgaus.SetLineWidth(2);
165 fgaus.SetLineStyle(9);
166 fgaus.DrawCopy(
"same")->SetName(get_name_of_isotope_gaussian(Z, a));
178int KVMultiGaussIsotopeFit::GetMostProbableA(
double PID,
double& P)
const
184 auto total =
Eval(PID);
185 std::map<double, int> probabilities;
187 for (
auto& a : Alist) {
188 probabilities[evaluate_gaussian(ig, PID) / total] =
a;
193 auto it = probabilities.rbegin();
205double KVMultiGaussIsotopeFit::GetMeanA(
double PID)
const
211 auto total =
Eval(PID);
213 double amean(0), totprob(0);
214 for (
auto& a : Alist) {
215 auto weight = evaluate_gaussian(ig, PID) / total;
220 return totprob > 0 ? amean / totprob : -1.;
231std::map<int, double> KVMultiGaussIsotopeFit::GetADistribution(
double PID)
const
238 auto total =
Eval(PID);
239 std::map<int, double> Adist;
241 for (
auto& a : Alist) {
242 Adist[
a] = evaluate_gaussian(ig, PID) / total;
263int KVMultiGaussIsotopeFit::GetA(
double PID,
double& P)
const
277 auto total =
Eval(PID);
281 for (
auto& a : Alist) {
282 auto w = evaluate_gaussian(ig, PID) / total;
303double KVMultiGaussIsotopeFit::GetProbability(
int A,
double PID)
const
310 auto it = std::find(std::begin(Alist), std::end(Alist), A);
311 if (it != std::end(Alist)) {
312 int ig = std::distance(std::begin(Alist), it);
313 return evaluate_gaussian(ig, PID) /
Eval(PID);
325void KVMultiGaussIsotopeFit::SetFitRange(
double min,
double max)
Option_t Option_t SetLineWidth
Option_t Option_t SetLineColor
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Function for fitting PID mass spectra.
double centroid_fit(double *x, double *p)
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Int_t GetIntValue(const Char_t *name) const
Double_t GetDoubleValue(const Char_t *name) const
Strings used to represent a set of ranges of values.
static const TArrayI & GetPalette()
virtual void SetRange(Double_t xmin, Double_t xmax)
virtual TF1 * DrawCopy(Option_t *option="") const
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
virtual void AddPoint(Double_t x, Double_t y)
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0)
virtual void SetName(const char *name)
virtual TObject * FindObject(const char *name) const
virtual Double_t Uniform(Double_t x1, Double_t x2)
double min(double x, double y)
double max(double x, double y)