Commit 16b9737c authored by Robert Applin's avatar Robert Applin
Browse files

Refs #0. Remove tolerance check for histogram data.

parent 6489c475
......@@ -147,8 +147,8 @@ public:
Types::Core::DateAndTime getLastPulseTime() const;
/// Returns the y index which corresponds to the X Value provided
std::size_t yIndexOfX(const double xValue, const std::size_t = 0,
const double tolerance = 0.0) const;
std::size_t yIndexOfX(double xValue, std::size_t const &index = 0,
double tolerance = 0.0) const;
//----------------------------------------------------------------------
// DATA ACCESSORS
......@@ -165,7 +165,7 @@ public:
return getSpectrum(index).histogram();
}
template <typename... T>
void setHistogram(const size_t index, T &&... data) & {
void setHistogram(const size_t index, T &&...data) & {
getSpectrum(index).setHistogram(std::forward<T>(data)...);
}
void convertToCounts(const size_t index) {
......@@ -184,20 +184,19 @@ public:
pointStandardDeviations(const size_t index) const {
return getSpectrum(index).pointStandardDeviations();
}
template <typename... T>
void setBinEdges(const size_t index, T &&... data) & {
template <typename... T> void setBinEdges(const size_t index, T &&...data) & {
getSpectrum(index).setBinEdges(std::forward<T>(data)...);
}
template <typename... T> void setPoints(const size_t index, T &&... data) & {
template <typename... T> void setPoints(const size_t index, T &&...data) & {
getSpectrum(index).setPoints(std::forward<T>(data)...);
}
template <typename... T>
void setPointVariances(const size_t index, T &&... data) & {
void setPointVariances(const size_t index, T &&...data) & {
getSpectrumWithoutInvalidation(index).setPointVariances(
std::forward<T>(data)...);
}
template <typename... T>
void setPointStandardDeviations(const size_t index, T &&... data) & {
void setPointStandardDeviations(const size_t index, T &&...data) & {
getSpectrumWithoutInvalidation(index).setPointStandardDeviations(
std::forward<T>(data)...);
}
......@@ -222,31 +221,31 @@ public:
frequencyStandardDeviations(const size_t index) const {
return getSpectrum(index).frequencyStandardDeviations();
}
template <typename... T> void setCounts(const size_t index, T &&... data) & {
template <typename... T> void setCounts(const size_t index, T &&...data) & {
getSpectrumWithoutInvalidation(index).setCounts(std::forward<T>(data)...);
}
template <typename... T>
void setCountVariances(const size_t index, T &&... data) & {
void setCountVariances(const size_t index, T &&...data) & {
getSpectrumWithoutInvalidation(index).setCountVariances(
std::forward<T>(data)...);
}
template <typename... T>
void setCountStandardDeviations(const size_t index, T &&... data) & {
void setCountStandardDeviations(const size_t index, T &&...data) & {
getSpectrumWithoutInvalidation(index).setCountStandardDeviations(
std::forward<T>(data)...);
}
template <typename... T>
void setFrequencies(const size_t index, T &&... data) & {
void setFrequencies(const size_t index, T &&...data) & {
getSpectrumWithoutInvalidation(index).setFrequencies(
std::forward<T>(data)...);
}
template <typename... T>
void setFrequencyVariances(const size_t index, T &&... data) & {
void setFrequencyVariances(const size_t index, T &&...data) & {
getSpectrumWithoutInvalidation(index).setFrequencyVariances(
std::forward<T>(data)...);
}
template <typename... T>
void setFrequencyStandardDeviations(const size_t index, T &&... data) & {
void setFrequencyStandardDeviations(const size_t index, T &&...data) & {
getSpectrumWithoutInvalidation(index).setFrequencyStandardDeviations(
std::forward<T>(data)...);
}
......@@ -582,11 +581,9 @@ protected:
private:
std::size_t binIndexOfValue(Mantid::HistogramData::HistogramX const &xValues,
double const &xValue, bool const &ascendingOrder,
double const &tolerance) const;
double xValue, bool ascendingOrder) const;
std::size_t xIndexOfValue(Mantid::HistogramData::HistogramX const &xValues,
double const &xValue,
double const &tolerance) const;
double xValue, double tolerance) const;
MatrixWorkspace *doClone() const override = 0;
MatrixWorkspace *doCloneEmpty() const override = 0;
......
......@@ -1374,12 +1374,11 @@ Types::Core::DateAndTime MatrixWorkspace::getLastPulseTime() const {
* @param xValue :: The X value to search for
* @param index :: The index within the workspace to search within (default = 0)
* @param tolerance :: The tolerance to accept between the passed xValue and the
* stored value (default = 0.0)
* stored value (default = 0.0). Used for point data only.
* @returns The index corresponding to the X value provided
*/
std::size_t MatrixWorkspace::yIndexOfX(const double xValue,
const std::size_t index,
const double tolerance) const {
std::size_t MatrixWorkspace::yIndexOfX(double xValue, std::size_t const &index,
double tolerance) const {
if (index >= getNumberHistograms())
throw std::out_of_range("MatrixWorkspace::yIndexOfX - Index out of range.");
......@@ -1388,17 +1387,21 @@ std::size_t MatrixWorkspace::yIndexOfX(const double xValue,
const auto minX = ascendingOrder ? xValues.front() : xValues.back();
const auto maxX = ascendingOrder ? xValues.back() : xValues.front();
if (xValue < minX)
throw std::out_of_range("MatrixWorkspace::yIndexOfX - X value is lower"
" than the lowest in the current range.");
else if (xValue > maxX)
throw std::out_of_range("MatrixWorkspace::yIndexOfX - X value is greater"
" than the highest in the current range.");
if (isHistogramDataByIndex(index)) {
UNUSED_ARG(tolerance);
if (xValue < minX || xValue > maxX)
throw std::out_of_range("MatrixWorkspace::yIndexOfX - X value is out of "
"the range of the min and max bin edges.");
return binIndexOfValue(xValues, xValue, ascendingOrder);
} else {
if (xValue < minX - tolerance || xValue > maxX + tolerance)
throw std::out_of_range("MatrixWorkspace::yIndexOfX - X value is out of "
"range for this point data.");
if (isHistogramDataByIndex(index))
return binIndexOfValue(xValues, xValue, ascendingOrder, tolerance);
else
return xIndexOfValue(xValues, xValue, tolerance);
}
}
/**
......@@ -1406,17 +1409,14 @@ std::size_t MatrixWorkspace::yIndexOfX(const double xValue,
* @param xValues :: The histogram to search
* @param xValue :: The X value to search for
* @param ascendingOrder :: True if the order of the xValues is ascending
* @param tolerance :: The tolerance to accept between the passed xValue and the
* stored value (default = 0.0)
* @returns An index to the bin containing X
*/
std::size_t MatrixWorkspace::binIndexOfValue(
HistogramData::HistogramX const &xValues, double const &xValue,
bool const &ascendingOrder, double const &tolerance) const {
std::size_t
MatrixWorkspace::binIndexOfValue(HistogramData::HistogramX const &xValues,
double xValue, bool ascendingOrder) const {
std::size_t hops;
if (ascendingOrder) {
auto lowerIter =
std::lower_bound(xValues.cbegin(), xValues.cend(), xValue - tolerance);
auto lowerIter = std::lower_bound(xValues.cbegin(), xValues.cend(), xValue);
// If we are pointing at the first value then we want to be in the first bin
if (lowerIter == xValues.cbegin())
......@@ -1424,8 +1424,8 @@ std::size_t MatrixWorkspace::binIndexOfValue(
hops = std::distance(xValues.cbegin(), lowerIter);
} else {
auto lowerIter = std::upper_bound(xValues.crbegin(), xValues.crend(),
xValue + tolerance);
auto lowerIter =
std::upper_bound(xValues.crbegin(), xValues.crend(), xValue);
if (lowerIter == xValues.crend())
--lowerIter;
......@@ -1449,8 +1449,7 @@ std::size_t MatrixWorkspace::binIndexOfValue(
*/
std::size_t
MatrixWorkspace::xIndexOfValue(HistogramData::HistogramX const &xValues,
double const &xValue,
double const &tolerance) const {
double xValue, double tolerance) const {
auto const iter = std::find_if(xValues.cbegin(), xValues.cend(),
[&xValue, &tolerance](double const &value) {
return std::abs(xValue - value) <= tolerance;
......
......@@ -42,10 +42,8 @@ void copyDataRange(const MatrixWorkspace_const_sptr &inputWorkspace,
int const &specMin, int const &specMax, double const &xMin,
double const &xMax, int yInsertionIndex,
int const &xInsertionIndex) {
auto const xMinIndex =
static_cast<int>(inputWorkspace->yIndexOfX(xMin, 0, 0.000001));
auto const xMaxIndex =
static_cast<int>(inputWorkspace->yIndexOfX(xMax, 0, 0.000001));
auto const xMinIndex = static_cast<int>(inputWorkspace->yIndexOfX(xMin, 0));
auto const xMaxIndex = static_cast<int>(inputWorkspace->yIndexOfX(xMax, 0));
copyDataRange(inputWorkspace, std::move(destWorkspace), specMin, specMax,
xMinIndex, xMaxIndex, yInsertionIndex, xInsertionIndex);
......@@ -96,11 +94,15 @@ void CopyDataRange::init() {
declareProperty("EndWorkspaceIndex", EMPTY_INT(), positiveInt,
"The index denoting the end of the spectra range.");
declareProperty("XMin", EMPTY_DBL(), anyDouble,
"An X value that is within the first (lowest X value) bin");
declareProperty(
"XMin", EMPTY_DBL(), anyDouble,
"An X value that is equal to the lowest point to copy (point data), or "
"an X value that is within the first bin to copy (histogram data).");
declareProperty("XMax", EMPTY_DBL(), anyDouble,
"An X value that is in the highest X value bin");
declareProperty(
"XMax", EMPTY_DBL(), anyDouble,
"An X value that is equal to the highest point to copy (point data), or "
"an X value that is within the last bin to copy (histogram data).");
declareProperty("InsertionYIndex", 0, positiveInt,
"The index denoting the histogram position for the start of "
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment