Hi! I am trying to implement the langaus fit described here in c++
https://root.cern.ch/doc/v614/langaus_8C_source.html
into a python code to use it with pyroot.
My code looks as follows:
import ROOT as rt
class langaus:
def __call__(self, t, par):
width_landau = par[0]
MP = par[1]
Area = par[2]
widt_gauss = par[3]
x = t[0]
invsq2pi = 0.3989422804014
mpshift = -0.22278298
np = 100.0
sc = 5.0
mpc = par[1] - mpshift * par[0]
xlow = x - sc * par[3]
xupp = x + sc * par[3]
step = (xupp-xlow) / np
summ = 0.0
for i in range(1, np/2):
xx = xlow + (i-.5) * step
fland = TMath.Landau(xx,mpc,par[0]) / par[0]
summ += fland * TMath.Gaus(x[0],xx,par[3])
xx = xupp - (i-.5) * step
fland = TMath.Landau(xx,mpc,par[0]) / par[0]
summ += fland * TMath.Gaus(x[0],xx,par[3])
return (par[2] * step * summ * invsq2pi / par[3])
I try to fit with:
parN = 4
langaus = langaus()
func = rt.TF1("myfunc", langaus, 60, 120, parN);
histoname.Fit(func, "R")
Unfortunately I get the error:
Traceback (most recent call last):
File ".........", line 359, in <module>
histoname.Fit(func "R")
TypeError: none of the 2 overloaded methods succeeded. Full details:
TFitResultPtr TH1::Fit(TF1* f1, const char* option = "", const char* goption = "", double xmin = 0, double xmax = 0) =>
TypeError: 'float' object cannot be interpreted as an integer
TFitResultPtr TH1::Fit(const char* formula, const char* option = "", const char* goption = "", double xmin = 0, double xmax = 0) =>
TypeError: could not convert argument 1 (bad argument type for built-in operation)
I don’t get which float object it is talking about. Someone can help? It is working perfectly when using the c++ code though. Thank you!