Mantid
Loading...
Searching...
No Matches
SpectrumDetectorMapping.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#include <exception>
10
11namespace Mantid::API {
17 : m_indexIsSpecNo(useSpecNoIndex) {
18 if (!workspace) {
19 throw std::invalid_argument("SpectrumDetectorMapping: Null shared workspace pointer passed");
20 }
21
22 for (size_t i = 0; i < workspace->getNumberHistograms(); ++i) {
23 auto &spectrum = workspace->getSpectrum(i);
24
25 int index;
27 index = spectrum.getSpectrumNo();
28 else
29 index = static_cast<int>(i);
30
31 m_mapping[index] = spectrum.getDetectorIDs();
32 }
33}
34
40SpectrumDetectorMapping::SpectrumDetectorMapping(const std::vector<specnum_t> &spectrumNumbers,
41 const std::vector<detid_t> &detectorIDs,
42 const std::vector<detid_t> &ignoreDetIDs)
43 : m_indexIsSpecNo(true) {
44 if (spectrumNumbers.size() != detectorIDs.size()) {
45 throw std::invalid_argument("SpectrumDetectorMapping: Different length "
46 "spectrum number & detector ID array passed");
47 }
48
49 fillMapFromVector(spectrumNumbers, detectorIDs, ignoreDetIDs);
50}
51
57 const detid_t *const detectorIDs, size_t arrayLengths)
58 : m_indexIsSpecNo(true) {
59 if (spectrumNumbers == nullptr || detectorIDs == nullptr) {
60 throw std::invalid_argument("SpectrumDetectorMapping: Null array pointer passed");
61 }
62
63 fillMapFromArray(spectrumNumbers, detectorIDs, arrayLengths);
64}
65
67void SpectrumDetectorMapping::fillMapFromArray(const specnum_t *const spectrumNumbers, const detid_t *const detectorIDs,
68 const size_t arrayLengths) {
69 for (size_t i = 0; i < arrayLengths; ++i) {
70 m_mapping[spectrumNumbers[i]].insert(detectorIDs[i]);
71 }
72}
73
75void SpectrumDetectorMapping::fillMapFromVector(const std::vector<specnum_t> &spectrumNumbers,
76 const std::vector<detid_t> &detectorIDs,
77 const std::vector<detid_t> &ignoreDetIDs) {
78 std::set<detid_t> ignoreIDs(ignoreDetIDs.begin(), ignoreDetIDs.end());
79 const size_t nspec(spectrumNumbers.size());
80 for (size_t i = 0; i < nspec; ++i) {
81 auto id = detectorIDs[i];
82 if (ignoreIDs.count(id) == 0)
83 m_mapping[spectrumNumbers[i]].insert(id);
84 }
85}
87SpectrumDetectorMapping::SpectrumDetectorMapping() : m_indexIsSpecNo(false), m_mapping() {}
88
91 std::set<specnum_t> specs;
92 auto itend = m_mapping.end();
93 for (auto it = m_mapping.begin(); it != itend; ++it) {
94 specs.insert(it->first);
95 }
96 return specs;
97}
98
99const std::set<detid_t> &SpectrumDetectorMapping::getDetectorIDsForSpectrumNo(const specnum_t spectrumNo) const {
100 if (!m_indexIsSpecNo)
101 throw std::runtime_error("Indices are in the spectrum detector map, not spectrum number.");
102 return m_mapping.at(spectrumNo);
103}
104
105const std::set<detid_t> &SpectrumDetectorMapping::getDetectorIDsForSpectrumIndex(const size_t spectrumIndex) const {
106 if (m_indexIsSpecNo)
107 throw std::runtime_error("Spectrum numbers are in the spectrum detector map, not index.");
108 return m_mapping.at(static_cast<int>(spectrumIndex));
109}
110
112
114
115} // namespace Mantid::API
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
void fillMapFromVector(const std::vector< specnum_t > &spectrumNumbers, const std::vector< detid_t > &detectorIDs, const std::vector< detid_t > &ignoreDetIDs)
Called by the vector constructors to do the actual filling.
sdmap m_mapping
The mapping of a spectrum number to zero or more detector IDs.
std::unordered_map< specnum_t, std::set< detid_t > > sdmap
const std::set< detid_t > & getDetectorIDsForSpectrumNo(const specnum_t spectrumNo) const
void fillMapFromArray(const specnum_t *const spectrumNumbers, const detid_t *const detectorIDs, const size_t arrayLengths)
Called by the c-array constructors to do the actual filling.
const std::set< detid_t > & getDetectorIDsForSpectrumIndex(const size_t spectrumIndex) const
std::set< specnum_t > getSpectrumNumbers() const
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
int32_t specnum_t
Typedef for a spectrum Number.
Definition: IDTypes.h:16