Skip to content

Commit

Permalink
Refs #11104. Add intensity/setIntensity methods to IPeakFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Feb 18, 2015
1 parent 06e5025 commit 173c231
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IPeakFunction.h
Expand Up @@ -49,6 +49,12 @@ class MANTID_API_DLL IPeakFunction : public IFunctionWithLocation {
/// Sets the parameters such that FWHM = w
virtual void setFwhm(const double w) = 0;

/// Returns the integral intensity of the peak
virtual double intensity() const;

/// Sets the integral intensity of the peak
virtual void setIntensity(const double intensity);

/// General implementation of the method for all peaks.
void function1D(double *out, const double *xValues, const size_t nData) const;
/// General implementation of the method for all peaks.
Expand Down
27 changes: 27 additions & 0 deletions Code/Mantid/Framework/API/src/IPeakFunction.cpp
Expand Up @@ -3,6 +3,7 @@
//----------------------------------------------------------------------
#include "MantidAPI/IPeakFunction.h"
#include "MantidAPI/Jacobian.h"
#include "MantidAPI/PeakFunctionIntegrator.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/ConfigService.h"

Expand Down Expand Up @@ -130,5 +131,31 @@ void IPeakFunction::setPeakRadius(const int &r) {
}
}

double IPeakFunction::intensity() const {
double x0 = centre();
double dx = fabs(s_peakRadius * fwhm());

PeakFunctionIntegrator integrator;
IntegrationResult result = integrator.integrate(*this, x0 - dx, x0 + dx);

if(!result.success) {
return 0.0;
}

return result.result;
}

void IPeakFunction::setIntensity(const double newIntensity)
{
double currentHeight = height();
double currentIntensity = intensity();

if(currentIntensity == 0.0) {
setHeight(0.0);
} else {
setHeight(newIntensity / currentIntensity * currentHeight);
}
}

} // namespace API
} // namespace Mantid

0 comments on commit 173c231

Please sign in to comment.