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

CalculatePolynomialBackground v1

../_images/CalculatePolynomialBackground-v1_dlg.png

CalculatePolynomialBackground dialog.

Summary

Fits a polynomial background to a workspace.

Properties

Name Direction Type Default Description
InputWorkspace Input MatrixWorkspace Mandatory An input workspace.
OutputWorkspace Output MatrixWorkspace Mandatory A workspace containing the fitted background.
Degree Input number 0 Degree of the fitted polynomial.
XRanges Input dbl list   A list of fitting ranges given as pairs of X values.
CostFunction Input string Least squares The cost function to be passed to the Fit algorithm. Allowed values: [‘Least squares’, ‘Unweighted least squares’]
Minimizer Input string Levenberg-MarquardtMD The minimizer to be passed to the Fit algorithm. Allowed values: [‘Levenberg-MarquardtMD’, ‘Levenberg-Marquardt’]

Description

This algorithm calculates backgrounds for the histograms in a workspace by fitting a polynomial to ranges given by XRanges. The fitting is done using Fit v1. The backgrounds are returned as the OutputWorkspace which can be subsequently subtracted from the original workspace. The degree of the polynomial can be given by Degree. A zeroth degree polynomial would correspond to fitting a constant value. The XRanges property is a list of range start and range end value pairs in the X axis units. Overlapping ranges are merged. If no XRanges are given, full histograms are used.

The value of CostFunction is passed to Fit v1 as-is. The default option is ‘Least squares’ which uses the histogram errors as weights. This might not be desirable, e.g. when there are bins with zero counts and zero errors. An ‘Unweighted least squares’ option is available to deal with such cases.

The property Minimizer is passed to Fit v1 as-is. The default for this is ‘Levenberg-MarquardtMD’.

Usage

Example - CalculatePolynomialBackground

import numpy

ws = CreateSampleWorkspace(Function='One Peak')
# ws has a background of 0.3
# There is a single peak around X = 10000 micro-s. Lets exclude it from
# the background fitting using XRanges.
bkg = CalculatePolynomialBackground(ws, XRanges=[0, 8000, 12000, 20000])
ws_bkg_subtr = ws - bkg

peakIndex = numpy.argmax(ws.extractY())
Y = ws.readY(0)[peakIndex]
print('Peak height with background: {:.1f}'.format(Y))
Y = ws_bkg_subtr.readY(0)[peakIndex]
print('Background subtracted peak height: {:.1f}'.format(Y))

Output:

Peak height with background: 10.3
Background subtracted peak height: 10.0

Categories: AlgorithmIndex | CorrectionFunctions\BackgroundCorrections

Source

C++ header: CalculatePolynomialBackground.h (last modified: 2020-03-20)

C++ source: CalculatePolynomialBackground.cpp (last modified: 2020-04-07)