Table of Contents
Name | Direction | Type | Default | Description |
---|---|---|---|---|
InputWorkspace | Input | MatrixWorkspace | Mandatory | Name of the input workspace for peak fitting. |
OutputWorkspace | Output | MatrixWorkspace | Mandatory | Name of the output workspace containing fitted peak. |
ParameterTableWorkspace | Output | TableWorkspace | Name of the table workspace containing the fitted parameters. | |
WorkspaceIndex | Input | number | 0 | Workspace index |
PeakFunctionType | Input | string | Mandatory | Peak function type. Allowed values: [‘BackToBackExponential’, ‘BackToBackExponential (I, A, B, X0, S)’, ‘Bk2BkExpConvPV’, ‘Bk2BkExpConvPV (TOF_h, Height, Alpha, Beta, Sigma2, Gamma)’, ‘DeltaFunction’, ‘DeltaFunction (Height, Centre)’, ‘ElasticDiffRotDiscreteCircle’, ‘ElasticDiffRotDiscreteCircle (Height, Centre, Radius)’, ‘ElasticDiffSphere’, ‘ElasticDiffSphere (Height, Centre, Radius)’, ‘ExamplePeakFunction’, ‘ExamplePeakFunction (Height, PeakCentre, Sigma)’, ‘Gaussian’, ‘Gaussian (Height, PeakCentre, Sigma)’, ‘IkedaCarpenterPV’, ‘IkedaCarpenterPV (I, Alpha0, Alpha1, Beta0, Kappa, SigmaSquared, Gamma, X0)’, ‘Lorentzian’, ‘Lorentzian (Amplitude, PeakCentre, FWHM)’, ‘LorentzianTest’, ‘LorentzianTest (Height, PeakCentre, HWHM)’, ‘Muon_ExpDecayOscTest’, ‘Muon_ExpDecayOscTest (A, lambda, frequency, phi)’, ‘PseudoVoigt’, ‘PseudoVoigt (Mixing, Height, PeakCentre, FWHM)’, ‘Voigt’, ‘Voigt (LorentzAmp, LorentzPos, LorentzFWHM, GaussianFWHM)’] |
PeakParameterNames | Input | str list | List of peak parameter names. | |
PeakParameterValues | Input | dbl list | List of peak parameter values. They must have a 1-to-1 mapping to PeakParameterNames list. | |
FittedPeakParameterValues | Output | dbl list | Fitted peak parameter values. | |
BackgroundType | Input | string | Linear | Type of Background. Allowed values: [‘Flat’, ‘Flat (A0)’, ‘Linear’, ‘Linear (A0, A1)’, ‘Quadratic’, ‘Quadratic (A0, A1, A2)’] |
BackgroundParameterNames | Input | str list | List of background parameter names. | |
BackgroundParameterValues | Input | dbl list | List of background parameter values. They must have a 1-to-1 mapping to BackgroundParameterNames list. | |
FittedBackgroundParameterValues | Output | dbl list | Fitted background parameter values. | |
FitWindow | Input | dbl list | Enter a comma-separated list of the expected X-position of windows to fit. The number of values must be 2. | |
PeakRange | Input | dbl list | Enter a comma-separated list of expected x-position as peak range. The number of values must be 2. | |
FitBackgroundFirst | Input | boolean | True | If true, then the algorithm will fit background first. And then the peak. |
RawParams | Input | boolean | True | If true, then the output table workspace contains the raw profile parameter. Otherwise, the effective parameters will be written. |
MinGuessedPeakWidth | Input | number | 2 | Minimum guessed peak width for fit. It is in unit of number of pixels. |
MaxGuessedPeakWidth | Input | number | 10 | Maximum guessed peak width for fit. It is in unit of number of pixels. |
GuessedPeakWidthStep | Input | number | Optional | Step of guessed peak width. It is in unit of number of pixels. |
PeakPositionTolerance | Input | number | Optional | Peak position tolerance. If fitted peak’s position differs from proposed value more than the given value, fit is treated as failure. |
CostFunction | Input | string | Chi-Square | Cost functions. Allowed values: [‘Chi-Square’, ‘Rwp’] |
Minimizer | Input | string | Levenberg-Marquardt | Minimizer to use for fitting. Minimizers available are “Levenberg-Marquardt”, “Simplex”,”Conjugate gradient (Fletcher-Reeves imp.)”, “Conjugate gradient (Polak-Ribiere imp.)”, “BFGS”, and “Levenberg-MarquardtMD”. Allowed values: [‘BFGS’, ‘Conjugate gradient (Fletcher-Reeves imp.)’, ‘Conjugate gradient (Polak-Ribiere imp.)’, ‘Damping’, ‘FABADA’, ‘Levenberg-Marquardt’, ‘Levenberg-MarquardtMD’, ‘Simplex’, ‘SteepestDescent’] |
CostFunctionValue | Output | number | Value of cost function of the fitted peak. |
This algorithm is used to fit a single peak with some checking mechanism to ensure its fitting result is physical.
The output TableWorkspace contains the following columns...
All peak profiles supported by Mantid are supported by FitPeak.
Starting parameter values specified by user should be close to the real values, unless the automatic starting values determination algorithm works well with that profile type.
But only [[Gaussian]] has been well tested with this functionalities.
There are only three types of backgrounds that are supported, including FlatBackground, LinearBackground and Quadratic.
FitPeak is designed to fit the parameters of a peak function with background function in a given region. In order to provide convenient UI to both user interactively and algorithms calling this algorithm automatically, a various formats for the input of the starting values of functions and output of the fitted values of the functions are implemented.
Input function parameters’ names should be exactly the same as those defined in Mantid. This brings some inconvenience to users through MantidPlot GUI. Thus user can input function parameters values in the default order, which is instructed in the list of functions. For example, one background function type is defined as ‘Linear (A0, A1)’. As user chooses this function, he does not need to input background function parameter names, but writes values of A0 and A1, respectively.
The output [[TableWorkspace]] contains the following columns... * parameter name * fitted parameter value * error
FindPeaks uses a more complicated approach to fit peaks if ‘’‘HighBackground’‘’ is flagged. In this case, FindPeak will fit the background first, and then do a Gaussian fit the peak with the fitted background removed. This procedure will be repeated for a couple of times with different guessed peak widths. And the parameters of the best result is selected. The last step is to fit the peak with a combo function including background and Gaussian by using the previously recorded best background and peak parameters as the starting values.
In the ‘simple fit’ mode, the algorithm will make a composite function including peak and background function and fit it agains the observed data.
It works well with good starting values of the peak and background function, especially when the peak is significant with low background.
In the ‘high background fit’ mode, the background will be removed first; then the fitting is focussed on the ‘pure’ peak function; and a composite function is fit agains the original data as the last step.
This approach is developed due to the failure of ‘simple fit’ mode on the cases that background level is much higher than the peak height. Without the background being removed, the optimizer intends to favor the background rather than the peak function.
FindPeaks finds peaks by fitting a Guassian with background to a certain range in the input histogram. Fit v1 may not give a correct result even if chi^2 is used as criteria alone. Thus some other criteria are provided as options to validate the result
1. Peak position. If peak positions are given, and trustful, then the fitted peak position must be within a short distance to the give one.
2. Peak height. In the certain number of trial, peak height can be used to select the best fit among various starting sigma values.
If FitWindows is defined, then a peak’s range to fit (i.e., x-min and x-max) is confined by this window.
If PeakRange is defined and starting peak centre given by user is not within this range, then the situation is considered illegal. In future, FitPeak might be able to estimate the peak centre in this situation by locating the X-value whose corresponding Y-value is largest within user-defined peak range.
Example - Fit a single peak with rough estimation on staring parameter values:
Load(Filename=r'focussed.nxs', OutputWorkspace='focussed')
FitPeak(InputWorkspace='focussed', OutputWorkspace='peak4', ParameterTableWorkspace='peak4result',
WorkspaceIndex='3',PeakFunctionType='Gaussian (Height, PeakCentre, Sigma)',
PeakParameterValues='2000,2.1,0.01',BackgroundType='Linear (A0, A1)',
BackgroundParameterValues='2500,2000',FitWindow='2,2.3',PeakRange='2.1,2.25')
tbws = mtd["peak4result"]
chi2 = tbws.cell(0, 1)
peakcentre = tbws.cell(2, 1)
peakheight = tbws.cell(3, 1)
sigma = tbws.cell(4, 1)
print "Chi-square = %f: Peak centre = %f, Height = %f, Sigma = %f" % (chi2, peakcentre, peakheight, sigma)
Output:
Chi-square = 7.138740: Peak centre = 8365.836316, Height = 2.141713, Sigma = 0.005644
Categories: Algorithms | Optimization