12#include "Math/ChebyshevPol.h"
33 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;
37 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 *
39 f = par[7] * x2 + ctp;
55 f = ROOT::Math::Chebyshev5(xx, par[0], par[1], par[2], par[3], par[4], par[5]);
59 ctp = ROOT::Math::Chebyshev5(x6, par[0], par[1], par[2], par[3], par[4], par[5]);
60 f = par[7] * x2 + ctp;
76 m_h1 = (TProfile*)h1->Clone();
77 m_h1->SetDirectory(0);
78 if (
m_mode == c_Chebyshev) {
89 m_h1 = (TProfile*)h1->Clone();
90 m_h1->SetDirectory(0);
92 if (
m_mode == c_Chebyshev) {
105 m_h1 = (TProfile*)h1->Clone();
106 m_h1->SetDirectory(0);
108 if (
m_mode == c_Chebyshev) {
131 for (
int i = 0; i < 8; ++i) {
155 for (
int i = 0; i < 8; ++i) {
203 for (
int i = 0; i < 8; ++i) {
m_XTParam[i] = p[i];}
210 double p4,
double p5,
double p6,
double p7)
279 if (
m_mode == c_Polynomial) {
281 }
else if (
m_mode == c_Chebyshev) {
284 B2ERROR(
"Undefined fitting function");
333 if (
m_mode != c_Polynomial) {
334 B2ERROR(
"Fitting function is wrong");
336 double max_dif = 0.12;
337 double max_dif2 = 0.05;
340 TF1* f1 = (TF1*)
m_h1->GetFunction(
"pol1");
341 double p0 = f1->GetParameter(0);
342 double p1 = f1->GetParameter(1);
343 double f10 = f1->Eval(10);
357 for (
int i = 0; i < 10; ++i) {
359 std::cout <<
"Fitting" << std::endl;
365 double fbehindp6 =
m_fitFunc->Eval(par[6] - 12) - 0.01;
366 if (fp6 < fbehindp6 || fp6 > 1) {
369 m_fitFunc->SetParameters(p0, p1, 0, 0, 0, 0, p6default, 0);
370 m_fitFunc->SetParLimits(6, p6default - 10, p6default + 10 - out / 2);
372 if (
m_tmax < p6default + 30) {
378 if (fabs(par[0] - p0) > max_dif || fabs(f10 -
m_fitFunc->Eval(10)) > max_dif2) {
380 if (i == 9) std::cout <<
"ERROR XT FIT inner part" << std::endl;
382 m_fitFunc->SetParameters(p0, p1, 0, 0, 0, 0, p6default, 0);
387 m_tmin = 14; std::cout <<
"ERROR: tmin so small, fit iter: " << std::endl;
393 if (
m_debug) {std::cout <<
"FIT Failure; Layer: " << std::endl;}
396 if (
m_debug) {printf(
"P6default= %3.2f, p6 fit = %3.2f", p6default, par[6]);}
399 if (
m_debug) std::cout <<
"Fit success" << std::endl;
406 if (
m_debug) B2INFO(
"Number of failures due to inner (outer) regions " << in <<
"(" << out <<
")");
409 TString hname =
m_h1->GetName();
410 TString name = hname +
".pdf";
411 TCanvas* c1 =
new TCanvas(
"c1",
"", 800, 600);
422 const double p6 =
m_fitFunc->GetParameter(6);
424 B2WARNING(
"Bad xt function");
427 }
else if (p6 < 50.0) {
428 B2WARNING(
"Unrealistic p6");
438 if (
m_mode != c_Chebyshev) {
439 B2ERROR(
"Fitting function is wrong");
448 double par[8] = {0.0};
451 if (fitresult >= 0) {
452 m_h1->GetFunction(
"chebyshev5")->GetParameters(par);
453 m_fitFunc->SetParameters(par[0], par[1], par[2], par[3], par[4], par[5],
m_XTParam[6], 0.000);
456 for (
int i = 0; i < 10; ++i) {
459 m_fitFunc->SetParameters(par[0], par[1], par[2], par[3], par[4], par[5],
m_XTParam[6] - 20, 0.000);
474 double fbehindp6 =
m_fitFunc->Eval(par[6] - 10) - 0.005;
475 if (fp6 < fbehindp6 || fp6 > 1) {
478 m_fitFunc->SetParameters(par[0], par[1], par[2], par[3], par[4], par[5], par[6] - 20, 0.000);
479 m_fitFunc->SetParLimits(6, par[6] - 50, par[6] - 10);
500 TString hname =
m_h1->GetName();
501 TString name = hname +
".pdf";
502 TCanvas* c1 =
new TCanvas(
"c1",
"", 800, 600);
Class to perform fitting for each xt function.
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.
bool validate()
Validate the xt has proper shape.
void setP6(double p6)
Set Parameter 6 for polynomia fit.
void setFitRange(double tmin, double tmax)
Set Fit range.
void FitChebyshev()
Fit xt histogram incase 5th order Chebeshev polynomial is used.
XTFunction & operator=(const XTFunction &x)
Assignment operator.
double getProb()
Get the chi2 probability.
TF1 * getXTFunction()
Get XT function.
TF1 * m_fitFunc
Fit function.
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.
XTFunction(TProfile *h1, int mode)
Initialized with TProfile histogram and mode.
XTFunction(TH1F *h1, int mode)
Initialized with TH1D histogram and mode.
void setDebug(bool debug)
Set Debug.
double m_Prob
Chi2 prob of fitting.
bool m_bField
With magnetic field or not.
void setMode(int mode)
Set XT mode.
void setBField(bool bfield)
set to use BField
void setSmallestEntryRequired(int min)
Set minimum number of entry required for fit.
double m_tmin
lower boundary of fit range
XTFunction(const XTFunction &x)
Copy constructor.
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.
bool m_draw
Draw and store png plot of each histo or not.
XTFunction(TProfile *h1)
Initialized with TProfile histogram.
double m_XTParam[8]
Parameter fo xt.
TProfile * getFittedHisto()
Get histogram.
void FitPol5()
Fit xt histogram incase 5th order polynomial is used.
int getFitStatus()
get fitted flag.
Double_t cheby5pol1(Double_t *x, Double_t *par)
helper function to initialize xt function with 5th order Chebshev Polynomial + linear.
Double_t pol5pol1(Double_t *x, Double_t *par)
helper function to initialize xt function with 5th order polynomial + linear.
Abstract base class for different kinds of events.