\(\renewcommand\AA{\unicode{x212B}}\)

FitPeak v1

Summary

Fit a single peak with checking mechanism.

Properties

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

Mandatory

Name of the table workspace containing the fitted parameters.

WorkspaceIndex

Input

number

0

Workspace index

PeakFunctionType

Input

string

Mandatory

Peak function type. Allowed values: [‘AsymmetricPearsonVII’, ‘AsymmetricPearsonVII (PeakHeight, PeakCentre, Width, LeftShape, RightShape)’, ‘BackToBackExponential’, ‘BackToBackExponential (I, A, B, X0, S)’, ‘Bk2BkExpConvPV’, ‘Bk2BkExpConvPV (X0, Intensity, Alpha, Beta, Sigma2, Gamma)’, ‘DeltaFunction’, ‘DeltaFunction (Height, Centre)’, ‘ElasticDiffRotDiscreteCircle’, ‘ElasticDiffRotDiscreteCircle (Height, Centre, Radius)’, ‘ElasticDiffSphere’, ‘ElasticDiffSphere (Height, Centre, Radius)’, ‘ElasticIsoRotDiff’, ‘ElasticIsoRotDiff (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)’, ‘PearsonIV’, ‘PearsonIV (Intensity, Centre, Sigma, Exponent, Skew)’, ‘PseudoVoigt’, ‘PseudoVoigt (Mixing, Intensity, 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.)’, ‘Damped GaussNewton’, ‘FABADA’, ‘Levenberg-Marquardt’, ‘Levenberg-MarquardtMD’, ‘Simplex’, ‘SteepestDescent’, ‘Trust Region’]

CostFunctionValue

Output

number

Value of cost function of the fitted peak.

Description

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…

Peak profile

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.

Background

There are only three types of backgrounds that are supported, including FlatBackground, LinearBackground and Quadratic.

Input and Output

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.

Default function parameters’ names

Input function parameters’ names should be exactly the same as those defined in Mantid. 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.

Output of function parameters

The output [[TableWorkspace]] contains the following columns… * parameter name * fitted parameter value * error

Fitting algorithm

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.

Simple fit

In the ‘simple fit’ mode, the algorithm will make a composite function including peak and background function and fit it against 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.

High background fit

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 against 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.

Starting values of the peak function

  • Peak height is estimated by the maximum value, with background removed, inside the peak range;

  • Peak position can be set up either to the X value of the maximum Y value in the peak range, or to the value specified by user accordin to user’s selection. For example, in the case of calibrating the offsets of detectors of powder diffractometers, the peak positions are unknown. Then it is better to use the X value with the maximum Y value as the starting peak centre. While in the case of striping vanadium peaks, all peaks’ centres should be exactly same as the theortical values.

Criteria To Validate Peaks Found

FindPeaks finds peaks by fitting a Gaussian 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.

  1. Peak width: Peak width cannot be equal or wider than the given fit window.

Fit Window and Peak Range

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.

Subalgorithms used

  • Fit

Usage

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.14,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)
peakheight = tbws.cell(2, 1)
peakcentre = tbws.cell(3, 1)
sigma = tbws.cell(4, 1)
print("Chi-square = {:.5f}: Peak centre = {:.5f}, Height = {:.2f}, Sigma = {:.5f}".format(chi2, peakcentre, peakheight, sigma))

Output:

Chi-square = 1.74892: Peak centre = 2.14201, Height = 7490.67, Sigma = 0.00776

Categories: AlgorithmIndex | Optimization

Source

C++ header: FitPeak.h

C++ source: FitPeak.cpp