Back to home page

EIC code displayed by LXR

 
 

    


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

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