\(\renewcommand\AA{\unicode{x212B}}\)
Three things happens when you click on the Fit Toolbar button:
The fitting range is the region of the data where you will attempt to do a fit, represented by the green vertical dashed lines. These match the StartX and EndX values in the Fit Property Browser.
In addition to StartX/EndX there are a number of other essential fit setting properties including:
More documentation of these is available from Fitting.
Let’s build a model consisting of a peak and a background function.
Note that two fit functions have appeared in the Fit
Property Browser called f0-Gaussian
and f1-FlatBackground
.
Click on the triangles beside these functions to reveal their fit parameters.
Just as with the StartX/EndX values, dragging on the plot and changing these values update each other.
Now you have created a CompositeFunction model, which is the sum of a Gaussian and a Flat-background
i.e. f0-Gaussian + f1-FlatBackground
The initial fit parameter values can affect the speed and the final result obtained from fitting. In general you want starting parameter that are a close as possible to the correct result.
Mantid has a tool to help you with this! Turn on “Display > Plot Guess”.
This plots the model of the initial parameters on top of the raw 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.
You may set up a custom model, which you can save and reload later.
After saving the model it can be imported using “Setup > Custom Setup” (note this replaces all functions in the browser).
The Mantid fitting framework allows you to tie or constrain parameters.
Tying sets a parameter equal to an expression of other parameters (from any of the selected functions).
Fixing is basically tying a parameter to a number (constant).
Constraining a parameter keeps its value above a lower bound, below an upper bound, or both!
To set a constraint/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.
Try Tying parameter f1.A0 from our built model to the custom function:
2-f0.Height
As this sets the FlatBackground height, A0 = 2 - GaussianHeight, the calculated Peak Height will be exactly 2 units above 0 (the x-axis).
After the model has been defined, its initial values 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:
Now examine the results in the Fit Property Browser and the output workspaces, as before. You can even show error bars to compare how good your fit is to the errors. To do so, as below, enter Figure Options (Gear Symbol) > Curves tab, check the curve selected is “spec 1”. Then un-Hide Errorbars, giving them a capsize of 2, displaying an Error (bar) Every 2 (points) and click “Apply” at the bottom of the window.