File indexing completed on 2025-01-18 09:12:48
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Seeding/BinnedGroup.hpp"
0012 #include "Acts/Utilities/Grid.hpp"
0013 #include "Acts/Utilities/GridBinFinder.hpp"
0014 #include "Acts/Utilities/GridIterator.hpp"
0015
0016 #include <array>
0017 #include <memory>
0018 #include <numbers>
0019 #include <vector>
0020
0021 namespace Acts::Test {
0022
0023 BOOST_AUTO_TEST_CASE(binned_group_constructor) {
0024 Acts::Axis xAxis(0, 100, 10);
0025 Acts::Axis yAxis(0, 100, 10);
0026 Acts::Axis zAxis(0, 100, 10);
0027
0028 constexpr auto data_type = Type<std::vector<std::size_t>>;
0029 Grid grid_1d(data_type, xAxis);
0030 using grid_1d_t = decltype(grid_1d);
0031 Grid grid_2d(data_type, xAxis, yAxis);
0032 using grid_2d_t = decltype(grid_2d);
0033 Grid grid_3d(data_type, xAxis, yAxis, zAxis);
0034 using grid_3d_t = decltype(grid_3d);
0035
0036 Acts::GridBinFinder<1ul> binFinder_1d(1);
0037 Acts::GridBinFinder<2ul> binFinder_2d(1, 1);
0038 Acts::GridBinFinder<3ul> binFinder_3d(1, 2, 1);
0039
0040 std::array<std::vector<std::size_t>, 1ul> navigation_1d;
0041 navigation_1d[0ul].resize(10);
0042 std::array<std::vector<std::size_t>, 2ul> navigation_2d;
0043 navigation_2d[1ul].resize(10);
0044
0045
0046
0047 Acts::BinnedGroup<grid_1d_t> group_1d(std::move(grid_1d), binFinder_1d,
0048 binFinder_1d, std::move(navigation_1d));
0049
0050 Acts::BinnedGroup<grid_2d_t> group_2d(std::move(grid_2d), binFinder_2d,
0051 binFinder_2d, std::move(navigation_2d));
0052
0053 Acts::BinnedGroup<grid_3d_t> group_3d(std::move(grid_3d), binFinder_3d,
0054 binFinder_3d);
0055
0056
0057 const Acts::BinnedGroup<grid_1d_t> group_1d_moved(std::move(group_1d));
0058 const Acts::BinnedGroup<grid_2d_t> group_2d_moved(std::move(group_2d));
0059 const Acts::BinnedGroup<grid_3d_t> group_3d_moved = std::move(group_3d);
0060
0061 [[maybe_unused]] const grid_1d_t& retrievedGrid = group_1d.grid();
0062 }
0063
0064 BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) {
0065 using binfinder_t = Acts::GridBinFinder<1ul>;
0066
0067 Acts::Axis xAxis(0, 100, 10);
0068 Grid grid(Type<std::vector<std::size_t>>, std::move(xAxis));
0069 using grid_t = decltype(grid);
0070 binfinder_t binfinder(0);
0071 Acts::BinnedGroup<grid_t> group(std::move(grid), binfinder, binfinder);
0072
0073 Acts::BinnedGroupIterator<grid_t> itrStart = group.begin();
0074 Acts::BinnedGroupIterator<grid_t> itrStop = group.end();
0075
0076 std::size_t nIterations = 0ul;
0077 for (; itrStart != itrStop; ++itrStart, ++nIterations) {
0078 [[maybe_unused]] auto candidates = *itrStart;
0079 }
0080
0081 BOOST_CHECK_EQUAL(nIterations, 0ul);
0082 }
0083
0084 BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) {
0085 using binfinder_t = Acts::GridBinFinder<2ul>;
0086
0087 Acts::Axis xAxis(0, 100, 10);
0088 Acts::Axis yAxis(0, 100, 10);
0089 Grid grid(Type<std::vector<std::size_t>>, std::move(xAxis), std::move(yAxis));
0090 using grid_t = decltype(grid);
0091 binfinder_t binfinder(0, 0);
0092 Acts::BinnedGroup<grid_t> group(std::move(grid), binfinder, binfinder);
0093
0094 Acts::BinnedGroupIterator<grid_t> itrStart = group.begin();
0095 Acts::BinnedGroupIterator<grid_t> itrStop = group.end();
0096
0097 std::size_t nIterations = 0ul;
0098 for (; itrStart != itrStop; ++itrStart, ++nIterations) {
0099 [[maybe_unused]] auto candidates = *itrStart;
0100 }
0101
0102 BOOST_CHECK_EQUAL(nIterations, 0ul);
0103 }
0104
0105 BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_perFilledGrid) {
0106 using binfinder_t = Acts::GridBinFinder<1ul>;
0107
0108 Acts::Axis xAxis(0, 100, 10);
0109 Grid grid(Type<std::vector<std::size_t>>, xAxis);
0110 using grid_t = decltype(grid);
0111
0112 grid.at(1ul).push_back(4ul);
0113 grid.at(1ul).push_back(1ul);
0114 grid.at(8ul).push_back(7ul);
0115 grid.at(9ul).push_back(2ul);
0116
0117 binfinder_t botBinfinder(0);
0118 binfinder_t topBinfinder(1);
0119 Acts::BinnedGroup<grid_t> group(std::move(grid), botBinfinder, topBinfinder);
0120
0121 std::size_t nIterations = 0ul;
0122 for (const auto [bottom, middle, top] : group) {
0123 ++nIterations;
0124 BOOST_CHECK_EQUAL(bottom.size(), 1ul);
0125 BOOST_CHECK_EQUAL(top.size(), 3ul);
0126 }
0127
0128 BOOST_CHECK_EQUAL(nIterations, 3ul);
0129 }
0130
0131 BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) {
0132 using binfinder_t = Acts::GridBinFinder<2ul>;
0133
0134 Acts::Axis xAxis(0, 100, 10);
0135 Acts::Axis yAxis(0, 100, 10);
0136 Grid grid(Type<std::vector<std::size_t>>, xAxis, yAxis);
0137 using grid_t = decltype(grid);
0138
0139 grid.atLocalBins({2ul, 4ul}).push_back(4ul);
0140 grid.atLocalBins({4ul, 4ul}).push_back(4ul);
0141
0142 binfinder_t botBinfinder(1, 2);
0143 binfinder_t topBinfinder(1, 1);
0144 Acts::BinnedGroup<grid_t> group(std::move(grid), botBinfinder, topBinfinder);
0145
0146 std::size_t nIterations = 0ul;
0147 for (const auto [bottom, middle, top] : group) {
0148 ++nIterations;
0149 BOOST_CHECK_EQUAL(bottom.size(), 15ul);
0150 BOOST_CHECK_EQUAL(top.size(), 9ul);
0151 }
0152
0153 BOOST_CHECK_EQUAL(nIterations, 2ul);
0154 }
0155
0156 BOOST_AUTO_TEST_CASE(binned_group_fill_2d) {
0157 using value_t = std::size_t;
0158 using binfinder_t = Acts::GridBinFinder<2ul>;
0159
0160 Axis phiAxis(AxisClosed, -std::numbers::pi, std::numbers::pi, 40);
0161 Axis zAxis(AxisBound, 0, 100, 10);
0162
0163 Grid grid(Type<std::vector<value_t>>, std::move(phiAxis), std::move(zAxis));
0164 using grid_t = decltype(grid);
0165 binfinder_t binfinder(1, 1);
0166 Acts::BinnedGroup<grid_t> group(std::move(grid), binfinder, binfinder);
0167
0168
0169
0170 std::array<std::size_t, 2ul> locPosition({4ul, 6ul});
0171 std::size_t globPos = group.grid().globalBinFromLocalBins(locPosition);
0172
0173 grid_t& storedGrid = group.grid();
0174 for (std::size_t i(0ul); i < 30ul; ++i) {
0175 storedGrid.at(globPos).push_back(1ul);
0176 }
0177
0178 std::size_t nIterations = 0ul;
0179 for (const auto [bottom, middle, top] : group) {
0180 ++nIterations;
0181 const auto& coll = group.grid().at(middle);
0182 BOOST_CHECK_EQUAL(coll.size(), 30ul);
0183 }
0184
0185 BOOST_CHECK_EQUAL(nIterations, 1ul);
0186 }
0187
0188 BOOST_AUTO_TEST_CASE(binned_group_fill_3d) {
0189 using value_t = std::size_t;
0190 using phiAxis_t = Acts::Axis<AxisType::Equidistant, AxisBoundaryType::Closed>;
0191 using zAxis_t = Axis<AxisType::Equidistant, AxisBoundaryType::Bound>;
0192 using rAxis_t = Axis<AxisType::Equidistant, AxisBoundaryType::Bound>;
0193 using grid_t = Acts::Grid<std::vector<value_t>, phiAxis_t, zAxis_t, rAxis_t>;
0194 using binfinder_t = Acts::GridBinFinder<3ul>;
0195
0196 phiAxis_t phiAxis(-std::numbers::pi, std::numbers::pi, 40);
0197 zAxis_t zAxis(0, 100, 10);
0198 rAxis_t rAxis(0, 11000, 1);
0199
0200 grid_t grid(
0201 std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis)));
0202 binfinder_t binfinder(1, 1, 0);
0203 Acts::BinnedGroup<grid_t> group(std::move(grid), binfinder, binfinder);
0204
0205
0206
0207 std::array<std::size_t, grid_t::DIM> locPosition({4ul, 6ul, 1ul});
0208 std::size_t globPos = group.grid().globalBinFromLocalBins(locPosition);
0209
0210 grid_t& storedGrid = group.grid();
0211 for (std::size_t i(0ul); i < 30ul; ++i) {
0212 storedGrid.at(globPos).push_back(1ul);
0213 }
0214
0215 std::size_t nIterations = 0ul;
0216 for (const auto [bottom, middle, top] : group) {
0217 ++nIterations;
0218 const auto& coll = group.grid().at(middle);
0219 BOOST_CHECK_EQUAL(coll.size(), 30ul);
0220 }
0221
0222 BOOST_CHECK_EQUAL(nIterations, 1ul);
0223 }
0224
0225 }