File indexing completed on 2024-11-15 09:01:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #pragma once
0014 #include "Acts/Utilities/BinUtility.hpp"
0015 #include "Acts/Utilities/BinnedArray.hpp"
0016
0017 #include <array>
0018 #include <iostream>
0019 #include <vector>
0020
0021 class MsgStream;
0022
0023 namespace Acts {
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 template <class T>
0034 class BinnedArrayXD : public BinnedArray<T> {
0035
0036 using TAP = std::pair<T, Vector3>;
0037
0038 public:
0039
0040
0041
0042 BinnedArrayXD(T object)
0043 : BinnedArray<T>(),
0044 m_objectGrid(
0045 1, std::vector<std::vector<T>>(1, std::vector<T>(1, nullptr))),
0046 m_arrayObjects({object}),
0047 m_binUtility(nullptr) {
0048
0049 m_objectGrid[0][0][0] = object;
0050 }
0051
0052
0053
0054
0055
0056
0057 BinnedArrayXD(const std::vector<TAP>& tapvector,
0058 std::unique_ptr<const BinUtility> bu)
0059 : BinnedArray<T>(),
0060 m_objectGrid(bu->bins(2),
0061 std::vector<std::vector<T>>(
0062 bu->bins(1), std::vector<T>(bu->bins(0), nullptr))),
0063 m_arrayObjects(),
0064 m_binUtility(std::move(bu)) {
0065
0066 m_arrayObjects.reserve(tapvector.size());
0067
0068 for (auto& tap : tapvector) {
0069
0070 if (m_binUtility->inside(tap.second)) {
0071
0072
0073 auto bins = m_binUtility->binTriple(tap.second);
0074
0075 m_objectGrid[bins[2]][bins[1]][bins[0]] = tap.first;
0076
0077 if (std::find(m_arrayObjects.begin(), m_arrayObjects.end(),
0078 tap.first) == m_arrayObjects.end()) {
0079 m_arrayObjects.push_back(tap.first);
0080 }
0081 }
0082 }
0083 }
0084
0085
0086
0087
0088
0089 BinnedArrayXD(const std::vector<std::vector<std::vector<T>>>& grid,
0090 std::unique_ptr<const BinUtility> bu)
0091 : BinnedArray<T>(),
0092 m_objectGrid(grid),
0093 m_arrayObjects(),
0094 m_binUtility(std::move(bu)) {
0095
0096 std::size_t objects =
0097 m_binUtility->bins(0) * m_binUtility->bins(1) * m_binUtility->bins(2);
0098
0099 m_arrayObjects.reserve(objects);
0100
0101 for (auto& o2 : m_objectGrid) {
0102 for (auto& o1 : o2) {
0103 for (auto& o0 : o1) {
0104 if (o0) {
0105
0106 if (std::find(m_arrayObjects.begin(), m_arrayObjects.end(), o0) ==
0107 m_arrayObjects.end()) {
0108 m_arrayObjects.push_back(o0);
0109 }
0110 }
0111 }
0112 }
0113 }
0114 }
0115
0116
0117
0118 BinnedArrayXD(const BinnedArrayXD<T>& barr) = delete;
0119
0120
0121
0122 BinnedArrayXD& operator=(const BinnedArrayXD<T>& barr) = delete;
0123
0124
0125 ~BinnedArrayXD() override = default;
0126
0127
0128
0129
0130
0131
0132
0133
0134 T object(const Vector2& lposition,
0135 std::array<std::size_t, 3>& bins) const final {
0136 if (m_binUtility) {
0137 std::size_t bdim = m_binUtility->dimensions();
0138 bins[2] = bdim > 2 ? m_binUtility->bin(lposition, 2) : 0;
0139 bins[1] = bdim > 1 ? m_binUtility->bin(lposition, 1) : 0;
0140 bins[0] = m_binUtility->bin(lposition, 0);
0141 return m_objectGrid[bins[2]][bins[1]][bins[0]];
0142 }
0143 return m_objectGrid[0][0][0];
0144 }
0145
0146
0147 T object(const Vector2& lposition) const override {
0148 std::array<std::size_t, 3> bins{};
0149 return object(lposition, bins);
0150 }
0151
0152
0153
0154
0155
0156
0157
0158 T object(const Vector3& position,
0159 std::array<std::size_t, 3>& bins) const final {
0160 if (m_binUtility) {
0161 std::size_t bdim = m_binUtility->dimensions();
0162 bins[2] = bdim > 2 ? m_binUtility->bin(position, 2) : 0;
0163 bins[1] = bdim > 1 ? m_binUtility->bin(position, 1) : 0;
0164 bins[0] = m_binUtility->bin(position, 0);
0165 return m_objectGrid[bins[2]][bins[1]][bins[0]];
0166 }
0167 return m_objectGrid[0][0][0];
0168 }
0169
0170
0171 T object(const Vector3& position) const override {
0172 std::array<std::size_t, 3> bins{};
0173 return object(position, bins);
0174 }
0175
0176
0177
0178 const std::vector<T>& arrayObjects() const final { return m_arrayObjects; }
0179
0180
0181
0182
0183 const std::vector<std::vector<std::vector<T>>>& objectGrid() const final {
0184 return m_objectGrid;
0185 }
0186
0187
0188
0189 const BinUtility* binUtility() const final { return (m_binUtility.get()); }
0190
0191 private:
0192
0193 std::vector<std::vector<std::vector<T>>> m_objectGrid;
0194
0195 std::vector<T> m_arrayObjects;
0196
0197 std::unique_ptr<const BinUtility> m_binUtility;
0198 };
0199 }