EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SurfaceTests.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 
15 #include "Acts/Surfaces/InfiniteBounds.hpp" //to get s_noBounds
16 #include "Acts/Surfaces/RectangleBounds.hpp" //to get s_noBounds
22 
23 #include <limits>
24 
25 #include "SurfaceStub.hpp"
26 
27 using boost::test_tools::output_test_stream;
28 namespace utf = boost::unit_test;
29 
30 namespace Acts {
32 class MockTrack {
33  public:
34  MockTrack(const Vector3D& mom, const Vector3D& pos) : m_mom(mom), m_pos(pos) {
35  // nop
36  }
37 
38  Vector3D momentum() const { return m_mom; }
39 
40  Vector3D position() const { return m_pos; }
41 
42  private:
45 };
46 
47 namespace Test {
48 
49 // Create a test context
51 
52 BOOST_AUTO_TEST_SUITE(Surfaces)
53 
54 
55 
57 BOOST_AUTO_TEST_CASE(SurfaceConstruction) {
58  // SurfaceStub s;
59  BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub().type());
60  SurfaceStub original;
61  BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub(original).type());
62  Translation3D translation{0., 1., 2.};
63  Transform3D transform(translation);
64  BOOST_CHECK_EQUAL(Surface::Other,
65  SurfaceStub(tgContext, original, transform).type());
66  // need some cruft to make the next one work
67  auto pTransform = Transform3D(translation);
68  std::shared_ptr<const Acts::PlanarBounds> p =
69  std::make_shared<const RectangleBounds>(5., 10.);
70  DetectorElementStub detElement{pTransform, p, 0.2, nullptr};
71  BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub(detElement).type());
72 }
73 
75 BOOST_AUTO_TEST_CASE(SurfaceProperties, *utf::expected_failures(1)) {
76  // build a test object , 'surface'
77  std::shared_ptr<const Acts::PlanarBounds> pPlanarBound =
78  std::make_shared<const RectangleBounds>(5., 10.);
79  Vector3D reference{0., 1., 2.};
80  Translation3D translation{0., 1., 2.};
81  auto pTransform = Transform3D(translation);
82  auto pLayer = PlaneLayer::create(pTransform, pPlanarBound);
83  auto pMaterial =
84  std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
85  DetectorElementStub detElement{pTransform, pPlanarBound, 0.2, pMaterial};
86  SurfaceStub surface(detElement);
87  // associatedDetectorElement
88  BOOST_CHECK_EQUAL(surface.associatedDetectorElement(), &detElement);
89  // test associatelayer, associatedLayer
90  surface.associateLayer(*pLayer);
91  BOOST_CHECK_EQUAL(surface.associatedLayer(), pLayer.get());
92  // associated Material is not set to the surface
93  // it is set to the detector element surface though
94  BOOST_CHECK_NE(surface.surfaceMaterial(), pMaterial.get());
95  // center()
96  CHECK_CLOSE_OR_SMALL(reference, surface.center(tgContext), 1e-6, 1e-9);
97  // insideBounds
98  Vector2D localPosition{0.1, 3.0};
99  BOOST_CHECK(surface.insideBounds(localPosition));
100  Vector2D outside{20., 20.};
101  BOOST_CHECK(!surface.insideBounds(
102  outside)); // fails: m_bounds only in derived classes
103  Vector3D mom{100., 200., 300.};
104  // isOnSurface
105  BOOST_CHECK(surface.isOnSurface(tgContext, reference, mom, false));
106  BOOST_CHECK(surface.isOnSurface(tgContext, reference, mom,
107  true)); // need to improve bounds()
108  // referenceFrame()
109  RotationMatrix3D unitary;
110  unitary << 1, 0, 0, 0, 1, 0, 0, 0, 1;
111  auto referenceFrame = surface.referenceFrame(
112  tgContext, reference, mom); // need more complex case to test
113  BOOST_CHECK_EQUAL(referenceFrame, unitary);
114  // normal()
115  auto normal = surface.Surface::normal(tgContext,
116  reference); // needs more complex
117  // test
118  Vector3D zero{0., 0., 0.};
119  BOOST_CHECK_EQUAL(zero, normal);
120  // pathCorrection is pure virtual
121  // surfaceMaterial()
122  auto pNewMaterial =
123  std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
124  surface.assignSurfaceMaterial(pNewMaterial);
125  BOOST_CHECK_EQUAL(surface.surfaceMaterial(),
126  pNewMaterial.get()); // passes ??
127  //
128  CHECK_CLOSE_OR_SMALL(surface.transform(tgContext), pTransform, 1e-6, 1e-9);
129  // type() is pure virtual
130 }
131 
132 BOOST_AUTO_TEST_CASE(EqualityOperators) {
133  // build some test objects
134  std::shared_ptr<const Acts::PlanarBounds> pPlanarBound =
135  std::make_shared<const RectangleBounds>(5., 10.);
136  Vector3D reference{0., 1., 2.};
137  Translation3D translation1{0., 1., 2.};
138  Translation3D translation2{1., 1., 2.};
139  auto pTransform1 = Transform3D(translation1);
140  auto pTransform2 = Transform3D(translation2);
141  // build a planeSurface to be compared
142  auto planeSurface =
143  Surface::makeShared<PlaneSurface>(pTransform1, pPlanarBound);
144  auto pLayer = PlaneLayer::create(pTransform1, pPlanarBound);
145  auto pMaterial =
146  std::make_shared<const HomogeneousSurfaceMaterial>(makePercentSlab());
147  DetectorElementStub detElement1{pTransform1, pPlanarBound, 0.2, pMaterial};
148  DetectorElementStub detElement2{pTransform1, pPlanarBound, 0.3, pMaterial};
149  DetectorElementStub detElement3{pTransform2, pPlanarBound, 0.3, pMaterial};
150  //
151  SurfaceStub surface1(detElement1);
152  SurfaceStub surface2(detElement1); // 1 and 2 are the same
153  SurfaceStub surface3(detElement2); // 3 differs in thickness
154  SurfaceStub surface4(detElement3); // 4 has a different transform and id
155  SurfaceStub surface5(detElement1);
156  surface5.assignSurfaceMaterial(pMaterial); // 5 has non-null surface matrial
157  //
158  BOOST_CHECK(surface1 == surface2);
159  //
160  // remove test for the moment,
161  // surfaces do not have a concept of thickness (only detector elements have)
162  // only thickness is different here
163  //
164  // BOOST_CHECK_NE(surface1, surface3); // will fail
165  //
166  BOOST_CHECK(surface1 != surface4);
167  //
168  BOOST_CHECK(surface1 != surface5);
169  //
170  BOOST_CHECK(surface1 != *planeSurface);
171  // Test the getSharedPtr
172  const auto surfacePtr = Surface::makeShared<const SurfaceStub>(detElement1);
173  const auto sharedSurfacePtr = surfacePtr->getSharedPtr();
174  BOOST_CHECK(*surfacePtr == *sharedSurfacePtr);
175 }
176 BOOST_AUTO_TEST_SUITE_END()
177 
178 } // namespace Test
179 
180 } // namespace Acts