diff --git a/Framework/API/inc/MantidAPI/MatrixWorkspace.h b/Framework/API/inc/MantidAPI/MatrixWorkspace.h index 00234ff6852a3b9543d8f3f114a281e32e53b6b5..86797a44b8448ab10d99855999cc1f07d4f07aad 100644 --- a/Framework/API/inc/MantidAPI/MatrixWorkspace.h +++ b/Framework/API/inc/MantidAPI/MatrixWorkspace.h @@ -514,17 +514,20 @@ public: // Check if this class has an oriented lattice on a sample object virtual bool hasOrientedLattice() const override; - //===================================================================================== - // End IMDWorkspace methods - //===================================================================================== + virtual std::pair<size_t, size_t> find(double value) + : - //===================================================================================== - // Image methods - //===================================================================================== + //===================================================================================== + // End IMDWorkspace methods + //===================================================================================== + + //===================================================================================== + // Image methods + //===================================================================================== - /// Get start and end x indices for images - std::pair<size_t, size_t> getImageStartEndXIndices(size_t i, double startX, - double endX) const; + /// Get start and end x indices for images + std::pair<size_t, size_t> getImageStartEndXIndices( + size_t i, double startX, double endX) const; /// Create an image of Ys. MantidImage_sptr getImageY(size_t start = 0, size_t stop = 0, size_t width = 0, double startX = EMPTY_DBL(), diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index 55d5ecf1d1c58baae56ffb22bc55fa22f0e38291..db16ee2f87d14fc9d0a511a2ba8f360b9b01394f 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -1931,6 +1931,20 @@ MantidImage_sptr MatrixWorkspace::getImage( return image; } +std::pair<size_t, size_t> MatrixWorkspace::find(double value) { + std::pair<size_t, size_t> out(-1, -1); + const int64_t numHists = + static_cast<int64_t>(inputWorkspace->getNumberHistograms()); + for (int64_t i = 0; i < numHists; ++i) { + const auto &Y = inputEventWorkspace->y(i); + if (auto it = std::find(Y.begin(), Y.end(), 0.), it != Y.end()) { + out = {i, std::distance(Y.begin().it)}; + break; + } + } + return out; +} + /** * Get start and end x indices for images * @param i :: Histogram index. diff --git a/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp b/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp index 20d86586614d853cdfb7fba4ff70eb20671d78db..683ce4e5f38fb6e229b8bce0d7d54b9d2952b825 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp @@ -365,7 +365,7 @@ void export_MatrixWorkspace() { ":class:`~mantid.api.MatrixWorkspace.hasMaskedBins` MUST be called " "first to check if any bins are " "masked, otherwise an exception will be thrown") - + .def("find", &find, (arg("self"), arg("value")), "find index of Y value") // Deprecated .def("getNumberBins", &getNumberBinsDeprecated, arg("self"), "Returns size of the Y data array (deprecated, use "