20using namespace Kernel;
34const std::string EstimatePeakErrors::summary()
const {
35 return "Calculates error estimates for peak parameters: "
36 "centre, height, FWHM and intensity.";
39const std::string EstimatePeakErrors::name()
const {
return "EstimatePeakErrors"; }
41int EstimatePeakErrors::version()
const {
return 1; }
43const std::string EstimatePeakErrors::category()
const {
return "Optimization"; }
65 for (
size_t ip = 0; ip < peak.
nParams(); ++ip) {
72 jacobian.set(0, ip, (peak.
centre() - centre) / dp);
74 jacobian.set(2, ip, (peak.
fwhm() - fwhm) / dp);
75 jacobian.set(3, ip, (peak.
intensity() - intensity) / dp);
86void calculatePeakValues(IPeakFunction &peak, ITableWorkspace &results,
const EigenMatrix &covariance,
87 const std::string &prefix) {
88 double centre,
height, fwhm, intensity;
89 EigenMatrix J = makeJacobian(peak, centre,
height, fwhm, intensity);
90 EigenMatrix JCJ = J * covariance * J.tr();
92 TableRow row = results.appendRow();
93 row << prefix +
"Centre" << centre << sqrt(JCJ.get(0, 0));
94 row = results.appendRow();
95 row << prefix +
"Height" <<
height << sqrt(JCJ.get(1, 1));
96 row = results.appendRow();
97 row << prefix +
"FWHM" << fwhm << sqrt(JCJ.get(2, 2));
98 row = results.appendRow();
99 row << prefix +
"Intensity" << intensity << sqrt(JCJ.get(3, 3));
104void EstimatePeakErrors::init() {
107 "Fitting function containing peaks. Must have a covariance "
112 "The name of the TableWorkspace with the output values and errors.");
116void EstimatePeakErrors::exec() {
121 results->addColumn(
"str",
"Parameter");
122 results->addColumn(
"double",
"Value");
123 results->addColumn(
"double",
"Error");
125 auto matrix = function->getCovarianceMatrix();
127 g_log.
warning() <<
"Function doesn't have covariance matrix.\n";
136 calculatePeakValues(*peak, *results, covariance,
"");
141 for (
size_t i = 0; i < cf->nFunctions(); ++i) {
148 calculatePeakValues(*peak, *results, covariance, prefix);
#define DECLARE_ALGORITHM(classname)
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A composite function is a function containing other functions.
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...
This is an interface to a fitting function - a semi-abstarct class.
virtual size_t nParams() const =0
Total number of parameters.
virtual std::shared_ptr< IFunction > getFunction(size_t i) const
Returns the pointer to i-th child function.
An interface to a peak function, which extend the interface of IFunctionWithLocation by adding method...
virtual double fwhm() const =0
Returns the peak FWHM.
virtual double intensity() const
Returns the integral intensity of the peak.
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.
size_t nParams() const override
Total number of parameters.
double getParameter(size_t i) const override
Get i-th parameter.
A property class for workspaces.
A wrapper around Eigen::Matrix.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void warning(const std::string &msg)
Logs at warning level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.
@ Output
An output workspace.