Fitting problem with TGraph and TF1 in 5.27

Hi,

I posted this originally in the PyRoot section http://root.cern.ch/phpBB3//viewtopic.php?f=14&t=12701, but have since verified that I see the same thing in Cint as well.

{
   const Double_t yVal[3] = {0.95, 1, 1.1};
   const Double_t xVal[3] = {-1, 0, 1};
   TCanvas *canvas = new TCanvas;
   TGraph *graph = new TGraph ( 3, xVal, yVal);
   graph->SetMarkerStyle (20);
   graph->SetMarkerColor (kRed);
   graph->SetMarkerSize  (1.4);
   graph->SetMaximum (1.3);
   graph->SetMinimum (0.7);
   TF1 *fun = new TF1("fun", "pol2");
   fun->FixParameter(0, 1);
   graph->Fit (fun);
   graph->Draw ("AP");
   canvas->Print ("fit.png");
}

Produces a good fit in 5.22:

[code]root [0]
Processing fitSTC.C…


Minimizer is Linear
Chi2 = 6.16298e-32
NDf = 0
Par_0 = 1 (fixed)
Par_1 = 0.075 +/- 0.707107
Par_2 = 0.025 +/- 0.707107
Info in TCanvas::Print: file fit.png has been created
root [1] .q
[/code]

But messes the fit up in 5.27.06b

Processing fitSTC.C...

****************************************
Minimizer is Linear
Chi2                      =            2
NDf                       =            0
p0                        =            1                         (fixed)
p1                        =        0.075   +/-   0.707107    
p2                        =        1.025   +/-   0.707107    
Info in <TCanvas::Print>: file fit.png has been created

One thing that is peculiar is that the fit parameter p1 (or par_1) has the same value, but p2/par_2 value differ by exactly 1.

Cheers,
Charles

One addition point (for the poor souls who are debugging this):

If I change “pol2” to “pol1”, the fit now works as expected in both 5.27 as well as 5.22.

Hi Charles,

Maybe this is something quite obscure, but when fixing or setting bounds on predefined functions, like
"polN", “gaus” , “landau”, etc…, one needs to use the fit option “B”

Cheers, Lorenzo

Hi Lorenzo,

[quote=“moneta”]Maybe this is something quite obscure, but when fixing or setting bounds on predefined functions, like
"polN", “gaus” , “landau”, etc…, one needs to use the fit option “B”
[/quote]

Thanks! It is, well, obscure. :slight_smile: Why did it work before? Is this really only necessary for built-in functions? (Even if I coded up the same function by hand?)

Thanks,
Charles

Hi Charles,

I was too fast before. Looking more deeply in your example, there is actually a bug (versions >= 5.26) when doing linear fits with fixed parameters.
As a workaround, you can use option F (or option B) which switch automatically to use Minuit instead of the linear fitter.
The bug is now fixed in the current trunk. Thanks a lot for reporting this problem

Best Regards

Lorenzo