Mantid
Loading...
Searching...
No Matches
IPeakFunction.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2009 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
13#include "boost/shared_ptr.hpp"
14
15namespace Mantid {
16namespace API {
17
18class TempJacobian : public Jacobian {
19public:
20 TempJacobian(size_t y, size_t p) : m_y(y), m_p(p), m_J(y * p) {}
21 void set(size_t iY, size_t iP, double value) override { m_J[iY * m_p + iP] = value; }
22 double get(size_t iY, size_t iP) override { return m_J[iY * m_p + iP]; }
23 size_t maxParam(size_t iY) {
24 double max = -DBL_MAX;
25 size_t maxIndex = 0;
26 for (size_t i = 0; i < m_p; ++i) {
27 double current = get(iY, i);
28 if (current > max) {
29 maxIndex = i;
30 max = current;
31 }
32 }
33
34 return maxIndex;
35 }
36 void zero() override { m_J.assign(m_J.size(), 0.0); }
37
38protected:
39 size_t m_y;
40 size_t m_p;
41 std::vector<double> m_J;
42};
43
44using IntegrationResultCache = std::pair<double, double>;
51class MANTID_API_DLL IPeakFunction : public IFunctionWithLocation {
52public:
55
56 void function(const FunctionDomain &domain, FunctionValues &values) const override;
57
59 virtual double fwhm() const = 0;
60
62 virtual void setFwhm(const double w) = 0;
63
65 virtual double intensity() const;
66
73 virtual double intensityError() const;
74
76 virtual void setIntensity(const double newIntensity);
77
79 void setParameter(const std::string &name, const double &value, bool explicitlySet = true) override;
80
82 void setParameter(size_t, const double &value, bool explicitlySet = true) override;
83
85 void function1D(double *out, const double *xValues, const size_t nData) const override;
87 void functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) override;
88
91 virtual std::pair<double, double> getDomainInterval(double level = DEFAULT_SEARCH_LEVEL) const;
92
94 virtual void functionLocal(double *out, const double *xValues, const size_t nData) const = 0;
96 virtual void functionDerivLocal(Jacobian *jacobian, const double *xValues, const size_t nData);
97
99 std::string getCentreParameterName() const;
100
108 virtual std::string getWidthParameterName() const { return ""; }
109
114 virtual void fixIntensity(bool isDefault = false) {
115 UNUSED_ARG(isDefault);
116 throw std::runtime_error("Generic intensity fixing isn't implemented for this function.");
117 }
118
120 virtual void unfixIntensity() {
121 throw std::runtime_error("Generic intensity fixing isn't implemented for this function.");
122 }
123
124protected:
125 virtual IntegrationResultCache integrate() const;
126
127private:
129 void setPeakRadius(int r) const;
132 mutable int m_peakRadius;
134 static constexpr double DEFAULT_SEARCH_LEVEL = 1e-5;
135 // Cache the result of a PeakFunctionIntegrator call
136 mutable boost::shared_ptr<IntegrationResultCache> integrationResult = nullptr;
137 // Flag to dirty the cache when a param has been set
138 mutable bool m_parameterContextDirty = false;
139};
140
141using IPeakFunction_sptr = std::shared_ptr<IPeakFunction>;
142using IPeakFunction_const_sptr = std::shared_ptr<const IPeakFunction>;
143
144} // namespace API
145} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
Base class that represents the domain of a function.
A class to store values calculated by a function.
An interface to a function with location, which here means a function for which the user may ask what...
An interface to a peak function, which extend the interface of IFunctionWithLocation by adding method...
Definition: IPeakFunction.h:51
virtual std::string getWidthParameterName() const
Get the name of the parameter that is changed when the fwhm is changed.
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 double fwhm() const =0
Returns the peak FWHM.
virtual void setFwhm(const double w)=0
Sets the parameters such that FWHM = w.
virtual void fixIntensity(bool isDefault=false)
Fix a parameter or set up a tie such that value returned by intensity() is constant during fitting.
virtual void unfixIntensity()
Free the intensity parameter.
int m_peakRadius
Defines the area around the centre where the peak values are to be calculated (in FWHM).
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
size_t maxParam(size_t iY)
Definition: IPeakFunction.h:23
std::vector< double > m_J
Definition: IPeakFunction.h:41
double get(size_t iY, size_t iP) override
Get the value to a Jacobian matrix element.
Definition: IPeakFunction.h:22
void set(size_t iY, size_t iP, double value) override
Set a value to a Jacobian matrix element.
Definition: IPeakFunction.h:21
TempJacobian(size_t y, size_t p)
Definition: IPeakFunction.h:20
void zero() override
Zero all matrix elements.
Definition: IPeakFunction.h:36
std::shared_ptr< IPeakFunction > IPeakFunction_sptr
std::pair< double, double > IntegrationResultCache
Definition: IPeakFunction.h:44
std::shared_ptr< const IPeakFunction > IPeakFunction_const_sptr
Helper class which provides the Collimation Length for SANS instruments.