ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConeSurfaceTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ConeSurfaceTests.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 
19 
20 namespace tt = boost::test_tools;
21 using boost::test_tools::output_test_stream;
22 namespace utf = boost::unit_test;
23 
24 namespace Acts {
25 
26 namespace Test {
27 
28 // Create a test context
30 
31 BOOST_AUTO_TEST_SUITE(ConeSurfaces)
33 BOOST_AUTO_TEST_CASE(ConeSurfaceConstruction) {
34  // ConeSurface default constructor is deleted
35  //
38  double alpha{M_PI / 8.}, halfPhiSector{M_PI / 16.}, zMin{1.0}, zMax{10.};
39  bool symmetric(false);
40  Translation3D translation{0., 1., 2.};
41  auto pTransform = std::make_shared<const Transform3D>(translation);
42  std::shared_ptr<const Transform3D> pNullTransform{};
43  BOOST_CHECK_EQUAL(
44  Surface::makeShared<ConeSurface>(pNullTransform, alpha, symmetric)
45  ->type(),
47  BOOST_CHECK_EQUAL(
48  Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric)->type(),
50  //
52  BOOST_CHECK_EQUAL(Surface::makeShared<ConeSurface>(pTransform, alpha, zMin,
53  zMax, halfPhiSector)
54  ->type(),
56  //
57 
59  // ConeBounds (double alpha, double zmin, double zmax, double halfphi=M_PI,
60  // double avphi=0.)
61  auto pConeBounds =
62  std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
63  BOOST_CHECK_EQUAL(
64  Surface::makeShared<ConeSurface>(pTransform, pConeBounds)->type(),
66  //
67  //
69  auto coneSurfaceObject =
70  Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
71  auto copiedConeSurface = Surface::makeShared<ConeSurface>(*coneSurfaceObject);
72  BOOST_CHECK_EQUAL(copiedConeSurface->type(), Surface::Cone);
73  BOOST_CHECK(*copiedConeSurface == *coneSurfaceObject);
74  //
76  auto copiedTransformedConeSurface = Surface::makeShared<ConeSurface>(
77  tgContext, *coneSurfaceObject, *pTransform);
78  BOOST_CHECK_EQUAL(copiedTransformedConeSurface->type(), Surface::Cone);
79 
81  BOOST_CHECK_THROW(
82  auto nullBounds = Surface::makeShared<ConeSurface>(nullptr, nullptr),
84 }
85 //
87 BOOST_AUTO_TEST_CASE(ConeSurfaceProperties) {
89  double alpha{M_PI / 8.} /*,halfPhiSector{M_PI/16.}, zMin{1.0}, zMax{10.}*/;
90  bool symmetric(false);
91  Translation3D translation{0., 1., 2.};
92  auto pTransform = std::make_shared<const Transform3D>(translation);
93  auto coneSurfaceObject =
94  Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
95  //
97  BOOST_CHECK_EQUAL(coneSurfaceObject->type(), Surface::Cone);
98  //
100  Vector3D binningPosition{0., 1., 2.};
102  coneSurfaceObject->binningPosition(tgContext, BinningValue::binPhi),
103  binningPosition, 1e-6);
104  //
106  Vector3D globalPosition{2.0, 2.0, 2.0};
107  Vector3D momentum{1.e6, 1.e6, 1.e6};
108  double rootHalf = std::sqrt(0.5);
109  RotationMatrix3D expectedFrame;
110  expectedFrame << -rootHalf, 0., rootHalf, rootHalf, 0., rootHalf, 0., 1., 0.;
112  coneSurfaceObject->referenceFrame(tgContext, globalPosition, momentum),
113  expectedFrame, 1e-6, 1e-9);
114  //
116  Vector3D origin{0., 0., 0.};
117  Vector3D normal3D = {0., -1., 0.};
118  CHECK_CLOSE_ABS(coneSurfaceObject->normal(tgContext, origin), normal3D, 1e-6);
119  //
121  Vector2D positionPiBy2(1.0, M_PI / 2.);
122  Vector3D normalAtPiBy2{0.0312768, 0.92335, -0.382683};
123 
124  CHECK_CLOSE_OR_SMALL(coneSurfaceObject->normal(tgContext, positionPiBy2),
125  normalAtPiBy2, 1e-2, 1e-9);
126  //
128  Vector3D symmetryAxis{0., 0., 1.};
129  CHECK_CLOSE_ABS(coneSurfaceObject->rotSymmetryAxis(tgContext), symmetryAxis,
130  1e-6);
131  //
133  BOOST_CHECK_EQUAL(coneSurfaceObject->bounds().type(), SurfaceBounds::eCone);
134  //
136  Vector2D localPosition{1.0, M_PI / 2.0};
137  coneSurfaceObject->localToGlobal(tgContext, localPosition, momentum,
138  globalPosition);
139  // std::cout<<globalPosition<<std::endl;
140  Vector3D expectedPosition{0.0220268, 1.65027, 3.5708};
141 
142  CHECK_CLOSE_REL(globalPosition, expectedPosition, 1e-2);
143  //
145  coneSurfaceObject->globalToLocal(tgContext, globalPosition, momentum,
146  localPosition);
147  // std::cout<<localPosition<<std::endl;
148  Vector2D expectedLocalPosition{1.0, M_PI / 2.0};
149 
150  CHECK_CLOSE_REL(localPosition, expectedLocalPosition, 1e-6);
151  //
153  Vector3D offSurface{100, 1, 2};
154  BOOST_CHECK(coneSurfaceObject->isOnSurface(tgContext, globalPosition,
155  momentum, true));
156  BOOST_CHECK(
157  !coneSurfaceObject->isOnSurface(tgContext, offSurface, momentum, true));
158 
160  CHECK_CLOSE_REL(coneSurfaceObject->pathCorrection(tgContext, offSurface,
161  momentum.normalized()),
162  0.40218866453252877, 0.01);
163  //
165  BOOST_CHECK_EQUAL(coneSurfaceObject->name(),
166  std::string("Acts::ConeSurface"));
167  //
169  // TODO 2017-04-12 msmk: check how to correctly check output
170  // boost::test_tools::output_test_stream dumpOuput;
171  // coneSurfaceObject.toStream(dumpOuput);
172  // BOOST_CHECK(dumpOuput.is_equal(
173  // "Acts::ConeSurface\n"
174  // " Center position (x, y, z) = (0.0000, 1.0000, 2.0000)\n"
175  // " Rotation: colX = (1.000000, 0.000000, 0.000000)\n"
176  // " colY = (0.000000, 1.000000, 0.000000)\n"
177  // " colZ = (0.000000, 0.000000, 1.000000)\n"
178  // " Bounds : Acts::ConeBounds: (tanAlpha, minZ, maxZ, averagePhi,
179  // halfPhiSector) = (0.4142136, 0.0000000, inf, 0.0000000,
180  // 3.1415927)"));
181 }
182 
183 BOOST_AUTO_TEST_CASE(EqualityOperators) {
184  double alpha{M_PI / 8.} /*, halfPhiSector{M_PI/16.}, zMin{1.0}, zMax{10.}*/;
185  bool symmetric(false);
186  Translation3D translation{0., 1., 2.};
187  auto pTransform = std::make_shared<const Transform3D>(translation);
188  auto coneSurfaceObject =
189  Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
190  //
191  auto coneSurfaceObject2 =
192  Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
193  //
195  BOOST_CHECK(*coneSurfaceObject == *coneSurfaceObject2);
196  //
197  BOOST_TEST_CHECKPOINT(
198  "Create and then assign a ConeSurface object to the existing one");
200  auto assignedConeSurface =
201  Surface::makeShared<ConeSurface>(nullptr, 0.1, true);
202  *assignedConeSurface = *coneSurfaceObject;
204  BOOST_CHECK(*assignedConeSurface == *coneSurfaceObject);
205 }
206 
207 BOOST_AUTO_TEST_SUITE_END()
208 
209 } // namespace Test
210 
211 } // namespace Acts