Backgrounds Class#

This class makes the backgrounds in RAT. Backgrounds are defined in a two stage process. Firstly we define the actual fitted parameters. These are held in a ‘ParametersClass’ table. Then, we group these into the backgrounds themselves using a multiTypeTable(table). So, we can then use the background parameters to either define background as constant, data or a function.

The methods on the left call the methods on the right in the table.#

Method in Project Class

Method in backgroundsClass

projectClass.addBackgroundParam()

backgroundsClass.backgroundParams.addParameter()

projectClass.removeBackgroundParam()

backgroundsClass.backgroundParams.removeParameter()

projectClass.setBackgroundParamValue()

backgroundsClass.backgroundParams.setValue()

projectClass.addBackground()

backgroundsClass.addBackground()

projectClass.removeBackground()

backgroundsClass.removeBackground()

Note

  1. For constant, only one parameter is supplied to multi type table.

  2. For data, only the data itself is supplied as a cell.

  3. For function, the function name is supplied, along with up to three parameters (from the parameters table) which are then supplied to the function to calculate the background.

In each case, the background can either be added to the simulation or subtracted from the data.

Example showing how backgroundsClass methods are called.#
    % Change the name of the existing parameters to refer to D2O
    problem.setBacksPar(1,'name','Backs par D2O','fit',true,'min',1e-8,'max',1e-5);

    % Add a new constant background
    problem.addBackground('Background SMW','constant','Backs par SMW');

Reference#

class API.projectClass.backgroundsClass(parameters, startBackground, allowedNames)#

Backgrounds are defined in a two stage process. Firstly we define the actual fitted parameters. These are held in a ‘Parameters’ table. Then, we group these into the backgrounds themselves using a multiTypeTable. So, we can then use the background parameters to either define background as constant, data or a function.

For constant only one background parameter is supplied to multi type table.

For data an entry in the data table and an optional offset is required

For function, the function name is supplied, along with up to five parameters (from the background parameters table) which are then passed to the function to calculate the background.

In each case, the background can either be added to the simulation or subtracted from the data.

addBackground(allowedNames, varargin)#

Adds a new entry to the background table.

background.addBackground(allowedNames, ‘New Row’); background.addBackground(allowedNames, ‘New Row’, ‘constant’, ‘param_name’); background.addBackground(allowedNames, ‘New Row’, ‘function’, ‘function_name’, ‘param_name’, ‘param_name’); background.addBackground(allowedNames, ‘New Row’, ‘data’, ‘data_name’, ‘param_name’);

backgroundsClass(parameters, startBackground, allowedNames)#

Creates a background object. The arguments should be an instance of the parameter class with the background parameters, a cell array of backgrounds and the struct of allowed data and function names.

params = parametersClass({‘Background Param 1’, 1e-7, 1e-6, 1e-5, false, ‘uniform’, 0, Inf}); background = backgroundClass(params, {‘Background 1’, ‘constant’, ‘Background Param 1’}, allowedNames);

displayBackgroundsObject(showPriors)#

Displays the background parameters and background table. Optional showPriors to display the priors default is false

background.displayBackgroundsObject(true);

getNames()#

Returns a N x 1 cell array of names of the backgrounds in the object.

names = background.getNames();

removeBackground(row)#

Removes a background entry from the table. Expects the index or array of indices of background(s) to remove.

background.removeBackground(2); background.removeBackground([1, 3]);

setBackground(row, allowedNames, varargin)#

Changes the value of a given background in the table. Expects the index or name of background, the struct of allowed data and function names, and keyword/value pairs to set.

background.setBackground(1, allowedNames, ‘name’, ‘back 1’, ‘type’, ‘constant’, ‘source’, ‘param_name’);

setBackgroundName(row, name)#

Sets the name of a given background in the table. Expects an index and the new name.

background.setBackgroundName(1, ‘new_name’);

toStruct()#

Converts the class parameters into a structure array