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
Processing /mnt/build/workspace/root-makedoc-v614/rootspi/rdoc/src/v6-14-00-patches/tutorials/fit/fitLinear.C...
****************************************
Minimizer is Linear
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
Chi2 = 46.7362
NDf = 38
p0 = 1.0005 +/- 0.0242765
p1 = 0.985942 +/- 0.0279149
****************************************
Minimizer is Linear
Chi2 = 43.6161
NDf = 38
p0 = -2.04095 +/- 0.0220454
p1 = 1.01171 +/- 0.00904363
void fitLinear()
{
"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");
}
{
if (p==2) {
e[i] = 0.1;
}
}
if (p==3) {
y[i] = -7 + 2*x[i]*x[i] + x[i]*x[i]*x[i]+ r.
Gaus()*0.1;
e[i] = 0.1;
}
}
if (p==4) {
e[i] = 0.1;
}
}
}
- Author
- Anna Kreshuk
Definition in file fitLinear.C.