Skip to content
Snippets Groups Projects
Commit 9434e3de authored by Verena Reimund's avatar Verena Reimund
Browse files

Improve documentation and diagram

Refs #22197
parent 92a25858
No related branches found
No related tags found
No related merge requests found
#include "MantidAlgorithms/Stitch1D.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Workspace.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidHistogramData/HistogramE.h"
#include "MantidHistogramData/HistogramDx.h"
......@@ -58,7 +56,7 @@ DECLARE_ALGORITHM(Stitch1D)
*/
MatrixWorkspace_sptr Stitch1D::maskAllBut(int a1, int a2,
MatrixWorkspace_sptr &source) {
MatrixWorkspace_sptr product = WorkspaceFactory::Instance().create(source);
MatrixWorkspace_sptr product = source->clone();
const int histogramCount = static_cast<int>(source->getNumberHistograms());
PARALLEL_FOR_IF(Kernel::threadSafe(*source, *product))
for (int i = 0; i < histogramCount; ++i) {
......@@ -637,7 +635,6 @@ void Stitch1D::exec() {
findStartEndIndexes(startOverlap, endOverlap, lhs);
int a1 = boost::tuples::get<0>(startEnd);
int a2 = boost::tuples::get<1>(startEnd);
// Mask out everything BUT the overlap region as a new workspace.
MatrixWorkspace_sptr overlap1 = maskAllBut(a1, a2, lhs);
// Mask out everything BUT the overlap region as a new workspace.
......
......@@ -20,7 +20,7 @@ are taken to be the region of X-axis intersection.
The type of the input workspaces (histogram or point data) determines the x values in the overlap range of the output workspace.
The algorithm workflow is as follows:
The algorithm workflow for histograms is as follows:
#. The workspaces are initially rebinned, as prescribed by the rebin :literal:`Params`. Note that
rebin parameters are determined automatically if not provided. In this case, the step size is
......@@ -44,14 +44,13 @@ The algorithm workflow is as follows:
#. The weighted mean of the two workspaces in range [:literal:`StartOverlap`, :literal:`EndOverlap`]
is calculated. Note that if both workspaces have zero errors, an un-weighted mean will be
performed instead.
#. For histograms, the output workspace will be created by summing the left-hand-side workspace (values in range
#. The output workspace will be created by summing the left-hand-side workspace (values in range
[:literal:`StartX`, :literal:`StartOverlap`], where :literal:`StartX` is the minimum X value
specified via :literal:`Params` or calculated from the left-hand-side workspace) + weighted
mean workspace + right-hand-side workspace (values in range [:literal:`EndOverlap`, :literal:`EndX`],
where :literal:`EndX` is the maximum X value specified via :literal:`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.
#. 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.
......@@ -63,6 +62,22 @@ workflow with a manual scale factor specified by the user.
.. diagram:: Stitch1D-v3.dot
The algorithm workflow for point data is as follows:
#. If :literal:`UseManualScaleFactor` was set to false, both workspaces will be integrated
according to the integration range defined by :literal:`StartOverlap` and :literal:`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 :literal:`ScaleRHSWorkspace`
was set to false), and the right-hand-side workspace (left-hand-side if :literal:`ScaleRHSWorkspace`
was set to false) is multiplied by the calculated factor.
#. Alternatively, if :literal:`UseManualScaleFactor` was set to true, the scale factor is applied
to the right-hand-side workspace (left-hand-side workspace if :literal:`ScaleRHSWorkspace` was
set to false).
#. The output workspace will be created by joining and sorted to guarantee ascending x values.
Dx values will be present in the output workspace.
Error propagation
#################
......@@ -94,7 +109,7 @@ Usage
ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=gaussian(x1[:-1], 0, 0.1)+1)
ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=gaussian(x2[:-1], 1, 0.05)+1)
#stitch the histograms together
# stitch the histograms together
stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, StartOverlap=0.4, EndOverlap=0.6, Params=0.02)
# plot the individual workspaces alongside the stitched one
......@@ -128,7 +143,7 @@ Usage
ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=gaussian(x1, 0, 0.1)+1)
ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=gaussian(x2, 1, 0.05)+1)
#stitch the histograms together
# stitch the histograms together
stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, StartOverlap=0.4, EndOverlap=0.6)
# plot the individual workspaces alongside the stitched one
......@@ -137,7 +152,7 @@ Usage
axs[0].plot(mtd['ws1'], wkspIndex=0, label='ws1')
axs[0].plot(mtd['ws2'], wkspIndex=0, label='ws2')
axs[0].legend()
axs[1].plot(mtd['stitched'], wkspIndex=0, color='k', label='stitched')
axs[1].plot(mtd['stitchedP'], wkspIndex=0, color='k', marker='.', ls='', label='stitched')
axs[1].legend()
# uncomment the following line to show the plot window
......
digraph Stitch1D {
splines=false
label = "\nStitch1D workflow - no manual scale factor Stitch1D workflow - manual scale factor given\n\n"
label = "\nStitch1D workflow for histograms - no manual scale factor Stitch1D workflow histograms - manual scale factor given\n\n"
$global_style
subgraph params {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment