Analysis Software
Documentation for sPHENIX simulation 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/tools/output_test_stream.hpp>
13 #include <algorithm>
14 #include <array>
15 #include <stdexcept>
16 #include <vector>
17 // clang-format on
18 
24 
25 namespace Acts {
26 
27 namespace Test {
28 BOOST_AUTO_TEST_SUITE(Surfaces)
29 
31 double maxRadius = 12.0;
32 double minPhi = 0.74195;
33 double maxPhi = 1.33970;
34 
35 Vector2 offset(-2., 2.);
36 
37 // Unit tests for AnnulusBounds constructors
38 BOOST_AUTO_TEST_CASE(AnnulusBoundsConstruction) {
39  // Test construction with radii and default sector
40  auto original = AnnulusBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
41  AnnulusBounds copied(original);
42  BOOST_CHECK_EQUAL(original, copied);
43 }
44 
45 // Unit tests for AnnulusBounds recreation
46 BOOST_AUTO_TEST_CASE(AnnulusBoundsRecreation) {
47  // Test construction with radii and default sector
48  auto original = AnnulusBounds(minRadius, maxRadius, minPhi, maxPhi, offset);
49  auto valvector = original.values();
50  std::array<double, AnnulusBounds::eSize> values{};
51  std::copy_n(valvector.begin(), AnnulusBounds::eSize, values.begin());
52  AnnulusBounds recreated(values);
53  BOOST_CHECK_EQUAL(original, recreated);
54 }
55 
56 // Unit tests for AnnulusBounds exception throwing
57 BOOST_AUTO_TEST_CASE(AnnulusBoundsExcpetion) {
58  // Exception for negative inner radius
59  BOOST_CHECK_THROW(AnnulusBounds(-1., maxRadius, minPhi, maxPhi, offset),
60  std::logic_error);
61  // Exception for negative outer radius
62  BOOST_CHECK_THROW(AnnulusBounds(minRadius, -1., minPhi, maxPhi, offset),
63  std::logic_error);
64  // Exception for swapped radii
65  BOOST_CHECK_THROW(AnnulusBounds(maxRadius, minRadius, minPhi, maxPhi, offset),
66  std::logic_error);
67  // Exception for out of range min phi
68  BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, -4., maxPhi, offset),
69  std::logic_error);
70  // Exception for out of range max phi
71  BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, minPhi, 4., offset),
72  std::logic_error);
73  // Exception for out of range max phi
74  BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, maxPhi, minPhi, offset),
75  std::logic_error);
76 }
77 
79 BOOST_AUTO_TEST_CASE(AnnulusBoundsProperties) {
82 
83  //
85  BOOST_CHECK_EQUAL(aBounds.type(), SurfaceBounds::eAnnulus);
86 
88  // - start from cartesian (from test drawing)
89  Vector2 inSurfaceXY(7., 7.);
90  Vector2 outsideXY1(5., 5.);
91  Vector2 outsideXY2(10., 3.);
92  Vector2 outsideXY3(10., 10.);
93  Vector2 outsideXY4(4., 10.);
94  std::vector<Vector2> testPoints = {inSurfaceXY, outsideXY1, outsideXY2,
95  outsideXY3, outsideXY4};
96 
97  auto toStripFrame = [&](const Vector2& xy) -> Vector2 {
98  auto shifted = xy + offset;
99  double r = VectorHelpers::perp(shifted);
100  double phi = VectorHelpers::phi(shifted);
101  return Vector2(r, phi);
102  };
103 
104  BOOST_CHECK(aBounds.inside(toStripFrame(inSurfaceXY), BoundaryCheck(true)));
105  BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY1), BoundaryCheck(true)));
106  BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY2), BoundaryCheck(true)));
107  BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY3), BoundaryCheck(true)));
108  BOOST_CHECK(!aBounds.inside(toStripFrame(outsideXY4), BoundaryCheck(true)));
109 
110  // Check radial inside
111  BOOST_CHECK(!aBounds.insideRadialBounds(0.5));
112  BOOST_CHECK(aBounds.insideRadialBounds(9.));
113  BOOST_CHECK(!aBounds.insideRadialBounds(18.));
114 
115  // Test rMin
116  BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMinR), minRadius);
117  // Test rMax
118  BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMaxR), maxRadius);
119  // Test phiMin
120  BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMinPhiRel), minPhi);
121  // Test phiMax
122  BOOST_CHECK_EQUAL(aBounds.get(AnnulusBounds::eMaxPhiRel), maxPhi);
123 }
124 
125 BOOST_AUTO_TEST_SUITE_END()
126 
127 } // namespace Test
128 
129 } // namespace Acts