Problem with fit parameters

Hi,
I’ve tried to do a linear fit over some istograms using the TH1F method Fit().
At first, I’ve defined a function named fit2 asTF1* fit2 = new TF1(“lin_fit2”,“pol1”),
then I’ve used for an istogram, say h, the TH1F method h->Fit(“lin_fit2”,“N”,"",-1,1).
Moreover I’ve used the method GetParError() in order to obtain the errors over the parameters.
The problem is that sometimes I get the correct values of the parameters but for the errors I get NAN! :confused:
I’ve tried to do the calculation by myself and I’ve obtained a value also for the errors!
This occours only in few istograms! :question:
What can I do?
Thanks
Best Regard
Dario

:slight_smile: :slight_smile:

Could you send a very short script + the histogram file showing this problem?

Rene

Hi,
here is two attachments with the file with the istogram and the script that makes the fit.
The problem occours also if I make the fit by the FitPanel menu.
Thank you for your help.
Dario
script_2.C (197 Bytes)
istog.root (3.51 KB)

Hi dario,

Your histogram is totally symmetric around x=0 and y=0.
When fitting with simple functions, ROOT estimates the initial values of the parameters. It turns out that these initial values are the final values in case there is nothing to minimize. In your example a straight line fit is the perfect model. In this case, ROOT/Minuit cannot improve on the initil values and the covariance matrix is not even computed.
You can bypass this very special case in setting initial values for your parameters and specyfying teh option “B” when fitting, as shown in your example modified:

void script_2(TString filename=“istog.root”){
TFile file = new TFile(filename);
h->Draw();
TF1
fit1 = new TF1(“lin_fit1”,“pol1”,-1,1);
fit1->SetParameters(0,1);
h->Fit(“lin_fit1”,“BN”);
fit1->Draw(“same”);
}

When you run this script, you will get;

root [4] .x script_2.C
FCN=11.3787 FROM MIGRAD STATUS=CONVERGED 25 CALLS 26 TOTAL
EDM=4.58584e-20 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 0.00000e+00 2.85924e-03 1.92455e-04 2.55715e-10
2 p1 2.28919e-02 4.95887e-03 2.88682e-05 6.10717e-08

Rene