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

SplineBackground v1

../_images/SplineBackground-v1_dlg.png

SplineBackground dialog.

Summary

Fit spectra background using b-splines.

See Also

Fit, SplineInterpolation, SplineSmoothing

Properties

Name

Direction

Type

Default

Description

InputWorkspace

Input

MatrixWorkspace

Mandatory

The name of the input workspace.

OutputWorkspace

Output

MatrixWorkspace

Mandatory

The name to use for the output workspace.

WorkspaceIndex

Input

number

0

The index of the spectrum for fitting.

NCoeff

Input

number

10

The number of b-spline coefficients.

Description

SplineBackground uses GSL b-spline and fitting functions to fit a spectrum. Masked bins are excluded from the fit making it possible to fit only the background signal. The output workspace has one spectrum of calculated values and the fitting errors.

Usage

import numpy as np

# Create a workspace with some data

# Fill array x with 100 float values equally spaced in the interval [-10, 10]
x = np.linspace(-10,10,100)
# Fill array y with values of a function for each number in array x. y has the same length as x
y = 1.0 / (x**2 + 10)
# Create array e of the same length as x and fill it with ones (1.0)
e = np.ones_like(x)
# Uses the above arrays to create a workspace
ws = CreateWorkspace( x, y, e )

# Run algorithm with low number of spline coefficients
out = SplineBackground(ws, WorkspaceIndex=0, NCoeff=4)
yout = out.readY(0)
# Sum the squares of the differences of elements of arrays y and yout
print('Fit quality is {}'.format(np.sum( (y - yout)**2 )))

# Increase the number of spline coefficients
out = SplineBackground(ws, WorkspaceIndex=0, NCoeff=20)
yout = out.readY(0)
# Sum the squares of the differences of elements of arrays y and yout
print('Fit quality is {}'.format(np.sum( (y - yout)**2 )))
Fit quality is ...
Fit quality is ...

Categories: AlgorithmIndex | Optimization | CorrectionFunctions\BackgroundCorrections

Source

C++ header: SplineBackground.h

C++ source: SplineBackground.cpp