36 int workspaceIndex = fittingAlgorithm.
getProperty(
"WorkspaceIndex" + suffix);
37 fit.
setProperty(
"WorkspaceIndex" + suffix, workspaceIndex);
39 double startX = fittingAlgorithm.
getProperty(
"StartX" + suffix);
40 double endX = fittingAlgorithm.
getProperty(
"EndX" + suffix);
44 std::vector<double> exclude = fittingAlgorithm.
getProperty(
"Exclude" + suffix);
49 const std::vector<Mantid::API::MatrixWorkspace_sptr> &workspaces) {
52 for (
auto i = 1u; i < workspaces.size(); ++i)
57 double firstPulseWeight,
double secondPulseWeight) {
58 auto clonedFunction = function->clone();
60 auto convolution = std::make_shared<Mantid::CurveFitting::Functions::Convolution>();
61 auto delta1 = std::make_shared<Mantid::CurveFitting::Functions::DeltaFunction>();
62 auto delta2 = std::make_shared<Mantid::CurveFitting::Functions::DeltaFunction>();
63 auto deltaComposite = std::make_shared<Mantid::API::CompositeFunction>();
65 convolution->setAttributeValue(
"FixResolution",
false);
66 delta1->setParameter(
"Centre", -0.5 * offset);
67 delta1->setParameter(
"Height", firstPulseWeight);
69 delta2->setParameter(
"Centre", 0.5 * offset);
70 delta2->setParameter(
"Height", secondPulseWeight);
72 deltaComposite->addFunction(delta1);
73 deltaComposite->addFunction(delta2);
75 convolution->addFunction(clonedFunction);
76 convolution->addFunction(deltaComposite);
83 double firstPulseWeight,
double secondPulseWeight) {
84 auto doublePulseFunc = std::make_shared<API::MultiDomainFunction>();
85 for (
size_t domain = 0; domain < initialFunction->getNumberDomains(); domain++) {
86 auto twoPulseInnerFunction =
88 doublePulseFunc->addFunction(twoPulseInnerFunction);
89 doublePulseFunc->setDomainIndex(domain, domain);
91 return doublePulseFunc;
95extractInnerFunction(std::shared_ptr<const Mantid::CurveFitting::Functions::Convolution>
const &convolutionFunction) {
96 return convolutionFunction->getFunction(0);
101 auto extractedFunction = std::make_shared<API::MultiDomainFunction>();
102 for (
size_t domain = 0; domain < doublePulseFunc->getNumberDomains(); domain++) {
103 auto convFunction = std::dynamic_pointer_cast<Convolution>(doublePulseFunc->getFunction(domain));
106 extractedFunction->setDomainIndex(domain, domain);
108 throw std::runtime_error(
"Cannot extract from non convolution function. DoublePulseFit.cpp");
111 return extractedFunction;
125 "the fitting function.");
128 auto mustBePositive = std::make_shared<Kernel::BoundedValidator<int>>();
129 mustBePositive->setLower(0);
131 "Stop after this number of iterations if a good fit is not found");
139 declareProperty(
"Minimizer",
"Levenberg-Marquardt", minimizerValidator,
"Minimizer to use for fitting.");
143 for (
auto &costFuncOption : costFuncOptions) {
144 auto costFunc = std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(
150 Kernel::IValidator_sptr costFuncValidator = std::make_shared<Kernel::ListValidator<std::string>>(costFuncOptions);
154 "Set to true to create output workspaces with the results of the fit"
155 "(default is false).");
157 "A base name for the output workspaces (if not "
158 "given default names will be created). The "
159 "default is to use the name of the original data workspace as prefix "
160 "followed by suffixes _Workspace, _Parameters, etc.");
162 "Set to true to calcuate errors when output isn't created "
163 "(default is false).");
165 "If true and CreateOutput is true then the value of each "
166 "member of a Composite Function is also output.");
168 "If true and OutputCompositeMembers is true members of any "
169 "Convolution are output convolved\n"
170 "with corresponding resolution");
172 "Set to true to output only the parameters and not "
173 "workspace(s) with the calculated values\n"
174 "(default is false, ignored if CreateOutput is false and "
175 "Output is an empty string).");
176 declareProperty(
"PulseOffset", 0.0,
"The time offset between the two pulses");
178 declareProperty(
"SecondPulseWeight", 0.5,
"Weighting of second pulse.");
189 auto firstPulseWeight =
getProperty(
"FirstPulseWeight");
190 auto secondPulseWeight =
getProperty(
"SecondPulseWeight");
191 if (
auto multiDomainFunction = std::dynamic_pointer_cast<Mantid::API::MultiDomainFunction>(function)) {
192 doublePulseFunction =
211 if (baseName.empty()) {
213 baseName = ws->getName();
219 "The name of the TableWorkspace in which to store the final "
220 "covariance matrix");
221 setPropertyValue(
"OutputNormalisedCovarianceMatrix", baseName +
"_NormalisedCovarianceMatrix");
225 "The name of the TableWorkspace in which to store the "
226 "final fit parameters");
234 "Name of the output Workspace holding resulting fitted "
240 "Name of the output Workspace holding resulting simulated "
249 std::vector<Mantid::API::MatrixWorkspace_sptr> workspaces;
253 workspaces.emplace_back(std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
workspace));
269 const bool convolveMembers =
getProperty(
"ConvolveMembers");
270 const bool ignoreInvalidData =
getProperty(
"IgnoreInvalidData");
273 const bool outputCompositeMembers =
getProperty(
"OutputCompositeMembers");
274 const bool outputParametersOnly =
getProperty(
"OutputParametersOnly");
276 fitAlg->setLogging(
true);
277 fitAlg->setProperty(
"Function", function);
279 fitAlg->setProperty(
"IgnoreInvalidData", ignoreInvalidData);
285 fitAlg->setProperty(
"MaxIterations", maxIterations);
288 fitAlg->setProperty(
"CalcErrors", calcErrors);
289 fitAlg->setProperty(
"OutputCompositeMembers", outputCompositeMembers);
290 fitAlg->setProperty(
"ConvolveMembers", convolveMembers);
292 fitAlg->setProperty(
"OutputParametersOnly", outputParametersOnly);
294 fitAlg->executeAsChildAlg();
300 if (
auto convFunction = std::dynamic_pointer_cast<Mantid::CurveFitting::Functions::Convolution>(function)) {
302 }
else if (
auto multiDomainFunction = std::dynamic_pointer_cast<Mantid::API::MultiDomainFunction>(function)) {
305 throw std::runtime_error(
"Incompatible function form. DoublePulseFit.cpp");
307 double outputChi2overDoF = fitAlg->getProperty(
"OutputChi2overDoF");
308 std::string outputStatus = fitAlg->getProperty(
"OutputStatus");
310 setProperty(
"OutputChi2overDoF", outputChi2overDoF);
313 setProperty(
"OutputNormalisedCovarianceMatrix", covarianceMatrix);
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
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.
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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
IAlgorithm is the interface implemented by the Algorithm base class.
A property class for workspaces.
A function to fit muon data from a double pulse source.
void createOutput(const Mantid::API::IAlgorithm_sptr &fitAlg, const Mantid::API::IFunction_sptr &function)
void runFitAlgorith(const Mantid::API::IAlgorithm_sptr &fitAlgorithm, const Mantid::API::IFunction_sptr &function, int maxIterations)
std::vector< Mantid::API::MatrixWorkspace_sptr > getWorkspaces() const
void initConcrete() override
Initialisation method.
void execConcrete() override
Child classes implement the algorithm logic here.
void setOutputProperties()
void declareAdditionalProperties()
This function declares the additional output properties which are not present in init.
A base class for fitting algorithms.
std::vector< std::string > m_workspacePropertyNames
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
The concrete, templated class for properties.
void setDocumentation(const std::string &documentation)
Sets the user level description of the property.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< const Workspace > Workspace_const_sptr
shared pointer to Mantid::API::Workspace (const version)
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
void setMultiDataProperties(const Mantid::API::IAlgorithm &fittingAlgorithm, Mantid::API::IAlgorithm &fit, const Mantid::API::MatrixWorkspace_sptr &workspace, const std::string &suffix)
MANTID_CURVEFITTING_DLL Mantid::API::IFunction_sptr getDoublePulseFunction(std::shared_ptr< const API::IFunction > const &function, double offset, double firstPulseWeight, double secondPulseWeight)
MANTID_CURVEFITTING_DLL Mantid::API::IFunction_sptr getDoublePulseMultiDomainFunction(std::shared_ptr< const API::MultiDomainFunction > const &function, double offset, double firstPulseWeight, double secondPulseWeight)
MANTID_CURVEFITTING_DLL Mantid::API::IFunction_sptr extractInnerFunction(std::shared_ptr< const Mantid::CurveFitting::Functions::Convolution > const &function)
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.
@ Output
An output workspace.