File indexing completed on 2026-08-16 08:16:42
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/EventData/SpacePointContainer.hpp"
0013 #include "Acts/Seeding/BinnedGroup.hpp"
0014 #include "Acts/Utilities/Logger.hpp"
0015 #include "Acts/Utilities/RangeXD.hpp"
0016
0017 #include <algorithm>
0018 #include <cstdint>
0019 #include <limits>
0020 #include <memory>
0021 #include <optional>
0022 #include <tuple>
0023 #include <vector>
0024
0025 namespace Acts::detail {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 template <typename derived_t, typename grid_t>
0036 class SpacePointGridBase {
0037 public:
0038
0039 using SpacePointIndex = std::uint32_t;
0040
0041 using BinType = std::vector<SpacePointIndex>;
0042
0043 using GridType = grid_t;
0044
0045 using BinnedGroupType = BinnedGroup<GridType>;
0046
0047
0048
0049
0050 template <std::size_t index>
0051 using AxisTypeAt =
0052 std::tuple_element_t<index, typename GridType::multi_axis_t::AxesTuple>;
0053
0054
0055
0056 void clear() {
0057 for (std::size_t i = 0; i < grid().size(); ++i) {
0058 grid().at(i).clear();
0059 }
0060 m_counter = 0;
0061 }
0062
0063
0064
0065
0066
0067 std::optional<std::size_t> binIndex(const Vector3& position) const {
0068 if (!grid().multiAxis().isInside(position)) {
0069 return std::nullopt;
0070 }
0071 return grid().multiAxis().getGlobalBinFromPoint(position);
0072 }
0073
0074
0075
0076
0077
0078
0079 std::optional<std::size_t> insert(SpacePointIndex index,
0080 const Vector3& position) {
0081 const std::optional<std::size_t> gridIndex = binIndex(position);
0082 if (gridIndex.has_value()) {
0083 grid().at(*gridIndex).push_back(index);
0084 ++m_counter;
0085 }
0086 return gridIndex;
0087 }
0088
0089
0090
0091 void extend(const SpacePointContainer::ConstRange& spacePoints) {
0092 ACTS_VERBOSE("Inserting " << spacePoints.size()
0093 << " space points to the grid");
0094
0095 for (const ConstSpacePointProxy& sp : spacePoints) {
0096 derived().insert(sp);
0097 }
0098 }
0099
0100
0101
0102
0103 BinType& at(std::size_t index) { return grid().at(index); }
0104
0105
0106
0107 const BinType& at(std::size_t index) const { return grid().at(index); }
0108
0109
0110
0111 GridType& grid() { return *m_grid; }
0112
0113
0114 const GridType& grid() const { return *m_grid; }
0115
0116
0117
0118 const BinnedGroupType& binnedGroup() const { return *m_binnedGroup; }
0119
0120
0121
0122 std::size_t numberOfSpacePoints() const { return m_counter; }
0123
0124
0125
0126 std::size_t numberOfBins() const { return grid().size(); }
0127
0128 protected:
0129
0130
0131
0132 explicit SpacePointGridBase(std::unique_ptr<const Logger> logger)
0133 : m_logger(std::move(logger)) {}
0134
0135 ~SpacePointGridBase() = default;
0136
0137
0138
0139
0140
0141
0142
0143 void initializeGrid(
0144 GridType&& grid, const GridBinFinder<GridType::DIM>& bottomBinFinder,
0145 const GridBinFinder<GridType::DIM>& topBinFinder,
0146 std::array<std::vector<std::size_t>, GridType::DIM> navigation) {
0147 m_binnedGroup.emplace(std::move(grid), bottomBinFinder, topBinFinder,
0148 std::move(navigation));
0149 m_grid = &m_binnedGroup->grid();
0150 }
0151
0152
0153
0154
0155 template <typename projection_t>
0156 void sortBinsBy(const SpacePointContainer& spacePoints,
0157 const projection_t& projection) {
0158 ACTS_VERBOSE("Sorting the grid");
0159
0160 for (std::size_t i = 0; i < grid().size(); ++i) {
0161 BinType& bin = grid().at(i);
0162 std::ranges::sort(bin, {}, [&](SpacePointIndex spIndex) {
0163 return projection(spacePoints[spIndex]);
0164 });
0165 }
0166
0167 ACTS_VERBOSE(
0168 "Number of space points inserted (within grid range): " << m_counter);
0169 }
0170
0171
0172
0173
0174
0175
0176 template <typename projection_t>
0177 Range1D<float> computeRange(const SpacePointContainer& spacePoints,
0178 const projection_t& projection) const {
0179 float minRange = std::numeric_limits<float>::max();
0180 float maxRange = std::numeric_limits<float>::lowest();
0181 for (const BinType& bin : grid()) {
0182 if (bin.empty()) {
0183 continue;
0184 }
0185 auto first = spacePoints[bin.front()];
0186 auto last = spacePoints[bin.back()];
0187 minRange = std::min(projection(first), minRange);
0188 maxRange = std::max(projection(last), maxRange);
0189 }
0190 return {minRange, maxRange};
0191 }
0192
0193
0194
0195 const Logger& logger() const { return *m_logger; }
0196
0197 private:
0198 derived_t& derived() { return static_cast<derived_t&>(*this); }
0199
0200 std::unique_ptr<const Logger> m_logger;
0201
0202 GridType* m_grid{};
0203 std::optional<BinnedGroupType> m_binnedGroup;
0204
0205 std::size_t m_counter{};
0206 };
0207
0208 }