From c44d496b258d714301e97b4379888e2ff3786720 Mon Sep 17 00:00:00 2001 From: Michael Wedel Date: Fri, 20 Feb 2015 14:52:15 +0100 Subject: [PATCH] Refs #10996. Providing fallback peak profile When PoldiPeakCollection has no profile function set, the one provided to PoldiFitPeaks2D should be used. --- Code/Mantid/Framework/SINQ/src/PoldiFitPeaks2D.cpp | 14 ++++++++++++-- .../Framework/SINQ/test/PoldiFitPeaks2DTest.h | 8 +++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Code/Mantid/Framework/SINQ/src/PoldiFitPeaks2D.cpp b/Code/Mantid/Framework/SINQ/src/PoldiFitPeaks2D.cpp index 3a99fdcd681b..5a3e9111e4a6 100644 --- a/Code/Mantid/Framework/SINQ/src/PoldiFitPeaks2D.cpp +++ b/Code/Mantid/Framework/SINQ/src/PoldiFitPeaks2D.cpp @@ -573,11 +573,21 @@ PoldiPeakCollection_sptr PoldiFitPeaks2D::getIntegratedPeakCollection( } /* If no profile function is specified, it's not possible to get integrated - * intensities at all and we need to abort at this point. + * intensities at all and we try to use the one specified by the user instead. */ + std::string profileFunctionName = rawPeakCollection->getProfileFunctionName(); + if (!rawPeakCollection->hasProfileFunctionName()) { + profileFunctionName = getPropertyValue("PeakProfileFunction"); + } + + std::vector allowedProfiles = + FunctionFactory::Instance().getFunctionNames(); + + if (std::find(allowedProfiles.begin(), allowedProfiles.end(), + profileFunctionName) == allowedProfiles.end()) { throw std::runtime_error( - "Cannot integrate peak profiles without profile function."); + "Cannot integrate peak profiles with invalid profile function."); } PoldiPeakCollection_sptr integratedPeakCollection = diff --git a/Code/Mantid/Framework/SINQ/test/PoldiFitPeaks2DTest.h b/Code/Mantid/Framework/SINQ/test/PoldiFitPeaks2DTest.h index a126b91d10b5..9c18d599c85b 100644 --- a/Code/Mantid/Framework/SINQ/test/PoldiFitPeaks2DTest.h +++ b/Code/Mantid/Framework/SINQ/test/PoldiFitPeaks2DTest.h @@ -96,6 +96,7 @@ class PoldiFitPeaks2DTest : public CxxTest::TestSuite PoldiPeakCollection_sptr testPeaks = PoldiPeakCollectionHelpers::createPoldiPeakCollectionMaximum(); TestablePoldiFitPeaks2D spectrumCalculator; + spectrumCalculator.initialize(); // deltaT is not set, so this must fail TS_ASSERT_THROWS(spectrumCalculator.getIntegratedPeakCollection(testPeaks), std::invalid_argument); spectrumCalculator.setDeltaT(3.0); @@ -138,8 +139,13 @@ class PoldiFitPeaks2DTest : public CxxTest::TestSuite TS_ASSERT_EQUALS(alreadyIntegratedResult->peakCount(), alreadyIntegratedPeaks->peakCount()); TS_ASSERT_EQUALS(alreadyIntegratedResult->peak(0)->d(), alreadyIntegratedPeaks->peak(0)->d()); - // Where there's no profile function specified, the integration can not be performed. + // Where there's no profile function in the peak collection, falling back to the property PeakProfileFunction. + // Default is Gaussian, so this is supposed to work. PoldiPeakCollection_sptr noProfilePeaks(new PoldiPeakCollection); + TS_ASSERT_THROWS_NOTHING(spectrumCalculator.getIntegratedPeakCollection(noProfilePeaks)); + + // While setting an invalid function name throws. + spectrumCalculator.setProperty("PeakProfileFunction", "InvalidFunctionName"); TS_ASSERT_THROWS(spectrumCalculator.getIntegratedPeakCollection(noProfilePeaks), std::runtime_error); // When there is no valid PoldiPeakCollection, the method also throws