Re-creating the fitted function - different from original?

Dear all,

I am using root v.5.15/06 and recently I found that when I fit the plot with pol9 (polX) function, I am not able to re-create this function again later. I will explain:

First I have the plot with some errors. Then I fit interactively (in the canvas window) using pol9 and intervals from -2.7 to -1.5… I get the parameter values for all 10 parameters.

Second step is to recreate this function so I can use it lately in my different code. For this I simply define my own pol9 function,

TF1* fit_logyjb = new TF1(“fit_logyjb”,“pol9”,-2.7, -1.5)

and copy all 10 parameters from the fitted function, using

fit_logyjb->SetParameters(par0, par1, par2, etc…)

As a cross-check I wanted to compare the “new” function with the fitted one. I expected exactly the same function (i.e.lines in the canvas would overlay), but that’s not the case (please, see the attachment).

Black function is the one that is FITTED, the red one is RECREATED using the same parameters of the fitted function. I verified that the parameters are the same in both functions.

This also happens when trying to fit and recreate another polynomials…

Do you know if this should be the correct way to get the same function as the fitted one? What I am missing/doing wrong?

Thank you very much for any hint,

Best regards,
Tomas
test.ps (11.5 KB)

Please provide the shortest possible RUNNING macro reproducing your problem.

Rene

I think I understood (partially) the problem, but I still have question:

Here is the working example (test.C). It

  1. reads histogram in test.root file and fit it with pol9 (black function)

  2. new function “newfit” is created using copy&paste of all parameters from the screen (red function)

Look at the printout:
when you compare the printout of parameters of both functions, they are the same, BUT

When I make the exact difference between parameters (inside the loop), you see that they are NOT exactly the same

And here is the point - the printout parameters are ROUNDED and therefore cannot be used to properly recreate the fitted function. The proof of it is the blue function which I create using “double” type when reading the original parameters.

Now I understand the problem, but still, I would like to know how can I properly recreate the original function without reading the histo stored in file and fitting it again??

For my analysis workflow it would be much better to fit this histo only once, then create the function within some class constructor (or whatever) and forget it…

Is it possible somehow to printout each parameter with let’s say the double precision, or is there some other possibility to “manually” set all the parameters exactly?

Thank you very much again,

Tomas
test.root (4.04 KB)
test.C (1.55 KB)

Hi Tomas,
try functions TF1::GetParameters(), TF1::SetParameters()

... ratio->Fit("pol9", "", "",-2.7, -1.5); Double_t *par = pol9->GetParameters(); // or more "complex" // Double_t *par = ((TF1*)(ratio->FindObject("pol9")))->GetParameters(); TF1* newfit = new TF1("newfit", "pol9", -2.7, -1.5); newfit->SetParameters(par); newfit->SetLineColor(kRed); newfit->Draw("same");Jan

Dear Jan,

thank you for help - indeed, I started to use something similar - to printout parameters with double precision and then feed them back into newfit.

Vdaka moc,

Cheers,
Tomas