From fe508fd0fad8769dbaaea82eeeec4e9f29573a49 Mon Sep 17 00:00:00 2001
From: Dan Nixon <dan@dan-nixon.com>
Date: Tue, 3 Mar 2015 11:55:52 +0000
Subject: [PATCH] Added documentation and error handing when no peaks found

Refs #6971
---
 .../WorkflowAlgorithms/TOSCABankCorrection.py | 10 ++++-
 .../algorithms/TOSCABankCorrection-v1.rst     | 37 +++++++++++++++++++
 2 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 Code/Mantid/docs/source/algorithms/TOSCABankCorrection-v1.rst

diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/TOSCABankCorrection.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/TOSCABankCorrection.py
index 5d8fb537f8b..6cc5b9522b3 100644
--- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/TOSCABankCorrection.py
+++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/TOSCABankCorrection.py
@@ -16,7 +16,7 @@ class TOSCABankCorrection(DataProcessorAlgorithm):
 
 
     def category(self):
-        return 'PythonAlgorithms;Inelastic'
+        return 'PythonAlgorithms;Inelastic;CorrectionFunctions'
 
 
     def summary(self):
@@ -28,7 +28,8 @@ class TOSCABankCorrection(DataProcessorAlgorithm):
                              direction=Direction.Input),
                              doc='Input reduced workspace')
 
-        self.declareProperty(FloatArrayProperty(name='SearchRange'),
+        self.declareProperty(FloatArrayProperty(name='SearchRange',
+                                                values=[200, 2000]),
                              doc='Range over which to find peaks')
 
         self.declareProperty(name='ClosePeakTolerance', defaultValue=20.0,
@@ -92,6 +93,11 @@ class TOSCABankCorrection(DataProcessorAlgorithm):
         peaks = self._get_peaks('__search_ws')
         DeleteWorkspace('__search_ws')
 
+        # Ensure there is at least one peak found
+        if len(peaks) < 1:
+            raise RuntimeError('Could not find any peaks. Try increasing \
+                                width of SearchRange and/or ClosePeakTolerance')
+
         delta = self._get_delta(peaks)
         offset = delta / 2
 
diff --git a/Code/Mantid/docs/source/algorithms/TOSCABankCorrection-v1.rst b/Code/Mantid/docs/source/algorithms/TOSCABankCorrection-v1.rst
new file mode 100644
index 00000000000..e927286c8d9
--- /dev/null
+++ b/Code/Mantid/docs/source/algorithms/TOSCABankCorrection-v1.rst
@@ -0,0 +1,37 @@
+.. algorithm::
+
+.. summary::
+
+.. alias::
+
+.. properties::
+
+Description
+-----------
+
+This algorithm attempts to automatically correct TOSCA data in which the
+position of the sample has been moved and has affected the alignment of features
+on the spectra from forward and backscattering detector banks.
+
+The input workspace should be an energy transfer reduction, for the default
+values of SearchRange and ClosePeakTolerance the X axis is assumed to be in
+cm-1, however the X axis is not restricted to this unit.
+
+The algorithm works by finding peaks of a given shape (using the :ref:`FindPeaks
+<algm-FindPeaks>`) on both the forward and backscattering banks and attempting
+to match them to what is believed to be the same feature on the other bank.
+
+The choice can then be made to either take the difference in peak centre between
+the tallest matched peaks or to average the difference of all matched peaks to
+determine the mount that both spectra must be moved by to correct for the change
+in sample position.
+
+The data is then corrected by providing a shift in the X axis of each bank
+spectra (using :ref:`ConvertAxisByFormula <algm-ConvertAxisByFormula>`) to bring
+the two individual bank spectra back into alignment.
+
+The corrected spectra are then rebinned to the input workspace (using
+:ref:`RebinToWorkspace <algm-RebinToWorkspace>`) to preserve the X range and to
+maintain bin alignment.
+
+.. categories::
-- 
GitLab