Mantid
Loading...
Searching...
No Matches
FunctionDomain1DSpectrumCreator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#include <utility>
8
11#include "MantidHistogramData/BinEdges.h"
12#include "MantidHistogramData/Points.h"
13
15
16namespace Mantid::CurveFitting {
17
18using namespace API;
19using namespace HistogramData;
24 : IDomainCreator(nullptr, std::vector<std::string>(), FunctionDomain1DSpectrumCreator::Simple), m_matrixWorkspace(),
25 m_workspaceIndex(0), m_workspaceIndexIsSet(false) {}
26
32 m_matrixWorkspace = std::move(matrixWorkspace);
33}
34
41 m_workspaceIndex = workspaceIndex;
42
44}
45
61void FunctionDomain1DSpectrumCreator::createDomain(std::shared_ptr<FunctionDomain> &domain,
62 std::shared_ptr<FunctionValues> &values, size_t i0) {
64
65 auto points = m_matrixWorkspace->points(m_workspaceIndex);
66 domain.reset(new FunctionDomain1DSpectrum(m_workspaceIndex, points.mutableRawData()));
67
68 if (!values) {
69 values.reset(new FunctionValues(*domain));
70 } else {
71 values->expand(i0 + domain->size());
72 }
73
74 const auto &yData = m_matrixWorkspace->y(m_workspaceIndex);
75 const auto &eData = m_matrixWorkspace->e(m_workspaceIndex);
76
77 for (size_t i = 0; i < yData.size(); ++i) {
78 values->setFitData(i, yData[i]);
79 values->setFitWeight(i, 1.0 / (eData[i] != 0 ? eData[i] : 1.0));
80 }
81}
82
94
95 size_t numberOfXValues = m_matrixWorkspace->x(m_workspaceIndex).size();
96
97 if (m_matrixWorkspace->isHistogramData()) {
98 return numberOfXValues - 1;
99 }
100
101 return numberOfXValues;
102}
103
106 if (!m_matrixWorkspace) {
107 throw std::invalid_argument("No matrix workspace assigned or does not "
108 "contain histogram data - cannot create "
109 "domain.");
110 }
111
112 if (!m_workspaceIndexIsSet || m_workspaceIndex >= m_matrixWorkspace->getNumberHistograms()) {
113 throw std::invalid_argument("Workspace index has not been set or is invalid.");
114 }
115}
116
117} // namespace Mantid::CurveFitting
Specialization of FunctionDomain1DVector for spectra of MatrixWorkspaces.
A class to store values calculated by a function.
An base class for domain creators for use in Fit.
void createDomain(std::shared_ptr< API::FunctionDomain > &domain, std::shared_ptr< API::FunctionValues > &values, size_t i0=0) override
Creates the domain according to the stored MatrixWorkspace and workspace index.
void throwIfWorkspaceInvalid() const
Checks the assigned MatrixWorkspace and workspace index.
size_t getDomainSize() const override
Returns the domain sizes.
void setWorkspaceIndex(size_t workspaceIndex)
Sets the workspace index for the created domain.
void setMatrixWorkspace(API::MatrixWorkspace_sptr matrixWorkspace)
Sets the matrix workspace this creator is working with.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
STL namespace.