Error in execution of sqrt()

Hello dear ROOT Forum,

I am trying to fit a Bright-Wigner function to a histogram, by defining it myself and using it as an input function.

 // Create a Breight-wigner function to fit! 
  //User defined (not predefined like the gauss!!!)
  std::string bw_A = "2*sqrt(2)*[0]*[1]*sqrt([0]*[0]*([0]*[0]+[1]*[1]))";
  std::string bw_B = "3.14159*sqrt([0]*[0]+sqrt([0]*[0]*([0]*[0]+[1]*[1])))";
  std::string bw_C = "(x*x-[0]*[0])*(x*x-[0]*[0]) + [0]*[0]*[1]*[1]";
  //form the BW function
  std::string bw = Form("[2]*((%s)/(%s))/(%s))", bw_A.c_str(), bw_B.c_str(), bw_C.c_str());// "[2]" is a normalization factor to the whole BW function, change it accordingly!
  //Now, we create the actual BW fit function, but in this case we also specify starting points for *two of the parameters to give it a hand* (as the Breit-Wigner is much more complex than the Gaussian function)
  TF1 bwFit("bwFit", bw.c_str(), 50.e3, 200.e3);
  bwFit.SetParameter(0, 100.e3);
  bwFit.SetParameter(1, 1.e3); 

However, I am getting the following error!

<TFormula::Eval>: Formula is invalid and not ready to execute 
sqrt is unknown.

How do I proceed?

ps: I have tried commenting out the ‘sqrt’ lines, and it gives a plot, albeit a nonsensical one but at least I am sure that the problem is those lines only.

Welcome to the ROOT Forum!
Can you try with TMath:Sqrt or maybe also std::sqrt?

Same issue :frowning:

Here you have 4 opening parentheses and 5 closing ones.

1 Like

Thank you very much for pointing it out!
It is solved !!!

See also:

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