13#include "MantidAPI/IFunction1D.tcc"
17#include "boost/make_shared.hpp"
29class PartialJacobian1 :
public Jacobian {
37 PartialJacobian1(Jacobian *J,
int iY0) :
m_J(J),
m_iY0(iY0) {}
44 void set(
size_t iY,
size_t iP,
double value)
override {
m_J->set(m_iY0 + iY, iP,
value); }
50 double get(
size_t iY,
size_t iP)
override {
return m_J->get(m_iY0 + iY, iP); }
53 void zero()
override {
54 throw Kernel::Exception::NotImplementedError(
"zero() is not implemented for PartialJacobian1");
59const double PEAK_TOLERANCE = 1e-14;
61const int MAX_PEAK_RADIUS = std::numeric_limits<int>::max();
71 auto peakRadius =
dynamic_cast<const FunctionDomain1D &
>(domain).getPeakRadius();
91 for (
size_t i = 0; i < nData; ++i) {
92 if (
fabs(xValues[i] - c) < dx) {
94 i0 =
static_cast<int>(i);
100 if (i0 < 0 ||
n == 0)
117 double c = this->
centre();
121 for (
size_t i = 0; i < nData; ++i) {
122 if (
fabs(xValues[i] - c) < dx) {
124 i0 =
static_cast<int>(i);
127 for (
size_t ip = 0; ip < this->
nParams(); ++ip) {
128 out->
set(i, ip, 0.0);
132 if (i0 < 0 ||
n == 0)
134 PartialJacobian1 J(out, i0);
167 auto const result = integrator.
integrate(*
this, interval.first, interval.second);
169 integrationResult = boost::make_shared<IntegrationResultCache>(result.result, result.error);
171 integrationResult = boost::make_shared<IntegrationResultCache>(std::nan(
""), std::nan(
""));
184 return integrator.
integrateError(*
this, interval.first, interval.second);
189 double currentHeight =
height();
192 if (currentIntensity == 0.0) {
200 if (currentIntensity == 0.0) {
201 throw std::invalid_argument(
"Cannot set new intensity, not enough information available.");
205 setHeight(newIntensity / currentIntensity * currentHeight);
213 throw std::runtime_error(
"PeakParameterFunction could not be created successfully.");
216 fn->setDecoratedFunction(this->
name());
221 fn->functionDeriv(domain, jacobian);
231 if (level < PEAK_TOLERANCE) {
232 level = PEAK_TOLERANCE;
240 if (h == 0.0 || w == 0.0 || level >= 1.0) {
241 return std::make_pair(c, c);
244 auto findBound = [
this, c, h, level](
double dx) {
245 for (
size_t i = 0; i < 100; ++i) {
249 if (
fabs(
y / h) < level) {
257 left = findBound(-w);
258 right = findBound(w);
269 auto evalMethod = [
this](
double *out,
const double *xValues,
const size_t nData) {
Jacobian * m_J
pointer to the overall Jacobian
int m_iY0
offset in the overall Jacobian for a particular function
double value
The value of the point.
Implements FunctionDomain1D with its own storage in form of a std::vector.
Represent a domain for functions of one real argument.
Base class that represents the domain of a function.
A class to store values calculated by a function.
void calcNumericalDerivative1D(Jacobian *jacobian, EvaluationMethod func1D, const double *xValues, const size_t nData)
Calculate a numerical derivative for the 1D data.
void function(const FunctionDomain &domain, FunctionValues &values) const override
Evaluates the function for all arguments in the domain.
virtual void setHeight(const double h)=0
Sets the parameters such that height == h.
virtual double height() const =0
Returns the height of the function.
virtual double centre() const =0
Returns the centre of the function, which may be something as simple as the centre of the fitting ran...
virtual std::string name() const =0
Returns the function's name.
virtual void setIntensity(const double newIntensity)
Sets the integral intensity of the peak.
virtual void functionLocal(double *out, const double *xValues, const size_t nData) const =0
Function evaluation method to be implemented in the inherited classes.
virtual void functionDerivLocal(Jacobian *jacobian, const double *xValues, const size_t nData)
Derivative evaluation method. Default is to calculate numerically.
void functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) override
General implementation of the method for all peaks.
std::string getCentreParameterName() const
Get name of parameter that is associated to centre.
virtual double fwhm() const =0
Returns the peak FWHM.
void function1D(double *out, const double *xValues, const size_t nData) const override
General implementation of the method for all peaks.
void function(const FunctionDomain &domain, FunctionValues &values) const override
Evaluates the function for all arguments in the domain.
virtual IntegrationResultCache integrate() const
bool m_parameterContextDirty
boost::shared_ptr< IntegrationResultCache > integrationResult
virtual double intensity() const
Returns the integral intensity of the peak.
void setPeakRadius(int r) const
Set new peak radius.
virtual double intensityError() const
Error in the integrated intensity of the peak due to uncertainties in the values of the fit parameter...
IPeakFunction()
Constructor.
int m_peakRadius
Defines the area around the centre where the peak values are to be calculated (in FWHM).
void setParameter(const std::string &name, const double &value, bool explicitlySet=true) override
Override parent so that we may bust the cache when a parameter is set.
virtual std::pair< double, double > getDomainInterval(double level=DEFAULT_SEARCH_LEVEL) const
Get the interval on which the peak has all its values above a certain level.
Represents the Jacobian in IFitFunction::functionDeriv.
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
size_t nParams() const override
Total number of parameters.
double integrateError(const IPeakFunction &peakFunction, double lowerLimit, double upperLimit) const
Error in the integrated intensity within an continuous interval due to uncertainties in the values of...
IntegrationResult integrate(const IPeakFunction &peakFunction, double lowerLimit, double upperLimit) const
Integration of peak function on the interval [a, b].
size_t maxParam(size_t iY)
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::pair< double, double > IntegrationResultCache
std::shared_ptr< FunctionParameterDecorator > FunctionParameterDecorator_sptr