31 m_function = std::dynamic_pointer_cast<MultiDomainFunction>(fun);
40 for (
int i = 0; i < nf; ++i) {
56 auto const numberOfFunctions =
m_function->nFunctions();
58 if (numberOfFunctions > 1) {
63 }
else if (numberOfFunctions == 1) {
64 auto const function =
m_function->getFunction(0)->clone();
65 auto const composite = std::dynamic_pointer_cast<CompositeFunction>(function);
67 if (composite && composite->nFunctions() == 1)
68 return composite->getFunction(0);
75 auto function = std::dynamic_pointer_cast<MultiDomainFunction>(
m_function->clone());
79 if (singleFun->hasParameter(*paramIter)) {
81 for (
auto i = 0u; i <
m_function->nFunctions(); ++i)
83 ties <<
"f" + QString::number(i) +
"." + QString::fromStdString(*paramIter);
85 ties <<
"f" + QString::number(
index) +
"." + QString::fromStdString(*paramIter);
86 function->addTies(ties.join(
"=").toStdString());
106 auto newFun = FunctionFactory::Instance().createInitialized(funStr);
108 for (
int i = 0; i < nf; ++i) {
111 auto cf = std::dynamic_pointer_cast<CompositeFunction>(parentFun);
113 cf->addFunction(newFun->clone());
114 }
else if (i == 0 && prefix.empty()) {
118 throw std::runtime_error(
"Function at " + prefix +
" is not composite.");
129 if (prefix.empty() &&
index == -1) {
134 for (
int i = 0; i < nf; ++i) {
137 auto cf = std::dynamic_pointer_cast<CompositeFunction>(parentFun);
139 throw std::runtime_error(
"Function at " + prefix +
" is not composite.");
141 cf->removeFunction(
index);
142 if (cf->nFunctions() == 1 && prefix.empty() && cf->name() ==
"CompositeFunction") {
143 m_function->replaceFunction(i, cf->getFunction(0));
163 throw std::logic_error(
"Function is undefined.");
165 if (fun->hasAttribute(attrName)) {
166 fun->setAttribute(attrName,
value);
172 auto const index = fun->parameterIndex(parameterName);
178 return fun && fun->hasParameter(parameterName) ? fun->getParameter(parameterName) : 0.0;
183 return fun && fun->hasAttribute(attrName) ? fun->getAttribute(attrName) :
IFunction::Attribute();
188 return fun && fun->hasParameter(parameterName) ? fun->getError(fun->parameterIndex(parameterName)) : 0.0;
193 return fun && fun->hasParameter(parameterName) ? fun->parameterDescription(fun->parameterIndex(parameterName)) :
"";
216 return std::vector<std::string>{};
222 return std::vector<std::string>{};
238 throw std::runtime_error(
"Number of domains shouldn't be less than 0.");
240 auto const nd =
static_cast<size_t>(nDomains);
248 auto const lastIndex = nfOld - 1;
249 auto const nf = nd > 0 ? nd : 1;
251 auto fun =
m_function->getFunction(lastIndex);
252 for (
size_t i = nfOld; i < nf; ++i) {
257 for (
size_t i = lastIndex; i >= nf; --i) {
262 for (
size_t i = 0; i <
m_function->nFunctions(); ++i) {
278 for (
const auto &datasetName : datasetNames)
297 for (
const auto &datasetName : datasetNames)
310 sort(indices.begin(), indices.end(), [](
int a,
int b) { return a > b; });
311 for (
auto i = indices.constBegin(); i != indices.constEnd(); ++i)
318 if (currentIndex >= nDomains)
319 currentIndex =
m_datasets.isEmpty() ? 0 : nDomains - 1;
328 std::vector<std::string> allDatasetNames;
330 for (
auto i = 0u; i < dataset.numberOfSpectra(); ++i) {
332 allDatasetNames.emplace_back(dataset.datasetName());
334 return allDatasetNames;
341 std::vector<std::string> allDomainNames;
343 auto const domainNames = dataset.domainNames();
344 allDomainNames.insert(allDomainNames.end(), domainNames.cbegin(), domainNames.cend());
346 return allDomainNames;
365 auto const parIndex = fun->parameterIndex(parameterName);
366 return fun->isFixed(parIndex);
371 auto const parIndex = fun->parameterIndex(parameterName);
372 auto const tie = fun->getTie(parIndex);
375 auto const tieStr = QString::fromStdString(tie->asString());
376 auto const j = tieStr.indexOf(
'=');
377 return tieStr.mid(j + 1).toStdString();
382 auto const parIndex = fun->parameterIndex(parameterName);
383 auto const constraint = fun->getConstraint(parIndex);
384 auto const out = (!constraint) ?
"" : constraint->asString();
390 if (function && function->hasParameter(parameterName))
391 function->setParameter(parameterName,
value);
396 auto const parIndex = fun->parameterIndex(parameterName);
397 fun->setParameter(parIndex,
value);
398 fun->setError(parIndex,
error);
403 auto const parIndex = fun->parameterIndex(parameterName);
406 }
else if (fun->isFixed(parIndex)) {
407 fun->unfix(parIndex);
412 auto logError = [¶meterName](
const std::string &msg) {
413 g_log.
error() <<
"Tie " << parameterName <<
": " << msg <<
'\n';
416 auto const name = parameterName;
418 fun->removeTie(fun->parameterIndex(
name));
420 auto const j = QString::fromStdString(tie).indexOf(
'=');
422 fun->tie(
name, QString::fromStdString(tie).mid(j + 1).toStdString());
423 }
catch (
const std::invalid_argument &e) {
425 }
catch (
const std::runtime_error &e) {
432 std::string
const &constraint) {
434 if (constraint !=
"" && parts.second.first ==
"" && parts.second.second ==
"") {
435 g_log.
error(
"Constraint " + parameterName +
": " + constraint +
" is not a valid constraint");
438 std::string prefix,
name;
441 if (constraint.empty()) {
442 fun->removeConstraint(
name);
444 auto newConstraint(QString::fromStdString(constraint));
445 newConstraint.replace(QString::fromStdString(parts.first), QString::fromStdString(
name));
446 fun->addConstraints(newConstraint.toStdString());
459 }
catch (std::exception &) {
466 fun->addConstraints(constraint);
476 if (parameterName.empty())
493 std::vector<std::string> locals;
494 std::copy_if(parameterNames.cbegin(), parameterNames.cend(), std::back_inserter(locals),
495 [&](
const std::string ¶meterName) { return !isGlobal(parameterName); });
511 throw std::runtime_error(
"Number of dataset domains doesn't match the number of domains.");
516 return std::accumulate(datasets.cbegin(), datasets.cend(), 0, [](
int lhs,
const auto &dataset) {
517 return lhs + static_cast<int>(dataset.numberOfSpectra());
526 assert(indexInRange);
538 auto const nRows = paramTable.
rowCount();
543 for (
auto &&
name : globalParameterNames) {
551 for (
auto &&
name : localParameterNames) {
555 for (
size_t i = 0; i < nRows; ++i) {
585 if (!fun->hasParameter(*it)) {
594 auto n = fun->getNumberDomains();
600 if (fun->hasAttribute(
"f0.Workspace")) {
601 std::string wsName = fun->getAttribute(
"f0.Workspace").asString();
602 if (AnalysisDataService::Instance().doesExist(wsName)) {
603 const auto ws = AnalysisDataService::Instance().retrieveWS<
MatrixWorkspace>(wsName);
612 auto analyser = inst->getStringParameter(
"analyser");
613 if (!analyser.empty()) {
614 auto comp = inst->getComponentByName(analyser[0]);
615 if (comp && comp->hasParameter(
"resolution")) {
616 auto params = comp->getNumberParameter(
"resolution",
true);
617 for (
const auto ¶m : fun->getParameterNames()) {
618 if (param.find(
"FWHM") != std::string::npos) {
619 fun->setParameter(param, params[0]);
632 std::string foundName;
634 auto getA0 = [](
IFunction const &f) -> std::string {
return f.hasParameter(
"A0") ?
"A0" :
""; };
635 auto const cf = std::dynamic_pointer_cast<CompositeFunction>(fun);
637 if (fun->name() !=
"CompositeFunction")
639 for (
size_t i = 0; i < cf->nFunctions(); ++i) {
640 foundName = getA0(*cf->getFunction(i));
641 if (!foundName.empty()) {
647 foundName = getA0(*fun);
649 if (!foundName.empty()) {
650 fun->setParameter(foundName,
value);
656 (void)fitResolutions;
double value
The value of the point.
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Attribute is a non-fitting parameter.
This is an interface to a fitting function - a semi-abstarct class.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
virtual std::vector< std::string > getAttributeNames() const
Returns a list of attribute names.
virtual size_t nAttributes() const
Returns the number of attributes associated with the function.
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
virtual Column_sptr getColumn(const std::string &name)=0
Gets the shared pointer to a column by name.
virtual size_t rowCount() const =0
Number of rows in the workspace.
Base MatrixWorkspace Abstract Class.
A composite function defined on a CompositeDomain.
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.
std::shared_ptr< MultiDomainFunction > MultiDomainFunction_sptr
Shared pointer to Mantid::API::MultiDomainFunction.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Kernel::Logger g_log("DetermineSpinStateOrder")
std::string to_string(const wide_integer< Bits, Signed > &n)