Fit in TGraphError

Hello,
I’ve maybe a trivial problem, but I’m not able to solve it…
I’m trying to fit a TGraphError with a user-defined function, but the fit seems to not work.
Here is a part of my code:

Double_t func(Double_t *x, Double_t *par)
{
Double_t result=0;
result=(par[2]/(x[0]-par[3]))+par[0] + par[1]*x[0];
return(result);
}

and then in the main function I have:

Double_t range_min=0;
TF1 *f1=new TF1(“f1”,func,range_min,17000,4);
TGraphErrors *gr=new TGraphErrors(npicchi,min,t,smin,dt);
gr->Fit(“f1”,“R”);

and I always get something like this:

FCN=0 FROM MIGRAD STATUS=CONVERGED 171 CALLS 172 TOTAL
EDM=0 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 100.0 per cent
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 0.00000e+00 1.41421e+00 0.00000e+00 0.00000e+00
2 p1 0.00000e+00 1.41421e+00 0.00000e+00 0.00000e+00
3 p2 0.00000e+00 1.41421e+00 0.00000e+00 0.00000e+00
4 p3 0.00000e+00 1.41421e+00 0.00000e+00 0.00000e+00

even if I simply define a linear function as a user-defined function.
Where am I wrong?

Thanks a lot for your help
Cheers
Paola

Hi ,

first of all you need probably to set some sensible initial parameter in your function by calling TF1::SetParameters

Then if you still have a problem, I would need a running script

Best Regards

Lorenzo

Hello Lorenzo,
thanks for your help!
I’ve solved the problem by setting a bigger error on the y axis…then I’ve a question: are the errors on the x axis taken into account during the fit procedure? How are they taken into account? Could I set only the errors on the x axis and set to 0 the ones on the y axis?
Thanks a lot!
Regards

Paola

Hello Paola,

see root.cern.ch/root/htmldoc/TGraph.html#TGraph:Fit
for how the errors are taken into account.
You should also be able to fit data points with only error in x and not in y.

Lorenzo