30bool isConvolution(
const IFunction *fun) {
return fun->
name() ==
"Convolution"; }
32bool isResolution(
const IFunction *fun) {
return fun->
name() ==
"Resolution"; }
34bool isDeltaFunction(
const IFunction *fun) {
return fun->
name() ==
"DeltaFunction"; }
36bool isTempFunction(
const IFunction *fun) {
return fun->
name() ==
"ConvTempCorrection"; }
40bool isLorentzianFunction(
const IFunction *fun) {
return fun->
name() ==
"Lorentzian"; }
41bool isfitTypeFunction(
const IFunction *fun) {
55 const std::string &peaks,
bool hasDeltaFunction) {
56 auto const resolution =
workspace.empty() ?
"name=Resolution"
57 :
"name=Resolution,Workspace=\"" +
workspace +
59 auto const model = hasDeltaFunction ?
"name=DeltaFunction;" + peaks : peaks;
60 auto const convolution =
"composite=Convolution;" + resolution +
";" + model;
61 auto const function = background.empty() ? convolution : background +
";(" + convolution +
")";
66 const std::vector<std::pair<std::string, size_t>> &resolutionWorkspaces,
67 const std::string &lorentzianPeaks,
const std::string &fitType,
68 bool hasDeltaFunction,
const std::vector<double> &qValues,
69 const bool isQDependent,
bool hasTempCorrection,
double tempValue) {
70 auto fitFunction = std::make_shared<MultiDomainFunction>();
72 for (
int i = 0; i < nf; ++i) {
74 auto qValue = qValues.empty() ? 0.0 : qValues[i];
75 auto innerFunction =
createInnerFunction(lorentzianPeaks, fitType, hasDeltaFunction, isQDependent, qValue,
76 hasTempCorrection, tempValue);
77 auto workspace = resolutionWorkspaces.empty() ?
"" : resolutionWorkspaces[i].first;
78 auto workspaceIndex = resolutionWorkspaces.empty() ? 0 : resolutionWorkspaces[i].second;
81 domainFunction =
addBackground(convolutionFunction, background);
83 fitFunction->addFunction(domainFunction);
84 fitFunction->setDomainIndex(i, i);
97 const std::string &background) {
98 if (background.empty())
99 return domainFunction;
102 auto functionWithBackground = std::make_shared<CompositeFunction>();
103 functionWithBackground->addFunction(backgroundFunction);
104 functionWithBackground->addFunction(domainFunction);
106 return functionWithBackground;
110 const std::string &fitType,
bool hasDeltaFunction,
111 bool isQDependent,
double qValue,
112 bool hasTempCorrection,
double tempValue) {
114 if (!lorentzianPeaks.empty()) {
116 auto peakFunctionComposite = std::dynamic_pointer_cast<CompositeFunction>(lorentzianPeakFunction);
117 if (peakFunctionComposite) {
118 innerFunction = peakFunctionComposite;
120 innerFunction->addFunction(lorentzianPeakFunction);
124 if (!fitType.empty()) {
126 innerFunction->addFunction(fitTypeFunction);
129 fitTypeFunction->setAttribute(
"Q", attr);
133 if (hasTempCorrection) {
137 if (hasDeltaFunction) {
139 auto lowerBound = std::unique_ptr<IConstraint>(
141 deltaFunction->addConstraint(std::move(lowerBound));
143 if (!hasTempCorrection) {
144 innerFunction->addFunction(deltaFunction);
147 innerFunctionNew->addFunction(deltaFunction);
148 innerFunctionNew->addFunction(innerFunction);
149 return innerFunctionNew;
153 return innerFunction;
161 productFunction->addFunction(tempFunction);
162 productFunction->addFunction(peaksFunction);
163 return productFunction;
168 tempFunc->setParameter(
"Temperature", correction);
169 tempFunc->fixParameter(
"Temperature",
false);
177 convolution->addFunction(std::move(resolutionFunction));
179 if (innerFunction->nFunctions() > 0)
180 convolution->addFunction(innerFunction);
186 size_t workspaceIndex) {
187 std::string resolution = workspaceName.empty() ?
"name=Resolution"
188 :
"name=Resolution,Workspace=\"" + workspaceName +
212 throw std::runtime_error(
"Model doesn't contain a convolution.");
217 auto numberOfSubFunction = func->
nFunctions();
220 if (numberOfSubFunction == 0) {
223 if (!isfitTypeFunction(func)) {
224 for (
size_t k = 0; k < numberOfSubFunction; ++k) {
231 if (isBackground(func)) {
233 throw std::runtime_error(
"Model cannot have more than one background.");
236 }
else if (isConvolution(func)) {
238 throw std::runtime_error(
"Model's resolution function must have type Resolution.");
244 }
else if (isDeltaFunction(func)) {
246 }
else if (isTempFunction(func)) {
248 }
else if (isResolution(func)) {
251 }
else if (isLorentzianFunction(func)) {
253 }
else if (isfitTypeFunction(func)) {
IPeaksWorkspace_sptr workspace
A composite function is a function containing other functions.
An interface to a background function.
Attribute is a non-fitting parameter.
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.
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::string name() const =0
Returns the function's name.
virtual std::shared_ptr< IFunction > getFunction(size_t i) const
Returns the pointer to i-th child function.
virtual std::size_t nFunctions() const
Number of child functions.
Immutable composite function is a composite function which members cannot be added or removed after c...
The Logger class is in charge of the publishing messages from the framework through various channels.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::shared_ptr< CompositeFunction > CompositeFunction_sptr
shared pointer to the composite function base class
std::string to_string(const wide_integer< Bits, Signed > &n)