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