19#include "MantidTypes/SpectrumDefinition.h"
39 this->declareParameter(
"Intensity", 1.0,
"scaling factor [no units]");
40 this->declareParameter(
"Radius", 1.0,
"Circle radius [Angstroms]");
41 this->declareParameter(
"Decay", 1.0,
42 "Inverse of transition rate, in nanoseconds "
43 "if energy in micro-ev, or picoseconds if "
45 this->declareParameter(
"Shift", 0.0,
"Shift in the centre of the peak");
56 auto IntensityConstraint =
57 std::make_unique<BConstraint>(
this,
"Intensity", std::numeric_limits<double>::epsilon(),
true);
60 auto RadiusConstraint = std::make_unique<BConstraint>(
this,
"Radius", std::numeric_limits<double>::epsilon(),
true);
63 auto DecayConstraint = std::make_unique<BConstraint>(
this,
"Decay", std::numeric_limits<double>::epsilon(),
true);
85 throw std::runtime_error(
"No Q attribute provided and cannot retrieve from workspace.");
90 g_log.
debug() <<
"Get Q value for workspace index " << specIdx <<
": " << Q <<
'\n';
94 g_log.
debug() <<
"Using Q attribute: " << Q <<
'\n';
97 std::vector<double> sph(N);
98 for (
int k = 1; k < N; k++) {
99 double x = 2 * Q * R * sin(M_PI * k / N);
104 std::vector<double> ratel(N);
105 for (
int l = 1; l < N; l++) {
107 ratel[l] = rate * 4 * pow(sin(M_PI * l / N), 2);
111 for (
size_t i = 0; i < nData; i++) {
112 double w = xValues[i] - shift;
114 for (
int l = 1; l < N; l++) {
115 double lorentzian = ratel[l] / (ratel[l] * ratel[l] + w * w);
117 for (
int k = 1; k < N; k++) {
118 double y = 2 * M_PI * l * k / N;
119 al += cos(
y) * sph[k];
123 S += al * lorentzian;
125 out[i] = I * S / M_PI;
137 auto workspace = std::dynamic_pointer_cast<const API::MatrixWorkspace>(ws);
141 const auto &spectrumInfo =
workspace->spectrumInfo();
142 const auto &detectorIDs =
workspace->detectorInfo().detectorIDs();
143 for (
size_t idx = 0; idx < spectrumInfo.size(); idx++) {
144 if (!spectrumInfo.hasDetectors(idx)) {
146 g_log.
information(
"Cannot populate Q values from workspace - no detectors set.");
150 const auto detectorIndex = spectrumInfo.spectrumDefinition(idx)[0].first;
154 double usingTheta = 0.5 * spectrumInfo.twoTheta(idx);
159 }
catch (std::runtime_error &) {
162 "find EFixed value.");
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
IPeaksWorkspace_sptr workspace
static Kernel::Logger g_log
Logger instance.
Attribute is a non-fitting parameter.
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
virtual void addConstraint(std::unique_ptr< IConstraint > ic)
Add a constraint to function.
double getParameter(size_t i) const override
Get i-th parameter.
A boundary constraint is designed to be used to set either upper or lower (or both) boundaries on a s...
std::vector< double > m_qValueCache
void init() override
Set constraints on fitting parameters.
void setWorkspace(std::shared_ptr< const API::Workspace > ws) override
Cache Q values from the workspace.
void function1D(double *out, const double *xValues, const size_t nData) const override
Calculate function values on an energy domain.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
void information(const std::string &msg)
Logs at information level.
static double convertToElasticQ(const double theta, const double efixed)
Convert to ElasticQ from Energy.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.