Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-22 07:53:18

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   // Build a translation
0035   Vector3 translation{1_mm, 2_mm, 3_mm};
0036 
0037   // Build a translation
0038   SquareMatrix3 rotation = RotationMatrix3::Identity();
0039   double rotationAngle = 60_degree;
0040   Vector3 xPos(cos(rotationAngle), 0., sin(rotationAngle));
0041   Vector3 yPos(0., 1., 0.);
0042   Vector3 zPos(-sin(rotationAngle), 0., cos(rotationAngle));
0043   rotation.col(0) = xPos;
0044   rotation.col(1) = yPos;
0045   rotation.col(2) = zPos;
0046 
0047   // Build a transform
0048   Transform3 transform(Transform3::Identity() * rotation);
0049   transform.translation() = translation;
0050   // Build the bounds
0051   CuboidVolumeBounds bounds(4_mm, 5_mm, 6_mm);
0052 
0053   // Build and test the volume
0054   Volume volume(transform, std::make_shared<CuboidVolumeBounds>(bounds));
0055   BOOST_CHECK_EQUAL(volume.transform().matrix(), transform.matrix());
0056   CHECK_CLOSE_ABS(volume.itransform().matrix(), transform.inverse().matrix(),
0057                   eps);
0058   BOOST_CHECK_EQUAL(volume.center(), translation);
0059   auto vBounds = static_cast<const decltype(bounds)*>(&volume.volumeBounds());
0060   BOOST_CHECK_EQUAL(*vBounds, bounds);
0061 
0062   // Build and test a shifted volume
0063   Transform3 shift(Transform3::Identity());
0064   Vector3 shiftTranslation{-4_mm, -5_mm, -6_mm};
0065   shift.translation() = shiftTranslation;
0066   Volume volumeShift(volume, shift);
0067   BOOST_CHECK_EQUAL(volumeShift.center(),
0068                     (shift * volume.transform()).translation());
0069   BOOST_CHECK_EQUAL(volumeShift.transform().rotation(),
0070                     volume.transform().rotation());
0071 
0072   // Inside/Outside check
0073   BOOST_CHECK(volume.inside(translation));
0074   BOOST_CHECK(!volume.inside({10_mm, 2_mm, 3_mm}));
0075   BOOST_CHECK(volume.inside({10_mm, 2_mm, 3_mm}, 2_mm));
0076 
0077   // Binning test
0078   GeometryContext gctx;
0079   BOOST_CHECK_EQUAL(volume.referencePosition(gctx, AxisDirection::AxisX),
0080                     volume.center());
0081 }
0082 
0083 BOOST_AUTO_TEST_CASE(VolumeUpdateTest) {
0084   using namespace UnitLiterals;
0085   auto volBounds = std::make_shared<CuboidVolumeBounds>(4_mm, 5_mm, 6_mm);
0086   auto volBounds2 = std::make_shared<CuboidVolumeBounds>(4_mm, 5_mm, 8_mm);
0087 
0088   Transform3 trf = Transform3::Identity();
0089 
0090   Volume volume(trf, volBounds);
0091 
0092   // Only update the bounds, keep the transform the same
0093   volume.update(volBounds2, std::nullopt);
0094   BOOST_CHECK_EQUAL(&volume.volumeBounds(), volBounds2.get());
0095   BOOST_CHECK_EQUAL(volume.transform().matrix(), trf.matrix());
0096 
0097   // Update the bounds and the transform
0098   Transform3 trf2{Translation3{1_mm, 2_mm, 3_mm}};
0099   volume.update(volBounds, trf2);
0100   BOOST_CHECK_EQUAL(&volume.volumeBounds(), volBounds.get());
0101   BOOST_CHECK_EQUAL(volume.transform().matrix(), trf2.matrix());
0102 }
0103 
0104 BOOST_AUTO_TEST_SUITE_END()
0105 
0106 }  // namespace ActsTests