Mantid
Loading...
Searching...
No Matches
Histogram1D.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 +
9
10namespace Mantid::DataObjects {
11
13Histogram1D::Histogram1D(HistogramData::Histogram::XMode xmode, HistogramData::Histogram::YMode ymode)
14 : API::ISpectrum(), m_histogram(xmode, ymode) {
15 if (ymode == HistogramData::Histogram::YMode::Counts) {
16 m_histogram.setCounts(0);
17 m_histogram.setCountStandardDeviations(0);
18 } else if (ymode == HistogramData::Histogram::YMode::Frequencies) {
19 m_histogram.setFrequencies(0);
20 m_histogram.setFrequencyStandardDeviations(0);
21 } else {
22 throw std::logic_error("Histogram1D: YMode must be Counts or Frequencies");
23 }
24}
25
27Histogram1D::Histogram1D(const ISpectrum &other) : ISpectrum(other), m_histogram(other.histogram()) {}
28
32 m_histogram = rhs.histogram();
33 return *this;
34}
35
37void Histogram1D::copyDataFrom(const ISpectrum &source) { source.copyDataInto(*this); }
38
41
43 MantidVec &yValues = this->dataY();
44 std::fill(yValues.begin(), yValues.end(), 0.0);
45 MantidVec &eValues = this->dataE();
46 std::fill(eValues.begin(), eValues.end(), 0.0);
47}
48
52
55
57const MantidVec &Histogram1D::dataX() const { return m_histogram.dataX(); }
58
60const MantidVec &Histogram1D::readX() const { return m_histogram.readX(); }
61
64
68const MantidVec &Histogram1D::dataDx() const { return m_histogram.dataDx(); }
70const MantidVec &Histogram1D::readDx() const { return m_histogram.readDx(); }
71
77void Histogram1D::checkAndSanitizeHistogram(HistogramData::Histogram &histogram) {
78 if (!histogram.sharedY()) {
79 throw std::invalid_argument("Histogram1D: invalid input: Y data set to nullptr");
80 }
81 if (!histogram.sharedE()) {
82 throw std::invalid_argument("Histogram1D: invalid input: E data set to nullptr");
83 }
84}
85
86} // namespace Mantid::DataObjects
const std::vector< double > & rhs
A "spectrum" is an object that holds the data for a particular spectrum, in particular:
Definition: ISpectrum.h:39
virtual HistogramData::Histogram histogram() const
Returns the Histogram associated with this spectrum.
Definition: ISpectrum.h:95
virtual void copyDataInto(DataObjects::EventList &) const
Override in child classes for polymorphic copying of data.
Definition: ISpectrum.cpp:201
ISpectrum & operator=(const ISpectrum &other)
Copy assignment.
Definition: ISpectrum.cpp:156
1D histogram implementation.
Definition: Histogram1D.h:18
void checkAndSanitizeHistogram(HistogramData::Histogram &histogram) override
Makes sure a histogram has valid Y and E data.
Definition: Histogram1D.cpp:77
Kernel::cow_ptr< HistogramData::HistogramX > ptrX() const override
Deprecated, use sharedX() instead. Returns a pointer to the x data.
Definition: Histogram1D.cpp:63
const MantidVec & readDx() const override
Deprecated, use dx() instead.
Definition: Histogram1D.cpp:70
HistogramData::Histogram m_histogram
Histogram object holding the histogram data.
Definition: Histogram1D.h:21
const MantidVec & dataE() const override
Deprecated, use e() instead. Returns the error data const.
Definition: Histogram1D.h:52
const MantidVec & dataY() const override
Deprecated, use y() instead. Returns the y data const.
Definition: Histogram1D.h:50
void copyDataInto(Histogram1D &sink) const override
Used by copyDataFrom for dynamic dispatch for its source.
Definition: Histogram1D.cpp:40
void setX(const Kernel::cow_ptr< HistogramData::HistogramX > &X) override
Deprecated, use setSharedX() instead.
Definition: Histogram1D.cpp:51
MantidVec & dataX() override
Deprecated, use mutableX() instead. Returns the x data.
Definition: Histogram1D.cpp:54
const MantidVec & readX() const override
Deprecated, use x() instead. Returns the x data const.
Definition: Histogram1D.cpp:60
Histogram1D & operator=(const Histogram1D &)=default
MantidVec & dataDx() override
Deprecated, use mutableDx() instead.
Definition: Histogram1D.cpp:66
void clearData() override
Zero the data (Y&E) in this spectrum.
Definition: Histogram1D.cpp:42
Histogram1D(HistogramData::Histogram::XMode xmode, HistogramData::Histogram::YMode ymode)
Construct empty.
Definition: Histogram1D.cpp:13
void copyDataFrom(const ISpectrum &source) override
Copy data from a Histogram1D or EventList, via ISpectrum reference.
Definition: Histogram1D.cpp:37
Implements a copy on write data template.
Definition: cow_ptr.h:41
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition: cow_ptr.h:172