ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlaneSurfaceTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PlaneSurfaceTests.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(PlaneSurfaces)
34 BOOST_AUTO_TEST_CASE(PlaneSurfaceConstruction) {
35  // PlaneSurface default constructor is deleted
36  // bounds object, rectangle type
37  auto rBounds = std::make_shared<const RectangleBounds>(3., 4.);
40  Translation3D translation{0., 1., 2.};
41  auto pTransform = std::make_shared<const Transform3D>(translation);
42  std::shared_ptr<const Transform3D> pNullTransform{};
43  // constructor with nullptr transform
44  BOOST_CHECK_EQUAL(
45  Surface::makeShared<PlaneSurface>(pNullTransform, rBounds)->type(),
47  // constructor with transform
48  BOOST_CHECK_EQUAL(
49  Surface::makeShared<PlaneSurface>(pTransform, rBounds)->type(),
52  auto planeSurfaceObject =
53  Surface::makeShared<PlaneSurface>(pTransform, rBounds);
54  auto copiedPlaneSurface =
55  Surface::makeShared<PlaneSurface>(*planeSurfaceObject);
56  BOOST_CHECK_EQUAL(copiedPlaneSurface->type(), Surface::Plane);
57  BOOST_CHECK(*copiedPlaneSurface == *planeSurfaceObject);
58  //
60  auto copiedTransformedPlaneSurface = Surface::makeShared<PlaneSurface>(
61  tgContext, *planeSurfaceObject, *pTransform);
62  BOOST_CHECK_EQUAL(copiedTransformedPlaneSurface->type(), Surface::Plane);
63 
65  DetectorElementStub detElem;
66  BOOST_CHECK_THROW(
67  auto nullBounds = Surface::makeShared<PlaneSurface>(nullptr, detElem),
69 }
70 //
72 BOOST_AUTO_TEST_CASE(PlaneSurfaceProperties) {
73  // bounds object, rectangle type
74  auto rBounds = std::make_shared<const RectangleBounds>(3., 4.);
76  Translation3D translation{0., 1., 2.};
77  auto pTransform = std::make_shared<const Transform3D>(translation);
78  auto planeSurfaceObject =
79  Surface::makeShared<PlaneSurface>(pTransform, rBounds);
80  // Is it in the right place?
81  Translation3D translation2{0., 2., 4.};
82  auto pTransform2 = std::make_shared<const Transform3D>(translation2);
83  auto planeSurfaceObject2 =
84  Surface::makeShared<PlaneSurface>(pTransform2, rBounds);
86  BOOST_CHECK_EQUAL(planeSurfaceObject->type(), Surface::Plane);
87  //
89  Vector3D binningPosition{0., 1., 2.};
90  BOOST_CHECK_EQUAL(
91  planeSurfaceObject->binningPosition(tgContext, BinningValue::binX),
92  binningPosition);
93  //
95  Vector3D globalPosition{2.0, 2.0, 0.0};
96  Vector3D momentum{1.e6, 1.e6, 1.e6};
97  RotationMatrix3D expectedFrame;
98  expectedFrame << 1., 0., 0., 0., 1., 0., 0., 0., 1.;
99 
101  planeSurfaceObject->referenceFrame(tgContext, globalPosition, momentum),
102  expectedFrame, 1e-6, 1e-9);
103  //
105  Vector3D normal3D(0., 0., 1.);
106  BOOST_CHECK_EQUAL(planeSurfaceObject->normal(tgContext), normal3D);
107  //
109  BOOST_CHECK_EQUAL(planeSurfaceObject->bounds().type(),
111 
113  Vector2D localPosition{1.5, 1.7};
114  planeSurfaceObject->localToGlobal(tgContext, localPosition, momentum,
115  globalPosition);
116  //
117  // expected position is the translated one
118  Vector3D expectedPosition{1.5 + translation.x(), 1.7 + translation.y(),
119  translation.z()};
120 
121  CHECK_CLOSE_REL(globalPosition, expectedPosition, 1e-2);
122  //
124  planeSurfaceObject->globalToLocal(tgContext, globalPosition, momentum,
125  localPosition);
126  Vector2D expectedLocalPosition{1.5, 1.7};
127 
128  CHECK_CLOSE_REL(localPosition, expectedLocalPosition, 1e-2);
129 
131  Vector3D offSurface{0, 1, -2.};
132  BOOST_CHECK(planeSurfaceObject->isOnSurface(tgContext, globalPosition,
133  momentum, true));
134  BOOST_CHECK(
135  !planeSurfaceObject->isOnSurface(tgContext, offSurface, momentum, true));
136  //
138  Vector3D direction{0., 0., 1.};
139  auto intersect = planeSurfaceObject->intersectionEstimate(
140  tgContext, offSurface, direction, true);
141  Intersection expectedIntersect{Vector3D{0, 1, 2}, 4.,
142  Intersection::Status::reachable};
143  BOOST_CHECK(bool(intersect));
144  BOOST_CHECK_EQUAL(intersect.position, expectedIntersect.position);
145  BOOST_CHECK_EQUAL(intersect.pathLength, expectedIntersect.pathLength);
146  //
147 
149  CHECK_CLOSE_REL(planeSurfaceObject->pathCorrection(tgContext, offSurface,
150  momentum.normalized()),
151  std::sqrt(3), 0.01);
152  //
154  BOOST_CHECK_EQUAL(planeSurfaceObject->name(),
155  std::string("Acts::PlaneSurface"));
156  //
158  // TODO 2017-04-12 msmk: check how to correctly check output
159  // boost::test_tools::output_test_stream dumpOuput;
160  // planeSurfaceObject.toStream(dumpOuput);
161  // BOOST_CHECK(dumpOuput.is_equal(
162  // "Acts::PlaneSurface\n"
163  // " Center position (x, y, z) = (0.0000, 1.0000, 2.0000)\n"
164  // " Rotation: colX = (1.000000, 0.000000, 0.000000)\n"
165  // " colY = (0.000000, 1.000000, 0.000000)\n"
166  // " colZ = (0.000000, 0.000000, 1.000000)\n"
167  // " Bounds : Acts::ConeBounds: (tanAlpha, minZ, maxZ, averagePhi,
168  // halfPhiSector) = (0.4142136, 0.0000000, inf, 0.0000000,
169  // 3.1415927)"));
170 }
171 
172 BOOST_AUTO_TEST_CASE(EqualityOperators) {
173  // rectangle bounds
174  auto rBounds = std::make_shared<const RectangleBounds>(3., 4.);
175  Translation3D translation{0., 1., 2.};
176  auto pTransform = std::make_shared<const Transform3D>(translation);
177  auto planeSurfaceObject =
178  Surface::makeShared<PlaneSurface>(pTransform, rBounds);
179  auto planeSurfaceObject2 =
180  Surface::makeShared<PlaneSurface>(pTransform, rBounds);
181  //
183  BOOST_CHECK(*planeSurfaceObject == *planeSurfaceObject2);
184  //
185  BOOST_TEST_CHECKPOINT(
186  "Create and then assign a PlaneSurface object to the existing one");
188  auto assignedPlaneSurface =
189  Surface::makeShared<PlaneSurface>(nullptr, nullptr);
190  *assignedPlaneSurface = *planeSurfaceObject;
192  BOOST_CHECK(*assignedPlaneSurface == *planeSurfaceObject);
193 }
194 
195 BOOST_AUTO_TEST_SUITE_END()
196 
197 } // namespace Test
198 
199 } // namespace Acts