Problem with TFormula

Hello, after I changed to ROOT v6 I got a weir error when running a fitting script.

The error looks like this

Double_t TFormula____id14364857767516896690(Double_t *x,Double_t *p){ return p[2]*(1+2*TMath::Power(p[0])*0.8*TMath::Cos(TMath::DegToR...
                                                                                       ^~~~~~~~~~~~
/usr/local/Cellar/root6/6.08.06/include/root/TMath.h:501:28: note: candidate function not viable: requires 2 arguments, but 1 was provided
inline LongDouble_t TMath::Power(LongDouble_t x, LongDouble_t y)
Error in <TFormula::Eval>: Can't find TFormula____id14364857767516896690 function prototype with arguments Double_t*,Double_t*
Error in <TFormula::Streamer>: number of parameters computed (3) is not same as the stored parameters (2)
               fitpsi : [0]*(1+2*[1]*0.8*cos(TMath::DegToRad()*2*(x))) Ndim= 1, Npar= 3, Number= 0 

If you check the line where the fitpsi FIt is located (line 5 or 6 from top to bottom), there is no TMath::Power used there.

From the error you get, it looks like you wrongly define your function. Make sure, you have written

Double_t yourFormula(Double_t *x, Double_t *p) { //your function code }
It seems the “_” is missing before the “x” variable

Hi,

what is the actual formula which does not work? Could you paste the code rather than the image?

Cheers,
D

the line of code is this one:

 TF1* fitpsi = new TF1("fitpsi","[0]*(1+2*[1]*0.8*cos(TMath::DegToRad()*2*(x)))");

the error I get is:

Double_t TFormula____id454975941475839924(Double_t *x,Double_t *p){ return p[2]*
(1-TMath::Power(p[0])*TMath::Cos(TMath::DegToRad()*2*(...

Can it be that some of your histograms (or graphs) come from an “old” root file (i.e. produced by ROOT 5)?
If yes then, if you fitted them with ROOT 5, they may have functions stored in them (with the “old” ROOT 5 formulas) and this may now create problems when the “new” ROOT 6 tries to deal with these “old” formulas.
Well, actually, you might even have standalone “function objects” stored in your “old” ROOT 5 produced files.

They were indeed produced for a version of root 5. How can I deal with the issue? re-write the code?
Is there a work-around that I can use?

Note: “old” histograms / graphs are not a problem, unless they have some “associated functions” from ROOT 5 (i.e. if you fitted them with ROOT 5 and then stored in a root file which you now try to read with ROOT 6).

I compile another macro with root 6, then I take the .root file produced and the histograms created there are the ones that I fit using this code.

Maybe you need to attach your root file here, plus a small macro which reproduces your problem.

Hi,

this is not possible. The error seems to be relative to another function.
The error seems to point to a formula which contains a mistake: a power function is called with one argument only and cling does not manage to compile this (as the function takes two arguments).
Indeed the error says:

include/root/TMath.h:501:28: note: candidate function not viable: requires 2 arguments, but 1 was provided
inline LongDouble_t TMath::Power(LongDouble_t x, LongDouble_t y)

Having the possibility to deal with the file can shed some light on this.

Cheers,
D

Hi,

Which ROOT version are you using ?
If you are using a version older than 6.10, it would be nice to try with the latest version.
However we would need your macro and eventually needed files to understand the problem

Thank you

Lorenzo

Here are the files I use respectively

This one produces a root file:sdmes_1.3.root (86.3 KB)

and this is the one that shows the problemSDEMs_ext.C (40.5 KB)

signal2noise_voigt_sdmes.txt is missing.

signal2noise_voigt_sdmes.txt (100 Bytes)

Well, I get no problems apart from many fitting errors.
It seems you never set initial values of your functions’ parameters (before fitting) and you should fix this (i.e. “reasonable” initial parameters are really crucial).
See:
SDEMs_ext.C.root_v6.10.00.out.txt.gz (3.8 KB)
sdmes_pars_1.3.root_v6.10.00.root (86.1 KB)

I get the same output, but the errors pops up when I open a TBrowser and try to check up the produced histograms.

See my improved reply above … I attached the produced root file (I can open all histograms in a TBrowser without any problems).

I just checked it, it blows up when I try the third histogram. Then it is something with my root version, root_v6.08.02.macosx64-10.10-clang70.dmg.
I get the same error for root 6.08.02 in ubuntu as well as in macOS.

:frowning: help please!!!

I tried “v6.08.06” and it indeed dies.
But “v6.09.02” and “v6.10.00” are fine.
So, try to upgrade your ROOT version to the newest one.

It works!!!

Thanks so much!!