37std::unique_ptr<IDomainCreator> createDomainCreator(
const IFunction *fun,
const std::string &workspacePropertyName,
40 std::unique_ptr<IDomainCreator> creator;
51 creator = std::make_unique<LatticeDomainCreator>(manager, workspacePropertyName);
52 }
else if (
dynamic_cast<const IFunctionMD *
>(fun)) {
53 creator = std::unique_ptr<IDomainCreator>(
54 API::DomainCreatorFactory::Instance().createDomainCreator(
"FitMD", manager, workspacePropertyName, domainType));
56 creator = std::make_unique<SeqDomainSpectrumCreator>(manager, workspacePropertyName);
58 creator = std::make_unique<GeneralDomainCreator>(*gfun, *manager, workspacePropertyName);
59 }
else if (std::dynamic_pointer_cast<ITableWorkspace>(ws)) {
60 creator = std::make_unique<TableWorkspaceDomainCreator>(manager, workspacePropertyName, domainType);
62 bool histogramFit = manager->
getPropertyValue(
"EvaluationType") ==
"Histogram";
64 creator = std::make_unique<HistogramDomainCreator>(*manager, workspacePropertyName);
66 creator = std::make_unique<FitMW>(manager, workspacePropertyName, domainType);
83 "Parameters defining the fitting function and its initial values");
87 "Name of the input Workspace");
88 declareProperty(
"IgnoreInvalidData",
false,
"Flag to ignore infinities, NaNs and data with zero errors.");
90 std::array<std::string, 3> domainTypes = {{
"Simple",
"Sequential",
"Parallel"}};
94 std::array<std::string, 2> evaluationTypes = {{
"CentrePoint",
"Histogram"}};
97 "The way the function is evaluated on histogram data sets. "
98 "If value is \"CentrePoint\" then function is evaluated at "
99 "centre of each bin. If it is \"Histogram\" then function is "
100 "integrated within the bin and the integrals returned.",
105 "The way the step size is calculated for numerical derivatives. See the section about step sizes in the Fit "
106 "algorithm documentation to understand the difference between \"" +
110 "A value of the peak radius the peak functions should use. A "
111 "peak radius defines an interval on the x axis around the "
112 "centre of the peak where its values are calculated. Values "
113 "outside the interval are not calculated and assumed zeros."
114 "Numerically the radius is a whole number of peak widths "
115 "(FWHM) that fit into the interval on each side from the "
116 "centre. The default value of 0 means the whole x axis.");
127 if (propName ==
"Function") {
129 }
else if (propName.size() >= 14 && propName.substr(0, 14) ==
"InputWorkspace") {
131 throw std::invalid_argument(
"Function must be set before InputWorkspace");
134 }
else if (propName ==
"DomainType") {
136 }
else if (propName ==
"StepSizeMethod") {
146 if (domainType ==
"Simple") {
148 }
else if (domainType ==
"Sequential") {
150 }
else if (domainType ==
"Parallel") {
166 for (
size_t i = 1; i < ndom; ++i) {
167 std::string workspacePropertyName =
"InputWorkspace_" +
std::to_string(i);
169 std::string workspaceIndexPropertyName =
"WorkspaceIndex_" +
std::to_string(i);
174 "Name of the input Workspace");
188 const std::string stepSizeMethod =
getProperty(
"StepSizeMethod");
190 m_function->setStepSizeMethod(IFunction::StepSizeMethod::SQRT_EPSILON);
192 m_function->setStepSizeMethod(IFunction::StepSizeMethod::CUSTOM);
193 const std::vector<double> customStepSizes =
getProperty(
"CustomStepSizes");
194 m_function->setCustomStepSizes(customStepSizes);
196 m_function->setStepSizeMethod(IFunction::StepSizeMethod::DEFAULT);
211 const size_t n = std::string(
"InputWorkspace").size();
212 const std::string suffix = (workspacePropertyName.size() >
n) ? workspacePropertyName.substr(
n) :
"";
213 const size_t index = suffix.empty() ? 0 : boost::lexical_cast<size_t>(suffix.substr(1));
218 auto creator = createDomainCreator(fun.get(), workspacePropertyName,
this,
m_domainType);
226 if (fun->getNumberDomains() > 1) {
228 creator->declareDatasetProperties(suffix, addProperties);
229 multiCreator->setCreator(
index, creator.release());
232 creator->declareDatasetProperties(suffix, addProperties);
236 if (fun->getNumberDomains() > 1) {
237 std::shared_ptr<MultiDomainCreator> multiCreator = std::dynamic_pointer_cast<MultiDomainCreator>(
m_domainCreator);
240 throw std::runtime_error(std::string(
"MultiDomainCreator expected, found ") +
typeid(reference).
name());
242 if (!multiCreator->hasCreator(
index)) {
243 creator->declareDatasetProperties(suffix, addProperties);
245 multiCreator->setCreator(
index, creator.release());
247 creator->declareDatasetProperties(suffix, addProperties);
262 for (
auto &prop : props) {
264 const std::string workspacePropertyName = (*prop).name();
267 const size_t n = std::string(
"InputWorkspace").size();
268 const std::string suffix = (workspacePropertyName.size() >
n) ? workspacePropertyName.substr(
n) :
"";
269 const size_t index = suffix.empty() ? 0 : boost::lexical_cast<size_t>(suffix.substr(1));
270 creator->declareDatasetProperties(suffix,
false);
274 auto multiCreator = std::dynamic_pointer_cast<MultiDomainCreator>(
m_domainCreator);
276 multiCreator->setCreator(
index, creator.release());
285 creator->declareDatasetProperties(
"",
true);
295 std::vector<std::string> out;
296 auto &factory = CostFunctionFactory::Instance();
297 auto names = factory.getKeys();
298 out.reserve(names.size());
299 for (
auto &
name : names) {
300 if (std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(factory.create(
name))) {
301 out.emplace_back(
name);
324 const bool ignoreInvalidData =
getProperty(
"IgnoreInvalidData");
332 if (peakRadius != 0) {
333 d1d->setPeakRadius(peakRadius);
341 auto costFunction = std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(
344 costFunction->setIgnoreInvalidData(ignoreInvalidData);
345 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...
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
const std::string CUSTOM_STEP_SIZE
const std::string SQRT_EPSILON_STEP_SIZE
const std::string DEFAULT_STEP_SIZE
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.