I am writing a simple python code to fit two Lorentzians to my data.

I am facing an error in the Fit function where I have set

OutputCompositeMembers=True

and

EvaluationType=“Histogram”

but this returns the following error:

RuntimeError Traceback (most recent call last)

in ()

33 #using the fit function for each workspace i

34 fit_out = Fit(Function=function,InputWorkspace=“sample”,WorkspaceIndex=i,StartX=-0.29, EndX=1.1,

—> 35 CreateOutput=True,Output=“fit_results”,MaxIterations=500,EvaluationType=‘Histogram’,OutputCompositeMembers=True)

36 #setting the parameters to the values

37 chi_sq = fit_out[1]/opt/Mantid/bin/mantid/simpleapi.pyc in wrapper(*Function, InputWorkspace, ****kwargs)

365 del kwargs[key]

366 set_properties(algm, **kwargs)

→ 367 algm.execute()

368 return _gather_returns(function_name, lhs, algm, inout=inout)

369 # end

RuntimeError: Integration is not implemented for this function.

But if I use CentrePoint evaluation type, this error is not encountered, but the fitting is quite poor.

PS : This is the whole script, highlighted the relevant values in bold

test = True

counter = 100

#starting values for all four parameters

g1[0] = 0.01 #initial value for g1

g2[0] = 0.1 #initial value for g2

a0[0] = 1e-2

a1[0] = 1e-2

for i in range(0,Qvalues):

test = True

while( test ):

function_composition = “(composite=Convolution,FixResolution=true,NumDeriv=true;”#composite function of convolution type

function_composition += “name=TabulatedFunction,Workspace=res,”#resolution workspace

function_composition += “WorkspaceIndex=”+str(i) #using the appropriate Q-valued resolution function.

function_composition += “,Scaling=1,Shift=0,XScaling=1,ties=(Scaling=1,Shift=0,XScaling=1);”

lorentzian_0 = “(name=Lorentzian”

lorentzian_0 += “,Amplitude=”+str(a0[i])

lorentzian_0 += “,PeakCentre=”+str(0.0)

lorentzian_0 += “,FWHM=”+str(g1[i])

ties_l0 = “” #leaving this open to add any constraints to lorentzian 1

constraints_l0 = “”

lorentzian_1 = “;name=Lorentzian”

lorentzian_1 += “,Amplitude=”+str(a1[i])

lorentzian_1 += “,PeakCentre=”+str(0.0)

lorentzian_1 += “,FWHM=”+str(g2[i])

constraints_l1 = “”

ties_l1 = “)” #leaving this open to add any constraints to lorentzian 1

bg_function_string = “);name=LinearBackground,A0=0,A1=0” #background is chosen linear

function = function_composition+lorentzian_0+ties_l0+lorentzian_1+ties_l1+bg_function_string

#print function

#using the fit function for each workspace i

fit_out = Fit(Function=function,InputWorkspace=“sample”,WorkspaceIndex=i,StartX=-0.29, EndX=1.1,

CreateOutput=True,Output=“fit_results”,MaxIterations=500,EvaluationType=‘Histogram’,OutputCompositeMembers=True)

#setting the parameters to the values

chi_sq = fit_out[1]

a0[i] = fit_out[3].row(3)[“Value”]

g1[i] = fit_out[3].row(5)[“Value”]

a1[i] = fit_out[3].row(6)[“Value”]

g2[i] = fit_out[3].row(8)[“Value”]

if (i <7):

a0[i+1], a1[i+1], g1[i+1], g2[i+1] = a0[i],a1[i],g1[i],g2[i]

if ( chi_sq < 3.0):

test = False

#just printing params after successful fitting

print (“Parameters obtained after “+str(i)+“th Q-value fitting”)

print qs[i],a0[i],a1[i],g1[i],g2[i],” Chi-qs: “,chi_sq

#store the fit of functions in sqw_fit for each Q-value

fit_Evalues = fit_out[4].blocksize()

#print fit_Evalues+1,fit_out[4].readX(1).size

energy_fit[:fit_Evalues+1] = fit_out[4].readX(1)

sqw_fit[i,:fit_Evalues] = fit_out[4].readY(1)

print(”\n”)

print(“Fitting done for all Q-values”)