Mantid
Loading...
Searching...
No Matches
GaussianComptonProfile.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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//------------------------------------------------------------------------------------------------
8// Includes
9//------------------------------------------------------------------------------------------------
12
13#include <cmath>
14
16
17using namespace CurveFitting;
18DECLARE_FUNCTION(GaussianComptonProfile)
19
20const char *WIDTH_PARAM = "Width";
21const char *AMP_PARAM = "Intensity";
22
23const double STDDEV_TO_HWHM = std::sqrt(std::log(4.0));
24
26
30std::string GaussianComptonProfile::name() const { return "GaussianComptonProfile"; }
31
34 declareParameter(WIDTH_PARAM, 1.0, "Gaussian width parameter");
35 declareParameter(AMP_PARAM, 1.0, "Gaussian intensity parameter");
36}
37
39 return std::vector<size_t>(1, this->parameterIndex(AMP_PARAM));
40}
41
52 const HistogramData::HistogramE &errors) const {
53 std::vector<double> result(ySpace().size());
54 const double amplitude = 1.0;
55 this->massProfile(result.data(), ySpace().size(), amplitude);
56 std::transform(result.begin(), result.end(), errors.begin(), result.begin(), std::divides<double>());
57 cmatrix.setColumn(start, result);
58 return 1;
59}
60
68void GaussianComptonProfile::massProfile(double *result, const size_t nData) const {
69 const double amplitude(getParameter(AMP_PARAM));
70 this->massProfile(result, nData, amplitude);
71}
72
81void GaussianComptonProfile::massProfile(double *result, const size_t nData, const double amplitude) const {
82 double lorentzPos(0.0), gaussWidth(getParameter(WIDTH_PARAM));
83 double gaussFWHM =
84 std::sqrt(std::pow(m_resolutionFunction->resolutionFWHM(), 2) + std::pow(2.0 * STDDEV_TO_HWHM * gaussWidth, 2));
85
86 const auto &yspace = ySpace();
87 // Gaussian already folded into Voigt
88 std::vector<double> voigt(yspace.size()), voigtDiffResult(yspace.size());
89 m_resolutionFunction->voigtApprox(voigt, yspace, lorentzPos, amplitude, m_resolutionFunction->lorentzFWHM(),
90 gaussFWHM);
91 voigtApproxDiff(voigtDiffResult, yspace, lorentzPos, amplitude, m_resolutionFunction->lorentzFWHM(), gaussFWHM);
92
93 const auto &modq = modQ();
94 const auto &ei = e0();
95 if (modq.empty() || ei.empty()) {
96 throw std::runtime_error("The Q values or e0 values have not been set");
97 }
98 // Include e_i^0.1*mass/q pre-factor
99 for (size_t j = 0; j < nData; ++j) {
100 const double q = modq[j];
101 const double prefactor = mass() * std::pow(ei[j], 0.1) / q;
102 result[j] = prefactor * (voigt[j] - std::pow(gaussWidth, 4.0) * voigtDiffResult[j] / (3.0 * q));
103 }
104}
105
106} // namespace Mantid::CurveFitting::Functions
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
size_t parameterIndex(const std::string &name) const override
Returns the index of parameter name.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
double getParameter(size_t i) const override
Get i-th parameter.
This class serves as a base-class for ComptonProfile type functions.
const std::vector< double > & modQ() const
Access Q values cache.
void declareParameters() override
Declare parameters that will never participate in the fit.
std::shared_ptr< VesuvioResolution > m_resolutionFunction
Vesuvio resolution function.
void voigtApproxDiff(std::vector< double > &voigtDiff, const std::vector< double > &yspace, const double lorentzPos, const double lorentzAmp, const double lorentzWidth, const double gaussWidth) const
Compute Voigt function interpolated around the given values.
const std::vector< double > & ySpace() const
Access y-values cache.
const std::vector< double > & e0() const
Access e0 values.
Implements a function to calculate the Compton profile of a nucleus using a Gaussian approximation co...
std::string name() const override
A string identifier for this function.
void massProfile(double *result, const size_t nData) const override
Compute the function.
std::vector< size_t > intensityParameterIndices() const override
Returns the indices of the intensity parameters.
size_t fillConstraintMatrix(Kernel::DblMatrix &cmatrix, const size_t start, const HistogramData::HistogramE &errors) const override
Fill in the columns of the matrix for this mass.
void declareParameters() override
Declare the function parameters.
void setColumn(const size_t nCol, const std::vector< T > &newCol)
Definition: Matrix.cpp:675
STL namespace.