Skip to content

Commit

Permalink
Re #11131. Correction for a case of h0 == 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Mar 6, 2015
1 parent 5ec5963 commit a0623f3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IPeakFunction.h
Expand Up @@ -71,7 +71,7 @@ class MANTID_API_DLL IPeakFunction : public IFunctionWithLocation {
const size_t nData) = 0;

/// Get name of parameter that is associated to centre.
std::string getCentreParameterName() const;
virtual std::string getCentreParameterName() const;

protected:
/// Defines the area around the centre where the peak values are to be
Expand Down
Expand Up @@ -56,6 +56,7 @@ class DLLExport PeakParametersNumeric : public API::IPeakFunction {
virtual void setParameter(size_t, const double &value,
bool explicitlySet = true);
using API::IPeakFunction::setParameter;
std::string getCentreParameterName() const;

/// Get boundaries for an interval within which the peak has
/// significant values. The interval must contain the maximum
Expand Down
14 changes: 12 additions & 2 deletions Code/Mantid/Framework/CurveFitting/src/PeakParametersNumeric.cpp
Expand Up @@ -55,7 +55,7 @@ double PeakParametersNumeric::height() const {
void PeakParametersNumeric::setHeight(const double h) {
double h0 = height();
if (h0 == 0.0) {
setParameter(m_heightIndex, 1e-6);
setParameter(m_heightIndex, 1.0);
h0 = height();
}
double parValue = getParameter(m_heightIndex);
Expand Down Expand Up @@ -96,7 +96,11 @@ double PeakParametersNumeric::fwhm() const {
/// @param w :: New value for the width.
void PeakParametersNumeric::setFwhm(const double w) {
const double c = centre();
const double h = height();
double h = height();
if (h == 0.0) {
setHeight(1.0);
h = 1.0;
}
double wOld = fwhm();
double factor = w / wOld;
for (size_t i = 0; i < m_widthIndices.size(); ++i) {
Expand Down Expand Up @@ -251,5 +255,11 @@ void PeakParametersNumeric::updateCache() const {
}
}

/// Override the base class implementation
std::string PeakParametersNumeric::getCentreParameterName() const
{
return parameterName(m_centreIndex);
}

} // namespace CurveFitting
} // namespace Mantid
Expand Up @@ -228,13 +228,11 @@ class PeakParametersNumericTest : public CxxTest::TestSuite {
TS_ASSERT_DELTA(fun.centre(), -1.0, tol);
TS_ASSERT_DELTA(fun.height(), 1.0, tol);
TS_ASSERT_DELTA(fun.fwhm(), 0.4027, tol);
std::cerr << fun.intensity() << std::endl;

fun.setHeight(10.0);
TS_ASSERT_DELTA(fun.centre(), -1.0, tol);
TS_ASSERT_DELTA(fun.height(), 10.0, tol);
TS_ASSERT_DELTA(fun.fwhm(), 0.4027, tol);
std::cerr << fun.intensity() << std::endl;

fun.setFwhm(1.0);
TS_ASSERT_DELTA(fun.centre(), -1.0, tol);
Expand Down

0 comments on commit a0623f3

Please sign in to comment.