EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtentTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ExtentTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 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/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 #include "Acts/Geometry/Extent.hpp"
16 #include "Acts/Utilities/Units.hpp"
17 
18 #include <iostream>
19 
20 namespace Acts {
21 
22 using namespace UnitLiterals;
23 
24 namespace Test {
25 
26 BOOST_AUTO_TEST_SUITE(Geometry)
27 
28 
29 BOOST_AUTO_TEST_CASE(ExtentTest) {
30  std::vector<Vector3D> vertices = {
31  Vector3D(15_mm, -3_mm, -10_mm), Vector3D(18_mm, 0_mm, -10_mm),
32  Vector3D(15_mm, 3_mm, -10_mm), Vector3D(15_mm, -3_mm, 10_mm),
33  Vector3D(18_mm, 0_mm, 10_mm), Vector3D(15_mm, 3_mm, 10_mm)};
34 
35  // Create an Extent
36  Extent gExt;
37  for (const auto& v : vertices) {
38  gExt.check(v);
39  }
40 
41  double phiMin = std::atan2(-3_mm, 15_mm);
42  double phiMax = std::atan2(3_mm, 15_mm);
43  double rMin = std::sqrt(15_mm * 15_mm + 3_mm * 3_mm);
44 
45  CHECK_CLOSE_ABS(gExt.min(binX), 15_mm, 1e-6);
46  CHECK_CLOSE_ABS(gExt.max(binX), 18_mm, 1e-6);
47  CHECK_CLOSE_ABS(gExt.min(binY), -3_mm, 1e-6);
48  CHECK_CLOSE_ABS(gExt.max(binY), 3_mm, 1e-6);
49  CHECK_CLOSE_ABS(gExt.min(binZ), -10_mm, 1e-6);
50  CHECK_CLOSE_ABS(gExt.max(binZ), 10_mm, 1e-6);
51  CHECK_CLOSE_ABS(gExt.min(binR), rMin, 1e-6);
52  CHECK_CLOSE_ABS(gExt.max(binR), 18_mm, 1e-6);
53  CHECK_CLOSE_ABS(gExt.min(binPhi), phiMin, 1e-6);
54  CHECK_CLOSE_ABS(gExt.max(binPhi), phiMax, 1e-6);
55 
56  // Create a second Extent
57  Extent otherExt;
58  otherExt.extend(gExt);
59 
60  CHECK_CLOSE_ABS(otherExt.min(binX), 15_mm, 1e-6);
61  CHECK_CLOSE_ABS(otherExt.max(binX), 18_mm, 1e-6);
62  CHECK_CLOSE_ABS(otherExt.min(binY), -3_mm, 1e-6);
63  CHECK_CLOSE_ABS(otherExt.max(binY), 3_mm, 1e-6);
64  CHECK_CLOSE_ABS(otherExt.min(binZ), -10_mm, 1e-6);
65  CHECK_CLOSE_ABS(otherExt.max(binZ), 10_mm, 1e-6);
66  CHECK_CLOSE_ABS(otherExt.min(binR), rMin, 1e-6);
67  CHECK_CLOSE_ABS(otherExt.max(binR), 18_mm, 1e-6);
68  CHECK_CLOSE_ABS(otherExt.min(binPhi), phiMin, 1e-6);
69  CHECK_CLOSE_ABS(otherExt.max(binPhi), phiMax, 1e-6);
70 }
71 
72 BOOST_AUTO_TEST_CASE(ExtentTestIntersects) {
73  Extent aExtent;
74  aExtent.ranges = {{1, 2}, {2, 3}, {4, 5}, {2., sqrt(5.)}, {-0.1, 1.4},
75  {-4., 4.}, {0., 0.}, {1., 2.}, {0., sqrt(9.)}};
76 
77  Extent bExtent;
78  bExtent.ranges = {{-2, -1}, {1, 2.5}, {6, 8},
79  {0., sqrt(12.)}, {-0.1, 1.4}, {-2., 2.},
80  {0., 0.}, {-2., 0.}, {0., sqrt(9.)}};
81 
82  // They certainly intersect
83  BOOST_CHECK(aExtent.intersects(bExtent));
84  // They do not intersect in x
85  BOOST_CHECK(!aExtent.intersects(bExtent, binX));
86  // They do with a large tolerance though in x
87  BOOST_CHECK(aExtent.intersects(bExtent, binX, 3.));
88  // They do intersect in y
89  BOOST_CHECK(aExtent.intersects(bExtent, binY));
90  // They do not intersect in z
91  BOOST_CHECK(!aExtent.intersects(bExtent, binZ));
92  // They do intersect in r
93  BOOST_CHECK(aExtent.intersects(bExtent, binR));
94  // They do not intersect in eta
95  BOOST_CHECK(!aExtent.intersects(bExtent, binEta));
96  // They do intersect with tolerance in eta
97  BOOST_CHECK(aExtent.intersects(bExtent, binEta, 3.));
98 }
99 
100 BOOST_AUTO_TEST_SUITE_END()
101 
102 } // namespace Test
103 } // namespace Acts