Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:32

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