Hi, I had some code using TF1
which stopped working properly after moving root-5 -> root-6. I’ve found in doc that new TFormula
behind TF1
has changed. Fine for me, however I found weird, inconsistent behavior of parameter enumeration. Maybe you can shine some light on it why it works like this.
Outputs below comes from TF1::print("V");
call.
I have two functions, on is a weighted sum of two gaussians. In the very fits version it was just plain sum, so it had 6 parameters: N1
, mean1
, sigma1
, N2
, mean2
, sigma2
. Later on it was turned into weighted sum with common mean, so params become: N
, mean
, sigma1
, dummy
, r
, sigma2
. r
replaced the old N2
, dummy
is in place for the old mean2
to keep backward compatibility. When printing, I get:
Formula based function: f_h_SignalInvMass_sig
f_h_SignalInvMass_sig : s2gs Ndim= 1, Npar= 5, Number= 0
Formula expression:
([p0]*([p4]/([p2]*TMath::Sqrt(2.0*TMath::Pi()))*TMath::Exp(-0.5*pow(((x-[p1])/[p2]),2))+(1.0-[p4])/([p5]*TMath::Sqrt(2.0*TMath::Pi()))*TMath::Exp(-0.5*pow(((x-[p1])/[p5]),2))))
List of Variables:
Var 0 x = 0.000000
List of Parameters:
Par 0 p0 = 0.000000
Par 1 p1 = 0.000000
Par 2 p2 = 0.000000
Par 3 p4 = 0.000000
Par 4 p5 = 0.000000
Expression passed to Cling:
Double_t TFormula____id2933220127093106735(Double_t *x,Double_t *p){ return (p[0]*(p[3]/(p[2]*TMath::Sqrt(2.0*TMath::Pi()))*TMath::Exp(-0.5*TMath::Power(((x[0]-p[1])/p[2]),2))+(1.0-p[3])/(p[4]*TMath::Sqrt(2.0*TMath::Pi()))*TMath::Exp(-0.5*TMath::Power(((x[0]-p[1])/p[4]),2)))) ; }
p3
is missing as it is not in the formula, that is fine, the param numbers goes 0…4. I the root version it was 1-1 enumeration, so my function had 6 parameters (tested with ROOT::v5::TFormula
):
Par 0 p0 = 0
Par 1 p1 = 0
Par 2 p2 = 0
Par 3 p3 = 0
Par 4 p4 = 0
Par 5 p5 = 0
This brought me some troubles but can handle it.
But now I have another function, which is background and is supposed to be concatenated to signal function above. Thus it params start with index 6. But when I print it:
Formula based function: f_h_SignalInvMass_bkg
f_h_SignalInvMass_bkg : pol5(6)+aexpo Ndim= 1, Npar= 15, Number= 0
Formula expression:
([p6]+[p7]*x+[p8]*pow(x,2)+[p9]*pow(x,3)+[p10]*pow(x,4)+[p11]*pow(x,5))+([p12]*exp([p13]*(x-[p14])))
List of Variables:
Var 0 x = 0.000000
List of Parameters:
Par 0 p0 = 0.000000
Par 1 p1 = 0.000000
Par 2 p2 = 0.000000
Par 3 p3 = 0.000000
Par 4 p4 = 0.000000
Par 5 p5 = 0.000000
Par 6 p6 = 0.000000
Par 7 p7 = 0.000000
Par 8 p8 = 0.000000
Par 9 p9 = 0.000000
Par 10 p10 = 0.000000
Par 11 p11 = 0.000000
Par 12 p12 = 0.000000
Par 13 p13 = 0.000000
Par 14 p14 = 0.000000
Expression passed to Cling:
Double_t TFormula____id1908495908384388024(Double_t *x,Double_t *p){ return (p[6]+p[7]*x[0]+p[8]*TMath::Power(x[0],2)+p[9]*TMath::Power(x[0],3)+p[10]*TMath::Power(x[0],4)+p[11]*TMath::Power(x[0],5))+(p[12]*TMath::Exp(p[13]*(x[0]-p[14]))) ; }
I see the inconsistency that p0
…p5
were not given in the formula but any way they appear on the list and are enumerated. Thus GetNPar()
returns me 14 parameters instead of 9.
The TFormula
was initiated with “pol5(6)+aexpo
” where aexpo
is another formula with “[0] * exp([1]*(x-[2]))
”.
Can you explain this? I would expect the second function is correct, but the first one is broken. If I defined parameters as [5]
in the formula, I want to access it with GetParameter(5)
, not GetParameter(4)
.
ROOT Version: 6.20.04
Platform: Linux
Compiler: GCC-9.3.0