ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LineSurfaceTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LineSurfaceTests.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 
21 
22 namespace utf = boost::unit_test;
23 
24 namespace Acts {
25 
26 namespace Test {
27 
28 // Create a test context
30 
31 // using boost::test_tools::output_test_stream;
32 
33 BOOST_AUTO_TEST_SUITE(Surfaces)
35 BOOST_AUTO_TEST_CASE(LineSurface_Constructors_test) {
36  // Default ctor is deleted
37  // LineSurfaceStub l;
38  // ctor with translation, radius, halfz
39  Translation3D translation{0., 1., 2.};
40  Transform3D transform(translation);
41  auto pTransform = std::make_shared<const Transform3D>(translation);
42  const double radius{2.0}, halfz{20.};
43  BOOST_CHECK(LineSurfaceStub(pTransform, radius, halfz).constructedOk());
44  // ctor with nullptr for LineBounds
45  BOOST_CHECK(LineSurfaceStub(pTransform).constructedOk());
46  // ctor with LineBounds
47  auto pLineBounds = std::make_shared<const LineBounds>(2., 10.0);
48  BOOST_CHECK(LineSurfaceStub(pTransform, pLineBounds).constructedOk());
49  // ctor with LineBounds, detector element, Identifier
50  MaterialProperties properties{1., 1., 1., 20., 10, 5.};
51  auto pMaterial =
52  std::make_shared<const HomogeneousSurfaceMaterial>(properties);
53  DetectorElementStub detElement{pTransform, pLineBounds, 0.2, pMaterial};
54  BOOST_CHECK(LineSurfaceStub(pLineBounds, detElement).constructedOk());
55  LineSurfaceStub lineToCopy(pTransform, 2.0, 20.);
56  // Copy ctor
57  BOOST_CHECK(LineSurfaceStub(lineToCopy).constructedOk());
58  // Copied and transformed ctor
59  BOOST_CHECK(
60  LineSurfaceStub(tgContext, lineToCopy, transform).constructedOk());
61 
63  DetectorElementStub detElem;
64  BOOST_CHECK_THROW(LineSurfaceStub nullBounds(nullptr, detElem),
66 
67  BOOST_TEST_MESSAGE(
68  "All LineSurface constructors are callable without problem");
69 }
71 BOOST_AUTO_TEST_CASE(LineSurface_allNamedMethods_test) {
72  // binningPosition()
73  Translation3D translation{0., 1., 2.};
74  Transform3D transform(translation);
75  auto pTransform = std::make_shared<const Transform3D>(translation);
76  LineSurfaceStub line(pTransform, 2.0, 20.);
77  Vector3D referencePosition{0., 1., 2.};
78  CHECK_CLOSE_ABS(referencePosition, line.binningPosition(tgContext, binX),
79  1e-6);
80  //
81  // bounds()
82  auto pLineBounds = std::make_shared<const LineBounds>(2., 10.0);
83  LineSurfaceStub boundedLine(pTransform, pLineBounds);
84  const LineBounds& bounds =
85  dynamic_cast<const LineBounds&>(boundedLine.bounds());
86  BOOST_CHECK_EQUAL(bounds, LineBounds(2., 10.0));
87  //
88  // globalToLocal()
89  Vector3D gpos{0., 1., 0.};
90  const Vector3D mom{20., 0., 0.}; // needs more realistic parameters
91  Vector2D localPosition;
92  BOOST_CHECK(line.globalToLocal(tgContext, gpos, mom, localPosition));
93  const Vector2D expectedResult{0, -2};
94  CHECK_CLOSE_ABS(expectedResult, localPosition, 1e-6);
95  //
96  // intersectionEstimate
97  const Vector3D direction{0., 1., 2.};
98  BoundaryCheck bcheck(false);
99  auto intersection = line.intersectionEstimate(tgContext, {0., 0., 0.},
100  direction.normalized(), bcheck);
101  BOOST_CHECK(bool(intersection));
102  Vector3D expectedIntersection(0, 1., 2.);
103  CHECK_CLOSE_ABS(intersection.position, expectedIntersection,
104  1e-6); // need more tests..
105  //
106  // isOnSurface
107  const Vector3D insidePosition{0., 2.5, 0.};
108  BOOST_CHECK(line.isOnSurface(tgContext, insidePosition, mom,
109  false)); // need better test here
110  const Vector3D outsidePosition{100., 100., 200.};
111  BOOST_CHECK(!line.isOnSurface(tgContext, outsidePosition, mom, true));
112  //
113  // localToGlobal
114  Vector3D returnedGlobalPosition{0., 0., 0.};
115  // Vector2D localPosition{0., 0.};
116  const Vector3D momentum{300., 200., 0.}; // find better values!
117  line.localToGlobal(tgContext, localPosition, momentum,
118  returnedGlobalPosition);
119  const Vector3D expectedGlobalPosition{0, 1, 0};
120  CHECK_CLOSE_ABS(returnedGlobalPosition, expectedGlobalPosition, 1e-6);
121  //
122  // referenceFrame
123  Vector3D globalPosition{0., 0., 0.};
124  auto returnedRotationMatrix =
125  line.referenceFrame(tgContext, globalPosition, momentum);
126  double v0 = std::cos(std::atan(2. / 3.));
127  double v1 = std::sin(std::atan(2. / 3.));
128  RotationMatrix3D expectedRotationMatrix;
129  expectedRotationMatrix << -v1, 0., v0, v0, 0., v1, 0., 1., -0.;
130  // std::cout<<returnedRotationMatrix<<std::endl;
131  // std::cout<<expectedRotationMatrix<<std::endl;
132  CHECK_CLOSE_OR_SMALL(returnedRotationMatrix, expectedRotationMatrix, 1e-6,
133  1e-9);
134  //
135  // name()
136  boost::test_tools::output_test_stream output;
137  output << line.name();
138  BOOST_CHECK(output.is_equal("Acts::LineSurface"));
139  //
140  // normal
141  Vector3D normalVector{0., 0., 1.}; // line direction is same as normal????
142  CHECK_CLOSE_ABS(line.normal(tgContext), normalVector, 1e-6);
143  //
144  // pathCorrection
145  auto any3DVector = normalVector;
146  CHECK_CLOSE_REL(line.pathCorrection(tgContext, any3DVector, any3DVector), 1.,
147  1e-6);
148 }
150 BOOST_AUTO_TEST_CASE(LineSurface_assignment_test) {
151  Translation3D translation{0., 1., 2.};
152  Transform3D transform(translation);
153  auto pTransform = std::make_shared<const Transform3D>(translation);
154  LineSurfaceStub originalLine(pTransform, 2.0, 20.);
155  LineSurfaceStub assignedLine(pTransform, 1.0, 1.0);
156  BOOST_CHECK(assignedLine != originalLine); // operator != from base
157  assignedLine = originalLine;
158  BOOST_CHECK(assignedLine == originalLine); // operator == from base
159 }
160 
161 BOOST_AUTO_TEST_SUITE_END()
162 
163 } // namespace Test
164 
165 } // namespace Acts