15#include <gsl/gsl_poly.h>
19using namespace CurveFitting;
20using namespace CurveFitting::Algorithms;
26const char *MASS_NAME =
"Mass";
34 m_yspace(), m_modQ(), m_e0(), m_mass(0.0) {}
73 double startX,
double endX) {
75 auto sample = inst->getSample();
76 auto source = inst->getSource();
77 if (!sample || !source) {
78 throw std::invalid_argument(
"ComptonProfile - Workspace has no source/sample.");
89 const auto &spectrumInfo =
m_workspace->spectrumInfo();
90 if (!spectrumInfo.hasDetectors(
m_wsIndex)) {
91 throw std::invalid_argument(
"ComptonProfile - Workspace has no detector "
92 "attached to histogram at index " +
122 const double v1 = std::sqrt(detpar.
efixed / massToMeV);
123 const double k1 = std::sqrt(detpar.
efixed / mevToK);
126 const size_t nData = tseconds.size();
131 for (
size_t i = 0; i < nData; ++i) {
132 const double tsec = tseconds[i];
164 const double lorentzPos,
const double lorentzAmp,
const double lorentzWidth,
165 const double gaussWidth)
const {
166 double miny(DBL_MAX), maxy(-DBL_MAX);
167 auto iend = yspace.end();
168 for (
auto itr = yspace.begin(); itr != iend; ++itr) {
169 const double absy = std::abs(*itr);
172 else if (absy > maxy)
175 const double epsilon = (maxy - miny) / 1000.0;
180 std::vector<double> ypmEps(yspace.size());
182 using std::placeholders::_1;
183 std::transform(yspace.begin(), yspace.end(), ypmEps.begin(),
184 std::bind(std::plus<double>(), _1, 2.0 * epsilon));
185 m_resolutionFunction->voigtApprox(voigtDiff, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
187 std::transform(yspace.begin(), yspace.end(), ypmEps.begin(),
188 std::bind(std::minus<double>(), _1, 2.0 * epsilon));
189 std::vector<double> tmpResult(yspace.size());
190 m_resolutionFunction->voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
192 std::transform(voigtDiff.begin(), voigtDiff.end(), tmpResult.begin(), voigtDiff.begin(), std::minus<double>());
195 std::transform(yspace.begin(), yspace.end(), ypmEps.begin(),
196 std::bind(std::plus<double>(), _1, epsilon));
197 m_resolutionFunction->voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
198 std::transform(tmpResult.begin(), tmpResult.end(), tmpResult.begin(),
199 std::bind(std::multiplies<double>(), _1, 2.0));
201 std::transform(voigtDiff.begin(), voigtDiff.end(), tmpResult.begin(), voigtDiff.begin(), std::minus<double>());
204 std::transform(yspace.begin(), yspace.end(), ypmEps.begin(),
205 std::bind(std::minus<double>(), _1, epsilon));
206 m_resolutionFunction->voigtApprox(tmpResult, ypmEps, lorentzPos, lorentzAmp, lorentzWidth, gaussWidth);
207 std::transform(tmpResult.begin(), tmpResult.end(), tmpResult.begin(),
208 std::bind(std::multiplies<double>(), _1, 2.0));
210 std::transform(voigtDiff.begin(), voigtDiff.end(), tmpResult.begin(), voigtDiff.begin(), std::plus<double>());
213 std::transform(voigtDiff.begin(), voigtDiff.end(), voigtDiff.begin(),
214 std::bind(std::divides<double>(), _1, 2.0 * std::pow(epsilon, 3)));
double value
The value of the point.
IPeaksWorkspace_sptr workspace
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
This is a specialization of IFunction for functions of one real argument.
Implements the part of IFunction interface dealing with parameters.
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
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.
static DetectorParams getDetectorParameters(const API::MatrixWorkspace_const_sptr &ws, const size_t index)
Creates a POD struct containing the required detector parameters for this spectrum.
static void calculateY(double &yspace, double &qspace, double &ei, const double mass, const double tsec, const double k1, const double v1, const DetectorParams &detpar)
Convert single time value to Y,Q & Ei values.
double m_mass
Atomic mass.
virtual void massProfile(double *result, const size_t nData) const =0
Override to calculate the value of the profile for this mass and store in the given array.
Kernel::Logger m_log
Logger.
std::vector< double > m_e0
Incident energies.
std::vector< double > m_modQ
Q-values.
std::shared_ptr< const API::MatrixWorkspace > m_workspace
Current workspace.
void declareParameters() override
Declare parameters that will never participate in the fit.
std::shared_ptr< VesuvioResolution > m_resolutionFunction
Vesuvio resolution function.
ComptonProfile()
Default constructor required for factory.
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.
void setParameter(size_t i, const double &value, bool explicitlySet=true) override
Set i-th parameter.
void setMatrixWorkspace(std::shared_ptr< const API::MatrixWorkspace > workspace, size_t wsIndex, double startX, double endX) override
Cache a copy of the workspace pointer and pull out the parameters.
void buildCaches()
Initiate a Y-space value chache rebuild when workspace of mass are changed.
std::shared_ptr< API::IPeakFunction > m_voigt
Voigt function.
void function1D(double *out, const double *xValues, const size_t nData) const override
Calculates the value of the function for each x value and stores in the given output array.
std::vector< double > m_yspace
void cacheYSpaceValues(const HistogramData::Points &tseconds, const Algorithms::DetectorParams &detpar, const ResolutionParams &respar)
Pre-calculate the Y-space values with specified resolution parameters.
size_t m_wsIndex
Current workspace index, required to access instrument parameters.
void setUpForFit() override
Ensure the object is ready to be fitted.
Calculate the resolution from a workspace of Vesuvio data using the mass & instrument definition.
void setEnabled(const bool enabled)
set if the logging is enabled
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
static constexpr double E_mev_toNeutronWavenumberSq
Transformation coefficient to transform neutron energy into neutron wavevector: K-neutron[m^-10] = sq...
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double meV
1 meV in Joules.
std::string to_string(const wide_integer< Bits, Signed > &n)
Simple data structure to store nominal detector values It avoids some functions taking a huge number ...
double efixed
final energy
Simple data structure to store resolution parameter values It avoids some functions taking a huge num...