Fitting of a TGraph2D with a 3D straight line
run this macro by doing:
Processing /mnt/build/workspace/root-makedoc-v614/rootspi/rdoc/src/v6-14-00-patches/tutorials/fit/line3Dfit.C...
Total Initial distance square = 8.65172e+07
Total final distance square 19988
****************************************
Minimizer is Minuit / Migrad
MinFCN = 19988
NDf = 0
Edm = 6.31385e-10
NCalls = 257
Par_0 = 10.3552 +/- 0.39454
Par_1 = 19.9602 +/- 0.0689483
Par_2 = 0.999198 +/- 0.0444211
Par_3 = 2.00379 +/- 0.00780946
(int) 0
#include <cassert>
void line(
double t,
const double *p,
double &x,
double &y,
double &z) {
x = p[0] + p[1]*t;
y = p[2] + p[3]*t;
z = t;
}
struct SumDistance2 {
double distance2(double x,double y,double z, const double *p) {
return d2;
}
assert(fGraph != 0);
double * x = fGraph->
GetX();
double * y = fGraph->
GetY();
double * z = fGraph->
GetZ();
int npoints = fGraph->
GetN();
double sum = 0;
for (int i = 0; i < npoints; ++i) {
double d = distance2(x[i],y[i],z[i],par);
}
if (first) {
std::cout << "Total Initial distance square = " << sum << std::endl;
}
first = false;
}
};
{
double p0[4] = {10,20,1,2};
double err = 1;
}
SumDistance2 sdist(gr);
double pStart[4] = {1,1,1,1};
if (!ok) {
Error(
"line3Dfit",
"Line3D Fit failed");
return 1;
}
std::cout <<
"Total final distance square " << result.
MinFcnValue() << std::endl;
int n = 1000;
double t0 = 0;
double dt = 10;
for (
int i = 0; i <
n;++i) {
}
for (
int i = 0; i <
n;++i) {
}
return 0;
}
return line3Dfit();
}
- Author
- Lorenzo Moneta
Definition in file line3Dfit.C.