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 
17 
18 #include <limits>
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)
32 
33 
34 BOOST_AUTO_TEST_CASE(ConeSurfaceConstruction) {
35  // ConeSurface default constructor is deleted
36  //
39  double alpha{M_PI / 8.}, halfPhiSector{M_PI / 16.}, zMin{1.0}, zMax{10.};
40  bool symmetric(false);
41  Translation3D translation{0., 1., 2.};
42  auto pTransform = Transform3D(translation);
43  BOOST_CHECK_EQUAL(Surface::makeShared<ConeSurface>(Transform3D::Identity(),
44  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 
58  // ConeBounds (double alpha, double zmin, double zmax, double halfphi=M_PI,
59  // double avphi=0.)
60  auto pConeBounds =
61  std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
62  BOOST_CHECK_EQUAL(
63  Surface::makeShared<ConeSurface>(pTransform, pConeBounds)->type(),
65  //
66  //
68  auto coneSurfaceObject =
69  Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
70  auto copiedConeSurface = Surface::makeShared<ConeSurface>(*coneSurfaceObject);
71  BOOST_CHECK_EQUAL(copiedConeSurface->type(), Surface::Cone);
72  BOOST_CHECK(*copiedConeSurface == *coneSurfaceObject);
73  //
75  auto copiedTransformedConeSurface = Surface::makeShared<ConeSurface>(
76  tgContext, *coneSurfaceObject, pTransform);
77  BOOST_CHECK_EQUAL(copiedTransformedConeSurface->type(), Surface::Cone);
78 
80  BOOST_CHECK_THROW(auto nullBounds = Surface::makeShared<ConeSurface>(
81  Transform3D::Identity(), nullptr),
83 }
84 //
86 BOOST_AUTO_TEST_CASE(ConeSurfaceProperties) {
88  double alpha{M_PI / 8.} /*,halfPhiSector{M_PI/16.}, zMin{1.0}, zMax{10.}*/;
89  bool symmetric(false);
90  Translation3D translation{0., 1., 2.};
91  auto pTransform = Transform3D(translation);
92  auto coneSurfaceObject =
93  Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
94  //
96  BOOST_CHECK_EQUAL(coneSurfaceObject->type(), Surface::Cone);
97  //
99  Vector3D binningPosition{0., 1., 2.};
101  coneSurfaceObject->binningPosition(tgContext, BinningValue::binPhi),
102  binningPosition, 1e-6);
103  //
105  Vector3D globalPosition{2.0, 2.0, 2.0};
106  Vector3D momentum{1.e6, 1.e6, 1.e6};
107  double rootHalf = std::sqrt(0.5);
108  RotationMatrix3D expectedFrame;
109  expectedFrame << -rootHalf, 0., rootHalf, rootHalf, 0., rootHalf, 0., 1., 0.;
111  coneSurfaceObject->referenceFrame(tgContext, globalPosition, momentum),
112  expectedFrame, 1e-6, 1e-9);
113  //
115  Vector3D origin{0., 0., 0.};
116  Vector3D normal3D = {0., -1., 0.};
117  CHECK_CLOSE_ABS(coneSurfaceObject->normal(tgContext, origin), normal3D, 1e-6);
118  //
120  Vector2D positionPiBy2(1.0, M_PI / 2.);
121  Vector3D normalAtPiBy2{0.0312768, 0.92335, -0.382683};
122 
123  CHECK_CLOSE_OR_SMALL(coneSurfaceObject->normal(tgContext, positionPiBy2),
124  normalAtPiBy2, 1e-2, 1e-9);
125  //
127  Vector3D symmetryAxis{0., 0., 1.};
128  CHECK_CLOSE_ABS(coneSurfaceObject->rotSymmetryAxis(tgContext), symmetryAxis,
129  1e-6);
130  //
132  BOOST_CHECK_EQUAL(coneSurfaceObject->bounds().type(), SurfaceBounds::eCone);
133  //
135  Vector2D localPosition{1.0, M_PI / 2.0};
136  globalPosition =
137  coneSurfaceObject->localToGlobal(tgContext, localPosition, momentum);
138  // std::cout<<globalPosition<<std::endl;
139  Vector3D expectedPosition{0.0220268, 1.65027, 3.5708};
140 
141  CHECK_CLOSE_REL(globalPosition, expectedPosition, 1e-2);
142  //
144  localPosition =
145  coneSurfaceObject->globalToLocal(tgContext, globalPosition, momentum)
146  .value();
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(ConeSurfaceEqualityOperators) {
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 = 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>(Transform3D::Identity(), 0.1, true);
202  *assignedConeSurface = *coneSurfaceObject;
204  BOOST_CHECK(*assignedConeSurface == *coneSurfaceObject);
205 }
206 
207 BOOST_AUTO_TEST_CASE(ConeSurfaceExtent) {
208  double alpha{M_PI / 8.}, zMin{0.}, zMax{10.};
209 
210  Translation3D translation{0., 0., 0.};
211 
212  // Testing a Full cone
213  auto pTransform = Transform3D(translation);
214  auto pConeBounds = std::make_shared<const ConeBounds>(alpha, zMin, zMax);
215  auto pCone = Surface::makeShared<ConeSurface>(pTransform, pConeBounds);
216  auto pConeExtent = pCone->polyhedronRepresentation(tgContext, 1).extent();
217 
218  double rMax = zMax * std::tan(alpha);
219  CHECK_CLOSE_ABS(zMin, pConeExtent.min(binZ), s_onSurfaceTolerance);
220  CHECK_CLOSE_ABS(zMax, pConeExtent.max(binZ), s_onSurfaceTolerance);
221  CHECK_CLOSE_ABS(0., pConeExtent.min(binR), s_onSurfaceTolerance);
222  CHECK_CLOSE_ABS(rMax, pConeExtent.max(binR), s_onSurfaceTolerance);
223  CHECK_CLOSE_ABS(-rMax, pConeExtent.min(binX), s_onSurfaceTolerance);
224  CHECK_CLOSE_ABS(rMax, pConeExtent.max(binX), s_onSurfaceTolerance);
225  CHECK_CLOSE_ABS(-rMax, pConeExtent.min(binY), s_onSurfaceTolerance);
226  CHECK_CLOSE_ABS(rMax, pConeExtent.max(binY), s_onSurfaceTolerance);
227 
228  // Now a sector
229  double halfPhiSector = M_PI / 8.;
230  pConeBounds =
231  std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
232  pCone = Surface::makeShared<ConeSurface>(pTransform, pConeBounds);
233  pConeExtent = pCone->polyhedronRepresentation(tgContext, 1).extent();
234 
235  CHECK_CLOSE_ABS(zMin, pConeExtent.min(binZ), s_onSurfaceTolerance);
236  CHECK_CLOSE_ABS(zMax, pConeExtent.max(binZ), s_onSurfaceTolerance);
237  CHECK_CLOSE_ABS(0., pConeExtent.min(binR), s_onSurfaceTolerance);
238  CHECK_CLOSE_ABS(rMax, pConeExtent.max(binR), s_onSurfaceTolerance);
239 }
240 
242 BOOST_AUTO_TEST_CASE(ConeSurfaceAlignment) {
243  double alpha{M_PI / 8.};
244  bool symmetric(false);
245  Translation3D translation{0., 1., 2.};
246  auto pTransform = Transform3D(translation);
247  auto coneSurfaceObject =
248  Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
249 
250  const auto& rotation = pTransform.rotation();
251  // The local frame z axis
252  const Vector3D localZAxis = rotation.col(2);
253  // Check the local z axis is aligned to global z axis
254  CHECK_CLOSE_ABS(localZAxis, Vector3D(0., 0., 1.), 1e-15);
255 
257  Vector3D globalPosition{0, 1. + std::tan(alpha), 3};
258 
259  // Test the derivative of bound track parameters local position w.r.t.
260  // position in local 3D Cartesian coordinates
261  const auto& loc3DToLocBound =
262  coneSurfaceObject->localCartesianToBoundLocalDerivative(tgContext,
263  globalPosition);
264  // Check if the result is as expected
265  LocalCartesianToBoundLocalMatrix expLoc3DToLocBound =
266  LocalCartesianToBoundLocalMatrix::Zero();
267  expLoc3DToLocBound << -1, 0, M_PI / 2. * std::tan(alpha), 0, 0, 1;
268  CHECK_CLOSE_ABS(loc3DToLocBound, expLoc3DToLocBound, 1e-10);
269 }
270 
271 BOOST_AUTO_TEST_SUITE_END()
272 
273 } // namespace Test
274 
275 } // namespace Acts