Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:57

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