Example of fitting with a linear function, using TLinearFitter This example is for a TGraphErrors, but it can also be used when fitting a histogram, a TGraph2D or a TMultiGraph
****************************************
Minimizer is Linear / Migrad
Chi2 = 36.5406
NDf = 36
p0 = -7.07142 +/- 0.0233493
p1 = -0.0194368 +/- 0.0354128
p2 = 2.03968 +/- 0.0136149
p3 = 1.00594 +/- 0.0139068
****************************************
Minimizer is Linear / Migrad
Chi2 = 46.7362
NDf = 38
p0 = 1.0005 +/- 0.0242765
p1 = 0.985942 +/- 0.0279149
****************************************
Minimizer is Linear / Migrad
Chi2 = 43.6161
NDf = 38
p0 = -2.04095 +/- 0.0220454
p1 = 1.01171 +/- 0.00904363
void makePoints(
int n,
double *
x,
double *
y,
double *
e,
int p);
void fitLinear()
{
double *
x =
new double[
n];
double *
y =
new double[
n];
double *
e =
new double[
n];
"Fitting 3 TGraphErrors with linear functions");
makePoints(
n,
x,
y,
e, 3);
makePoints(
n,
x,
y,
e, 2);
TF1 *f2 =
new TF1(
"f2",
"sin(x) ++ sin(2*x)", -2, 2);
makePoints(
n,
x,
y,
e, 4);
gre4->
Fit(
"1 ++ exp(-x)");
leg->AddEntry(gre3,
" -7 + 2*x*x + x*x*x",
"p");
leg->AddEntry(gre2,
"sin(x) + sin(2*x)",
"p");
leg->AddEntry(gre4,
"-2 + exp(-x)",
"p");
}
void makePoints(
int n,
double *
x,
double *
y,
double *
e,
int p)
{
int i;
}
}
y[i] = -7 + 2*
x[i]*
x[i] +
x[i]*
x[i]*
x[i]+
r.Gaus()*0.1;
}
}
}
}
}
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
A TGraphErrors is a TGraph with error bars.
TF1 * GetFunction(const char *name) const
Return pointer to function with name.
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0)
Fit this graph with function with name fname.
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
This class displays a legend box (TPaveText) containing several legend entries.
virtual void SetName(const char *name)
Set the name of the TNamed.
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
This is the base class for the ROOT Random number generators.
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
- Author
- Anna Kreshuk
Definition in file fitLinear.C.