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
{
double *
x =
new double[
n];
double *
y =
new double[
n];
double *
e =
new double[
n];
"Fitting 3 TGraphErrors with linear functions");
TF1 *f3 =
gre3->GetFunction(
"pol3");
TF1 *f2 =
new TF1(
"f2",
"sin(x) ++ sin(2*x)", -2, 2);
f2 =
gre2->GetFunction(
"f2");
gre4->Fit(
"1 ++ exp(-x)");
TF1 *f4 =
gre4->GetFunction(
"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");
}
{
int i;
}
}
y[i] = -7 + 2*
x[i]*
x[i] +
x[i]*
x[i]*
x[i]+
r.Gaus()*0.1;
}
}
}
}
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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.
A TGraphErrors is a TGraph with error bars.
This class displays a legend box (TPaveText) containing several legend entries.
virtual void SetName(const char *name)
Set the name of the TNamed.
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.