12#include "Math/ChebyshevPol.h"
19Double_t pol5pol1(Double_t* x, Double_t* par)
25 f = par[0] + par[1] * xx + par[2] * xx * xx + par[3] * xx * xx * xx + par[4] * xx * xx * xx * xx + par[5] * xx * xx * xx * xx * xx;
29 ctp = par[0] + par[1] * x6 + par[2] * x6 * x6 + par[3] * x6 * x6 * x6 + par[4] * x6 * x6 * x6 * x6 + par[5] * x6 * x6 * x6 * x6 *
31 f = par[7] * x2 + ctp;
40Double_t Cheb5pol1(Double_t* x, Double_t* par)
47 f = ROOT::Math::Chebyshev5(xx, par[0], par[1], par[2], par[3], par[4], par[5]);
51 ctp = ROOT::Math::Chebyshev5(x6, par[0], par[1], par[2], par[3], par[4], par[5]);
52 f = par[7] * x2 + ctp;
65 explicit XT(TProfile* h1)
67 m_h1 = (TProfile*)h1->Clone();
68 m_h1->SetDirectory(0);
73 XT(TProfile* h1,
int mode)
75 m_h1 = (TProfile*)h1->Clone();
76 m_h1->SetDirectory(0);
83 XT(TH1D* h1,
int mode)
85 m_h1 = (TProfile*)h1->Clone();
86 m_h1->SetDirectory(0);
117 for (
int i = 0; i < 8; ++i) {
m_XTParam[i] = p[i];}
124 double p4,
double p5,
double p6,
double p7)
181 if (mode == 0)
return xtpol5;
225 TF1*
xtpol5 =
new TF1(
"xtpol5", pol5pol1, 0.0, 700, 8);
226 TF1*
xtCheb5 =
new TF1(
"xtCheb5", Cheb5pol1, 0.0, 700, 8);
252 double max_dif = 0.12;
253 double max_dif2 = 0.05;
256 TF1* f1 = (TF1*)
m_h1->GetFunction(
"pol1");
257 double p0 = f1->GetParameter(0);
258 double p1 = f1->GetParameter(1);
259 double f10 = f1->Eval(10);
265 xtpol5->SetParLimits(7, 0.0, 0.001);
266 xtpol5->SetParLimits(1, 0.0, 0.01);
268 xtpol5->SetParLimits(7, 0.0, 0.01);
269 xtpol5->SetParLimits(1, 0.0, 0.01);
272 for (
int i = 0; i < 10; ++i) {
274 std::cout <<
"Fitting" << std::endl;
276 xtpol5->GetParameters(par);
279 double fp6 =
xtpol5->Eval(par[6]);
280 double fbehindp6 =
xtpol5->Eval(par[6] - 12) - 0.01;
281 if (fp6 < fbehindp6 || fp6 > 1) {
284 xtpol5->SetParameters(p0, p1, 0, 0, 0, 0, p6default, 0);
285 xtpol5->SetParLimits(6, p6default - 10, p6default + 10 - out / 2);
287 if (
m_tmax < p6default + 30) {
293 if (fabs(par[0] - p0) > max_dif || fabs(f10 -
xtpol5->Eval(10)) > max_dif2) {
295 if (i == 9) std::cout <<
"ERROR XT FIT inner part" << std::endl;
296 xtpol5->SetParameters(p0, p1, 0, 0, 0, 0, p6default, 0);
297 xtpol5->SetParLimits(1, 0, 0.08);
301 m_tmin = 14; std::cout <<
"ERROR: tmin so small, fit iter: " << std::endl;
307 if (
m_debug) {std::cout <<
"FIT Failure; Layer: " << std::endl;}
310 if (
m_debug) {printf(
"P6default= %3.2f, p6 fit = %3.2f", p6default, par[6]);}
313 if (
m_debug) std::cout <<
"Fit success" << std::endl;
321 TString hname =
m_h1->GetName();
322 TString name = hname +
".pdf";
323 TCanvas* c1 =
new TCanvas(
"c1",
"", 800, 600);
325 xtpol5->SetLineColor(kBlack);
326 xtpol5->DrawF1(0, 400,
"same");
342 xtCheb5->SetParLimits(7, 0., 0.001);
344 m_h1->GetFunction(
"chebyshev5")->GetParameters(p);
345 xtCheb5->SetParameters(p[0], p[1], p[2], p[3], p[4], p[5],
m_XTParam[6], 0.000);
348 for (
int i = 0; i < 10; ++i) {
351 xtCheb5->SetParameters(p[0], p[1], p[2], p[3], p[4], p[5],
m_XTParam[6] - 20, 0.000);
357 double fp6 =
xtCheb5->Eval(par[6]);
358 double fbehindp6 =
xtCheb5->Eval(par[6] - 10) - 0.005;
359 if (fp6 < fbehindp6 || fp6 > 1) {
362 xtCheb5->SetParameters(p[0], p[1], p[2], p[3], p[4], p[5], par[6] - 20, 0.000);
363 xtCheb5->SetParLimits(6, par[6] - 50, par[6] - 10);
382 TString hname =
m_h1->GetName();
383 TString name = hname +
".pdf";
384 TCanvas* c1 =
new TCanvas(
"c1",
"", 800, 600);
387 xtCheb5->DrawF1(0, 400,
"same");
Class to perform fitting for each xt function.
bool m_BField
With magnetic field or not.
void setXTParams(const double p[8])
Set Parameters for fit.
int m_minRequiredEntry
Minimum entry required for each histo.
double m_FittedXTParams[8]
Fitted parameters.
XT(TProfile *h1)
Initialized with TProfile histogram.
void setP6(double p6)
Set Parameter 6 for polynomial fit.
void setFitRange(double tmin, double tmax)
Set Fit range.
void FitChebyshev()
Fit xt histogram incase 5th order Chebeshev polynomial is used.
double getProb()
Get the chi2 probability.
TF1 * getXTFunction()
Get XT function.
XT(TH1D *h1, int mode)
Initialized with TH1D histogram and mode.
int m_mode
XT mode, 0 is for 5th order polynomial, 1 is Chebshev polynomial.
int m_fitflag
Fit Flag =-1: low statitic =1: good =0: Fit failure =2: Error Outer =3: Error Inner part;.
bool m_debug
Print debug durring fitting or not.
TF1 * xtpol5
5th order polynomial function
void setDebug(bool debug)
Set Debug.
void FitXT(int mode)
Do fitting.
double m_Prob
Chi2 prob of fitting.
void setMode(int mode)
Set XT mode.
TF1 * xtCheb5
5th order Cheb.
void setSmallestEntryRequired(int min)
Set minimum number of entry required for fit.
double m_tmin
lower boundary of fit range
double m_tmax
upper boundary of fit range
void getFittedXTParams(double pa[8])
get fit parameters.
void setXTParams(double p0, double p1, double p2, double p3, double p4, double p5, double p6, double p7)
Set Initial parameters for fitting.
TProfile * m_h1
Histogram of xt relation.
TF1 * getXTFunction(int mode)
Get XT function.
bool m_draw
Draw and store png plot of each histo or not.
double m_XTParam[8]
Parameter fo xt.
XT(TProfile *h1, int mode)
Initialized with TProfile histogram and mode.
TProfile * getFittedHisto()
Get histogram.
void FitPol5()
Fit xt histogram incase 5th order polynomial is used.
int getFitStatus()
get fitted flag.
void BField(bool bfield)
set to use BField