File indexing completed on 2026-08-20 08:19:52
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/Axis.hpp"
0013 #include "Acts/Utilities/AxisDefinitions.hpp"
0014 #include "Acts/Utilities/Grid.hpp"
0015 #include "Acts/Utilities/GridBinFinder.hpp"
0016
0017 #include <array>
0018 #include <cstddef>
0019 #include <stdexcept>
0020 #include <vector>
0021
0022 namespace Acts::Test {
0023
0024 namespace {
0025
0026 using AxisType = Axis<Acts::AxisType::Equidistant, AxisBoundaryType::Open>;
0027 using GridType = Grid<std::vector<std::size_t>, AxisType, AxisType>;
0028 using BinFinderType = GridBinFinder<2ul>;
0029
0030
0031 GridType makeFilledGrid() {
0032 AxisType xAxis(AxisOpen, 0., 3., 3ul);
0033 AxisType yAxis(AxisOpen, 0., 4., 4ul);
0034 GridType grid(std::make_tuple(std::move(xAxis), std::move(yAxis)));
0035 for (std::size_t i(1ul); i <= 3ul; ++i) {
0036 for (std::size_t j(1ul); j <= 4ul; ++j) {
0037 grid.atLocalBins({i, j}).push_back(1ul);
0038 }
0039 }
0040 return grid;
0041 }
0042
0043
0044 std::vector<std::array<std::size_t, 2ul>> visitedBins(
0045 const BinnedGroup<GridType>& group) {
0046 std::vector<std::array<std::size_t, 2ul>> visited;
0047 for (const auto& [bottom, middle, top] : group) {
0048 static_cast<void>(bottom);
0049 static_cast<void>(top);
0050 visited.push_back(
0051 group.grid().multiAxis().getLocalBinsFromGlobalBin(middle));
0052 }
0053 return visited;
0054 }
0055
0056 }
0057
0058 BOOST_AUTO_TEST_SUITE(BinnedGroupTests)
0059
0060 BOOST_AUTO_TEST_CASE(EmptyNavigationVisitsAllBinsInOrder) {
0061 BinFinderType bottomFinder(1, 1);
0062 BinFinderType topFinder(1, 1);
0063 BinnedGroup<GridType> group(makeFilledGrid(), bottomFinder, topFinder);
0064
0065 const auto visited = visitedBins(group);
0066 BOOST_REQUIRE_EQUAL(visited.size(), 12ul);
0067 BOOST_CHECK_EQUAL(visited.front()[0], 1ul);
0068 BOOST_CHECK_EQUAL(visited.front()[1], 1ul);
0069 BOOST_CHECK_EQUAL(visited.back()[0], 3ul);
0070 BOOST_CHECK_EQUAL(visited.back()[1], 4ul);
0071 }
0072
0073 BOOST_AUTO_TEST_CASE(CustomNavigationVisitsOnlyRequestedBins) {
0074 BinFinderType bottomFinder(1, 1);
0075 BinFinderType topFinder(1, 1);
0076
0077 std::array<std::vector<std::size_t>, 2ul> navigation{
0078 std::vector<std::size_t>{3ul, 2ul}, std::vector<std::size_t>{4ul, 2ul}};
0079 BinnedGroup<GridType> group(makeFilledGrid(), bottomFinder, topFinder,
0080 navigation);
0081
0082 const std::vector<std::array<std::size_t, 2ul>> expected{
0083 {3ul, 4ul}, {3ul, 2ul}, {2ul, 4ul}, {2ul, 2ul}};
0084 BOOST_CHECK(visitedBins(group) == expected);
0085 }
0086
0087 BOOST_AUTO_TEST_CASE(NavigationRejectsUnderflowBin) {
0088 BinFinderType bottomFinder(1, 1);
0089 BinFinderType topFinder(1, 1);
0090
0091 std::array<std::vector<std::size_t>, 2ul> navigation{
0092 std::vector<std::size_t>{0ul, 1ul, 2ul}, std::vector<std::size_t>{}};
0093 BOOST_CHECK_THROW(BinnedGroup<GridType>(makeFilledGrid(), bottomFinder,
0094 topFinder, navigation),
0095 std::invalid_argument);
0096 }
0097
0098 BOOST_AUTO_TEST_CASE(NavigationRejectsOverflowBin) {
0099 BinFinderType bottomFinder(1, 1);
0100 BinFinderType topFinder(1, 1);
0101
0102 std::array<std::vector<std::size_t>, 2ul> navigation{
0103 std::vector<std::size_t>{1ul, 4ul}, std::vector<std::size_t>{}};
0104 BOOST_CHECK_THROW(BinnedGroup<GridType>(makeFilledGrid(), bottomFinder,
0105 topFinder, navigation),
0106 std::invalid_argument);
0107 }
0108
0109 BOOST_AUTO_TEST_CASE(NavigationRejectsDuplicatedBin) {
0110 BinFinderType bottomFinder(1, 1);
0111 BinFinderType topFinder(1, 1);
0112 std::array<std::vector<std::size_t>, 2ul> navigation{
0113 std::vector<std::size_t>{}, std::vector<std::size_t>{2ul, 3ul, 2ul}};
0114 BOOST_CHECK_THROW(BinnedGroup<GridType>(makeFilledGrid(), bottomFinder,
0115 topFinder, navigation),
0116 std::invalid_argument);
0117 }
0118
0119 BOOST_AUTO_TEST_CASE(NavigationIsValidatedWithMaskConstructor) {
0120 BinFinderType bottomFinder(1, 1);
0121 BinFinderType topFinder(1, 1);
0122 GridType grid = makeFilledGrid();
0123 std::vector<bool> mask(grid.size(true), true);
0124 std::array<std::vector<std::size_t>, 2ul> navigation{
0125 std::vector<std::size_t>{0ul}, std::vector<std::size_t>{}};
0126 BOOST_CHECK_THROW(BinnedGroup<GridType>(std::move(grid), std::move(mask),
0127 bottomFinder, topFinder, navigation),
0128 std::invalid_argument);
0129 }
0130
0131 BOOST_AUTO_TEST_SUITE_END()
0132
0133 }