Mantid
Loading...
Searching...
No Matches
WorkspaceNearestNeighbourInfo.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 +
11
12namespace Mantid::API {
13
22 const bool ignoreMaskedDetectors, const int nNeighbours)
23 : m_workspace(workspace) {
24 std::vector<specnum_t> spectrumNumbers;
25 const auto nhist = m_workspace.getNumberHistograms();
26 spectrumNumbers.reserve(nhist);
27 for (size_t i = 0; i < nhist; ++i)
28 spectrumNumbers.emplace_back(m_workspace.getSpectrum(i).getSpectrumNo());
29
30 m_nearestNeighbours = std::make_unique<WorkspaceNearestNeighbours>(nNeighbours, workspace.spectrumInfo(),
31 std::move(spectrumNumbers), ignoreMaskedDetectors);
32}
33
34// Defined as default in source for forward declaration with std::unique_ptr.
36
44std::map<specnum_t, Kernel::V3D> WorkspaceNearestNeighbourInfo::getNeighbours(const Geometry::IDetector *comp,
45 const double radius) const {
46 // Find the spectrum number
47 std::vector<specnum_t> spectra = m_workspace.getSpectraFromDetectorIDs(std::vector<detid_t>(1, comp->getID()));
48 if (spectra.empty()) {
49 throw Kernel::Exception::NotFoundError("MatrixWorkspace::getNeighbours - "
50 "Cannot find spectrum number for "
51 "detector",
52 comp->getID());
53 }
54 return m_nearestNeighbours->neighboursInRadius(spectra[0], radius);
55}
56
64std::map<specnum_t, Kernel::V3D> WorkspaceNearestNeighbourInfo::getNeighbours(specnum_t spec,
65 const double radius) const {
66 return m_nearestNeighbours->neighboursInRadius(spec, radius);
67}
68
75std::map<specnum_t, Kernel::V3D> WorkspaceNearestNeighbourInfo::getNeighboursExact(specnum_t spec) const {
76 return m_nearestNeighbours->neighbours(spec);
77}
78
79} // namespace Mantid::API
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
double radius
Definition: Rasterize.cpp:31
specnum_t getSpectrumNo() const
Definition: ISpectrum.cpp:123
Base MatrixWorkspace Abstract Class.
std::vector< specnum_t > getSpectraFromDetectorIDs(const std::vector< detid_t > &detIdList) const
Converts a list of detector IDs to the corresponding spectrum numbers.
virtual ISpectrum & getSpectrum(const size_t index)=0
Return the underlying ISpectrum ptr at the given workspace index.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
std::map< specnum_t, Kernel::V3D > getNeighbours(const Geometry::IDetector *comp, const double radius=0.0) const
Queries the WorkspaceNearestNeighbours object for the selected detector.
WorkspaceNearestNeighbourInfo(const MatrixWorkspace &workspace, const bool ignoreMaskedDetectors, const int nNeighbours=8)
Creates WorkspaceNearestNeighbourInfo.
std::unique_ptr< WorkspaceNearestNeighbours > m_nearestNeighbours
std::map< specnum_t, Kernel::V3D > getNeighboursExact(specnum_t spec) const
Queries the WorkspaceNearestNeighbours object for the selected spectrum number.
Interface class for detector objects.
Definition: IDetector.h:43
virtual detid_t getID() const =0
Get the detector ID.
Exception for when an item is not found in a collection.
Definition: Exception.h:145
int32_t specnum_t
Typedef for a spectrum Number.
Definition: IDTypes.h:16