ConvertFitFunctionForMuonTFAsymmetry v1


ConvertFitFunctionForMuonTFAsymmetry dialog.


This algorithm converts adds/removes the normalisation to the fit function for calculating the TF asymmetry.


Name Direction Type Default Description
InputFunction Input Function Mandatory The fitting function to be converted.
NormalizationTable Input TableWorkspace   Name of the table containing the normalizations for the asymmetries.
WorkspaceList Input str list Mandatory An ordered list of workspaces (to get the initial values for the normalizations).
Mode Input string Construct Mode to run in. Construct will convert theinput function into one suitable for calculating the TF Asymmetry. Extract will find the original user function from a function that is suitable for TF Asymmetry calculations. Allowed values: [‘Extract’, ‘Construct’]
OutputFunction Output Function   The converted fitting function.
CopyTies Input boolean True Set to true to copy over ties from input function(default is true).


This algorithm can be run in two modes. The first is construct, which takes a user fitting function \(f(t)\) and it converts it to a TF normalisation function

\[N_0[1+f(t)] + A\exp(-\lambda t)\]

where \(N_0\) is the normalisation constant, \(A\) is fixed to zero by default and \(\lambda\) is fixed to the Muon lifetime. The initial value for the normalisation constant is from the normalisation table.

The second mode is extract, if the TF normalisation function is given it will return the user function.

This algorithm works for both single and multi domain functions.

The algorithm takes an optional boolean parameter CopyTies, which when true will copy the ties present in the input function. By default it is set to true.


Example - Converting a function: This example is for converting a function.

import mantid.simpleapi as mantid
#create a normalisation table
tab = CreateEmptyTableWorkspace()
tab.addColumn('double', 'norm')
tab.addColumn('str', 'name')
tab.addColumn('str', 'method')


#create original function and workspace
myFunc='name=LinearBackground,A0=3,A1=    4;name=LinearBackground,A0=0,A1=2;ties=(f0.A1=3, f0.A0=f1.A0)'
ws = CreateWorkspace(DataX=[1,2,3,4,5,6,7],    DataY=[1,2,3,4,5,6],OutputWorkspace="Run; Group; a; Asym; #1")

TFFunc = ConvertFitFunctionForMuonTFAsymmetry(InputFunction=myFunc, NormalizationTable=tab,
                                              WorkspaceList=["Run; Group; a; Asym; #1"], Mode="Construct")

# do a fit with new function
fit =mantid.AlgorithmManager.create("Fit")
fittedFunc = fit.getPropertyValue("Function")

returnFunc =    ConvertFitFunctionForMuonTFAsymmetry(InputFunction=str(fittedFunc),NormalizationTable=tab,
                                                     WorkspaceList=["Run; Group; a; Asym; #1"], Mode="Extract")
# 0 iteration fit to get param table -> wont change function values
fit_output =    Fit(Function=str(returnFunc),InputWorkspace=ws,MaxIterations=0,Output="return_params")

paramTable = fit_output.OutputParameters  # table containing the optimal fit parameters

if paramTable.column(1)[0] == paramTable.column(1)[2]:
    print("Constant tie has been preserved")
    print("Constant tie has not been preserved")

if paramTable.column(1)[1] == 3.0:
   print("Fix has been preserved")
   print("Fix has not been presreved")


Constant tie has been preserved
Fix has been preserved

Categories: AlgorithmIndex | Muon