Analysis Software
Documentation for sPHENIX simulation 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 
15 #include "Acts/Geometry/Volume.hpp"
18 
19 #include <cmath>
20 #include <limits>
21 #include <memory>
22 #include <utility>
23 
24 namespace tt = boost::test_tools;
25 
26 namespace Acts {
27 
28 namespace Test {
29 
30 BOOST_AUTO_TEST_CASE(VolumeTest) {
31  using namespace Acts::UnitLiterals;
32  double eps = std::numeric_limits<double>::epsilon();
33 
34  // Build a translation
35  Vector3 translation{1_mm, 2_mm, 3_mm};
36 
37  // Build a translation
38  ActsMatrix<3, 3> rotation = RotationMatrix3::Identity();
39  double rotationAngle = 60_degree;
40  Vector3 xPos(cos(rotationAngle), 0., sin(rotationAngle));
41  Vector3 yPos(0., 1., 0.);
42  Vector3 zPos(-sin(rotationAngle), 0., cos(rotationAngle));
43  rotation.col(0) = xPos;
44  rotation.col(1) = yPos;
45  rotation.col(2) = zPos;
46 
47  // Build a transform
48  Transform3 transform(Transform3::Identity() * rotation);
49  transform.translation() = translation;
50  // Build the bounds
51  CuboidVolumeBounds bounds(4_mm, 5_mm, 6_mm);
52 
53  // Build and test the volume
54  Volume volume(transform, std::make_shared<const CuboidVolumeBounds>(bounds));
55  BOOST_CHECK_EQUAL(volume.transform().matrix(), transform.matrix());
56  CHECK_CLOSE_ABS(volume.itransform().matrix(), transform.inverse().matrix(),
57  eps);
58  BOOST_CHECK_EQUAL(volume.center(), translation);
59  auto vBounds = static_cast<const decltype(bounds)*>(&volume.volumeBounds());
60  BOOST_CHECK_EQUAL(*vBounds, bounds);
61 
62  // Build and test a shifted volume
63  Transform3 shift(Transform3::Identity());
64  Vector3 shiftTranslation{-4_mm, -5_mm, -6_mm};
65  shift.translation() = shiftTranslation;
66  Volume volumeShift(volume, shift);
67  BOOST_CHECK_EQUAL(volumeShift.center(),
68  (shift * volume.transform()).translation());
69  BOOST_CHECK_EQUAL(volumeShift.transform().rotation(),
70  volume.transform().rotation());
71 
72  // Inside/Outside check
73  BOOST_CHECK(volume.inside(translation));
74  BOOST_CHECK(!volume.inside({10_mm, 2_mm, 3_mm}));
75  BOOST_CHECK(volume.inside({10_mm, 2_mm, 3_mm}, 2_mm));
76 
77  // Binning test
79  BOOST_CHECK_EQUAL(volume.binningPosition(gctx, binX), volume.center());
80 }
81 } // namespace Test
82 } // namespace Acts