A strange bug in rf708_bphysics.C

Dear experts,
I found a trange bug in line 169 of rf708_bphysics.C.
For the RooBDecay, if we change the definition of bcpg to

RooBDecay bcpg("bcpg", "bcpg", dt, tau, DG, RooConst(1), fsinh, fcos, fsin, RooConst(0.), truthModel, RooBDecay::DoubleSided);

where dm is changed to constant 0.
The following bug will be obtained:

input_line_61:2:89: error: array subscript is not an integer
Double_t TFormula____id9800548585748267179(Double_t *x){ return TMath::Exp(-TMath::Abs(x[x[2]])/x[1])*TMath::Cos(x[x[2]]*x[2]) ; }
                                                                                        ^~~~~
input_line_61:2:115: error: array subscript is not an integer
Double_t TFormula____id9800548585748267179(Double_t *x){ return TMath::Exp(-TMath::Abs(x[x[2]])/x[1])*TMath::Cos(x[x[2]]*x[2]) ; }
                                                                                                                  ^~~~~
input_line_62:2:89: error: array subscript is not an integer
Double_t TFormula____id9800548585748267179(Double_t *x){ return TMath::Exp(-TMath::Abs(x[x[2]])/x[1])*TMath::Cos(x[x[2]]*x[2]) ; }
                                                                                        ^~~~~
input_line_62:2:115: error: array subscript is not an integer
Double_t TFormula____id9800548585748267179(Double_t *x){ return TMath::Exp(-TMath::Abs(x[x[2]])/x[1])*TMath::Cos(x[x[2]]*x[2]) ; }
                                                                                                                  ^~~~~
Error in <prepareMethod>: Can't compile function TFormula____id9800548585748267179 prototype with arguments Double_t*
Error in <TFormula::InputFormulaIntoCling>: Error compiling formula expression in Cling
Error in <TFormula::ProcessFormula>: Formula "exp(-abs(x[x[2]])/x[1])*cos(x[x[2]]*x[2])" is invalid !
[#0] FATAL:InputArguments -- RooFormula 'exp(-abs(@0)/@1)*cos(@0*@2)_dt_tau_0' did not compile or is invalid.
Input:
	exp(-abs(@0)/@1)*cos(@0*@2)
Passed over to TFormula:
	exp(-abs(x[x[2]])/x[1])*cos(x[x[2]]*x[2])
terminate called after throwing an instance of 'std::runtime_error'
  what():  RooFormula 'exp(-abs(@0)/@1)*cos(@0*@2)_dt_tau_0' did not compile or is invalid.
Input:
	exp(-abs(@0)/@1)*cos(@0*@2)
Passed over to TFormula:
	exp(-abs(x[x[2]])/x[1])*cos(x[x[2]]*x[2])

However, when we change the definition of dm to

RooRealVar dm1("dm1", "delta m(B0)", 0);

The bug disappears.
This is very strange.
Could anyone give me some advide?

My Root version is 6.24.00.
The same bug also appear in ROOT6.22

Thanks inadvance!

Best Wishes,
Zhihong

Hi @Zhihong_Shen,

thanks for reporting this problem!

Indeed, it’s a bug in the RooFormula that behaves wrongly if one of the variable has just an integer as a name, like RooConst(0.0) whose name is simply “0”. That’s why it works when you give your zero constant a different name, like “dm1” which you tried later where you didn’t hit the bug. So as you noticed, the workaround is easy :slight_smile:

I have created a PR to fix the bug:

It will be fixed in the next patch release.

Thanks again for reporting and have a nice evening!
Jonas

@jonas Thanks very much !

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.