Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Stitch1D-v3.rst 6.04 KiB

Description

Stitches single histogram :ref:`Matrix Workspaces <MatrixWorkspace>` together outputting a stitched Matrix Workspace. Note that workspaces must be histogrammed, you may want to use :ref:`algm-ConvertToHistogram` on workspaces prior to passing them to this algorithm.

Either the right-hand-side or left-hand-side workspace can be chosen to be scaled. Users can optionally provide :ref:`algm-Rebin` Params, otherwise they are calculated from the input workspaces. Likewise, StartOverlap and EndOverlap are optional. If not provided, then these are taken to be the region of X-axis intersection.

The type of the input workspaces (histogram or point data) define the calculation of x values in the overlap range of the output workspace.

The algorithm workflow is as follows:

  1. The workspaces are initially rebinned, as prescribed by the rebin Params. Note that rebin parameters are determined automatically if not provided. In this case, the step size is taken from the step size of the LHS workspace (or from the RHS workspace if ScaleRHSWorkspace was set to false) and rebin boundaries are taken from the minimum X value in the LHS workspace and the maximum X value in the RHS workspace respectively.
  2. After rebinning, each spectrum is searched for special values. Special values refer to signal (Y) and error (E) values that are either infinite or NaN. These special values are masked out as zeroes and their positions are recorded for later reinsertion.
  3. Next, if UseManualScaleFactor was set to false, both workspaces will be integrated according to the integration range defined by StartOverlap and EndOverlap. Note that the integration is performed without special values, as those have been masked out in the previous step. The scale factor is then calculated as the quotient of the integral of the left-hand-side workspace by the integral of the right-hand-side workspace (or the quotient of the right-hand-side workspace by the left-hand-side workspace if ScaleRHSWorkspace was set to false), and the right-hand-side workspace (left-hand-side if ScaleRHSWorkspace was set to false) is multiplied by the calculated factor.
  4. Alternatively, if UseManualScaleFactor was set to true, the scale factor is applied to the right-hand-side workspace (left-hand-side workspace if ScaleRHSWorkspace was set to false).
  5. The weighted mean of the two workspaces in range [StartOverlap, EndOverlap] is calculated. Note that if both workspaces have zero errors, an un-weighted mean will be performed instead.
  6. For histograms, the output workspace will be created by summing the left-hand-side workspace (values in range [StartX, StartOverlap], where StartX is the minimum X value specified via Params or calculated from the left-hand-side workspace) + weighted mean workspace + right-hand-side workspace (values in range [EndOverlap, EndX], where EndX is the maximum X value specified via Params or calculated from the right-hand-side workspace) multiplied by the scale factor. Dx values will not be present in the output workspace. For point data, the output workspace will propagate x values and Dx values present in the overlap range to the output workspace.
  7. The special values are put back in the output workspace. Note that if both the left-hand-side workspace and the right-hand-side workspace happen to have a different special value in the same bin, this bin will be set to infinite in the output workspace.

Below is a flowchart illustrating the steps in the algorithm (it assumes ScaleRHSWorkspace is true). Figure on the left corresponds to the workflow when no scale factor is provided, while figure on the right corresponds to workflow with a manual scale factor specified by the user.

Error propagation

Errors are are handled and propagated in every step according to :ref:`Error Propagation`. This includes every child algorithm: :ref:`algm-Rebin`, :ref:`algm-Integration`, :ref:`algm-Divide`, :ref:`algm-Multiply` and :ref:`algm-WeightedMean`. In particular, when the scale factor is calculated as the quotient of the left-hand-side integral and the right-hand-side integral, the result is a number with an error associated, and therefore the multiplication of the right-hand-side workspace by this number takes into account its error.

Usage

Example - a basic example using stitch1D to stitch two workspaces together.

Output:

Stitch1D output

Example - a practical example using reflectometry data and a scale factor.

Output:

Stitch1D output