28using namespace CurveFitting;
29using namespace Kernel;
36 declareAttribute(
"PeakShape",
Attribute(
"Lorentzian"));
38 std::vector<double> vec;
39 declareAttribute(
"FWHMX",
Attribute(vec));
40 declareAttribute(
"FWHMY",
Attribute(vec));
41 declareAttribute(
"FWHMVariation",
Attribute(0.1));
43 declareAttribute(
"FixAllPeaks",
Attribute(
false));
49 }
catch (std::runtime_error
const &ex) {
67 if (values.
size() == 0) {
71 if (values.
size() % 2 != 0) {
72 throw std::runtime_error(
"CrystalFieldPeaks returned odd number of values.");
84 defaultFWHM, nRequiredPeaks, fixAllPeaks);
114 std::ostringstream ostr;
115 ostr <<
"name=" << this->
name();
118 for (
const auto &attName : attr) {
120 if (!attValue.empty() && attValue !=
"\"\"" && attValue !=
"()") {
121 ostr <<
',' << attName <<
'=' << attValue;
124 ostr << parentLocalAttributesStr;
125 std::vector<std::string> ties;
128 std::ostringstream paramOut;
131 ostr <<
',' << paramOut.str();
133 ties.emplace_back(paramOut.str());
138 for (
size_t ip = 0; ip < spectrum.nFunctions(); ++ip) {
139 const auto &peak =
dynamic_cast<IPeakFunction &
>(*spectrum.getFunction(ip));
144 for (
const auto &attName : attrNames) {
145 const std::string attValue = peak.getAttribute(attName).value();
146 if (!attValue.empty() && attValue !=
"\"\"") {
147 ostr <<
",f" << ip <<
"." << attName <<
'=' << attValue;
152 for (
size_t i = 0; i < peak.nParams(); i++) {
154 std::ostringstream paramString;
155 paramString <<
"f" << ip <<
"." << peak.parameterName(i) <<
'=' << peak.getParameter(i);
157 ostr <<
',' << paramString.str();
160 if (peak.isFixed(i) && !peak.isFixedByDefault(i)) {
161 ties.emplace_back(paramString.str());
165 const auto peakTies = peak.writeTies();
166 if (!peakTies.empty())
167 ties.emplace_back(peakTies);
173 if (!constraints.empty()) {
174 ostr <<
",constraints=(" << constraints <<
")";
179 if (!tiesString.empty()) {
180 ties.emplace_back(tiesString);
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
Mantid::API::IFunction::Attribute Attribute
A composite function is a function containing other functions.
Represent a domain of a very general type.
FunctionGenerator is a partial implementation of IFunction that defines a function consisting of two ...
IFunction_sptr m_source
Function that calculates parameters of the target function.
double getParameter(size_t i) const override
Get i-th parameter.
std::vector< std::string > getAttributeNames() const override
Returns a list of attribute names.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
IFunction_sptr m_target
Function that actually calculates the output.
bool m_dirty
Flag indicating that updateTargetFunction() is required.
Attribute getAttribute(const std::string &name) const override
Return a value of attribute attName.
size_t m_nOwnParams
Cached number of parameters in m_source.
A class to store values calculated by a function.
size_t size() const
Return the number of values.
Attribute is a non-fitting parameter.
std::vector< double > asVector() const
Returns vector<double> if attribute is vector<double>, throws exception otherwise.
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
std::string asString() const
Returns string value if attribute is a string, throws exception otherwise.
std::string value() const
Returns the attribute value as a string.
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
bool asBool() const
Returns bool value if attribute is a bool, throws exception otherwise.
bool isActive(size_t i) const
Check if an active parameter i is actually active.
std::string writeTies() const
Write a parameter tie to a string.
void storeReadOnlyAttribute(const std::string &name, const API::IFunction::Attribute &value) const
A read-only ("mutable") attribute can be stored in a const method.
virtual void tie(const std::string &parName, const std::string &expr, bool isDefault=false)
Tie a parameter to other parameters (or a constant)
virtual std::vector< std::string > getAttributeNames() const
Returns a list of attribute names.
std::string writeConstraints() const
Write a parameter constraint to a string.
bool isFixed(size_t i) const
Check if a parameter i is fixed.
An interface to a peak function, which extend the interface of IFunctionWithLocation by adding method...
CrystalFieldPeaks is a function that calculates crystal field peak positions and intensities.
Calculates crystal field spectrum.
void init() override
overwrite IFunction base class method, which declare function parameters
std::string writeToString(const std::string &parentLocalAttributesStr="") const override
Custom string conversion method.
void updateTargetFunction() const override
Update m_spectrum function.
void buildTargetFunction() const override
Uses m_crystalField to calculate peak centres and intensities then populates m_spectrum with peaks of...
std::string name() const override
Returns the function's name.
size_t m_nPeaks
Number of fitted peaks in the spectrum.
The Logger class is in charge of the publishing messages from the framework through various channels.
void error(const std::string &msg)
Logs at error level.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
size_t updateSpectrumFunction(API::CompositeFunction &spectrum, const std::string &peakShape, const API::FunctionValues ¢resAndIntensities, size_t iFirst, const std::vector< double > &xVec, const std::vector< double > &yVec, double fwhmVariation, double defaultFWHM, bool fixAllPeaks)
Update the peaks parameters after recalculationof the crystal field.
size_t calculateNPeaks(const API::FunctionValues ¢resAndIntensities)
Calculate the number of visible peaks.
size_t buildSpectrumFunction(API::CompositeFunction &spectrum, const std::string &peakShape, const API::FunctionValues ¢resAndIntensities, const std::vector< double > &xVec, const std::vector< double > &yVec, double fwhmVariation, double defaultFWHM, size_t nRequiredPeaks, bool fixAllPeaks)
Utility functions to help set up peak functions in a Crystal Field spectrum.
DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end, const std::string &separator, typename std::enable_if<!(std::is_same< typename std::iterator_traits< ITERATOR_TYPE >::iterator_category, std::random_access_iterator_tag >::value)>::type *=nullptr)
Join a set or vector of (something that turns into a string) together into one string,...