ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DiscSurfaceTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DiscSurfaceTests.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 
22 
23 namespace utf = boost::unit_test;
24 namespace tt = boost::test_tools;
25 
26 namespace Acts {
27 
28 namespace Test {
29 // using boost::test_tools::output_test_stream;
30 // Create a test context
32 
33 BOOST_AUTO_TEST_SUITE(Surfaces)
35 BOOST_AUTO_TEST_CASE(DiscSurface_constructors_test) {
36  // default constructor is deleted
37  // scaffolding...
38  double rMin(1.0), rMax(5.0), halfPhiSector(M_PI / 8.);
39  //
41  BOOST_CHECK_NO_THROW(
42  Surface::makeShared<DiscSurface>(nullptr, rMin, rMax, halfPhiSector));
43  //
45  BOOST_CHECK_NO_THROW(Surface::makeShared<DiscSurface>(nullptr, rMin, rMax));
46  //
48  Translation3D translation{0., 1., 2.};
49  auto pTransform = std::make_shared<const Transform3D>(translation);
50  BOOST_CHECK_NO_THROW(
51  Surface::makeShared<DiscSurface>(pTransform, rMin, rMax, halfPhiSector));
52  //
54  auto anotherDiscSurface =
55  Surface::makeShared<DiscSurface>(pTransform, rMin, rMax, halfPhiSector);
56  // N.B. Just using
57  // BOOST_CHECK_NO_THROW(Surface::makeShared<DiscSurface>(anotherDiscSurface))
58  // tries to call
59  // the (deleted) default constructor.
60  auto copiedSurface = Surface::makeShared<DiscSurface>(*anotherDiscSurface);
61  BOOST_TEST_MESSAGE("Copy constructed DiscSurface ok");
62  //
64  BOOST_CHECK_NO_THROW(Surface::makeShared<DiscSurface>(
65  tgContext, *anotherDiscSurface, *pTransform));
66 
68  DetectorElementStub detElem;
69  BOOST_CHECK_THROW(
70  auto nullBounds = Surface::makeShared<DiscSurface>(nullptr, detElem),
72 }
73 
75 BOOST_AUTO_TEST_CASE(DiscSurface_properties_test, *utf::expected_failures(2)) {
76  Vector3D origin3D{0, 0, 0};
77  std::shared_ptr<const Transform3D> pTransform; // nullptr
78  double rMin(1.0), rMax(5.0), halfPhiSector(M_PI / 8.);
79  auto discSurfaceObject =
80  Surface::makeShared<DiscSurface>(pTransform, rMin, rMax, halfPhiSector);
81  //
83  BOOST_CHECK_EQUAL(discSurfaceObject->type(), Surface::Disc);
84  //
86  Vector3D zAxis{0, 0, 1};
87  BOOST_CHECK_EQUAL(discSurfaceObject->normal(tgContext), zAxis);
88  //
90  Vector2D lpos(2.0, 0.05);
91  BOOST_CHECK_EQUAL(discSurfaceObject->normal(tgContext, lpos), zAxis);
92  //
94  // auto binningPosition=
95  // discSurfaceObject.binningPosition(BinningValue::binRPhi );
96  // std::cout<<binningPosition<<std::endl;
97  BOOST_CHECK_EQUAL(
98  discSurfaceObject->binningPosition(tgContext, BinningValue::binRPhi),
99  origin3D);
100  //
102  BOOST_CHECK_EQUAL(discSurfaceObject->bounds().type(), SurfaceBounds::eDisc);
103  //
104  Vector3D ignoredMomentum{0., 0., 0.};
106  Vector3D point3DNotInSector{0.0, 1.2, 0};
107  Vector3D point3DOnSurface{1.2, 0.0, 0};
108  BOOST_CHECK(!discSurfaceObject->isOnSurface(
109  tgContext, point3DNotInSector, ignoredMomentum, true)); // passes
110  BOOST_CHECK(discSurfaceObject->isOnSurface(tgContext, point3DOnSurface,
111  ignoredMomentum, true)); // passes
112  //
114  Vector3D returnedPosition{10.9, 8.7, 6.5};
115  Vector3D expectedPosition{1.2, 0, 0};
116  Vector2D rPhiOnDisc{1.2, 0.0};
117  Vector2D rPhiNotInSector{1.2, M_PI}; // outside sector at Phi=0, +/- pi/8
118  discSurfaceObject->localToGlobal(tgContext, rPhiOnDisc, ignoredMomentum,
119  returnedPosition);
120  CHECK_CLOSE_ABS(returnedPosition, expectedPosition, 1e-6);
121  //
122  discSurfaceObject->localToGlobal(tgContext, rPhiNotInSector, ignoredMomentum,
123  returnedPosition);
124  Vector3D expectedNonPosition{-1.2, 0, 0};
125  CHECK_CLOSE_ABS(returnedPosition, expectedNonPosition, 1e-6);
126  //
128  Vector2D returnedLocalPosition{33., 44.};
129  Vector2D expectedLocalPosition{1.2, 0.0};
130  BOOST_CHECK(discSurfaceObject->globalToLocal(tgContext, point3DOnSurface,
131  ignoredMomentum,
132  returnedLocalPosition)); // pass
133  CHECK_CLOSE_ABS(returnedLocalPosition, expectedLocalPosition, 1e-6);
134 
135  // Global to local does not check inside bounds
136  BOOST_CHECK(discSurfaceObject->globalToLocal(
137  tgContext, point3DNotInSector, ignoredMomentum, returnedLocalPosition));
138  //
139  Vector3D pointOutsideR{0.0, 100., 0};
140  BOOST_CHECK(discSurfaceObject->globalToLocal(
141  tgContext, pointOutsideR, ignoredMomentum, returnedLocalPosition));
142  //
144  Vector2D rPhi1_1{std::sqrt(2.), M_PI / 4.};
145  Vector2D cartesian1_1{1., 1.};
146  CHECK_CLOSE_REL(discSurfaceObject->localPolarToCartesian(rPhi1_1),
147  cartesian1_1, 1e-6);
148  //
150  CHECK_CLOSE_REL(discSurfaceObject->localCartesianToPolar(cartesian1_1),
151  rPhi1_1, 1e-6);
152  //
154  CHECK_CLOSE_REL(discSurfaceObject->localPolarToLocalCartesian(rPhi1_1),
155  cartesian1_1, 1e-6);
156  //
158  Vector3D cartesian3D1_1{1., 1., 0.};
160  discSurfaceObject->localCartesianToGlobal(tgContext, cartesian1_1),
161  cartesian3D1_1, 1e-6);
162  //
165  discSurfaceObject->globalToLocalCartesian(tgContext, cartesian3D1_1),
166  cartesian1_1, 1e-6);
167  //
169  double projected3DMomentum = std::sqrt(3.) * 1.e6;
170  Vector3D momentum{projected3DMomentum, projected3DMomentum,
171  projected3DMomentum};
172  Vector3D ignoredPosition{1.1, 2.2, 3.3};
173  CHECK_CLOSE_REL(discSurfaceObject->pathCorrection(tgContext, ignoredPosition,
174  momentum.normalized()),
175  std::sqrt(3), 0.01);
176  //
178  Vector3D globalPosition{1.2, 0.0, -10.};
179  Vector3D direction{0., 0., 1.}; // must be normalised
180  Vector3D expected{1.2, 0.0, 0.0};
181  // intersect is a struct of (Vector3D) position, pathLength, distance and
182  // (bool) valid
183  auto intersect = discSurfaceObject->intersectionEstimate(
184  tgContext, globalPosition, direction, false);
185  Intersection expectedIntersect{Vector3D{1.2, 0., 0.}, 10.,
186  Intersection::Status::reachable};
187  BOOST_CHECK(bool(intersect));
188  CHECK_CLOSE_ABS(intersect.position, expectedIntersect.position, 1e-9);
189  CHECK_CLOSE_ABS(intersect.pathLength, expectedIntersect.pathLength, 1e-9);
190  //
192  boost::test_tools::output_test_stream nameOuput;
193  nameOuput << discSurfaceObject->name();
194  BOOST_CHECK(nameOuput.is_equal("Acts::DiscSurface"));
195 }
196 //
198 BOOST_AUTO_TEST_CASE(DiscSurface_assignment_test) {
199  Vector3D origin3D{0, 0, 0};
200  std::shared_ptr<const Transform3D> pTransform; // nullptr
201  double rMin(1.0), rMax(5.0), halfPhiSector(M_PI / 8.);
202  auto discSurfaceObject =
203  Surface::makeShared<DiscSurface>(pTransform, rMin, rMax, halfPhiSector);
204  auto assignedDisc = Surface::makeShared<DiscSurface>(nullptr, 2.2, 4.4, 0.07);
205  //
206  BOOST_CHECK_NO_THROW(*assignedDisc = *discSurfaceObject);
207  BOOST_CHECK((*assignedDisc) == (*discSurfaceObject));
208 }
209 
210 BOOST_AUTO_TEST_SUITE_END()
211 
212 } // namespace Test
213 
214 } // namespace Acts