Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:02

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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 using namespace Acts;
0022 
0023 namespace ActsTests {
0024 
0025 BOOST_AUTO_TEST_SUITE(SeedingSuite)
0026 
0027 BOOST_AUTO_TEST_CASE(binned_group_constructor) {
0028   Axis xAxis(0, 100, 10);
0029   Axis yAxis(0, 100, 10);
0030   Axis zAxis(0, 100, 10);
0031 
0032   constexpr auto data_type = Type<std::vector<std::size_t>>;
0033   Grid grid_1d(data_type, xAxis);
0034   using grid_1d_t = decltype(grid_1d);
0035   Grid grid_2d(data_type, xAxis, yAxis);
0036   using grid_2d_t = decltype(grid_2d);
0037   Grid grid_3d(data_type, xAxis, yAxis, zAxis);
0038   using grid_3d_t = decltype(grid_3d);
0039 
0040   GridBinFinder<1ul> binFinder_1d(1);
0041   GridBinFinder<2ul> binFinder_2d(1, 1);
0042   GridBinFinder<3ul> binFinder_3d(1, 2, 1);
0043 
0044   std::array<std::vector<std::size_t>, 1ul> navigation_1d;
0045   navigation_1d[0ul].resize(10);
0046   std::array<std::vector<std::size_t>, 2ul> navigation_2d;
0047   navigation_2d[1ul].resize(10);
0048 
0049   // Costructors
0050   // We provide a proper navigation
0051   BinnedGroup<grid_1d_t> group_1d(std::move(grid_1d), binFinder_1d,
0052                                   binFinder_1d, std::move(navigation_1d));
0053   // We provide a partial navigation, the constructor will complete it
0054   BinnedGroup<grid_2d_t> group_2d(std::move(grid_2d), binFinder_2d,
0055                                   binFinder_2d, std::move(navigation_2d));
0056   // We do not provide navigation, the constructor will define it
0057   BinnedGroup<grid_3d_t> group_3d(std::move(grid_3d), binFinder_3d,
0058                                   binFinder_3d);
0059 
0060   // Move Constructor/Assignment
0061   const BinnedGroup<grid_1d_t> group_1d_moved(std::move(group_1d));
0062   const BinnedGroup<grid_2d_t> group_2d_moved(std::move(group_2d));
0063   const BinnedGroup<grid_3d_t> group_3d_moved = std::move(group_3d);
0064 
0065   [[maybe_unused]] const grid_1d_t& retrievedGrid = group_1d.grid();
0066 }
0067 
0068 BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) {
0069   using binfinder_t = GridBinFinder<1ul>;
0070 
0071   Axis xAxis(0, 100, 10);
0072   Grid grid(Type<std::vector<std::size_t>>, std::move(xAxis));
0073   using grid_t = decltype(grid);
0074   binfinder_t binfinder(0);
0075   BinnedGroup<grid_t> group(std::move(grid), binfinder, binfinder);
0076 
0077   BinnedGroupIterator<grid_t> itrStart = group.begin();
0078   BinnedGroupIterator<grid_t> itrStop = group.end();
0079 
0080   std::size_t nIterations = 0ul;
0081   for (; itrStart != itrStop; ++itrStart, ++nIterations) {
0082     [[maybe_unused]] auto candidates = *itrStart;
0083   }
0084 
0085   BOOST_CHECK_EQUAL(nIterations, 0ul);
0086 }
0087 
0088 BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) {
0089   using binfinder_t = GridBinFinder<2ul>;
0090 
0091   Axis xAxis(0, 100, 10);
0092   Axis yAxis(0, 100, 10);
0093   Grid grid(Type<std::vector<std::size_t>>, std::move(xAxis), std::move(yAxis));
0094   using grid_t = decltype(grid);
0095   binfinder_t binfinder(0, 0);
0096   BinnedGroup<grid_t> group(std::move(grid), binfinder, binfinder);
0097 
0098   BinnedGroupIterator<grid_t> itrStart = group.begin();
0099   BinnedGroupIterator<grid_t> itrStop = group.end();
0100 
0101   std::size_t nIterations = 0ul;
0102   for (; itrStart != itrStop; ++itrStart, ++nIterations) {
0103     [[maybe_unused]] auto candidates = *itrStart;
0104   }
0105 
0106   BOOST_CHECK_EQUAL(nIterations, 0ul);
0107 }
0108 
0109 BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_perFilledGrid) {
0110   using binfinder_t = GridBinFinder<1ul>;
0111 
0112   Axis xAxis(0, 100, 10);
0113   Grid grid(Type<std::vector<std::size_t>>, xAxis);
0114   using grid_t = decltype(grid);
0115   /// Add some entries to the grid
0116   grid.at(1ul).push_back(4ul);
0117   grid.at(1ul).push_back(1ul);
0118   grid.at(8ul).push_back(7ul);
0119   grid.at(9ul).push_back(2ul);
0120 
0121   binfinder_t botBinfinder(0);
0122   binfinder_t topBinfinder(1);
0123   BinnedGroup<grid_t> group(std::move(grid), botBinfinder, topBinfinder);
0124 
0125   std::size_t nIterations = 0ul;
0126   for (const auto [bottom, middle, top] : group) {
0127     ++nIterations;
0128     BOOST_CHECK_EQUAL(bottom.size(), 1ul);
0129     BOOST_CHECK_EQUAL(top.size(), 3ul);
0130   }
0131 
0132   BOOST_CHECK_EQUAL(nIterations, 3ul);
0133 }
0134 
0135 BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) {
0136   using binfinder_t = GridBinFinder<2ul>;
0137 
0138   Axis xAxis(0, 100, 10);
0139   Axis yAxis(0, 100, 10);
0140   Grid grid(Type<std::vector<std::size_t>>, xAxis, yAxis);
0141   using grid_t = decltype(grid);
0142   /// Add some entries to the grid
0143   grid.atLocalBins({2ul, 4ul}).push_back(4ul);
0144   grid.atLocalBins({4ul, 4ul}).push_back(4ul);
0145 
0146   binfinder_t botBinfinder(1, 2);
0147   binfinder_t topBinfinder(1, 1);
0148   BinnedGroup<grid_t> group(std::move(grid), botBinfinder, topBinfinder);
0149 
0150   std::size_t nIterations = 0ul;
0151   for (const auto [bottom, middle, top] : group) {
0152     ++nIterations;
0153     BOOST_CHECK_EQUAL(bottom.size(), 15ul);
0154     BOOST_CHECK_EQUAL(top.size(), 9ul);
0155   }
0156 
0157   BOOST_CHECK_EQUAL(nIterations, 2ul);
0158 }
0159 
0160 BOOST_AUTO_TEST_CASE(binned_group_fill_2d) {
0161   using value_t = std::size_t;
0162   using binfinder_t = GridBinFinder<2ul>;
0163 
0164   Axis phiAxis(AxisClosed, -std::numbers::pi, std::numbers::pi, 40);
0165   Axis zAxis(AxisBound, 0, 100, 10);
0166 
0167   Grid grid(Type<std::vector<value_t>>, std::move(phiAxis), std::move(zAxis));
0168   using grid_t = decltype(grid);
0169   binfinder_t binfinder(1, 1);
0170   BinnedGroup<grid_t> group(std::move(grid), binfinder, binfinder);
0171 
0172   /// Fill the grid already owned by the group filling only one bin at a
0173   /// specific local position
0174   std::array<std::size_t, 2ul> locPosition({4ul, 6ul});
0175   std::size_t globPos = group.grid().globalBinFromLocalBins(locPosition);
0176 
0177   grid_t& storedGrid = group.grid();
0178   for (std::size_t i(0ul); i < 30ul; ++i) {
0179     storedGrid.at(globPos).push_back(1ul);
0180   }
0181 
0182   std::size_t nIterations = 0ul;
0183   for (const auto [bottom, middle, top] : group) {
0184     ++nIterations;
0185     const auto& coll = group.grid().at(middle);
0186     BOOST_CHECK_EQUAL(coll.size(), 30ul);
0187   }
0188 
0189   BOOST_CHECK_EQUAL(nIterations, 1ul);
0190 }
0191 
0192 BOOST_AUTO_TEST_CASE(binned_group_fill_3d) {
0193   using value_t = std::size_t;
0194   using phiAxis_t = Axis<AxisType::Equidistant, AxisBoundaryType::Closed>;
0195   using zAxis_t = Axis<AxisType::Equidistant, AxisBoundaryType::Bound>;
0196   using rAxis_t = Axis<AxisType::Equidistant, AxisBoundaryType::Bound>;
0197   using grid_t = Grid<std::vector<value_t>, phiAxis_t, zAxis_t, rAxis_t>;
0198   using binfinder_t = GridBinFinder<3ul>;
0199 
0200   phiAxis_t phiAxis(-std::numbers::pi, std::numbers::pi, 40);
0201   zAxis_t zAxis(0, 100, 10);
0202   rAxis_t rAxis(0, 11000, 1);
0203 
0204   grid_t grid(
0205       std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis)));
0206   binfinder_t binfinder(1, 1, 0);
0207   BinnedGroup<grid_t> group(std::move(grid), binfinder, binfinder);
0208 
0209   /// Fill the grid already owned by the group filling only one bin at a
0210   /// specific local position
0211   std::array<std::size_t, grid_t::DIM> locPosition({4ul, 6ul, 1ul});
0212   std::size_t globPos = group.grid().globalBinFromLocalBins(locPosition);
0213 
0214   grid_t& storedGrid = group.grid();
0215   for (std::size_t i(0ul); i < 30ul; ++i) {
0216     storedGrid.at(globPos).push_back(1ul);
0217   }
0218 
0219   std::size_t nIterations = 0ul;
0220   for (const auto [bottom, middle, top] : group) {
0221     ++nIterations;
0222     const auto& coll = group.grid().at(middle);
0223     BOOST_CHECK_EQUAL(coll.size(), 30ul);
0224   }
0225 
0226   BOOST_CHECK_EQUAL(nIterations, 1ul);
0227 }
0228 
0229 BOOST_AUTO_TEST_SUITE_END()
0230 
0231 }  // namespace ActsTests