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

ReflectometryBackgroundSubtraction v1

Summary

Calculates and subtracts the background from a given workspace.

Properties

Name

Direction

Type

Default

Description

InputWorkspace

Input

MatrixWorkspace

Mandatory

An input workspace.

InputWorkspaceIndexType

Input

string

The type of indices in the optional index set; For optimal performance WorkspaceIndex should be preferred;. Allowed values: [‘WorkspaceIndex’, ‘SpectrumNumber’]

ProcessingInstructions

Input

long list

An optional set of spectra containing the background. If not set all spectra will be processed. The indices in this list can be workspace indices or spectrum numbers, depending on the selection made for the index type; Indices are entered as a comma-separated list of values, and/or ranges.

BackgroundCalculationMethod

Input

string

PerDetectorAverage

The type of background reduction to perform. Allowed values: [‘PerDetectorAverage’, ‘Polynomial’, ‘AveragePixelFit’]

DegreeOfPolynomial

Input

number

0

Degree of the fitted polynomial.

CostFunction

Input

string

Least squares

The cost function to be passed to the Fit algorithm. Allowed values: [‘Least squares’, ‘Unweighted least squares’]

PeakRange

Input

long list

A set of spectra defining the reflectivity peak. If not set all spectra will be processed. The indices in this list can be workspace indices or spectrum numbers, depending on the InputWorkspaceIndexType

SumPeak

Input

boolean

False

If True, the resulting peak will be summed

OutputWorkspace

Output

MatrixWorkspace

The output workspace containing the InputWorkspace with the background removed.

Description

This algorithm calculates and subtracts the background from a given workspace using the spectrum ranges in ProcessingInstructions. If no spectrum ranges are given the whole input workspace is used.

The background can be calculated using three methods. PerDetectorAverage which groups the background spectrum together and divides it by the total number of spectra. This is done using GroupDetectors v2. This is then subtracted from the input workspace. Polynomial uses Transpose v1 so the spectrum numbers are in the X (horizontal) axis and TOF channels are the vertical axis. Then the background is calculated by fitting a polynomial of the given degree to each TOF using the background spectra given in InputWorkspaceIndexSet. This is done using CalculatePolynomialBackground v1. The minimizer used is ‘Levenberg-Marquardt’ and the value of CostFunction is passed to CalculatePolynomialBackground v1 as-is. The default option for the CostFunction 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. Once this has been done the workspace is then transposed again and subtracted from the input workspace. AveragePixelFit uses RefRoi v1 to sum the background region on either side of the peak and finding average of these regions. Then the average is subtracted from the sum of the whole region of interest of the detector. It takes the background range from the ProcessingInstructions and the PeakRange which is the range of pixels containing the peak. Note when using the average pixel fit method the background must only be one region either side of the peak. If any more regions are given the background will be taken as all the spectra between the highest and lowest spectra entered excluding the peak. This is done using LRSubtractAverageBackground v1.

Usage

Example - Subtracting background using Per detector average:

import numpy

dataX = [1, 2, 3, 4, 5]
background = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
peak = [5, 5, 5, 5, 5]
dataY = background + peak + background
#workspace has a background of 2 and a peak of 5 in the 2nd index
ws = CreateWorkspace(dataX, dataY, NSpec = 5)

ws_bkg_subtr = ReflectometryBackgroundSubtraction(ws, ProcessingInstructions = "0,1,3,4", BackgroundCalculationMethod = "PerDetectorAverage")

Y = ws.readY(2)[0]
print('Peak height with background: {}'.format(Y))
Y = ws_bkg_subtr.readY(2)[0]
print('Background subtracted peak height: {}'.format(Y))

Output:

Peak height with background: 5.0
Background subtracted peak height: 3.0

Example - Subtracting background using Polynomial:

import numpy

#create a workspace with a polynomial background of degree 2 and a peak of 5 in the 5th spectra
dataX = [1]
polynomial = [1, 8, 13, 16, 17, 16, 13, 8, 1]
peak = [0, 0, 0, 0, 5, 0, 0, 0, 0]
dataY = [a + b for a, b in zip(polynomial, peak)]
ws = CreateWorkspace(dataX, dataY, NSpec = 9)

ws_bkg_subtr = ReflectometryBackgroundSubtraction(ws, InputWorkspaceIndexType='SpectrumNumber', ProcessingInstructions = "1-4,6-9", BackgroundCalculationMethod = "Polynomial", DegreeOfPolynomial = 2)

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

Output:

Peak height with background: 22.0
Background subtracted peak height: 5.0

Categories: AlgorithmIndex | Reflectometry | Reflectometry\ISIS

Source

C++ header: ReflectometryBackgroundSubtraction.h

C++ source: ReflectometryBackgroundSubtraction.cpp