Fitting is the modelling of data where parameters of a model are allowed to vary during a fitting process until the agreement between model and data has seen an improvement according to some cost function.
In summary the Mantid fitting provides
The main focus of this basic course is to cover the basic mantid fitting capabilities.
- Select the fitting tool button:
- Right click on the plot to select a fitting function.
Three things happens when you click on the Fit Function toolbar button
The fitting range is the region of the data where you will attempt to do a fit.
This vertical dashed lines shows the fitting region of the data. These are in sync with the Fit Function setting properties: StartX and EndX values highlighted in green in the image above.
In addition to StartX and EndX there are a number of other essential fit setting properties including:
More documentation of these is available from Fitting.
Here start up with building up a model consisting of one peak and one background function.
This can in fact be done using just the Fit Function toolbox. However in practice it is advantegeous to also use the fitting tools available on the plot and from the plot right click menu.
Select the right click plot menu option ‘Add peak...’. This pops up a new window and in the combobox, select Gaussian. The mouse cursor then changes to a cross. Move this cross near the top of the peak and click any mouse button
Click on the red line and drag it sideways to set the initial width (FWHM) of the peak.
Now you can see 3 red lines - one solid line indicating peak’s position and height, and two dashed ones representing the width of the peak. The dashed lines usually show the points of half peak’s maximum. All three lines can be dragged within the plot to modify its centre, height or with parameters which is instantly reflected in the Fit Function browser.
Select the right click plot menu option ‘Add background...’. This pops up a new window and in the combobox, select FlatBackground
The result of this is
Note that a vertical line has appeared in the plot where the peak was positioned and two fit function entries have appeared in the Fit Function property browser called ‘f0-Gaussian’ and ‘f1-FlatBackground’.
In summary from the Fit Function property browser you have created model consisting of a CompositeFunction which contains a Gaussian and a flat-background. The CompositeFunction part means that the model is sum of its parts, i.e. here the model is
'f0-Gaussian' + 'f1-FlatBackground'
When you do fitting the starting fit function parameter values can greatly affect both the speed and the result you obtain from fitting. In general you want to use staring parameter that are a close as possible to the result you want to obtain.
Fit tools are available on the plot to help you with doing this. In doing this it can be helpful to turn on Plot Guess,
what this means does is to plot how the model you have created looks like compared to your data.
The aim is to have this plot and your data overlap reasonable well before you do the actual fit. Note this is not an absolute requirement but your chances of a successful fit increase this way.
If you have spent a considerable amount of type setting up a model you can save it and then load it later.
After saving the model it can be imported into Fit Function browser at any time using Custom Setup option from the same menu. Importing (loading) a model replaces all functions in the browser.
Mantid fitting framework allows you to tie or constrain parameters during the fit. We define tying as setting a parameter equal to an expression involving other parameters from any of the selected functions. The expression can be a constant (doesn’t involve any parameters), in which case we would say the parameter is fixed.
Constraining a parameter is where its value is kept above a lower bound, below an upper bound or both.
To set a constraint or a tie right click on a parameter name:
The menu offers three options:
The tying expression can be as simple as a parameter name:
f0.Height
Note that parameter names of a model include prefixes such as “f0.” which indicate the particular function they belong to.
A more interesting example is setting parameter f1.A0 from our earlier model to formula
20 - f0.Height
This will ensure that the maximum point is exactly 20 units above 0.
After the model has been defined, its initial values are set, any ties and constraints defined we are ready to run a fit. It is done by selecting the Fit option from the Fit menu:
After a successful fit the results can be examined in three ways.
There are three output workspaces:
1. A TableWorkspace with the name suffixed with “_Parameters”. It contains the fitting parameters and their corresponding errors.
2. A MatrixWorkspace with the name suffixed with “_Workspace”. Its first three spectra are: the original data, the calculated model, and the difference.
3. A TableWorkspace with the name suffixed with “_NormalisedCovarianceMatrix”. It contains the variance-covariance matrix normalized to 100.