Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-19 07:59:16

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/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/Grid.hpp"
0013 #include "Acts/Utilities/GridAccessHelpers.hpp"
0014 #include "Acts/Utilities/GridAxisGenerators.hpp"
0015 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 using namespace Acts;
0018 
0019 namespace ActsTests {
0020 
0021 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0022 
0023 BOOST_AUTO_TEST_CASE(Grid1DAccess) {
0024   GridAxisGenerators::EqBound eqBound{{0., 10.}, 10};
0025   using GridType = GridAxisGenerators::EqBound::grid_type<std::size_t>;
0026   using PointType = GridType::point_t;
0027   auto grid = GridType(eqBound());
0028 
0029   for (std::size_t i = 0; i < 10; ++i) {
0030     grid.atPosition(PointType{i + 0.5}) = i;
0031   }
0032 
0033   // Local access
0034   std::vector<std::size_t> fAccessor = {0u};
0035   std::vector<std::size_t> sAccessor = {1u};
0036 
0037   Vector2 lPosition{3.5, 6.5};
0038   auto flAccess =
0039       GridAccessHelpers::accessLocal<GridType>(lPosition, fAccessor);
0040   auto slAccess =
0041       GridAccessHelpers::accessLocal<GridType>(lPosition, sAccessor);
0042 
0043   // This should take out local 1D either first or second
0044   BOOST_CHECK_EQUAL(grid.atPosition(flAccess), 3u);
0045   BOOST_CHECK_EQUAL(grid.atPosition(slAccess), 6u);
0046 
0047   // Global access
0048   Vector3 gPosition{0.5, 3.5, 6.5};
0049   std::vector<AxisDirection> fCast = {AxisDirection::AxisX};
0050   std::vector<AxisDirection> sCast = {AxisDirection::AxisY};
0051   std::vector<AxisDirection> tCast = {AxisDirection::AxisZ};
0052 
0053   auto fgAccess = GridAccessHelpers::castPosition<GridType>(gPosition, fCast);
0054   auto sgAccess = GridAccessHelpers::castPosition<GridType>(gPosition, sCast);
0055   auto tgAccess = GridAccessHelpers::castPosition<GridType>(gPosition, tCast);
0056   BOOST_CHECK_EQUAL(grid.atPosition(fgAccess), 0u);
0057   BOOST_CHECK_EQUAL(grid.atPosition(sgAccess), 3u);
0058   BOOST_CHECK_EQUAL(grid.atPosition(tgAccess), 6u);
0059 
0060   // Can this go into a delegate?
0061   auto gsu = std::make_unique<
0062       const GridAccess::GlobalSubspace<AxisDirection::AxisX>>();
0063   GridAccess::GlobalToGridLocal1DimDelegate gsuDelegate;
0064   gsuDelegate
0065       .connect<&GridAccess::GlobalSubspace<AxisDirection::AxisX>::toGridLocal>(
0066           std::move(gsu));
0067 
0068   BOOST_CHECK(gsuDelegate.connected());
0069 }
0070 
0071 BOOST_AUTO_TEST_CASE(Grid2DAccess) {
0072   GridAxisGenerators::EqBoundEqBound eqeqBound{{0., 10.}, 10, {0., 10.}, 10};
0073   using GridType = GridAxisGenerators::EqBoundEqBound::grid_type<std::size_t>;
0074   using PointType = GridType::point_t;
0075   auto grid = GridType(eqeqBound());
0076   for (std::size_t j = 0; j < 10u; ++j) {
0077     for (std::size_t i = 0; i < 10u; ++i) {
0078       grid.atPosition(PointType{i + 0.5, j + 0.5}) = j * 100 + i;
0079     }
0080   }
0081 
0082   // Local access
0083   std::vector<std::size_t> fAccessor = {0u, 1u};
0084   Vector2 lPosition{3.5, 6.5};
0085   auto flAccess =
0086       GridAccessHelpers::accessLocal<GridType>(lPosition, fAccessor);
0087   BOOST_CHECK_EQUAL(grid.atPosition(flAccess), 603u);
0088 
0089   // Global access
0090   Vector3 gPosition{0.5, 3.5, 6.5};
0091   std::vector<AxisDirection> fCast = {AxisDirection::AxisX,
0092                                       AxisDirection::AxisY};
0093   auto fgAccess = GridAccessHelpers::castPosition<GridType>(gPosition, fCast);
0094   BOOST_CHECK_EQUAL(grid.atPosition(fgAccess), 300u);
0095 }
0096 
0097 BOOST_AUTO_TEST_CASE(GlobalToGridLocalTests) {
0098   GridAccess::GlobalSubspace<AxisDirection::AxisX, AxisDirection::AxisY> gssXY;
0099 
0100   auto xy = gssXY.toGridLocal(Vector3{1., 2., 3.});
0101   BOOST_CHECK_EQUAL(xy[0], 1.);
0102   BOOST_CHECK_EQUAL(xy[1], 2.);
0103 
0104   GridAccess::GlobalSubspace<AxisDirection::AxisZ> gssZ;
0105   auto z = gssZ.toGridLocal(Vector3{1., 2., 3.});
0106   BOOST_CHECK_EQUAL(z[0], 3.);
0107 
0108   GridAccess::Affine3Transformed<
0109       GridAccess::GlobalSubspace<AxisDirection::AxisZ>>
0110       gssZT(gssZ, Transform3{Transform3::Identity()}.pretranslate(
0111                       Vector3{0., 0., 100.}));
0112 
0113   auto zt = gssZT.toGridLocal(Vector3{1., 2., 3.});
0114   BOOST_CHECK_EQUAL(zt[0], 103.);
0115 }
0116 
0117 BOOST_AUTO_TEST_CASE(BoundToGridLocalTests) {
0118   GridAccess::LocalSubspace<0u, 1u> bssXY;
0119   auto xy = bssXY.toGridLocal(Vector2{
0120       1.,
0121       2.,
0122   });
0123 
0124   BOOST_CHECK_EQUAL(xy[0], 1.);
0125   BOOST_CHECK_EQUAL(xy[1], 2.);
0126 }
0127 
0128 BOOST_AUTO_TEST_CASE(BoundCylinderToZPhiTests) {
0129   double radius = 100.;
0130   double shift = 0.;
0131   GridAccess::BoundCylinderToZPhi bctzp(radius, shift);
0132 
0133   auto zphi = bctzp.toGridLocal(Vector2{0.25 * radius, 52.});
0134 
0135   CHECK_CLOSE_ABS(zphi[0], 52., 1.e-6);
0136   CHECK_CLOSE_ABS(zphi[1], 0.25, 1.e-6);
0137 }
0138 
0139 BOOST_AUTO_TEST_SUITE_END()
0140 
0141 }  // namespace ActsTests