ECCE @ 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 
13 #include <limits>
14 
17 #include "Acts/Surfaces/InfiniteBounds.hpp" //to get s_noBounds
18 #include "Acts/Surfaces/RectangleBounds.hpp" //to get s_noBounds
23 
24 #include "SurfaceStub.hpp"
25 
26 using boost::test_tools::output_test_stream;
27 namespace utf = boost::unit_test;
28 
29 namespace Acts {
31 class MockTrack {
32  public:
33  MockTrack(const Vector3D& mom, const Vector3D& pos) : m_mom(mom), m_pos(pos) {
34  // nop
35  }
36 
37  Vector3D momentum() const { return m_mom; }
38 
39  Vector3D position() const { return m_pos; }
40 
41  private:
44 };
45 
46 namespace Test {
47 
48 // Create a test context
50 
51 BOOST_AUTO_TEST_SUITE(Surfaces)
52 
53 
54 
56 BOOST_AUTO_TEST_CASE(SurfaceConstruction) {
57  // SurfaceStub s;
58  BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub().type());
59  SurfaceStub original;
60  BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub(original).type());
61  Translation3D translation{0., 1., 2.};
62  Transform3D transform(translation);
63  BOOST_CHECK_EQUAL(Surface::Other,
64  SurfaceStub(tgContext, original, transform).type());
65  // need some cruft to make the next one work
66  auto pTransform = std::make_shared<const Transform3D>(translation);
67  std::shared_ptr<const Acts::PlanarBounds> p =
68  std::make_shared<const RectangleBounds>(5., 10.);
69  DetectorElementStub detElement{pTransform, p, 0.2, nullptr};
70  BOOST_CHECK_EQUAL(Surface::Other, SurfaceStub(detElement).type());
71 }
72 
74 BOOST_AUTO_TEST_CASE(SurfaceProperties, *utf::expected_failures(1)) {
75  // build a test object , 'surface'
76  std::shared_ptr<const Acts::PlanarBounds> pPlanarBound =
77  std::make_shared<const RectangleBounds>(5., 10.);
78  Vector3D reference{0., 1., 2.};
79  Translation3D translation{0., 1., 2.};
80  auto pTransform = std::make_shared<const Transform3D>(translation);
81  auto pLayer = PlaneLayer::create(pTransform, pPlanarBound);
82  MaterialProperties properties{0.2, 0.2, 0.2, 20., 10, 5.};
83  auto pMaterial =
84  std::make_shared<const HomogeneousSurfaceMaterial>(properties);
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  // intersectionEstimate (should delegate to derived class method of same
104  // name)
105  Vector3D mom{100., 200., 300.};
107  tgContext, reference, mom.normalized(), false);
108  const Intersection ref{Vector3D{1, 1, 1}, 20.,
109  Intersection::Status::reachable};
110  BOOST_CHECK_EQUAL(ref.position, intersectionEstimate.position);
111  // isOnSurface
112  BOOST_CHECK(surface.isOnSurface(tgContext, reference, mom, false));
113  BOOST_CHECK(surface.isOnSurface(tgContext, reference, mom,
114  true)); // need to improve bounds()
115  // referenceFrame()
116  RotationMatrix3D unitary;
117  unitary << 1, 0, 0, 0, 1, 0, 0, 0, 1;
118  auto referenceFrame = surface.referenceFrame(
119  tgContext, reference, mom); // need more complex case to test
120  BOOST_CHECK_EQUAL(referenceFrame, unitary);
121  // normal()
122  auto normal = surface.Surface::normal(tgContext,
123  reference); // needs more complex
124  // test
125  Vector3D zero{0., 0., 0.};
126  BOOST_CHECK_EQUAL(zero, normal);
127  // pathCorrection is pure virtual
128  // surfaceMaterial()
129  MaterialProperties newProperties{0.5, 0.5, 0.5, 20., 10., 5.};
130  auto pNewMaterial =
131  std::make_shared<const HomogeneousSurfaceMaterial>(newProperties);
132  surface.assignSurfaceMaterial(pNewMaterial);
133  BOOST_CHECK_EQUAL(surface.surfaceMaterial(),
134  pNewMaterial.get()); // passes ??
135  //
136  CHECK_CLOSE_OR_SMALL(surface.transform(tgContext), *pTransform, 1e-6, 1e-9);
137  // type() is pure virtual
138 }
139 
140 BOOST_AUTO_TEST_CASE(EqualityOperators) {
141  // build some test objects
142  std::shared_ptr<const Acts::PlanarBounds> pPlanarBound =
143  std::make_shared<const RectangleBounds>(5., 10.);
144  Vector3D reference{0., 1., 2.};
145  Translation3D translation1{0., 1., 2.};
146  Translation3D translation2{1., 1., 2.};
147  auto pTransform1 = std::make_shared<const Transform3D>(translation1);
148  auto pTransform2 = std::make_shared<const Transform3D>(translation2);
149  auto pLayer = PlaneLayer::create(pTransform1, pPlanarBound);
150  MaterialProperties properties{1., 1., 1., 20., 10, 5.};
151  auto pMaterial =
152  std::make_shared<const HomogeneousSurfaceMaterial>(properties);
153  DetectorElementStub detElement1{pTransform1, pPlanarBound, 0.2, pMaterial};
154  DetectorElementStub detElement2{pTransform1, pPlanarBound, 0.3, pMaterial};
155  DetectorElementStub detElement3{pTransform2, pPlanarBound, 0.3, pMaterial};
156  //
157  SurfaceStub surface1(detElement1);
158  SurfaceStub surface2(detElement1); // 1 and 2 are the same
159  SurfaceStub surface3(detElement2); // 3 differs in thickness
160  SurfaceStub surface4(detElement3); // 4 has a different transform and id
161  //
162  BOOST_CHECK(surface1 == surface2);
163  //
164  // remove test for the moment,
165  // surfaces do not have a concept of thickness (only detector elements have)
166  // only thickness is different here
167  //
168  // BOOST_CHECK_NE(surface1, surface3); // will fail
169  //
170  BOOST_CHECK(surface1 != surface4);
171 }
172 BOOST_AUTO_TEST_SUITE_END()
173 
174 } // namespace Test
175 
176 } // namespace Acts