From bbc314baaca79b78c75abdf96ca742e4e2750e5a Mon Sep 17 00:00:00 2001
From: Owen Arnold <owen.arnold@stfc.ac.uk>
Date: Mon, 15 Sep 2014 11:44:56 +0100
Subject: [PATCH] refs #10208. Fix issues raised in testing.

---
 .../Framework/Algorithms/src/LorentzCorrection.cpp | 12 ++++++++++--
 .../Algorithms/test/LorentzCorrectionTest.h        | 14 ++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/Code/Mantid/Framework/Algorithms/src/LorentzCorrection.cpp b/Code/Mantid/Framework/Algorithms/src/LorentzCorrection.cpp
index 111af9bf01a..e58e67ebe45 100644
--- a/Code/Mantid/Framework/Algorithms/src/LorentzCorrection.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/LorentzCorrection.cpp
@@ -119,12 +119,20 @@ namespace Mantid
           continue;
 
         const double twoTheta = inWS->detectorTwoTheta(detector);
+        const double sinTheta = std::sin(twoTheta / 2);
+        double sinThetaSq = sinTheta * sinTheta;
 
         for (size_t j = 0; j < inY.size(); ++j)
         {
           const double wL = isHist ? (0.5 * (inX[j] + inX[j + 1])) : inX[j];
-          double sinTheta = std::sin(twoTheta / 2);
-          double weight = sinTheta * sinTheta / (wL * wL * wL * wL);
+          if(wL == 0)
+          {
+            std::stringstream buffer;
+            buffer << "Cannot have zero values Wavelength. At workspace index: " << i; 
+            throw std::runtime_error(buffer.str());
+          }
+          
+          double weight = sinThetaSq / (wL * wL * wL * wL);
           outY[j] *= weight;
           outE[j] *= weight;
         }
diff --git a/Code/Mantid/Framework/Algorithms/test/LorentzCorrectionTest.h b/Code/Mantid/Framework/Algorithms/test/LorentzCorrectionTest.h
index 1a5fdafa23b..bd553d7cea5 100644
--- a/Code/Mantid/Framework/Algorithms/test/LorentzCorrectionTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/LorentzCorrectionTest.h
@@ -115,6 +115,20 @@ public:
         alg.setProperty("InputWorkspace", ws_tof), std::invalid_argument&);
   }
 
+  void test_throws_if_wavelength_zero()
+  {
+    auto ws_lam = this->create_workspace(2 /*nBins*/);
+    ws_lam->dataX(0)[0] = 0; // Make wavelength zero
+    ws_lam->dataX(0)[1] = 0; // Make wavelength zero
+    LorentzCorrection alg;
+    alg.setChild(true);
+    alg.setRethrows(true);
+    alg.initialize();
+    alg.setProperty("InputWorkspace", ws_lam);
+    alg.setPropertyValue("OutputWorkspace", "temp");
+    TSM_ASSERT_THROWS("Should throw with zero wavelength values.", alg.execute(), std::runtime_error&);
+  }
+
   void test_execute()
   {
     auto ws_lam = this->create_workspace(2 /*nBins*/);
-- 
GitLab