36std::unique_ptr<IDomainCreator> createDomainCreator(
const IFunction *fun,
const std::string &workspacePropertyName,
39 std::unique_ptr<IDomainCreator> creator;
50 creator = std::make_unique<LatticeDomainCreator>(manager, workspacePropertyName);
51 }
else if (
dynamic_cast<const IFunctionMD *
>(fun)) {
52 creator = std::unique_ptr<IDomainCreator>(
55 creator = std::make_unique<SeqDomainSpectrumCreator>(manager, workspacePropertyName);
57 creator = std::make_unique<GeneralDomainCreator>(*gfun, *manager, workspacePropertyName);
58 }
else if (std::dynamic_pointer_cast<ITableWorkspace>(ws)) {
59 creator = std::make_unique<TableWorkspaceDomainCreator>(manager, workspacePropertyName, domainType);
61 bool histogramFit = manager->
getPropertyValue(
"EvaluationType") ==
"Histogram";
63 creator = std::make_unique<HistogramDomainCreator>(*manager, workspacePropertyName);
65 creator = std::make_unique<FitMW>(manager, workspacePropertyName, domainType);
82 "Parameters defining the fitting function and its initial values");
86 "Name of the input Workspace");
87 declareProperty(
"IgnoreInvalidData",
false,
"Flag to ignore infinities, NaNs and data with zero errors.");
89 std::array<std::string, 3> domainTypes = {{
"Simple",
"Sequential",
"Parallel"}};
93 std::array<std::string, 2> evaluationTypes = {{
"CentrePoint",
"Histogram"}};
96 "The way the function is evaluated on histogram data sets. "
97 "If value is \"CentrePoint\" then function is evaluated at "
98 "centre of each bin. If it is \"Histogram\" then function is "
99 "integrated within the bin and the integrals returned.",
101 const std::array<std::string, 2> stepSizes = {{
"Default",
"Sqrt epsilon"}};
104 "The way the step size is calculated for numerical derivatives. See the section about step sizes in the Fit "
105 "algorithm documentation to understand the difference between \"Default\" and \"Sqrt epsilon\".",
108 "A value of the peak radius the peak functions should use. A "
109 "peak radius defines an interval on the x axis around the "
110 "centre of the peak where its values are calculated. Values "
111 "outside the interval are not calculated and assumed zeros."
112 "Numerically the radius is a whole number of peak widths "
113 "(FWHM) that fit into the interval on each side from the "
114 "centre. The default value of 0 means the whole x axis.");
125 if (propName ==
"Function") {
127 }
else if (propName.size() >= 14 && propName.substr(0, 14) ==
"InputWorkspace") {
129 throw std::invalid_argument(
"Function must be set before InputWorkspace");
132 }
else if (propName ==
"DomainType") {
134 }
else if (propName ==
"StepSizeMethod") {
144 if (domainType ==
"Simple") {
146 }
else if (domainType ==
"Sequential") {
148 }
else if (domainType ==
"Parallel") {
164 for (
size_t i = 1; i < ndom; ++i) {
165 std::string workspacePropertyName =
"InputWorkspace_" +
std::to_string(i);
167 std::string workspaceIndexPropertyName =
"WorkspaceIndex_" +
std::to_string(i);
172 "Name of the input Workspace");
186 const std::string stepSizeMethod =
getProperty(
"StepSizeMethod");
187 m_function->setStepSizeMethod(stepSizeMethod ==
"Sqrt epsilon" ? IFunction::StepSizeMethod::SQRT_EPSILON
188 : IFunction::StepSizeMethod::DEFAULT);
202 const size_t n = std::string(
"InputWorkspace").size();
203 const std::string suffix = (workspacePropertyName.size() >
n) ? workspacePropertyName.substr(
n) :
"";
204 const size_t index = suffix.empty() ? 0 : boost::lexical_cast<size_t>(suffix.substr(1));
209 auto creator = createDomainCreator(fun.get(), workspacePropertyName,
this,
m_domainType);
217 if (fun->getNumberDomains() > 1) {
219 creator->declareDatasetProperties(suffix, addProperties);
220 multiCreator->setCreator(
index, creator.release());
223 creator->declareDatasetProperties(suffix, addProperties);
227 if (fun->getNumberDomains() > 1) {
228 std::shared_ptr<MultiDomainCreator> multiCreator = std::dynamic_pointer_cast<MultiDomainCreator>(
m_domainCreator);
231 throw std::runtime_error(std::string(
"MultiDomainCreator expected, found ") +
typeid(reference).
name());
233 if (!multiCreator->hasCreator(
index)) {
234 creator->declareDatasetProperties(suffix, addProperties);
236 multiCreator->setCreator(
index, creator.release());
238 creator->declareDatasetProperties(suffix, addProperties);
253 for (
auto &prop : props) {
255 const std::string workspacePropertyName = (*prop).name();
258 const size_t n = std::string(
"InputWorkspace").size();
259 const std::string suffix = (workspacePropertyName.size() >
n) ? workspacePropertyName.substr(
n) :
"";
260 const size_t index = suffix.empty() ? 0 : boost::lexical_cast<size_t>(suffix.substr(1));
261 creator->declareDatasetProperties(suffix,
false);
265 auto multiCreator = std::dynamic_pointer_cast<MultiDomainCreator>(
m_domainCreator);
267 multiCreator->setCreator(
index, creator.release());
276 creator->declareDatasetProperties(
"",
true);
286 std::vector<std::string> out;
288 auto names = factory.getKeys();
289 out.reserve(names.size());
290 for (
auto &
name : names) {
291 if (std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(factory.create(
name))) {
292 out.emplace_back(
name);
322 if (peakRadius != 0) {
323 d1d->setPeakRadius(peakRadius);
331 auto costFunction = std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(
334 costFunction->setFittingFunction(
m_function, domain, values);
std::map< DeltaEMode::Type, std::string > index
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Kernel::Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
bool existsProperty(const std::string &name) const override
Checks whether the named property is already in the list of managed property.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
bool isDefault(const std::string &name) const
const std::vector< Kernel::Property * > & getProperties() const override
Get the list of managed properties.
const std::string name() const override=0
function to return a name of the algorithm, must be overridden in all algorithms
Represent a domain for functions of one real argument.
DomainType
Type of domain to create.
IFunctionGeneral: a very general function definition.
This is a specialization of IFunction for functions defined on an IMDWorkspace.
This is an interface to a fitting function - a semi-abstarct class.
An interface that is implemented by WorkspaceProperty.
A property class for workspaces.
void declareCostFunctionProperty()
Declare a "CostFunction" property.
virtual void execConcrete()=0
Child classes implement the algorithm logic here.
void setDomainType()
Read domain type property and cache the value.
std::shared_ptr< API::IDomainCreator > m_domainCreator
Pointer to a domain creator.
void addWorkspace(const std::string &workspacePropertyName, bool addProperties=true)
Add a new workspace to the fit.
const std::string category() const override
Algorithm's category for identification.
std::vector< std::string > m_workspacePropertyNames
std::shared_ptr< CostFunctions::CostFuncFitting > getCostFunctionInitialized() const
Create a cost function from the "CostFunction" property and make it ready for evaluation.
void exec() override
Execute the algorithm.
std::shared_ptr< API::IFunction > m_function
Pointer to the fitting function.
std::vector< std::string > getCostFunctionNames() const
Return names of registered cost function for CostFuncFitting dynamic type.
void init() override
Initialize the algorithm's properties.
void setStepSizeMethod()
Sets the method to use when calculating the step size for the numerical derivative.
virtual void initConcrete()=0
Child classes declare their properties here.
void afterPropertySet(const std::string &propName) override
Examine "Function" and "InputWorkspace" properties to decide which domain creator to use.
API::IDomainCreator::DomainType m_domainType
Keep the domain type.
void addWorkspaces()
Collect all input workspace property names in the m_workspacePropertyNames vector.
std::vector< std::string > m_workspaceIndexPropertyNames
Creates a composite domain.
Interface to PropertyManager.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
virtual std::string getPropertyValue(const std::string &name) const =0
Get the value of a property as a string.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< FunctionValues > FunctionValues_sptr
typedef for a shared pointer
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::shared_ptr< FunctionDomain > FunctionDomain_sptr
typedef for a shared pointer
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.
@ Input
An input workspace.