25#include <boost/optional.hpp>
26#include <boost/regex.hpp>
33using namespace CurveFitting;
34using namespace Kernel;
41const std::string ION_PREFIX(
"ion");
42const std::string SPECTRUM_PREFIX(
"sp");
43const std::string BACKGROUND_PREFIX(
"bg");
44const std::string PEAK_PREFIX(
"pk");
48const boost::regex SPECTRUM_ATTR_REGEX(SPECTRUM_PREFIX +
"([0-9]+)\\.(.+)");
51const boost::regex BACKGROUND_ATTR_REGEX(BACKGROUND_PREFIX +
"\\.(.+)");
54const boost::regex PEAK_ATTR_REGEX(PEAK_PREFIX +
"([0-9]+)\\.(.+)");
57const boost::regex ION_ATTR_REGEX(ION_PREFIX +
"([0-9]+)\\.(.+)");
60const boost::regex PHYS_PROP_ATTR_REGEX(
"((ion[0-9]+\\.)?(cv|chi|mh|mt))\\.(.+)");
64class Peaks :
public CrystalFieldPeaksBase,
public API::IFunctionGeneral {
66 Peaks() : CrystalFieldPeaksBase() {}
67 std::string name()
const override {
return "Peaks"; }
68 size_t getNumberDomainColumns()
const override {
69 throw Exception::NotImplementedError(
"This method is intentionally not implemented.");
71 size_t getNumberValuesPerArgument()
const override {
72 throw Exception::NotImplementedError(
"This method is intentionally not implemented.");
74 void functionGeneral(
const API::FunctionDomainGeneral & , API::FunctionValues & )
const override {
75 throw Exception::NotImplementedError(
"This method is intentionally not implemented.");
81 void declareIntensityScaling(
size_t nSpec) {
85 for (
size_t i = 0; i < nSpec; ++i) {
88 declareParameter(
"IntensityScaling" + si, 1.0,
"Intensity scaling factor for spectrum " + si);
89 }
catch (std::invalid_argument &) {
100 :
IFunction(), m_nControlParams(0), m_nControlSourceParams(0), m_dirtyTarget(true) {}
106 throw std::logic_error(
"FunctionGenerator failed to generate target function.");
121 throw std::runtime_error(
"Failed to build target function.");
123 return m_target->getNumberDomains();
128 std::vector<IFunction_sptr> funs;
130 for (
size_t i = 0; i < composite.nFunctions(); ++i) {
136 funs.emplace_back(fun);
187 }
catch (std::invalid_argument &) {
197 }
catch (std::invalid_argument &) {
200 if (!boost::regex_search(
name, match, PEAK_ATTR_REGEX)) {
242 throw std::invalid_argument(
"CrystalFieldFunction parameter not found: " +
name);
244 return found->second;
250 throw std::invalid_argument(
"CrystalFieldFunction's parameter index " +
std::to_string(i) +
" is out of range " +
379 if (index < m_source->
nParams()) {
394 const std::string & ) {
406 for (
size_t i = 0; i < numAttributes; ++i) {
413 auto moveAttributeName = [&](
const std::string &
name) {
414 auto iterFound = std::find(controlAttributeNames.begin(), controlAttributeNames.end(),
name);
415 if (iterFound != controlAttributeNames.end()) {
416 controlAttributeNames.erase(iterFound);
421 auto prependPrefix = [&](
const std::string &prefix,
const std::vector<std::string> &names) {
422 for (
auto name : names) {
423 if (
name.find(
"NumDeriv") != std::string::npos)
425 name.insert(
name.begin(), prefix.begin(), prefix.end());
430 moveAttributeName(
"Ions");
431 moveAttributeName(
"Symmetries");
432 moveAttributeName(
"Temperatures");
433 moveAttributeName(
"Background");
437 std::copy_if(controlAttributeNames.begin(), controlAttributeNames.end(), std::back_inserter(
m_attributeNames),
438 [](
const auto &
name) { return name.find(
".") == std::string::npos; });
441 std::string prefix(SPECTRUM_PREFIX);
444 for (
auto &
name : names) {
445 name.insert(
name.begin(), prefix.begin(), prefix.end());
451 auto fun =
m_target->getFunction(iSpec).get();
453 if (compositePhysProp) {
455 std::string physPropPrefix(compositePhysProp->getFunction(0)->name());
456 physPropPrefix.append(
".");
457 for (
size_t ion = 0; ion < compositePhysProp->nFunctions(); ++ion) {
458 std::string prefix(ION_PREFIX);
459 prefix.append(
std::to_string(ion)).append(
".").append(physPropPrefix);
460 auto names = compositePhysProp->getFunction(ion)->getAttributeNames();
461 prependPrefix(prefix, names);
465 std::string prefix(fun->name());
467 auto names = fun->getAttributeNames();
468 prependPrefix(prefix, names);
489 if (attRef.first ==
nullptr) {
493 return attRef.first->getAttribute(attRef.second);
499 if (attRef.first ==
nullptr) {
506 attRef.first->setAttribute(attRef.second, attr);
507 if (attName.find(
"FWHM") != std::string::npos || attName.find(
"Background") != std::string::npos) {
515 if (attRef.first ==
nullptr) {
518 return attRef.first->hasAttribute(attRef.second);
529 if (boost::regex_match(attName, match, SPECTRUM_ATTR_REGEX)) {
530 auto i = std::stoul(match[1]);
531 auto name = match[2].str();
535 if (
name ==
"FWHMX" ||
name ==
"FWHMY") {
539 return std::make_pair(
nullptr,
"");
542 return std::make_pair(
nullptr,
"");
543 }
else if (boost::regex_match(attName, match, PHYS_PROP_ATTR_REGEX)) {
544 auto prop = match[1].str();
545 auto name = match[4].str();
548 return std::make_pair(propIt->second.get(),
name);
550 return std::make_pair(
nullptr,
"");
552 return std::make_pair(&
m_control, attName);
582 return tie.ownerFunction()->name() ==
"Gaussian" &&
tie.parameterName() ==
"Height" &&
583 tie.asString().find(
"/Sigma") != std::string::npos;
590 if (constraint ==
nullptr) {
628 if (composite ==
nullptr) {
629 throw std::logic_error(
"Source of CrystalFieldFunction is not composite.");
663 throw std::logic_error(
"CrystalFieldFunction failed to generate target function.");
702 m_target->setAttributeValue(
"NumDeriv",
true);
706 if (!bkgdShape.empty()) {
708 spectrum->addFunction(background);
715 if (values.
size() == 0) {
719 if (values.
size() % 2 != 0) {
720 throw std::runtime_error(
"CrystalFieldPeaks returned odd number of values.");
726 auto defaultFWHM = FWHMs.empty() ? 0.0 : FWHMs[0];
732 nRequiredPeaks, fixAllPeaks);
746 peakCalculator.
calculateEigenSystem(energies, waveFunctions, hamiltonian, hamiltonianZeeman, nre);
747 hamiltonian += hamiltonianZeeman;
752 const bool addBackground =
true;
753 for (
size_t i = 0; i < nSpec; ++i) {
755 fun->addFunction(
buildSpectrum(nre, energies, waveFunctions, temperatures[i], FWHMs.size() > i ? FWHMs[i] : 0., i,
756 addBackground, intensityScaling));
757 fun->setDomainIndex(i, i);
761 for (
auto &prop : physProps) {
762 auto physPropFun =
buildPhysprop(nre, energies, waveFunctions, hamiltonian, prop);
763 fun->addFunction(physPropFun);
764 fun->setDomainIndex(i, i);
775 m_target->setAttributeValue(
"NumDeriv",
true);
779 if (!bkgdShape.empty()) {
781 spectrum->addFunction(background);
785 auto defaultFWHM = FWHMs.empty() ? 0.0 : FWHMs[0];
793 for (
size_t ionIndex = 0; ionIndex < compSource.nFunctions(); ++ionIndex) {
796 compSource.getFunction(ionIndex)->function(domain, values);
798 if (values.
size() == 0) {
802 if (values.
size() % 2 != 0) {
803 throw std::runtime_error(
"CrystalFieldPeaks returned odd number of values.");
806 auto ionSpectrum = std::make_shared<CompositeFunction>();
808 nRequiredPeaks, fixAllPeaks);
809 spectrum->addFunction(ionSpectrum);
819 std::vector<CompositeFunction *> spectra(nSpec);
820 for (
size_t i = 0; i < nSpec; ++i) {
821 auto spectrum = std::make_shared<CompositeFunction>();
822 spectra[i] = spectrum.get();
823 multiDomain->addFunction(spectrum);
824 multiDomain->setDomainIndex(i, i);
827 std::vector<CompositeFunction_sptr> compositePhysProps(physProps.size());
828 std::generate(compositePhysProps.begin(), compositePhysProps.end(),
829 []() { return std::make_shared<CompositeFunction>(); });
832 for (
size_t ionIndex = 0; ionIndex < compSource.nFunctions(); ++ionIndex) {
839 peakCalculator.
calculateEigenSystem(energies, waveFunctions, hamiltonian, hamiltonianZeeman, nre);
840 hamiltonian += hamiltonianZeeman;
844 const bool addBackground = ionIndex == 0;
845 auto ionIntensityScaling = compSource.getFunction(ionIndex)->getParameter(
"IntensityScaling");
846 for (
size_t i = 0; i < nSpec; ++i) {
848 spectra[i]->addFunction(
buildSpectrum(nre, energies, waveFunctions, temperatures[i],
849 FWHMs.size() > i ? FWHMs[i] : 0., i, addBackground,
850 ionIntensityScaling * spectrumIntensityScaling));
854 for (
auto &prop : physProps) {
855 auto physPropFun =
buildPhysprop(nre, energies, waveFunctions, hamiltonian, prop);
856 compositePhysProps[i]->addFunction(physPropFun);
857 std::string propName =
"ion";
858 propName.append(
std::to_string(ionIndex)).append(
".").append(prop);
865 for (
auto &propFun : compositePhysProps) {
866 multiDomain->addFunction(propFun);
867 multiDomain->setDomainIndex(i, i);
890 calculateIntensities(nre, energies, waveFunctions, temperature, toleranceEnergy, degeneration, eEnergies, iEnergies);
891 calculateExcitations(eEnergies, iEnergies, toleranceEnergy, toleranceIntensity, eExcitations, iExcitations);
892 const auto nPeaks = eExcitations.
size();
893 values.
expand(2 * nPeaks);
894 for (
size_t i = 0; i < nPeaks; ++i) {
912 double fwhm,
size_t iSpec,
bool addBackground,
913 double intensityScaling)
const {
915 calcExcitations(nre, energies, waveFunctions, temperature, values, intensityScaling);
924 if (addBackground && !bkgdShape.empty()) {
925 if (bkgdShape.find(
"name=") != 0 && bkgdShape.front() !=
'(') {
926 bkgdShape =
"name=" + bkgdShape;
929 spectrum->addFunction(background);
935 nRequiredPeaks, fixAllPeaks);
948 const std::string &propName)
const {
950 if (propName ==
"cv") {
951 auto propFun = std::make_shared<CrystalFieldHeatCapacityCalculation>();
952 propFun->setEnergy(energies);
955 if (propName ==
"chi") {
956 auto propFun = std::make_shared<CrystalFieldSusceptibilityCalculation>();
957 propFun->setEigensystem(energies, waveFunctions, nre);
960 if (propName ==
"mh") {
961 auto propFun = std::make_shared<CrystalFieldMagnetisationCalculation>();
962 propFun->setHamiltonian(hamiltonian, nre);
965 if (propName ==
"mt") {
966 auto propFun = std::make_shared<CrystalFieldMomentCalculation>();
967 propFun->setHamiltonian(hamiltonian, nre);
971 throw std::runtime_error(
"Physical property type not understood: " + propName);
986 if (propName ==
"cv") {
989 }
else if (propName ==
"chi") {
992 }
else if (propName ==
"mh") {
995 }
else if (propName ==
"mt") {
999 throw std::runtime_error(
"Physical property type not understood: " + propName);
1044 auto defaultFWHM = FWHMs.empty() ? 0.0 : FWHMs[0];
1049 m_source->function(domain, values);
1050 m_target->setAttributeValue(
"NumDeriv",
true);
1053 defaultFWHM, fixAllPeaks);
1064 peakCalculator.
calculateEigenSystem(energies, waveFunctions, hamiltonian, hamiltonianZeeman, nre);
1065 hamiltonian += hamiltonianZeeman;
1071 for (
size_t iSpec = 0; iSpec < temperatures.size(); ++iSpec) {
1073 updateSpectrum(*fun.getFunction(iSpec), nre, energies, waveFunctions, temperatures[iSpec],
1074 FWHMs.size() > iSpec ? FWHMs[iSpec] : 0., iSpec, iFirst, intensityScaling);
1078 updatePhysprop(nre, energies, waveFunctions, hamiltonian, *prop.second);
1090 auto defaultFWHM = FWHMs.empty() ? 0.0 : FWHMs[0];
1094 for (
size_t ionIndex = 0; ionIndex < compSource.nFunctions(); ++ionIndex) {
1097 compSource.getFunction(ionIndex)->function(domain, values);
1108 for (
size_t ionIndex = 0; ionIndex < compSource.nFunctions(); ++ionIndex) {
1115 peakCalculator.
calculateEigenSystem(energies, waveFunctions, hamiltonian, hamiltonianZeeman, nre);
1116 hamiltonian += hamiltonianZeeman;
1121 auto ionIntensityScaling = compSource.getFunction(ionIndex)->getParameter(
"IntensityScaling");
1122 for (
size_t iSpec = 0; iSpec < temperatures.size(); ++iSpec) {
1124 auto &ionSpectrum =
dynamic_cast<CompositeFunction &
>(*spectrum.getFunction(ionIndex));
1125 auto spectrumIntensityScaling =
m_control.
getFunction(iSpec)->getParameter(
"IntensityScaling");
1126 updateSpectrum(ionSpectrum, nre, energies, waveFunctions, temperatures[iSpec],
1127 FWHMs.size() > iSpec ? FWHMs[iSpec] : 0., iSpec, iFirst,
1128 ionIntensityScaling * spectrumIntensityScaling);
1131 std::string prefix(
"ion");
1133 auto prefixSize = prefix.size();
1135 if (prop.first.substr(0, prefixSize) == prefix) {
1136 updatePhysprop(nre, energies, waveFunctions, hamiltonian, *prop.second);
1155 size_t iSpec,
size_t iFirst,
double intensityScaling)
const {
1163 calcExcitations(nre, energies, waveFunctions, temperature, values, intensityScaling);
1194 for (
size_t i = 0; i <
n; ++i) {
1195 size_t j = i + iFirst;
1208 size_t peakIndex = 0;
1211 auto &background = *
m_target->getFunction(0);
1216 for (
size_t ip = peakIndex; ip <
m_target->nFunctions(); ++ip) {
1217 std::string prefix(PEAK_PREFIX);
1228 std::string prefix(SPECTRUM_PREFIX);
1235 size_t peakIndex = 0;
1236 for (
size_t iSpec = 0; iSpec <
m_target->nFunctions(); ++iSpec) {
1239 std::string spectrumPrefix(SPECTRUM_PREFIX);
1243 auto &background = *spectrum->getFunction(0);
1248 for (
size_t ip = peakIndex; ip < spectrum->nFunctions(); ++ip) {
1249 std::string prefix(spectrumPrefix);
1250 prefix.append(PEAK_PREFIX).append(
std::to_string(ip - peakIndex)).append(
".");
1267 for (
size_t ion = 0; ion < crystalField.nFunctions(); ++ion) {
1268 std::string prefix(ION_PREFIX);
1274 size_t ionIndex = 0;
1277 auto &background = *
m_target->getFunction(0);
1282 for (
size_t ion = ionIndex; ion <
m_target->nFunctions(); ++ion) {
1283 std::string ionPrefix(ION_PREFIX);
1287 for (
size_t ip = 0; ip < spectrum.nFunctions(); ++ip) {
1288 std::string prefix(ionPrefix);
1289 prefix.append(PEAK_PREFIX).append(
std::to_string(ip)).append(
".");
1300 std::string prefix(SPECTRUM_PREFIX);
1306 for (
size_t ion = 0; ion < crystalField.nFunctions(); ++ion) {
1307 std::string prefix(ION_PREFIX);
1313 for (
size_t iSpec = 0; iSpec <
nSpectra(); ++iSpec) {
1315 std::string spectrumPrefix(SPECTRUM_PREFIX);
1319 for (
size_t ion = 0; ion < crystalField.nFunctions(); ++ion) {
1320 auto &ionSpectrum =
dynamic_cast<const CompositeFunction &
>(*spectrum.getFunction(ion));
1321 size_t peakIndex = 0;
1324 std::string prefix(spectrumPrefix);
1325 prefix.append(BACKGROUND_PREFIX).append(
".");
1328 std::string ionPrefix(ION_PREFIX);
1329 ionPrefix.append(
std::to_string(ion)).append(
".").append(spectrumPrefix);
1331 for (
size_t ip = peakIndex; ip < ionSpectrum.nFunctions(); ++ip) {
1332 std::string prefix(ionPrefix);
1333 prefix.append(PEAK_PREFIX).append(
std::to_string(ip - peakIndex)).append(
".");
1341 std::string physPropPrefix(spectrum.getFunction(0)->name());
1342 physPropPrefix.append(
".");
1343 for (
size_t ion = 0; ion < crystalField.nFunctions(); ++ion) {
1344 std::string prefix(ION_PREFIX);
1345 prefix.append(
std::to_string(ion)).append(
".").append(physPropPrefix);
1362 for (
size_t i = 0; i < np; ++i) {
std::vector< size_t > m_IntensityScalingIdx
std::vector< size_t > m_PPLambdaIdxChild
std::vector< size_t > m_PPLambdaIdxSelf
double value
The value of the point.
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
std::map< DeltaEMode::Type, std::string > index
A composite function is a function containing other functions.
ParameterTie * getTie(size_t i) const override
Get the tie of i-th parameter.
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
size_t getParameterIndex(const ParameterReference &ref) const override
Return parameter index from a parameter reference.
void setParameterDescription(size_t, const std::string &description) override
Set i-th parameter description.
std::size_t nFunctions() const override
Number of functions.
bool isExplicitlySet(size_t i) const override
Checks if a parameter has been set explicitly.
size_t nParams() const override
Total number of parameters.
double getParameter(size_t i) const override
Get i-th parameter.
double getError(size_t i) const override
Get the fitting error for a parameter.
Attribute getAttribute(const std::string &name) const override
Return a value of attribute attName.
std::string parameterDescription(size_t i) const override
Returns the description of parameter i.
IFunction_sptr getFunction(std::size_t i) const override
Returns the pointer to i-th function.
void setError(size_t i, double err) override
Set the fitting error for a parameter.
IConstraint * getConstraint(size_t i) const override
Get constraint of i-th parameter.
ParameterStatus getParameterStatus(size_t i) const override
Get status of parameter.
void checkFunction()
Check the function.
void setParameterStatus(size_t i, ParameterStatus status) override
Change status of parameter.
Represent a domain of a very general type.
Base class that represents the domain of a function.
A class to store values calculated by a function.
size_t size() const
Return the number of values.
void expand(size_t n)
Expand values to a new size, preserve stored values.
void setCalculated(double value)
set all calculated values to same number
An interface to a constraint.
Attribute is a non-fitting parameter.
std::string asUnquotedString() const
Returns a string value that is guarenteed to be unquoted.
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.
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
bool isEmpty() const
Check if a string attribute is empty.
bool asBool() const
Returns bool value if attribute is a bool, throws exception otherwise.
This is an interface to a fitting function - a semi-abstarct class.
virtual size_t nParams() const =0
Total number of parameters.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
friend class CompositeFunction
ParameterStatus
Describe parameter status in relation to fitting: Active: Fit varies such parameter directly.
virtual void tie(const std::string &parName, const std::string &expr, bool isDefault=false)
Tie a parameter to other parameters (or a constant)
virtual ParameterTie * getTie(size_t i) const
Get the tie of i-th parameter.
virtual void setAttribute(const std::string &name, const Attribute &)
Set a value to attribute attName.
virtual void setUpForFit()
Set up the function for a fit.
virtual std::vector< std::string > getAttributeNames() const
Returns a list of attribute names.
virtual std::string attributeName(size_t index) const
Get name of ith attribute.
virtual std::string parameterName(size_t i) const =0
Returns the name of parameter i.
virtual size_t nAttributes() const
Returns the number of attributes associated with the function.
virtual IConstraint * getConstraint(size_t i) const
Get constraint of i-th parameter.
A composite function defined on a CompositeDomain.
A reference to a parameter in a function.
std::size_t getLocalIndex() const
Return parameter index in the local function.
IFunction * getLocalFunction() const
Return pointer to the local function.
double get(const size_t i) const
Get an element.
size_t size() const
Size of the vector.
const std::vector< double > & temperatures() const
API::IFunction_sptr buildSource()
Build the source function.
void buildControls()
Build control functions for individual spectra.
const std::vector< std::string > & physProps() const
const std::vector< double > & FWHMs() const
bool hasPhysProperties() const
Check if there are any phys. properties.
bool isMultiSpectrum() const
Is it a multi-spectrum case?
bool isMultiSite() const
Are there multiple ions?
bool hasPeaks() const
Any peaks defined?
void updateMultiSite() const
Update the target function in a multi site case.
Attribute getAttribute(const std::string &name) const override
Return a value of attribute attName.
std::unordered_map< std::string, size_t > m_mapNames2Indices
Map parameter names to indices.
void updatePhysprop(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, const ComplexFortranMatrix &ham, API::IFunction &fun) const
Update a physical property function.
API::IFunction_sptr buildPhysprop(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, const ComplexFortranMatrix &ham, const std::string &propName) const
Build a physical property function.
void checkTargetFunction() const
Update target function if necessary.
API::IFunction_sptr m_source
Function that calculates parameters of the target function.
bool m_dirtyTarget
Flag indicating that updateTargetFunction() is required.
void calcExcitations(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, double temperature, API::FunctionValues &values, double intensityScaling) const
Calculate excitations at given temperature.
void updateMultiSiteMultiSpectrum() const
Update the target function in a multi site - multi spectrum case.
void updateMultiSiteSingleSpectrum() const
Update the target function in a multi site - single spectrum case.
void makeMapsSingleSiteMultiSpectrum() const
Parameter-index map for single-site multi-spectrum.
std::pair< API::IFunction *, std::string > getAttributeReference(const std::string &attName) const
Get a reference to an attribute.
void updateSpectrum(API::IFunction &spectrum, int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, double temperature, double fwhm, size_t iSpec, size_t iFirst, double intensityScaling) const
Update a function for a single spectrum.
size_t makeMapsForFunction(const IFunction &fun, size_t iFirst, const std::string &prefix) const
Make parameter names from names of a function and map them to indices.
void buildMultiSiteSingleSpectrum() const
Build the target function in a multi site - single spectrum case.
double getParameter(size_t i) const override
Get i-th parameter.
size_t parameterIndex(const std::string &name) const override
Returns the index of parameter name.
std::vector< std::string > m_attributeNames
Attribute names.
void setSource(API::IFunction_sptr source) const
Set the source function.
void setAttribute(const std::string &name, const Attribute &) override
Set a value to attribute attName.
CrystalFieldFunction()
Constructor.
std::vector< std::string > m_mapIndices2Names
Map parameter indices to names.
void makeMapsMultiSiteMultiSpectrum() const
Parameter-index map for multi-site multi-spectrum.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
API::ParameterTie * getTie(size_t i) const override
Get the tie for i-th parameter.
API::CompositeFunction & compositeSource() const
Get a reference to the source function if it's composite.
std::vector< std::string > getAttributeNames() const override
Returns a list of attribute names.
std::vector< double > m_parameterResetCache
Temporary cache for parameter values during source function resetting.
bool hasParameter(const std::string &name) const override
Check if function has a parameter with this name.
void buildMultiSite() const
Build the target function in a multi site case.
bool hasBackground() const
Check if the spectra have a background.
API::IFunction_sptr buildSpectrum(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, double temperature, double fwhm, size_t i, bool addBackground, double intensityScaling) const
Build a function for a single spectrum.
bool hasPhysProperties() const
Check if there are any phys. properties.
size_t nSpectra() const
Get number of the number of spectra (excluding phys prop data).
void makeMapsMultiSiteSingleSpectrum() const
Parameter-index map for multi-site single-spectrum.
double getError(size_t i) const override
Get the fitting error for a parameter.
void buildSingleSiteSingleSpectrum() const
Build the target function in a single site - single spectrum case.
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
bool ignoreTie(const API::ParameterTie &tie) const override
Checks if whether tie should be ignored.
bool hasAttribute(const std::string &name) const override
Check if attribute attName exists.
void setUpForFit() override
Set up the function for a fit.
void buildSingleSiteMultiSpectrum() const
Build the target function in a single site - multi spectrum case.
void setError(size_t i, double err) override
Set the fitting error for a parameter.
void checkSourceFunction() const
Build source function if necessary.
bool isMultiSpectrum() const
Check if the function is set up for a multi-spectrum calculations (Multiple temperatures defined)
void buildMultiSiteMultiSpectrum() const
Build the target function in a multi site - multi spectrum case.
size_t getNumberDomains() const override
Get number of domains required by this function.
std::unordered_map< std::string, API::IFunction_sptr > m_mapPrefixes2PhysProps
Map parameter/attribute prefixes to pointers to phys prop functions.
void buildSourceFunction() const
Build the source function.
void makeMaps() const
Make maps between parameter names and indices.
void buildSingleSite() const
Build the target function in a single site case.
void cacheSourceParameters() const
Temporary cache parameter values of the source function if it's initialised.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
std::vector< bool > m_fixResetCache
size_t m_nControlParams
Cached number of parameters in m_control.
void updateTargetFunction() const
Update the target function.
bool isExplicitlySet(size_t i) const override
Checks if a parameter has been set explicitly.
CrystalFieldControl m_control
Function that creates the source function.
void buildTargetFunction() const
Build target function.
void buildAttributeNames() const
Build and cache the attribute names.
void setParameterStatus(size_t i, ParameterStatus status) override
Change status of parameter.
void updateSingleSite() const
Update the target function in a single site case.
size_t m_nControlSourceParams
Cached number of parameters in m_control and m_source.
void updateSingleSiteMultiSpectrum() const
Update the target function in a single site - multi spectrum case.
void setParameterDescription(size_t, const std::string &description) override
Set i-th parameter description.
API::CompositeFunction_sptr m_target
Function that actually calculates the output.
API::IConstraint * getConstraint(size_t i) const override
Get the i-th constraint.
bool isMultiSite() const
Check if the function is set up for a multi-site calculations.
std::string name() const override
Returns the function's name.
void makeMapsSingleSiteSingleSpectrum() const
Parameter-index map for single-site single-spectrum.
size_t getParameterIndex(const API::ParameterReference &ref) const override
Return parameter index from a parameter reference.
ParameterStatus getParameterStatus(size_t i) const override
Get status of parameter.
std::string parameterDescription(size_t i) const override
Returns the description of parameter i.
void updateSingleSiteSingleSpectrum() const
Update the target function in a single site - single spectrum case.
bool hasPeaks() const
Check if there are peaks (there is at least one spectrum).
size_t nAttributes() const override
Returns the number of attributes associated with the function.
void function(const API::FunctionDomain &domain, API::FunctionValues &values) const override
Evaluate the function.
std::vector< API::IFunction_sptr > createEquivalentFunctions() const override
Split this function (if needed) into a list of independent functions.
size_t nParams() const override
Total number of parameters.
void setEnergy(const DoubleFortranVector &en)
void setHamiltonian(const ComplexFortranMatrix &ham, const int nre)
void setHamiltonian(const ComplexFortranMatrix &ham, const int nre)
CrystalFieldPeaks is a function that calculates crystal field peak positions and intensities.
void calculateEigenSystem(DoubleFortranVector &en, ComplexFortranMatrix &wf, ComplexFortranMatrix &ham, ComplexFortranMatrix &hz, int &nre) const
Calculate the crystal field eigensystem.
void setEigensystem(const DoubleFortranVector &en, const ComplexFortranMatrix &wf, const int nre)
Marks code as not implemented yet.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
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 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.
void MANTID_CURVEFITTING_DLL calculateExcitations(const DoubleFortranVector &e_energies, const DoubleFortranMatrix &i_energies, double de, double di, DoubleFortranVector &e_excitations, DoubleFortranVector &i_excitations)
Calculate the excitations (transition energies) and their intensities.
void MANTID_CURVEFITTING_DLL calculateIntensities(int nre, const DoubleFortranVector &energies, const ComplexFortranMatrix &wavefunctions, double temperature, double de, IntFortranVector °eneration, DoubleFortranVector &e_energies, DoubleFortranMatrix &i_energies)
Calculate the intensities of transitions.
std::string to_string(const wide_integer< Bits, Signed > &n)