CalculateFlatBackground v1

../_images/CalculateFlatBackground-v1_dlg.png

CalculateFlatBackground dialog.

Summary

Finds a constant value fit to an appropriate range of each desired spectrum and subtracts that value from the entire spectrum.

Properties

Name Direction Type Default Description
InputWorkspace Input MatrixWorkspace Mandatory The input workspace must either have constant width bins or is a distribution workspace. It is also assumed that all spectra have the same X bin boundaries
OutputWorkspace Output MatrixWorkspace Mandatory Name to use for the output workspace.
StartX Input number Mandatory The X value at which to start the background fit
EndX Input number Mandatory The X value at which to end the background fit
WorkspaceIndexList Input int list   Indices of the spectra that will have their background removed default: modify all spectra
Mode Input string Linear Fit The background count rate is estimated either by taking a mean or doing a linear fit (default: Linear Fit). Allowed values: [‘Linear Fit’, ‘Mean’]
OutputMode Input string Subtract Background Once the background has been determined it can either be subtracted from the InputWorkspace and returned or just returned (default: Subtract Background). Allowed values: [‘Subtract Background’, ‘Return Background’]
SkipMonitors Input boolean False By default, the algorithm calculates and removes background from monitors in the same way as from normal detectors If this property is set to true, background is not calculated/removed from monitors.
NullifyNegativeValues Input boolean True When background is subtracted, signals in some time channels may become negative. If this option is true, signal in such bins is nullified and the module of the removed signalis added to the error. If false, the signal and errors are left unchanged

Description

This algorithm takes a list of spectra and for each spectrum calculates an average count rate in the given region, usually a region when there are only background neutrons. This count rate is then subtracted from the counts in all the spectrum’s bins. However, no bin will take a negative value as bins with count rates less than the background are set to zero (and their error is set to the backgound value).

The average background count rate is estimated in one of two ways. When Mode is set to “Mean” it is the sum of the values in the bins in the background region divided by the width of the X range. Selecting “Linear Fit” sets the background value to the height in the centre of the background region of a line of best fit through that region.

The error on the background value is only calculated when “Mean” is used. It is the errors in all the bins in the background region summed in quadrature divided by the number of bins. This background error value is added in quadrature to the errors in each bin.

Usage

Example - Subtracting background using Linear Fit:

import numpy as np

y = [3, 1, 1, 1, 7, -3]
x = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5]
input = CreateWorkspace(x,y)

output = CalculateFlatBackground('input',
                                 StartX=2,
                                 EndX=4,
                                 Mode='Linear Fit',
                                 OutputMode='Subtract Background')

print 'Values with subtracted background:', np.around(output.readY(0))

Output:

Values with subtracted background: [ 2.  0.  0.  0.  6.  0.]

Example - Returning background using Mean:

import numpy as np

y = [3, 4, 2, 3, -3]
x = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5]
input = CreateWorkspace(x,y)

output = CalculateFlatBackground('input',
                                 StartX=1,
                                 EndX=3,
                                 Mode='Mean',
                                 OutputMode='Return Background')

print 'Calculated Mean background:', np.around(output.readY(0))

Output:

Calculated Mean background: [ 3.  3.  3.  3.  3.]

Categories: Algorithms | SANS | CorrectionFunctions\BackgroundCorrections