From a197ebc34f025f141852233e797347adc84a860d Mon Sep 17 00:00:00 2001
From: Owen Arnold <owen.arnold@stfc.ac.uk>
Date: Sat, 7 Jun 2014 16:59:31 +0100
Subject: [PATCH] refs #9549. Protect against bad scale factors.

---
 .../Mantid/Framework/Algorithms/src/Stitch1D.cpp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp b/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp
index 31de555f170..129a0391a31 100644
--- a/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp
@@ -14,14 +14,17 @@
 #include "MantidKernel/PropertyWithValue.h"
 #include "MantidKernel/RebinParamsValidator.h"
 #include "MantidKernel/MultiThreaded.h"
+#include "MantidKernel/BoundedValidator.h"
 
 #include <boost/make_shared.hpp>
 #include <boost/tuple/tuple.hpp>
 #include <boost/format.hpp>
 #include <boost/algorithm/string.hpp>
+#include <boost/math/special_functions.hpp>
 #include <vector>
 #include <algorithm>
 
+
 using namespace Mantid::Kernel;
 using namespace Mantid::API;
 using Mantid::MantidVec;
@@ -85,7 +88,10 @@ namespace Mantid
           "Scaling either with respect to workspace 1 or workspace 2");
       declareProperty(new PropertyWithValue<bool>("UseManualScaleFactor", false, Direction::Input),
           "True to use a provided value for the scale factor.");
-      declareProperty(new PropertyWithValue<double>("ManualScaleFactor", 1.0, Direction::Input),
+      auto manualScaleFactorValidator = boost::make_shared<BoundedValidator<double> >();
+      manualScaleFactorValidator->setLower(0);
+      manualScaleFactorValidator->setExclusive(true);
+      declareProperty(new PropertyWithValue<double>("ManualScaleFactor", 1.0, manualScaleFactorValidator, Direction::Input),
           "Provided value for the scale factor. Optional.");
       declareProperty(
           new PropertyWithValue<double>("OutScaleFactor", Mantid::EMPTY_DBL(), Direction::Output),
@@ -457,8 +463,14 @@ namespace Mantid
       }
       scaleFactor = ratio->readY(0).front();
       errorScaleFactor = ratio->readE(0).front();
+      if(scaleFactor == 0 || boost::math::isnan(scaleFactor))
+      {
+        std::stringstream messageBuffer;
+        messageBuffer << "Stitch1D calculated scale factor is: " << scaleFactor << ". Check that in both input workspaces the integrated overlap region is non-zero.";
+        g_log.warning(messageBuffer.str());
+      }
+
     }
-    //manualscalefactor end if
 
     int a1 = boost::tuples::get<0>(startEnd);
     int a2 = boost::tuples::get<1>(startEnd);
-- 
GitLab