23using namespace Kernel;
24using namespace DataObjects;
25using namespace CurveFitting::Algorithms;
31 m_workspacePropertyName(m_workspacePropertyNames.front()), m_workspace() {}
49 std::shared_ptr<API::FunctionValues> &values,
size_t i0) {
78 std::shared_ptr<FunctionDomain> domain,
79 std::shared_ptr<FunctionValues> values,
80 const std::string &outputWorkspacePropertyName) {
82 std::shared_ptr<LatticeDomain> latticeDomain = std::dynamic_pointer_cast<LatticeDomain>(domain);
84 throw std::invalid_argument(
"LatticeDomain is required.");
88 if (!latticeFunction) {
89 throw std::invalid_argument(
"LatticeDomainCreator can only process ILatticeFunction.");
93 latticeFunction->functionLattice(*latticeDomain, *values);
98 tableWorkspace->addColumn(
"V3D",
"HKL");
99 tableWorkspace->addColumn(
"double",
"d(obs)");
100 tableWorkspace->addColumn(
"double",
"d(calc)");
101 tableWorkspace->addColumn(
"double",
"d(obs) - d(calc)");
103 for (
size_t i = 0; i < values->size(); ++i) {
104 double dObs = values->getFitData(i);
105 double dCalc = values->getCalculated(i);
107 TableRow newRow = tableWorkspace->appendRow();
108 newRow << (*latticeDomain)[i] << dObs << dCalc << dObs - dCalc;
112 if (
m_manager && !outputWorkspacePropertyName.empty()) {
120 return tableWorkspace;
125 if (peaksWorkspace) {
126 return peaksWorkspace->getNumberPeaks();
130 if (tableWorkspace) {
131 return tableWorkspace->rowCount();
140 throw std::invalid_argument(
"PropertyManager not set in LatticeDomainCreator.");
146 throw std::invalid_argument(
"Could not extract workspace from PropertyManager.");
152 std::shared_ptr<API::FunctionDomain> &domain,
153 std::shared_ptr<API::FunctionValues> &values,
size_t i0) {
155 throw std::invalid_argument(
"This function only works on an IPeaksWorkspace-object.");
158 size_t peakCount =
workspace->getNumberPeaks();
161 throw std::range_error(
"Cannot create a domain for 0 peaks.");
164 std::vector<V3D> hkls;
165 hkls.reserve(peakCount);
167 std::vector<double> dSpacings;
168 dSpacings.reserve(peakCount);
170 for (
size_t i = 0; i < peakCount; ++i) {
174 if (hkl !=
V3D(0, 0, 0)) {
175 hkls.emplace_back(hkl);
176 dSpacings.emplace_back(currentPeak->
getDSpacing());
181 domain.reset(latticeDomain);
185 values.reset(functionValues);
187 values->expand(i0 + latticeDomain->size());
190 values->setFitData(dSpacings);
193 values->setFitWeights(1.0);
211 std::shared_ptr<FunctionDomain> &domain,
212 std::shared_ptr<FunctionValues> &values,
size_t i0) {
214 size_t peakCount =
workspace->rowCount();
217 throw std::range_error(
"Cannot create a domain for 0 peaks.");
224 std::vector<V3D> hkls;
225 hkls.reserve(peakCount);
227 std::vector<double> dSpacings;
228 dSpacings.reserve(peakCount);
232 for (
size_t i = 0; i < peakCount; ++i) {
234 V3D hkl = extractor(hklColumn, i);
236 if (hkl !=
V3D(0, 0, 0)) {
237 hkls.emplace_back(hkl);
239 double d = (*dColumn)[i];
240 dSpacings.emplace_back(
d);
242 }
catch (
const std::bad_alloc &) {
247 domain = std::make_shared<LatticeDomain>(hkls);
249 values = std::make_shared<FunctionValues>(*domain);
251 values->expand(i0 + domain->size());
254 values->setFitData(dSpacings);
256 values->setFitWeights(1.0);
257 }
catch (
const std::runtime_error &) {
259 throw std::runtime_error(
"Can not process table, the following columns are "
260 "required: HKL, d.");
IPeaksWorkspace_sptr workspace
A class to store values calculated by a function.
An base class for domain creators for use in Fit.
DomainType
Type of domain to create.
Kernel::IPropertyManager * m_manager
Pointer to a property manager.
void declareProperty(Kernel::Property *prop, const std::string &doc)
Declare a property to the algorithm.
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
API::Workspace_sptr m_workspace
API::Workspace_sptr 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) override
Creates an output workspace from calculated and observed values.
void createDomainFromPeakTable(const API::ITableWorkspace_sptr &workspace, std::shared_ptr< API::FunctionDomain > &domain, std::shared_ptr< API::FunctionValues > &values, size_t i0)
Creates a domain from an ITableWorkspace.
std::string m_workspacePropertyName
void createDomainFromPeaksWorkspace(const API::IPeaksWorkspace_sptr &workspace, std::shared_ptr< API::FunctionDomain > &domain, std::shared_ptr< API::FunctionValues > &values, size_t i0)
Creates a LatticeDomain from an IPeaksWorkspace, using HKL and d-values.
void createDomain(std::shared_ptr< API::FunctionDomain > &domain, std::shared_ptr< API::FunctionValues > &values, size_t i0) override
Creates a LatticeDomain from the assigned Workspace.
LatticeDomainCreator(Kernel::IPropertyManager *manager, const std::string &workspacePropertyName, DomainType domainType=Simple)
Constructor.
void setWorkspaceFromPropertyManager()
Get the workspace with peak data from the property manager.
size_t getDomainSize() const override
Return the size of the domain to be created.
Structure describing a single-crystal peak.
virtual double getDSpacing() const =0
virtual Mantid::Kernel::V3D getHKL() const =0
Exception for when an item is not found in a collection.
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 TypedValue getProperty(const std::string &name) const =0
Get the value of a 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< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< ILatticeFunction > ILatticeFunction_sptr
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< const Column > Column_const_sptr
Small helper class to extract HKLs as V3D from table columns.
@ Output
An output workspace.