ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnnulusBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AnnulusBoundsTests.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 // clang-format off
10 #include <boost/test/unit_test.hpp>
11 #include <boost/test/data/test_case.hpp>
12 #include <boost/test/output_test_stream.hpp>
13 // clang-format on
14 
15 #include <limits>
16 #include <fstream>
17 
22 
23 namespace Acts {
24 
25 namespace Test {
26 BOOST_AUTO_TEST_SUITE(Surfaces)
27 
28 double minRadius = 7.2;
29 double maxRadius = 12.0;
30 double minPhi = 0.74195;
31 double maxPhi = 1.33970;
32 
33 Vector2D offset(-2., 2.);
34 
35 // Unit tests for AnnulusBounds constrcuctors
36 BOOST_AUTO_TEST_CASE(AnnulusBoundsConstruction) {
37  // Test construction with radii and default sector
38  auto original = AnnulusBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
39  AnnulusBounds copied(original);
40  BOOST_CHECK_EQUAL(original, copied);
41 }
42 
43 // Unit tests for AnnulusBounds recreation
44 BOOST_AUTO_TEST_CASE(AnnulusBoundsRecreation) {
45  // Test construction with radii and default sector
46  auto original = AnnulusBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
47  auto valvector = original.values();
48  std::array<double, AnnulusBounds::eSize> values;
49  std::copy_n(valvector.begin(), AnnulusBounds::eSize, values.begin());
50  AnnulusBounds recreated(values);
51  BOOST_CHECK_EQUAL(original, recreated);
52 }
53 
54 // Unit tests for AnnulusBounds exception throwing
55 BOOST_AUTO_TEST_CASE(AnnulusBoundsExcpetion) {
56  // Exception for negative inenr radius
57  BOOST_CHECK_THROW(AnnulusBounds(-1., maxRadius, minPhi, maxPhi, offset),
58  std::logic_error);
59  // Exception for negative outer radius
60  BOOST_CHECK_THROW(AnnulusBounds(minRadius, -1., minPhi, maxPhi, offset),
61  std::logic_error);
62  // Exception for swapped radii
63  BOOST_CHECK_THROW(AnnulusBounds(maxRadius, minRadius, minPhi, maxPhi, offset),
64  std::logic_error);
65  // Exception for out of range min phi
66  BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, -4., maxPhi, offset),
67  std::logic_error);
68  // Exception for out of range max phi
69  BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, minPhi, 4., offset),
70  std::logic_error);
71  // Exception for out of range max phi
72  BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, maxPhi, minPhi, offset),
73  std::logic_error);
74 }
75 
77 BOOST_AUTO_TEST_CASE(AnnulusBoundsProperties) {
80 
81  //
83  BOOST_CHECK_EQUAL(aBounds.type(), SurfaceBounds::eAnnulus);
84 
86  // - start from cartesian (from test drawing)
87  Vector2D inSurfaceXY(7., 7.);
88  Vector2D outsideXY1(5., 5.);
89  Vector2D outsideXY2(10., 3.);
90  Vector2D outsideXY3(10., 10.);
91  Vector2D outsideXY4(4., 10.);
92  std::vector<Vector2D> testPoints = {inSurfaceXY, outsideXY1, outsideXY2,
93  outsideXY3, outsideXY4};
94 
95  auto toStripFrame = [&](const Vector2D& xy) -> Vector2D {
96  auto shifted = xy + offset;
97  double r = VectorHelpers::perp(shifted);
98  double phi = VectorHelpers::phi(shifted);
99  return Vector2D(r, phi);
100  };
101 
102  BOOST_CHECK(aBounds.inside(toStripFrame(inSurfaceXY), BoundaryCheck(true)));
103  BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY1), BoundaryCheck(true)));
104  BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY2), BoundaryCheck(true)));
105  BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY3), BoundaryCheck(true)));
106  BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY4), BoundaryCheck(true)));
107 
108  // Check radial inside
109  BOOST_CHECK(!aBounds.insideRadialBounds(0.5));
110  BOOST_CHECK(aBounds.insideRadialBounds(9.));
111  BOOST_CHECK(!aBounds.insideRadialBounds(18.));
112 
113  // Test rMin
114  BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMinR), minRadius);
115  // Test rMax
116  BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMaxR), maxRadius);
117  // Test phiMin
118  BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMinPhiRel), minPhi);
119  // Test phiMax
120  BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMaxPhiRel), maxPhi);
121 }
122 
123 BOOST_AUTO_TEST_SUITE_END()
124 
125 } // namespace Test
126 
127 } // namespace Acts