Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-21 07:48:30

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/Definitions/Units.hpp"
0013 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/Volume.hpp"
0016 #include "Acts/Utilities/BinningType.hpp"
0017 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0018 
0019 #include <cmath>
0020 #include <limits>
0021 #include <memory>
0022 #include <utility>
0023 
0024 using namespace Acts;
0025 
0026 namespace ActsTests {
0027 
0028 BOOST_AUTO_TEST_SUITE(GeometrySuite)
0029 
0030 BOOST_AUTO_TEST_CASE(VolumeTest) {
0031   using namespace UnitLiterals;
0032   double eps = std::numeric_limits<double>::epsilon();
0033 
0034   const auto gctx = GeometryContext::dangerouslyDefaultConstruct();
0035 
0036   // Build a translation
0037   Vector3 translation{1_mm, 2_mm, 3_mm};
0038 
0039   // Build a translation
0040   SquareMatrix3 rotation = RotationMatrix3::Identity();
0041   double rotationAngle = 60_degree;
0042   Vector3 xPos(std::cos(rotationAngle), 0., std::sin(rotationAngle));
0043   Vector3 yPos(0., 1., 0.);
0044   Vector3 zPos(-std::sin(rotationAngle), 0., std::cos(rotationAngle));
0045   rotation.col(0) = xPos;
0046   rotation.col(1) = yPos;
0047   rotation.col(2) = zPos;
0048 
0049   // Build a transform
0050   Transform3 transform(Transform3::Identity() * rotation);
0051   transform.translation() = translation;
0052   // Build the bounds
0053   CuboidVolumeBounds bounds(4_mm, 5_mm, 6_mm);
0054 
0055   // Build and test the volume
0056   Volume volume(transform, std::make_shared<CuboidVolumeBounds>(bounds));
0057   BOOST_CHECK_EQUAL(volume.localToGlobalTransform(gctx).matrix(),
0058                     transform.matrix());
0059   CHECK_CLOSE_ABS(volume.globalToLocalTransform(gctx).matrix(),
0060                   transform.inverse().matrix(), eps);
0061   BOOST_CHECK_EQUAL(volume.center(gctx), translation);
0062   auto vBounds = static_cast<const decltype(bounds)*>(&volume.volumeBounds());
0063   BOOST_CHECK_EQUAL(*vBounds, bounds);
0064 
0065   // Build and test a shifted volume
0066   Transform3 shift(Transform3::Identity());
0067   Vector3 shiftTranslation{-4_mm, -5_mm, -6_mm};
0068   shift.translation() = shiftTranslation;
0069   Volume volumeShift = volume.shifted(gctx, shift);
0070   BOOST_CHECK_EQUAL(
0071       volumeShift.center(gctx),
0072       (shift * volume.localToGlobalTransform(gctx)).translation());
0073   BOOST_CHECK_EQUAL(volumeShift.localToGlobalTransform(gctx).rotation(),
0074                     volume.localToGlobalTransform(gctx).rotation());
0075 
0076   // Inside/Outside check
0077   BOOST_CHECK(volume.inside(gctx, translation));
0078   BOOST_CHECK(!volume.inside(gctx, {10_mm, 2_mm, 3_mm}));
0079   BOOST_CHECK(volume.inside(gctx, {10_mm, 2_mm, 3_mm}, 2_mm));
0080   BOOST_CHECK_EQUAL(volume.referencePosition(gctx, AxisDirection::AxisX),
0081                     volume.center(gctx));
0082 }
0083 
0084 BOOST_AUTO_TEST_CASE(VolumeUpdateTest) {
0085   using namespace UnitLiterals;
0086   auto volBounds = std::make_shared<CuboidVolumeBounds>(4_mm, 5_mm, 6_mm);
0087   auto volBounds2 = std::make_shared<CuboidVolumeBounds>(4_mm, 5_mm, 8_mm);
0088 
0089   const auto gctx = GeometryContext::dangerouslyDefaultConstruct();
0090 
0091   Transform3 trf = Transform3::Identity();
0092 
0093   Volume volume(trf, volBounds);
0094 
0095   // Only update the bounds, keep the transform the same
0096   volume.update(gctx, volBounds2, std::nullopt);
0097   BOOST_CHECK_EQUAL(&volume.volumeBounds(), volBounds2.get());
0098   BOOST_CHECK_EQUAL(volume.localToGlobalTransform(gctx).matrix(), trf.matrix());
0099 
0100   // Update the bounds and the transform
0101   Transform3 trf2{Translation3{1_mm, 2_mm, 3_mm}};
0102   volume.update(gctx, volBounds, trf2);
0103   BOOST_CHECK_EQUAL(&volume.volumeBounds(), volBounds.get());
0104   BOOST_CHECK_EQUAL(volume.localToGlobalTransform(gctx).matrix(),
0105                     trf2.matrix());
0106 }
0107 
0108 BOOST_AUTO_TEST_SUITE_END()
0109 
0110 }  // namespace ActsTests