Fitting a histogram with a bivariate normal distribution

Hi everyone! I’m trying to fit a TH2F with a bivariate normal distribution; I have written the function this way:

TF2 *f2 = new TF2("f2","(1.0/(2*TMath::Pi()*[0]*[1]*sqrt(1-TMath::Power([2],2))))*TMath::Exp(-(1.0/(2.0*(1-TMath::Power([2],2))))*((TMath::Power(x-[3],2))/(TMath::([0],2)) -2.0*[2]*(x-[3])*(y-[4])/([0]*[1]) +(TMath::Power(y-[4],2))/(TMath::Power([1],2))))",0.1,0.35,0.1,0.35);

but ROOT gives this error:

Error in <TFormula::Compile>:  Bad numerical expression : "TMath::([0],2)"
Error in <TF2::TF2>: function: f2/(1.0/(2*TMath::Pi()*[0]*[1]*sqrt(1-TMath::Powe
r([2],2))))*TMath::Exp(-(1.0/(2.0*(1-TMath::Power([2],2))))*((TMath::Power(x-[3]
,2))/(TMath::([0],2)) -2.0*[2]*(x-[3])*(y-[4])/([0]*[1]) +(TMath::Power(y-[4],2)
)/(TMath::Power([1],2)))) has 0 parameters instead of 2
Error: Non-static-const variable in array dimension C:\root_v5.34.36\macros\gaus
siana.C(26)
 (cint allows this only in interactive command and special form macro which
  is special extension. It is not allowed in source code. Please ignore
  subsequent errors.)
*** Interpreter error recovered ***

How can I fix it?
Thanks in advance for helping me!

TF2 *f2 = new TF2("f2","(1.0/(2*TMath::Pi()*[0]*[1]*sqrt(1-TMath::Power([2],2))))*TMath::Exp(-(1.0/(2.0*(1-TMath::Power([2],2))))*((TMath::Power(x-[3],2))/(TMath::Power([0],2)) -2.0*[2]*(x-[3])*(y-[4])/([0]*[1]) +(TMath::Power(y-[4],2))/(TMath::Power([1],2))))",0.1,0.35,0.1,0.35);

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

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