30using namespace DataObjects;
31using namespace Kernel;
45 m_startIndex(0), m_count(0) {
47 throw std::runtime_error(
"FitMD only supports simple domains");
50 throw std::runtime_error(
"Cannot create FitMD: no workspace given");
79 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
80 mustBePositive->setLower(1);
82 "The maximum number of values per a simple domain.");
93void FitMD::createDomain(std::shared_ptr<API::FunctionDomain> &domain, std::shared_ptr<API::FunctionValues> &ivalues,
98 const size_t n = iterator->getDataSize();
107 ivalues.reset(values);
112 values->setFitData(i, iter->getNormalizedSignal());
117 values->setFitWeight(i, 1.0);
137 std::shared_ptr<API::FunctionDomain> domain,
138 std::shared_ptr<API::FunctionValues> values,
139 const std::string &outputWorkspacePropertyName) {
141 return std::shared_ptr<API::Workspace>();
143 auto functionMD = std::dynamic_pointer_cast<API::FunctionDomainMD>(domain);
145 return std::shared_ptr<API::Workspace>();
149 auto inputEventWS = std::dynamic_pointer_cast<const API::IMDEventWorkspace>(domainWS);
154 auto inputHistoWS = std::dynamic_pointer_cast<const API::IMDHistoWorkspace>(domainWS);
159 return std::shared_ptr<API::Workspace>();
173 const std::string &outputWorkspacePropertyName) {
177 auto mdWS = std::dynamic_pointer_cast<DataObjects::MDEventWorkspace<DataObjects::MDEvent<4>, 4>>(outputWS);
179 return std::shared_ptr<API::Workspace>();
183 for (
size_t i = 0; i < 4; ++i) {
184 std::shared_ptr<const Geometry::IMDDimension> inputDim = inputWorkspace.
getDimension(i);
186 builder.
setName(inputDim->getName());
187 builder.
setId(inputDim->getDimensionId());
188 builder.
setUnits(inputDim->getUnits());
190 builder.
setMin(inputDim->getMinimum());
191 builder.
setMax(inputDim->getMaximum());
194 outputWS->addDimension(builder.
create());
198 outputWS->copyExperimentInfos(inputWorkspace);
204 bc->setSplitThreshold(3000);
205 outputWS->initialize();
206 outputWS->splitBox();
209 size_t resultValueIndex(0);
210 const float errorSq = 0.0;
212 const size_t numEvents = inputIter->getNumEvents();
213 const auto signal =
static_cast<float>(values.
getCalculated(resultValueIndex));
215 coord_t centers[4] = {inputIter->getInnerPosition(i, 0), inputIter->getInnerPosition(i, 1),
216 inputIter->getInnerPosition(i, 2), inputIter->getInnerPosition(i, 3)};
217 mdWS->addEvent(
MDEvent<4>(signal, errorSq, inputIter->getInnerExpInfoIndex(i),
218 inputIter->getInnerGoniometerIndex(i), inputIter->getInnerDetectorID(i), centers));
221 }
while (inputIter->next());
226 outputWS->splitAllIfNeeded(threadScheduler);
228 outputWS->refreshCache();
231 if (!outputWorkspacePropertyName.empty()) {
234 "Name of the output Workspace holding resulting simulated spectrum");
250std::shared_ptr<API::Workspace>
253 const std::string &outputWorkspacePropertyName) {
256 std::const_pointer_cast<API::IMDHistoWorkspace, const API::IMDHistoWorkspace>(inputWorkspace);
260 alg->setRethrows(
true);
262 alg->setProperty(
"Function", function);
263 alg->setProperty(
"InputWorkspace", nonConstInputWS);
264 alg->setProperty(
"OutputWorkspace",
"__FitMD_createHistoOutputWorkspace_outputWorkspace");
270 if (!outputWorkspacePropertyName.empty()) {
273 "Name of the output Workspace holding resulting simulated spectrum");
278 return outputWorkspace;
288 throw std::runtime_error(
"Cannot create FunctionDomainMD: no workspace given");
292 m_IMDWorkspace = std::dynamic_pointer_cast<API::IMDWorkspace>(ws);
294 throw std::invalid_argument(
"InputWorkspace must be a MatrixWorkspace.");
298 m_maxSize =
static_cast<size_t>(maxSizeInt);
319 throw std::runtime_error(
"FitMD: workspace wasn't defined");
321 size_t n = iterator->getDataSize();
324 throw std::range_error(
"FitMD: index is out of range");
#define DECLARE_DOMAINCREATOR(classname)
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Implements a domain for MD functions (IFunctionMD).
const IMDIterator * getNextIterator() const
Next iterator.
void reset() const override
Reset the iterator to point to the start of the domain.
A class to store values calculated by a function.
double getCalculated(size_t i) const
Get i-th calculated value.
An base class for domain creators for use in Fit.
DomainType
Type of domain to create.
std::vector< std::string > m_workspacePropertyNames
Property names for workspaces to get the data from.
Kernel::IPropertyManager * m_manager
Pointer to a property manager.
void declareProperty(Kernel::Property *prop, const std::string &doc)
Declare a property to the algorithm.
DomainType m_domainType
Domain type.
Abstract base class for multi-dimension event workspaces (MDEventWorkspace).
virtual Kernel::SpecialCoordinateSystem getSpecialCoordinateSystem() const =0
std::unique_ptr< IMDIterator > createIterator(Mantid::Geometry::MDImplicitFunction *function=nullptr) const
Creates a single iterator and returns it.
virtual std::shared_ptr< const Mantid::Geometry::IMDDimension > getDimension(size_t index) const
Get a dimension.
virtual size_t getNumDims() const
A property class for workspaces.
static API::IMDEventWorkspace_sptr CreateMDWorkspace(size_t nd, const std::string &eventType="MDLeanEvent", const Mantid::API::MDNormalization &preferredNormalization=Mantid::API::MDNormalization::VolumeNormalization, const Mantid::API::MDNormalization &preferredNormalizationHisto=Mantid::API::MDNormalization::VolumeNormalization)
Create a MDEventWorkspace of the given type.
Templated class holding data about a neutron detection event in N-dimensions (for example,...
MDHistoDimensionBuilder :
void setId(std::string id)
void setFrameName(std::string frameName)
Setter for the frame name.
IMDDimension_sptr create()
void setNumBins(size_t nbins)
void setName(const std::string &name)
void setUnits(const Kernel::UnitLabel &units)
Interface to PropertyManager.
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
virtual bool existsProperty(const std::string &name) const =0
Checks whether the named property is already in the list of managed property.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
A Thread Pool implementation that keeps a certain number of threads running (normally,...
void joinAll()
Wait for all threads that have started to finish.
A First-In-First-Out Thread Scheduler.
FitMD()
Default constructor.
void declareDatasetProperties(const std::string &suffix="", bool addProp=true) override
declare properties that specify the dataset within the workspace to fit to.
std::string m_maxSizePropertyName
Store maxSize property name.
void createDomain(std::shared_ptr< API::FunctionDomain > &, std::shared_ptr< API::FunctionValues > &, size_t i0) override
Create a domain from the input workspace.
size_t m_maxSize
Max size for seq domain.
std::shared_ptr< API::Workspace > createEventOutputWorkspace(const std::string &baseName, const API::IMDEventWorkspace &inputWorkspace, const API::FunctionValues &values, const std::string &outputWorkspacePropertyName)
Create event output workspace.
size_t m_count
Size of the domain if part of the workspace is used.
void setParameters() const
Set all parameters.
std::string m_workspacePropertyName
Store workspace property name.
std::shared_ptr< API::Workspace > createOutputWorkspace(const std::string &baseName, API::IFunction_sptr function, std::shared_ptr< API::FunctionDomain > domain, std::shared_ptr< API::FunctionValues > values, const std::string &outputWorkspacePropertyName="OutputWorkspace") override
Create an output workspace filled with data simulated with the fitting function.
void initialize(Kernel::IPropertyManager *pm, const std::string &workspacePropertyName, DomainType domainType) override
Initialize.
void setRange(size_t startIndex, size_t count)
Set the range.
std::shared_ptr< API::Workspace > createHistoOutputWorkspace(const std::string &baseName, const API::IFunction_sptr &function, const std::shared_ptr< const API::IMDHistoWorkspace > &inputWorkspace, const std::string &outputWorkspacePropertyName)
Create histo output workspace.
size_t m_startIndex
Starting index.
std::shared_ptr< API::IMDWorkspace > m_IMDWorkspace
The input IMDWorkspace.
size_t getDomainSize() const override
Return the size of the domain to be created.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< const IMDWorkspace > IMDWorkspace_const_sptr
Shared pointer to the IMDWorkspace base class (const version)
std::shared_ptr< IMDHistoWorkspace > IMDHistoWorkspace_sptr
shared pointer to Mantid::API::IMDHistoWorkspace
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
std::shared_ptr< const IMDHistoWorkspace > IMDHistoWorkspace_const_sptr
shared pointer to Mantid::API::IMDHistoWorkspace (const version)
std::size_t numEvents(::NeXus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const NexusHDF5Descriptor &descriptor)
Get the number of events in the currently opened group.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
@ Output
An output workspace.