diff --git a/Code/Mantid/Framework/Algorithms/src/LorentzCorrection.cpp b/Code/Mantid/Framework/Algorithms/src/LorentzCorrection.cpp index 111af9bf01a5a6b9b2d13949f609ed14012b73db..e58e67ebe457760eca11af4b2d0df23c4a188926 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 1a5fdafa23bfe1b96f1d2363938a087a8d039c5b..bd553d7cea50cfdc9c2aba77cace6cdf0176527e 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*/);