55 auto compositeValidator = std::make_shared<CompositeValidator>();
56 compositeValidator->add(std::make_shared<API::WorkspaceUnitValidator>(
"Wavelength"));
57 compositeValidator->add(std::make_shared<API::HistogramValidator>());
61 "An input workspace in wavelength");
64 "An output workspace.");
69 const std::string &detectorName) {
70 if (parameter ==
nullptr) {
71 std::stringstream stream;
72 stream << detectorName
73 <<
" and all of it's parent components, have no "
74 "fitting type parameters. This algorithm "
75 "cannot be run without fitting parameters. See "
76 "wiki help for details on setup.";
78 throw std::runtime_error(stream.str());
97 const auto &componentInfo = inWS->componentInfo();
98 const auto &spectrumInfo = inWS->spectrumInfo();
100 const bool hasParameters = spectrumInfo.hasUniqueDetector(wsIndex);
101 const auto detIndex = spectrumInfo.spectrumDefinition(wsIndex)[0].first;
102 const auto &detName = componentInfo.name(detIndex);
103 const std::string type =
"fitting";
104 const auto foundParam = hasParameters ? componentInfo.parameterByType(detIndex, type) :
nullptr;
108 const std::string &fitFunctionName = foundFittingParam.
getFunction();
109 IFunction_sptr function = FunctionFactory::Instance().createFunction(fitFunctionName);
110 using ParamNames = std::vector<std::string>;
111 ParamNames allParamNames = function->getParameterNames();
114 for (
auto ¶mName : allParamNames) {
115 const auto param = componentInfo.parameter(detIndex, paramName, type);
120 throw std::runtime_error(
"A Forumla has not been provided for a fit function");
123 if (!resultUnitStr.empty() && resultUnitStr !=
"Wavelength") {
124 throw std::runtime_error(
"Units for function parameters must be in Wavelength");
129 double paramValue = p.Eval();
131 function->setParameter(fitParam.
getName(), paramValue);
135 auto const wavelengths = inWS->points(wsIndex);
138 function->function(domain, values);
140 auto &
Y = denominatorWS->mutableY(wsIndex);
141 for (
size_t i = 0; i < domain.
size(); ++i) {
145 denominatorWS->mutableE(wsIndex) = 0.0;
157 const size_t nHistograms = inWS->getNumberHistograms();
158 const auto progress_items =
static_cast<size_t>(double(nHistograms) * 1.2);
159 Progress prog(
this, 0.0, 1.0, progress_items);
163 cloneAlg->setProperty(
"InputWorkspace", inWS);
164 cloneAlg->setPropertyValue(
"OutputWorkspace",
"temp");
165 cloneAlg->executeAsChildAlg();
173 for (
int wsIndex = 0; wsIndex < static_cast<int>(nHistograms); ++wsIndex) {
180 for (
size_t wsIndex = 0; wsIndex < nHistograms; ++wsIndex) {
185 return denominatorWS;
200 divideAlg->setRethrows(
true);
201 divideAlg->setProperty(
"LHSWorkspace", inWS);
202 divideAlg->setProperty(
"RHSWorkspace", denominatorWS);
203 divideAlg->executeAsChildAlg();
#define DECLARE_ALGORITHM(classname)
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
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.
Implements FunctionDomain1D with its own storage in form of a std::vector.
size_t size() const override
Return the number of arguments in the domain.
A class to store values calculated by a function.
Helper class for reporting progress from algorithms.
A property class for workspaces.
NormaliseByDetector : Normalises a workspace with respect to the detector efficiency function stored ...
std::shared_ptr< Mantid::API::MatrixWorkspace > processHistograms(const std::shared_ptr< Mantid::API::MatrixWorkspace > &inWS)
Block to process histograms.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
const std::string category() const override
Algorithm's category for identification.
void processHistogram(size_t wsIndex, const std::shared_ptr< const Mantid::API::MatrixWorkspace > &inWS, const std::shared_ptr< Mantid::API::MatrixWorkspace > &denominatorWS, Mantid::API::Progress &prog)
Process indivdual histogram.
const bool m_parallelExecution
Flag to indicate that the histograms should be processed in parallel.
const Mantid::Geometry::FitParameter tryParseFunctionParameter(const std::shared_ptr< const Mantid::Geometry::Parameter > ¶meter, const std::string &detectorName)
Try to parse a function parameter and extract the correctly typed parameter.
int version() const override
Algorithm's version for identification.
const std::string name() const override
Algorithm's name for identification.
Store information about a fitting parameter such as its value if it is constrained or tied.
const std::string & getName() const
get name
const std::string & getFormula() const
get formula
const std::string & getFunction() const
get function
const std::string & getResultUnit() const
get result formula unit, and Empty string is no unit has been specified
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void warning(const std::string &msg)
Logs at warning level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
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
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
@ Input
An input workspace.
@ Output
An output workspace.