Skip to content

Commit

Permalink
Refs #10996. Providing fallback peak profile
Browse files Browse the repository at this point in the history
When PoldiPeakCollection has no profile function set, the one provided to PoldiFitPeaks2D should be used.
  • Loading branch information
Michael Wedel committed Feb 20, 2015
1 parent 5a1ac75 commit c44d496
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Code/Mantid/Framework/SINQ/src/PoldiFitPeaks2D.cpp
Expand Up @@ -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<std::string> allowedProfiles =
FunctionFactory::Instance().getFunctionNames<IPeakFunction>();

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 =
Expand Down
8 changes: 7 additions & 1 deletion Code/Mantid/Framework/SINQ/test/PoldiFitPeaks2DTest.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c44d496

Please sign in to comment.