3 #include <TFitResult.h>
4 #include "TVirtualFitter.h"
10 TF1 * GetDeuteronFitFunction(
double fitMinPt = 0.0,
double fitMaxPt = 0.6,
const string &particle_name =
"deuteron")
13 if (particle_name==
"proton")
15 else if (particle_name==
"deuteron")
21 TF1 * FitD =
new TF1(
"FitD", Form(
"[0]*x*exp(-(sqrt(x*x + %f*%f) - %f)/[1])", mass, mass, mass), fitMinPt, fitMaxPt);
32 vector<TF1*> GetPtSpectraFit (
const vector<TGraphErrors*> vDataGraphs,
33 vector<TGraphErrors*> &vGConfidenceBands,
34 const string &particle_name,
36 double T_initial_guess = 0.0373538,
37 double fitMinPt = 0.0,
38 double fitMaxPt = 0.6,
39 bool LimitParameters =
true)
43 for (
int i = 0; i < int(vDataGraphs.size()); i++)
47 TF1 * FitD = GetDeuteronFitFunction(fitMinPt, fitMaxPt, particle_name);
49 FitD->SetParameters(1e-4, T_initial_guess);
50 if (LimitParameters ==
true)
52 FitD->SetParLimits(0, 1e-4, 6e-3);
53 FitD->SetParLimits(1, 0.010, 0.600);
56 FitD->FixParameter (1, T_initial_guess);
60 TFitResultPtr fit_ptr = vDataGraphs[i]->Fit(FitD,
"NQSWEM",
"", fitMinPt, fitMaxPt);
64 int ngr = vDataGraphs[i]->GetN();
65 TGraphErrors * grint =
new TGraphErrors(ngr);
66 grint->SetName(Form(
"graph_fit_confdinterval_%d", i));
67 for (
int k = 0; k < ngr; k++)
68 grint->SetPoint(k, vDataGraphs[i]->GetX()[k], 0);
71 (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint, 0.95);
85 vGConfidenceBands.push_back(grint);
86 vFits.push_back(FitD);
89 FitD->GetParameters(Param);
92 ParEr[0] = FitD->GetParError(0);
93 ParEr[1] = FitD->GetParError(1);
96 cerr<<Form(
"Fit completed. Normalization = %e +/-%6.2f%%, T = %.8f +/-%6.2f%%, Chi-squared/NDF = %e", Param[0], 100*ParEr[0]/Param[0], Param[1], 100*ParEr[1]/Param[1], fit_ptr->Chi2()/fit_ptr->Ndf())<<endl;
99 if (vGConfidenceBands.size() != vFits.size())
100 cerr<<
"\n\n[WARNING] vGConfidenceBands size != vFits size"<<endl;
108 vector<TF1*> GetPtSpectraFitAndEval (vector<TGraphErrors*> vDataGraphs,
109 vector<TGraphErrors*> &vGConfidenceBands,
110 vector<int> &vMissingPointIndex,
111 const string &particle_name,
113 double T_initial_guess = 0.0373538,
114 double fitMinPt = 0.0,
115 double fitMaxPt = 0.6,
116 bool add_missing_points_from_fit =
false)
119 fixT =
false;
if (particle_name ==
"deuteron") fixT =
true;
120 T_initial_guess = 0.14;
if (particle_name ==
"deuteron") T_initial_guess = 0.0373538;
121 fitMinPt = 0.2;
if (particle_name ==
"deuteron") fitMinPt = 0.0;
122 fitMaxPt = 1.0;
if (particle_name ==
"deuteron") fitMaxPt = 0.6;
123 add_missing_points_from_fit =
false;
if (particle_name ==
"deuteron") add_missing_points_from_fit =
true;
128 for (
int i = 0; i < int(vDataGraphs.size()); i++)
132 TF1 * FitD = GetDeuteronFitFunction(fitMinPt, fitMaxPt);
134 FitD->SetParameters(1e-4, T_initial_guess);
136 FitD->FixParameter (1, T_initial_guess);
139 int ngr = vDataGraphs[i]->GetN();
140 TGraphErrors * grint =
new TGraphErrors(ngr);
141 grint->SetName(Form(
"graph_fit_confdinterval_%d", i));
144 cerr<<
"\n\n[WARNING] TGraphError is empty for i="<<i<<
". Setting fit to zero!"<<endl;
145 FitD->FixParameter (0, 0);
146 vFits.push_back(FitD);
147 vGConfidenceBands.push_back(grint);
151 TFitResultPtr fit_ptr = vDataGraphs[i]->Fit(FitD,
"NQS",
"", fitMinPt, fitMaxPt);
155 if (add_missing_points_from_fit ==
true)
156 AddMissingPointAndErrorToGraphFromFit(vDataGraphs[i], fit_ptr, FitD, vMissingPointIndex,
true);
160 for (
int k = 0; k < ngr; k++)
161 grint->SetPoint(k, vDataGraphs[i]->GetX()[k], 0);
164 (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint, 0.95);
178 vGConfidenceBands.push_back(grint);
179 vFits.push_back(FitD);
182 FitD->GetParameters(Param);
186 ParEr[0] = FitD->GetParError(0);
187 ParEr[1] = FitD->GetParError(1);
190 cerr<<Form(
"Spectrum fit completed. Normalization = %e +/-%6.2f%%, T = %.8f +/-%6.2f%%, Chi-squared/NDF = %e", Param[0], 100*ParEr[0]/Param[0], Param[1], 100*ParEr[1]/Param[1], fit_ptr->Chi2()/fit_ptr->Ndf())<<endl;
193 if (vGConfidenceBands.size() != vFits.size())
194 cerr<<
"\n\n[WARNING] Size of vGConfidenceBands = "<<vGConfidenceBands.size()<<
". Size of vFits = "<<vFits.size()<<endl<<endl;
202 vector<TGraphErrors*> GetFitEvaluatedIntegratedYSpectraGraphs (
const vector<TGraphErrors*> vDataGraphs,
203 vector<TGraphErrors*> &vGConfidenceBands,
205 double T_initial_guess = 0.0373538,
206 double fitMinPt = 0.0,
207 double fitMaxPt = 0.6
210 vector<TGraphErrors*> vIntegratedSpectraGraphs;
212 for (
int i = 0; i < int(vDataGraphs.size()); i++)
215 TF1 * FitD = GetDeuteronFitFunction(fitMinPt, fitMaxPt);
217 FitD->SetParameters(1e-4, T_initial_guess);
219 FitD->FixParameter (1, T_initial_guess);
222 int ngr = vDataGraphs[i]->GetN();
225 cerr<<
"\n\n[WARNING] TGraphError is empty for i="<<i<<
". Moving to next..."<<endl;
227 TGraphErrors * GraphYIntegrated =
new TGraphErrors(ngr);
228 TGraphErrors * GConfidenceBand =
new TGraphErrors(ngr);
229 vIntegratedSpectraGraphs.push_back(GraphYIntegrated);
230 vGConfidenceBands.push_back(GConfidenceBand);
237 TFitResultPtr fit_ptr = vDataGraphs[i]->Fit(FitD,
"NQS",
"", fitMinPt, fitMaxPt);
239 FitD->GetParameters(Param);
243 ParEr[0] = FitD->GetParError(0);
244 ParEr[1] = FitD->GetParError(1);
247 cerr<<Form(
"Spectrum fit completed. Normalization = %e +/-%6.2f%%, T = %.8f +/-%6.2f%%, Chi-squared/NDF = %e", Param[0], 100*ParEr[0]/Param[0], Param[1], 100*ParEr[1]/Param[1], fit_ptr->Chi2()/fit_ptr->Ndf())<<endl;
251 auto GConfidenceBand =
new TGraphErrors(1);
255 TGraphErrors * GraphYIntegrated = GetdndyGraphFromFit(fit_ptr, FitD, vDataGraphs[i], GConfidenceBand, nPoints, i);
257 vGConfidenceBands.push_back(GConfidenceBand);
258 vIntegratedSpectraGraphs.push_back(GraphYIntegrated);
261 if (vGConfidenceBands.size() != vIntegratedSpectraGraphs.size())
262 cerr<<
"\n\n[WARNING] Size of vGConfidenceBands = "<<vGConfidenceBands.size()<<
". Size of vIntegratedSpectraGraphs = "<<vIntegratedSpectraGraphs.size()<<endl<<endl;
263 return vIntegratedSpectraGraphs;