Behaviour of fitting a TProfile histogram

Hello,

I have a TProfile histogram that has all the points lined up in a nice polynomial curve. So I fitted using a TF1 and Trofile->Fit(…). The thing I dont understand is the Fit algorithm fits the curve onto the bottom of the error bars of the points and I get an enourmous chi2/dof.

I have to modify my polynomial to add an extra constant term of 0.004. Then the curve is fit to the central values of the points and my chi2/dof is sensible.

I dont understand why I should have to shift the curve like this. Is this is expected behaviour? I hope someone can explain this behaviour to me.

I am using root 3.10/02 with gcc 3.3.2

Here is my code:

Double_t Poly(Double_t *x, Double_t *par){

return ( par[0]*x[0]+(par[1]*x[0]*x[0]*x[0]) + 0.0004 );

}

void main(){

gStyle->SetOptFit();

TF1 *fit = new TF1(“fit”,Poly,-1,1,2);

fit->SetParameters(1,1);

TFile file = new TFile("/home/markhod/Hists.root");
TProfile
Hist = (TH1D*)file->Get(“HistName;1”);

Hist->Fit(“fit”,“RMQ”);

Hist->Draw();

}

Thanks,

Mark

Could you send your file Hist.root?

Rene

Hi,

I added the file as an attachment. I should say I made the file using root 3.10/03 with gcc 2.95 and then moved the file to my laptop where i have root 3.10/02 with gcc 3.2.2. This shouldnt matter though?

Thanks,

Mark
Hist.root (4.19 KB)

I do not see any problem with your example. see gif file in attachement

Rene


Did you take away the “+0.004” from the poly function first? This is the problem I dont understand. Without this +0.0004 added to the polynomiial the curve will not fit properly - it is fit to the base of the error bars, rather than the central value of each point, which gives a better fit. Why does the fit algorithm not fit the curve in the more reasonable (through the center of the majority of points) position without me forcing it to by adding an extra constant term?

See the plot I attach for what happens if I remove the +0.0004 term from Poly.

Thanks,

Mark


It looks obvious that your profile cannot be fitted without the constant term. To check this, I have added a 3rd parameter to your function, see below. The fit converge with the constant parameter=3.6794e-4

Rene

Double_t Poly(Double_t *x, Double_t *par){

//return ( par[0]*x[0]+(par[1]*x[0]*x[0]*x[0]) + 0.0004 );
return ( par[0]*x[0]+(par[1]*x[0]*x[0]*x[0]) + par[2] );

}

void prfit(){

gStyle->SetOptFit();

TF1 *fit = new TF1(“fit”,Poly,-1,1,3);

fit->SetParameters(1,1,0);

TFile file = new TFile(“Hist.root”);
TProfile
Hist = (TH1D*)file->Get(“hist;1”);

Hist->Fit(“fit”,“RM”);

Hist->Draw();

}