ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CylinderSurfaceTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CylinderSurfaceTests.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 <limits>
14 
20 
21 namespace tt = boost::test_tools;
22 using boost::test_tools::output_test_stream;
23 namespace utf = boost::unit_test;
24 
25 namespace Acts {
26 
27 namespace Test {
28 
29 // Create a test context
31 
32 BOOST_AUTO_TEST_SUITE(CylinderSurfaces)
34 BOOST_AUTO_TEST_CASE(CylinderSurfaceConstruction) {
35  // CylinderSurface default constructor is deleted
36  //
38  double radius(1.0), halfZ(10.), halfPhiSector(M_PI / 8.);
39  Translation3D translation{0., 1., 2.};
40  auto pTransform = std::make_shared<const Transform3D>(translation);
41  std::shared_ptr<const Transform3D> pNullTransform{};
42  BOOST_CHECK_EQUAL(
43  Surface::makeShared<CylinderSurface>(pNullTransform, radius, halfZ)
44  ->type(),
46  BOOST_CHECK_EQUAL(
47  Surface::makeShared<CylinderSurface>(pTransform, radius, halfZ)->type(),
49  //
51  BOOST_CHECK_EQUAL(Surface::makeShared<CylinderSurface>(pTransform, radius,
52  halfZ, halfPhiSector)
53  ->type(),
55 
57  auto pCylinderBounds = std::make_shared<const CylinderBounds>(radius, halfZ);
58  BOOST_CHECK_EQUAL(
59  Surface::makeShared<CylinderSurface>(pTransform, pCylinderBounds)->type(),
61  //
62  //
64  auto cylinderSurfaceObject =
65  Surface::makeShared<CylinderSurface>(pTransform, radius, halfZ);
66  auto copiedCylinderSurface =
67  Surface::makeShared<CylinderSurface>(*cylinderSurfaceObject);
68  BOOST_CHECK_EQUAL(copiedCylinderSurface->type(), Surface::Cylinder);
69  BOOST_CHECK(*copiedCylinderSurface == *cylinderSurfaceObject);
70  //
72  auto copiedTransformedCylinderSurface = Surface::makeShared<CylinderSurface>(
73  testContext, *cylinderSurfaceObject, *pTransform);
74  BOOST_CHECK_EQUAL(copiedTransformedCylinderSurface->type(),
76 
78  BOOST_CHECK_THROW(
79  auto nullBounds = Surface::makeShared<CylinderSurface>(nullptr, nullptr),
81 }
82 //
84 BOOST_AUTO_TEST_CASE(CylinderSurfaceProperties) {
86  double radius(1.0), halfZ(10.);
87  Translation3D translation{0., 1., 2.};
88  auto pTransform = std::make_shared<const Transform3D>(translation);
89  auto cylinderSurfaceObject =
90  Surface::makeShared<CylinderSurface>(pTransform, radius, halfZ);
91  //
93  BOOST_CHECK_EQUAL(cylinderSurfaceObject->type(), Surface::Cylinder);
94  //
96  Vector3D binningPosition{0., 1., 2.};
98  cylinderSurfaceObject->binningPosition(testContext, BinningValue::binPhi),
99  binningPosition, 1e-9);
100  //
102  double rootHalf = std::sqrt(0.5);
103  Vector3D globalPosition{rootHalf, 1. - rootHalf, 0.};
104  Vector3D globalPositionZ{rootHalf, 1. - rootHalf, 2.0};
105  Vector3D momentum{15., 15., 15.};
106  Vector3D momentum2{6.6, -3., 2.};
107  RotationMatrix3D expectedFrame;
108  expectedFrame << rootHalf, 0., rootHalf, rootHalf, 0., -rootHalf, 0., 1., 0.;
109  // check without shift
110  CHECK_CLOSE_OR_SMALL(cylinderSurfaceObject->referenceFrame(
111  testContext, globalPosition, momentum),
112  expectedFrame, 1e-6, 1e-9);
113  // check with shift and different momentum
114  CHECK_CLOSE_OR_SMALL(cylinderSurfaceObject->referenceFrame(
115  testContext, globalPositionZ, momentum2),
116  expectedFrame, 1e-6, 1e-9);
117  //
119  Vector3D origin{0., 0., 0.};
120  Vector3D normal3D = {0., -1., 0.};
121  CHECK_CLOSE_ABS(cylinderSurfaceObject->normal(testContext, origin), normal3D,
122  1e-9);
123 
124  Vector3D pos45deg = {rootHalf, 1 + rootHalf, 0.};
125  Vector3D pos45degZ = {rootHalf, 1 + rootHalf, 4.};
126  Vector3D normal45deg = {rootHalf, rootHalf, 0.};
127  // test the normal vector
128  CHECK_CLOSE_ABS(cylinderSurfaceObject->normal(testContext, pos45deg),
129  normal45deg, 1e-6 * rootHalf);
130  // thest that the normal vector is independent of z coordinate
131  CHECK_CLOSE_ABS(cylinderSurfaceObject->normal(testContext, pos45degZ),
132  normal45deg, 1e-6 * rootHalf);
133  //
135  Vector2D positionPiBy2(1.0, 0.);
136  Vector3D normalAtPiBy2{std::cos(1.), std::sin(1.), 0.};
137  CHECK_CLOSE_ABS(cylinderSurfaceObject->normal(testContext, positionPiBy2),
138  normalAtPiBy2, 1e-9);
139 
140  //
142  Vector3D symmetryAxis{0., 0., 1.};
143  CHECK_CLOSE_ABS(cylinderSurfaceObject->rotSymmetryAxis(testContext),
144  symmetryAxis, 1e-9);
145  //
147  BOOST_CHECK_EQUAL(cylinderSurfaceObject->bounds().type(),
149  //
151  Vector2D localPosition{0., 0.};
152  cylinderSurfaceObject->localToGlobal(testContext, localPosition, momentum,
153  globalPosition);
154  Vector3D expectedPosition{1, 1, 2};
155  BOOST_CHECK_EQUAL(globalPosition, expectedPosition);
156  //
158  cylinderSurfaceObject->globalToLocal(testContext, globalPosition, momentum,
159  localPosition);
160  Vector2D expectedLocalPosition{0., 0.};
161  BOOST_CHECK_EQUAL(localPosition, expectedLocalPosition);
162  //
164  Vector3D offSurface{100, 1, 2};
165  BOOST_CHECK(cylinderSurfaceObject->isOnSurface(testContext, globalPosition,
166  momentum, true));
167  BOOST_CHECK(!cylinderSurfaceObject->isOnSurface(testContext, offSurface,
168  momentum, true));
169  //
171  Vector3D direction{-1., 0, 0};
172  auto intersect = cylinderSurfaceObject->intersectionEstimate(
173  testContext, offSurface, direction, false);
174  Intersection expectedIntersect{Vector3D{1, 1, 2}, 99.,
175  Intersection::Status::reachable};
176  // check the result
177  BOOST_CHECK(bool(intersect));
178  CHECK_CLOSE_ABS(intersect.position, expectedIntersect.position, 1e-9);
179  CHECK_CLOSE_ABS(intersect.pathLength, expectedIntersect.pathLength, 1e-9);
180 
182  auto surfaceIntersect = cylinderSurfaceObject->intersect(
183  testContext, offSurface, direction, false);
184  BOOST_CHECK(bool(surfaceIntersect));
185  // there is a second solution & and it should be valid
186  BOOST_CHECK(surfaceIntersect.alternative);
187  // And it's path should be further away then the primary solution
188  double pn = surfaceIntersect.intersection.pathLength;
189  double pa = surfaceIntersect.alternative.pathLength;
190  BOOST_CHECK(pn * pn < pa * pa);
191  //
193  CHECK_CLOSE_REL(cylinderSurfaceObject->pathCorrection(testContext, offSurface,
194  momentum.normalized()),
195  std::sqrt(3.), 0.01);
196  //
198  BOOST_CHECK_EQUAL(cylinderSurfaceObject->name(),
199  std::string("Acts::CylinderSurface"));
200  //
202  boost::test_tools::output_test_stream dumpOuput;
203  cylinderSurfaceObject->toStream(testContext, dumpOuput);
204  BOOST_CHECK(
205  dumpOuput.is_equal("Acts::CylinderSurface\n\
206  Center position (x, y, z) = (0.0000, 1.0000, 2.0000)\n\
207  Rotation: colX = (1.000000, 0.000000, 0.000000)\n\
208  colY = (0.000000, 1.000000, 0.000000)\n\
209  colZ = (0.000000, 0.000000, 1.000000)\n\
210  Bounds : Acts::CylinderBounds: (radius, halfLengthZ, halfPhiSector, averagePhi) = (1.0000000, 10.0000000, 3.1415927, 0.0000000)"));
211 }
212 
213 BOOST_AUTO_TEST_CASE(EqualityOperators) {
214  double radius(1.0), halfZ(10.);
215  Translation3D translation{0., 1., 2.};
216  auto pTransform = std::make_shared<const Transform3D>(translation);
217  auto cylinderSurfaceObject =
218  Surface::makeShared<CylinderSurface>(pTransform, radius, halfZ);
219  //
220  auto cylinderSurfaceObject2 =
221  Surface::makeShared<CylinderSurface>(pTransform, radius, halfZ);
222  //
224  BOOST_CHECK(*cylinderSurfaceObject == *cylinderSurfaceObject2);
225  //
226  BOOST_TEST_CHECKPOINT(
227  "Create and then assign a CylinderSurface object to the existing one");
229  auto assignedCylinderSurface =
230  Surface::makeShared<CylinderSurface>(nullptr, 6.6, 5.4);
231  *assignedCylinderSurface = *cylinderSurfaceObject;
233  BOOST_CHECK(*assignedCylinderSurface == *cylinderSurfaceObject);
234 }
235 
236 BOOST_AUTO_TEST_SUITE_END()
237 
238 } // namespace Test
239 
240 } // namespace Acts