Fitting problem

Hello,

I have a user-defied function: sqrt(a²/E +b² + c²/E²) whiich I want to fit a TGraph(Errors), but Its not working. I followed the myfit.c exaple and defined that function like this:

Double_t fitf(Double_t *x, Double_t *par)
{
Double_t arg = 0;
Double_t arg1 = 0;
if (x[0] != 0) arg = (par[0]*par[0])/x[0];
if (x[0] != 0) arg1 = (par[2]*par[2])/(x[0]*x[0]);
Double_t fitval = sqrt( arg + par[1]*par[1] + arg1 );
}
and set initial values as following:
TF1 *fitf = new TF1(“fitf”,fitf,5,.1,.1);
fitf->SetParameters(10,0.5,0.4);
fitf->SetParNames(“a”,“b”,“c”);

The full file is attached to this post.
And it is not drawing the errors as well :frowning:

Can anyone tell what is going wrong here?

Thanks
eta_energi.c (6.15 KB)

Can anyone please help…?

There is (at least) one thing wrong in your script. The line
TF1 *fitf = new TF1(“fitf”,fitf,5,.1,.1);
does not make much sense. You are supposed to specified
xmin,xmax,number_of_params instead of 5,.1,.1

Fix this problem first. If you still have problems and you expect a prompt reply, please provide the necessary files to run your setup.
We need only the definition of your TGraphErrors point. In particular
we do not need your Tree file, etc.

Rene

After correcting for that, its still now fitting the TGraphErrors. On the screen am I getting the initial parameter values.

Its also not plotting the errors:-(

I have attached the necessary files to run it. My TGraphErrors points are in the TTree, so I am sending TTree. There are 8 trees because the sigma.c program is getting points from 8 different TTrees (8 different energies).

Thanks!
ntuple10.root (306 KB)
ntuple1.root (437 KB)
sigma.c (4.89 KB)

Your script sigma.C is creating a TChain with plenty of files in directories like
ntuples/elec_100_eta1/Ntuple*.root
However, you sent only two files. I commented all the chain.Add lines and replaced them by
chain.Add(“ntuple*.root”);
This takes your two files ntuple1.root and ntuple2.root.
With this change the script runs and the TGraphErrors generated at the end contains only two points. Hence fitting with 3 parameters is not going to work well.
If you suspect that your problem (which problem?) is in fitting the TGraphErrors, please send the smallest possible script creating the TGraphErrors with the few points and the instructions to fit it.

Rene