EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VolumeTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VolumeTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
13 #include "Acts/Geometry/Volume.hpp"
17 #include "Acts/Utilities/Units.hpp"
18 
19 namespace tt = boost::test_tools;
20 
21 namespace Acts {
22 
23 namespace Test {
24 
25 BOOST_AUTO_TEST_CASE(VolumeTest) {
26  using namespace Acts::UnitLiterals;
28 
29  // Build a translation
30  Vector3D translation{1_mm, 2_mm, 3_mm};
31 
32  // Build a translation
33  ActsMatrixD<3, 3> rotation = RotationMatrix3D::Identity();
34  double rotationAngle = 60_degree;
35  Vector3D xPos(cos(rotationAngle), 0., sin(rotationAngle));
36  Vector3D yPos(0., 1., 0.);
37  Vector3D zPos(-sin(rotationAngle), 0., cos(rotationAngle));
38  rotation.col(0) = xPos;
39  rotation.col(1) = yPos;
40  rotation.col(2) = zPos;
41 
42  // Build a transform
43  Transform3D transform(Transform3D::Identity() * rotation);
44  transform.translation() = translation;
45  // Build the bounds
46  CuboidVolumeBounds bounds(4_mm, 5_mm, 6_mm);
47 
48  // Build and test the volume
49  Volume volume(transform, std::make_shared<const CuboidVolumeBounds>(bounds));
50  BOOST_CHECK_EQUAL(volume.transform().matrix(), transform.matrix());
51  CHECK_CLOSE_ABS(volume.itransform().matrix(), transform.inverse().matrix(),
52  eps);
53  BOOST_CHECK_EQUAL(volume.center(), translation);
54  auto vBounds = static_cast<const decltype(bounds)*>(&volume.volumeBounds());
55  BOOST_CHECK_EQUAL(*vBounds, bounds);
56 
57  // Build and test a shifted volume
58  Transform3D shift(Transform3D::Identity());
59  Vector3D shiftTranslation{-4_mm, -5_mm, -6_mm};
60  shift.translation() = shiftTranslation;
61  Volume volumeShift(volume, shift);
62  BOOST_CHECK_EQUAL(volumeShift.center(),
63  (shift * volume.transform()).translation());
64  BOOST_CHECK_EQUAL(volumeShift.transform().rotation(),
65  volume.transform().rotation());
66 
67  // Inside/Outside check
68  BOOST_CHECK(volume.inside(translation));
69  BOOST_CHECK(!volume.inside({10_mm, 2_mm, 3_mm}));
70  BOOST_CHECK(volume.inside({10_mm, 2_mm, 3_mm}, 2_mm));
71 
72  // Binning test
74  BOOST_CHECK_EQUAL(volume.binningPosition(gctx, binX), volume.center());
75 }
76 } // namespace Test
77 } // namespace Acts