ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BoundParametersTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BoundParametersTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2019 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/unit_test.hpp>
11 
24 #include "Acts/Utilities/Units.hpp"
25 
26 #include "ParametersTestHelper.hpp"
27 
28 namespace bdata = boost::unit_test::data;
29 namespace tt = boost::test_tools;
30 
31 namespace Acts {
32 
33 namespace Test {
34 
35 // Create a test context
37 
41  bound_to_plane_test,
42  bdata::random((bdata::seed = 1240,
43  bdata::distribution =
44  std::uniform_real_distribution<>(-1000., 1000.))) ^
45  bdata::random((bdata::seed = 2351,
46  bdata::distribution =
47  std::uniform_real_distribution<>(-1000., 1000.))) ^
48  bdata::random((bdata::seed = 3412,
49  bdata::distribution =
50  std::uniform_real_distribution<>(-1000., 1000.))) ^
51  bdata::random((
52  bdata::seed = 5732,
53  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
54  bdata::random((
55  bdata::seed = 8941,
56  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
57  bdata::random((
58  bdata::seed = 1295,
59  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
60  bdata::xrange(100),
61  x, y, z, a, b, c, index) {
62  (void)index;
63  Vector3D center{x, y, z};
64  auto transform = std::make_shared<Transform3D>();
65  transform->setIdentity();
66  RotationMatrix3D rot;
67  rot = AngleAxis3D(a, Vector3D::UnitX()) * AngleAxis3D(b, Vector3D::UnitY()) *
68  AngleAxis3D(c, Vector3D::UnitZ());
69  transform->prerotate(rot);
70  transform->pretranslate(center);
71  // create the surfacex
72  auto bounds = std::make_shared<RectangleBounds>(100., 100.);
73  auto pSurface = Surface::makeShared<PlaneSurface>(transform, bounds);
74 
75  // now create parameters on this surface
76  // l_x, l_y, phi, theta, q/p (1/p), t
77  std::array<double, 6> pars_array = {
78  {-0.1234, 9.8765, 0.45, 0.888, 0.001, 21.}};
80  pars << pars_array[0], pars_array[1], pars_array[2], pars_array[3],
81  pars_array[4], pars_array[5];
82 
83  const double phi = pars_array[2];
84  const double theta = pars_array[3];
85  double p = fabs(1. / pars_array[4]);
86  Vector3D direction(cos(phi) * sin(theta), sin(phi) * sin(theta), cos(theta));
87  Vector3D mom = p * direction;
88  // the global position
89  Vector3D pos =
90  center + pars_array[0] * rot.col(0) + pars_array[1] * rot.col(1);
91  // constructor from parameter vector
92  BoundParameters ataPlane_from_pars(tgContext, std::nullopt, pars, pSurface);
93  consistencyCheck(ataPlane_from_pars, pos, mom, 1., 21., pars_array);
94  // constructor from global parameters
95  BoundParameters ataPlane_from_global(tgContext, std::nullopt, pos, mom, 1.,
96  21., pSurface);
97  consistencyCheck(ataPlane_from_global, pos, mom, 1., 21., pars_array);
98  // constructor for neutral parameters
99  NeutralBoundParameters n_ataPlane_from_pars(tgContext, std::nullopt, pars,
100  pSurface);
101  consistencyCheck(n_ataPlane_from_pars, pos, mom, 0., 21., pars_array);
102  // constructor for neutral global parameters
103  NeutralBoundParameters n_ataPlane_from_global(tgContext, std::nullopt, pos,
104  mom, 21., pSurface);
105  consistencyCheck(n_ataPlane_from_global, pos, mom, 0., 21., pars_array);
106 
107  // check shared ownership of same surface
108  BOOST_CHECK_EQUAL(&ataPlane_from_pars.referenceSurface(), pSurface.get());
109  BOOST_CHECK_EQUAL(&ataPlane_from_pars.referenceSurface(),
110  &ataPlane_from_global.referenceSurface());
111  BOOST_CHECK_EQUAL(&n_ataPlane_from_pars.referenceSurface(), pSurface.get());
112  BOOST_CHECK_EQUAL(&n_ataPlane_from_pars.referenceSurface(),
113  &n_ataPlane_from_global.referenceSurface());
114  BOOST_CHECK_EQUAL(pSurface.use_count(), 5u);
115 
116  // check that the reference frame is the rotation matrix
117  CHECK_CLOSE_REL(ataPlane_from_pars.referenceFrame(tgContext), rot, 1e-6);
118 
120  double ux = 0.3;
121  double uy = 0.4;
122 
123  ataPlane_from_pars.set<Acts::eLOC_X>(tgContext, ux);
124  ataPlane_from_pars.set<Acts::eLOC_Y>(tgContext, uy);
125  // we should have a new updated position
126  Vector3D lPosition3D(ux, uy, 0.);
127  Vector3D uposition = rot * lPosition3D + center;
128  CHECK_CLOSE_REL(uposition, ataPlane_from_pars.position(), 1e-6);
129 
130  double uphi = 1.2;
131  double utheta = 0.2;
132  double uqop = 0.025;
133  double ut = 1337.;
134 
135  ataPlane_from_pars.set<Acts::ePHI>(tgContext, uphi);
136  ataPlane_from_pars.set<Acts::eTHETA>(tgContext, utheta);
137  ataPlane_from_pars.set<Acts::eQOP>(tgContext, uqop);
138  ataPlane_from_pars.set<Acts::eT>(tgContext, ut);
139  // we should have a new updated momentum
140  Vector3D umomentum = 40. * Vector3D(cos(uphi) * sin(utheta),
141  sin(uphi) * sin(utheta), cos(utheta));
142 
143  CHECK_CLOSE_REL(umomentum, ataPlane_from_pars.momentum(), 1e-6);
144 }
145 
149  bound_to_disc_test,
150  bdata::random((bdata::seed = 9810,
151  bdata::distribution =
152  std::uniform_real_distribution<>(-1000., 1000.))) ^
153  bdata::random((bdata::seed = 1221,
154  bdata::distribution =
155  std::uniform_real_distribution<>(-1000., 1000.))) ^
156  bdata::random((bdata::seed = 12132,
157  bdata::distribution =
158  std::uniform_real_distribution<>(-1000., 1000.))) ^
159  bdata::random((
160  bdata::seed = 16783,
161  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
162  bdata::random((
163  bdata::seed = 13984,
164  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
165  bdata::random((
166  bdata::seed = 77615,
167  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
168  bdata::xrange(100),
169  x, y, z, a, b, c, index) {
170  (void)index;
171  Vector3D center{x, y, z};
172  auto transform = std::make_shared<Transform3D>();
173  transform->setIdentity();
174  RotationMatrix3D rot;
175  rot = AngleAxis3D(a, Vector3D::UnitX()) * AngleAxis3D(b, Vector3D::UnitY()) *
176  AngleAxis3D(c, Vector3D::UnitZ());
177  transform->prerotate(rot);
178  transform->pretranslate(center);
179 
180  auto bounds = std::make_shared<RadialBounds>(100., 1200.);
181  auto dSurface = Surface::makeShared<DiscSurface>(transform, bounds);
182 
183  // now create parameters on this surface
184  // r, phi, phi, theta, q/p (1/p), t
185  std::array<double, 6> pars_array = {{125., 0.345, 0.45, 0.888, 0.001, 21.}};
187  pars << pars_array[0], pars_array[1], pars_array[2], pars_array[3],
188  pars_array[4], pars_array[5];
189 
190  const double phi = pars_array[2];
191  const double theta = pars_array[3];
192  double p = fabs(1. / pars_array[4]);
193  Vector3D direction(cos(phi) * sin(theta), sin(phi) * sin(theta), cos(theta));
194  Vector3D mom = p * direction;
195  Vector3D pos = (pars_array[0] * cos(pars_array[1])) * rot.col(0) +
196  (pars_array[0] * sin(pars_array[1])) * rot.col(1) + center;
197  // constructor from parameter vector
198  BoundParameters ataDisc_from_pars(tgContext, std::nullopt, pars, dSurface);
199  consistencyCheck(ataDisc_from_pars, pos, mom, 1., 21., pars_array);
200  // constructor from global parameters
201  BoundParameters ataDisc_from_global(tgContext, std::nullopt, pos, mom, 1.,
202  21., dSurface);
203  consistencyCheck(ataDisc_from_global, pos, mom, 1., 21., pars_array);
204  // constructor for neutral parameters
205  NeutralBoundParameters n_ataDisc_from_pars(tgContext, std::nullopt, pars,
206  dSurface);
207  consistencyCheck(n_ataDisc_from_pars, pos, mom, 0., 21., pars_array);
208  // constructor for neutral global parameters
209  NeutralBoundParameters n_ataDisc_from_global(tgContext, std::nullopt, pos,
210  mom, 21., dSurface);
211  consistencyCheck(n_ataDisc_from_global, pos, mom, 0., 21., pars_array);
212 
213  // check shared ownership of same surface
214  BOOST_CHECK_EQUAL(&ataDisc_from_pars.referenceSurface(), dSurface.get());
215  BOOST_CHECK_EQUAL(&ataDisc_from_pars.referenceSurface(),
216  &ataDisc_from_global.referenceSurface());
217  BOOST_CHECK_EQUAL(&n_ataDisc_from_pars.referenceSurface(), dSurface.get());
218  BOOST_CHECK_EQUAL(&n_ataDisc_from_pars.referenceSurface(),
219  &n_ataDisc_from_global.referenceSurface());
220  BOOST_CHECK_EQUAL(dSurface.use_count(), 5u);
221 
222  // check that the reference frame is the
223  // rotation matrix of the surface
224  const auto& dRotation =
225  dSurface->transform(tgContext).matrix().block<3, 3>(0, 0);
226  CHECK_CLOSE_REL(ataDisc_from_pars.referenceFrame(tgContext), dRotation, 1e-6);
227 }
228 
232  bound_to_cylinder_test,
233  bdata::random((bdata::seed = 39810,
234  bdata::distribution =
235  std::uniform_real_distribution<>(-1000., 1000.))) ^
236  bdata::random((bdata::seed = 21221,
237  bdata::distribution =
238  std::uniform_real_distribution<>(-1000., 1000.))) ^
239  bdata::random((bdata::seed = 62132,
240  bdata::distribution =
241  std::uniform_real_distribution<>(-1000., 1000.))) ^
242  bdata::random((
243  bdata::seed = 91683,
244  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
245  bdata::random((
246  bdata::seed = 39847,
247  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
248  bdata::random((
249  bdata::seed = 72615,
250  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
251  bdata::xrange(100),
252  x, y, z, a, b, c, index) {
253  (void)index;
254 
255  Vector3D center{x, y, z};
256  auto transform = std::make_shared<Transform3D>();
257  transform->setIdentity();
258  RotationMatrix3D rot;
259  rot = AngleAxis3D(a, Vector3D::UnitX()) * AngleAxis3D(b, Vector3D::UnitY()) *
260  AngleAxis3D(c, Vector3D::UnitZ());
261  transform->prerotate(rot);
262  transform->pretranslate(center);
263 
264  auto bounds = std::make_shared<CylinderBounds>(100., 1200.);
265  std::shared_ptr<const Surface> cSurface =
266  Surface::makeShared<CylinderSurface>(transform, bounds);
267 
268  // now create parameters on this surface
269  // rPhi, a, phi, theta, q/p (1/p), t
270  std::array<double, 6> pars_array = {{125., 343., 0.45, 0.888, 0.001, 21.}};
272  pars << pars_array[0], pars_array[1], pars_array[2], pars_array[3],
273  pars_array[4], pars_array[5];
274 
275  const double phi = pars_array[2];
276  const double theta = pars_array[3];
277  double p = fabs(1. / pars_array[4]);
278  Vector3D direction(cos(phi) * sin(theta), sin(phi) * sin(theta), cos(theta));
279  Vector3D mom = p * direction;
280 
281  // 3D position in local frame
282  double r = bounds->get(CylinderBounds::eR);
283  const double phi_l = pars_array[0] / r;
284  Vector3D pos = (r * cos(phi_l)) * rot.col(0) + (r * sin(phi_l)) * rot.col(1) +
285  (pars_array[1]) * rot.col(2) + center;
286 
287  // constructor from parameter vector
288  BoundParameters ataCylinder_from_pars(tgContext, std::nullopt, pars,
289  cSurface);
290  consistencyCheck(ataCylinder_from_pars, pos, mom, 1., 21., pars_array);
291  // constructor from global parameters
292  BoundParameters ataCylinder_from_global(tgContext, std::nullopt, pos, mom, 1.,
293  21., cSurface);
294  consistencyCheck(ataCylinder_from_global, pos, mom, 1., 21., pars_array);
295  // constructor for neutral parameters
296  NeutralBoundParameters n_ataCylinder_from_pars(tgContext, std::nullopt, pars,
297  cSurface);
298  consistencyCheck(n_ataCylinder_from_pars, pos, mom, 0., 21., pars_array);
299  // constructor for neutral global parameters
300  NeutralBoundParameters n_ataCylinder_from_global(tgContext, std::nullopt, pos,
301  mom, 21., cSurface);
302  consistencyCheck(n_ataCylinder_from_global, pos, mom, 0., 21., pars_array);
303 
304  // check shared ownership of same surface
305  BOOST_CHECK_EQUAL(&ataCylinder_from_pars.referenceSurface(), cSurface.get());
306  BOOST_CHECK_EQUAL(&ataCylinder_from_pars.referenceSurface(),
307  &ataCylinder_from_global.referenceSurface());
308  BOOST_CHECK_EQUAL(&n_ataCylinder_from_pars.referenceSurface(),
309  cSurface.get());
310  BOOST_CHECK_EQUAL(&n_ataCylinder_from_pars.referenceSurface(),
311  &n_ataCylinder_from_global.referenceSurface());
312  BOOST_CHECK_EQUAL(cSurface.use_count(), 5u);
313 
314  auto pPosition = ataCylinder_from_pars.position();
315  // the reference frame is
316  // transverse plane to the cylinder at the intersect
317  Vector3D normal_at_intersect = cSurface->normal(tgContext, pPosition);
318  Vector3D transverse_y = rot.col(2);
319  Vector3D transverse_x = transverse_y.cross(normal_at_intersect);
320  RotationMatrix3D refframe;
321  refframe.col(0) = transverse_x;
322  refframe.col(1) = transverse_y;
323  refframe.col(2) = normal_at_intersect;
324  // check if the manually constructed reference frame is the provided one
325  CHECK_CLOSE_REL(ataCylinder_from_pars.referenceFrame(tgContext), refframe,
326  1e-6);
327 }
328 
332  bound_to_perigee_test,
333  bdata::random(
334  (bdata::seed = 3980,
335  bdata::distribution = std::uniform_real_distribution<>(-10., 10.))) ^
336  bdata::random((bdata::seed = 2221,
337  bdata::distribution =
338  std::uniform_real_distribution<>(-10., 10.))) ^
339  bdata::random((bdata::seed = 2132,
340  bdata::distribution =
341  std::uniform_real_distribution<>(-10., 10.))) ^
342  bdata::random((
343  bdata::seed = 9183,
344  bdata::distribution = std::uniform_real_distribution<>(0., 0.05))) ^
345  bdata::random((
346  bdata::seed = 3947,
347  bdata::distribution = std::uniform_real_distribution<>(0., 0.05))) ^
348  bdata::xrange(100),
349  x, y, z, a, b, index) {
350  (void)index;
351  Vector3D center{x, y, z};
352  auto transform = std::make_shared<Transform3D>();
353  transform->setIdentity();
354  RotationMatrix3D rot;
355  rot = AngleAxis3D(a, Vector3D::UnitX()) * AngleAxis3D(b, Vector3D::UnitY());
356  transform->prerotate(rot);
357  transform->pretranslate(center);
358 
359  // the straw surface
360  std::shared_ptr<const Surface> pSurface = Surface::makeShared<PerigeeSurface>(
361  std::make_shared<const Transform3D>(*transform));
362 
363  // now create parameters on this surface
364  // d0, z0, phi, theta, q/p (1/p), t
365  std::array<double, 6> pars_array = {{-0.7321, 22.5, 0.45, 0.888, 0.001, 21.}};
367  pars << pars_array[0], pars_array[1], pars_array[2], pars_array[3],
368  pars_array[4], pars_array[5];
369 
370  BoundParameters ataPerigee_from_pars(tgContext, std::nullopt, pars, pSurface);
371  auto pos = ataPerigee_from_pars.position();
372  auto mom = ataPerigee_from_pars.momentum();
373  consistencyCheck(ataPerigee_from_pars, pos, mom, 1., 21., pars_array);
374  // constructor from global parameters
375  BoundParameters ataPerigee_from_global(tgContext, std::nullopt, pos, mom, 1.,
376  21., pSurface);
377  consistencyCheck(ataPerigee_from_global, pos, mom, 1., 21., pars_array);
378  // constructor for neutral parameters
379  NeutralBoundParameters n_ataPerigee_from_pars(tgContext, std::nullopt, pars,
380  pSurface);
381  consistencyCheck(n_ataPerigee_from_pars, pos, mom, 0., 21., pars_array);
382  // constructor for neutral global parameters
383  NeutralBoundParameters n_ataPerigee_from_global(tgContext, std::nullopt, pos,
384  mom, 21., pSurface);
385  consistencyCheck(n_ataPerigee_from_global, pos, mom, 0., 21., pars_array);
386 
387  // check shared ownership of same surface
388  BOOST_CHECK_EQUAL(&ataPerigee_from_pars.referenceSurface(), pSurface.get());
389  BOOST_CHECK_EQUAL(&ataPerigee_from_pars.referenceSurface(),
390  &ataPerigee_from_global.referenceSurface());
391  BOOST_CHECK_EQUAL(&n_ataPerigee_from_pars.referenceSurface(), pSurface.get());
392  BOOST_CHECK_EQUAL(&n_ataPerigee_from_pars.referenceSurface(),
393  &n_ataPerigee_from_global.referenceSurface());
394  BOOST_CHECK_EQUAL(pSurface.use_count(), 5u);
395 }
396 
400  bound_to_line_test,
401  bdata::random((bdata::seed = 73980,
402  bdata::distribution =
403  std::uniform_real_distribution<>(-1000., 1000.))) ^
404  bdata::random((bdata::seed = 21221,
405  bdata::distribution =
406  std::uniform_real_distribution<>(-1000., 1000.))) ^
407  bdata::random((bdata::seed = 62992,
408  bdata::distribution =
409  std::uniform_real_distribution<>(-1000., 1000.))) ^
410  bdata::random((
411  bdata::seed = 900683,
412  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
413  bdata::random((
414  bdata::seed = 5439847,
415  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
416  bdata::random((
417  bdata::seed = 1972615,
418  bdata::distribution = std::uniform_real_distribution<>(0., M_PI))) ^
419  bdata::xrange(100),
420  x, y, z, a, b, c, index) {
421  using namespace Acts::UnitLiterals;
422 
423  (void)index;
424 
425  Vector3D center{x, y, z};
426  auto transform = std::make_shared<Transform3D>();
427  transform->setIdentity();
428  RotationMatrix3D rot;
429  rot = AngleAxis3D(a, Vector3D::UnitX()) * AngleAxis3D(b, Vector3D::UnitY()) *
430  AngleAxis3D(c, Vector3D::UnitZ());
431  transform->prerotate(rot);
432  transform->pretranslate(center);
433 
434  // the straw surface
435  auto sSurface = Surface::makeShared<StrawSurface>(transform, 2_mm, 1_m);
436 
437  // now create parameters on this surface
438  // r, z, phi, theta, q/p (1/p), t
439  std::array<double, 6> pars_array = {{0.2321, 22.5, 0.45, 0.888, 0.001, 21.}};
441  pars << pars_array[0], pars_array[1], pars_array[2], pars_array[3],
442  pars_array[4], pars_array[5];
443 
444  // constructor from parameter vector
445  BoundParameters ataLine_from_pars(tgContext, std::nullopt, pars, sSurface);
446  auto pos = ataLine_from_pars.position();
447  auto mom = ataLine_from_pars.momentum();
448  consistencyCheck(ataLine_from_pars, pos, mom, 1., 21., pars_array);
449  // constructor from global parameters
450  BoundParameters ataLine_from_global(tgContext, std::nullopt, pos, mom, 1.,
451  21., sSurface);
452  consistencyCheck(ataLine_from_global, pos, mom, 1., 21., pars_array);
453  // constructor for neutral parameters
454  NeutralBoundParameters n_ataLine_from_pars(tgContext, std::nullopt, pars,
455  sSurface);
456  consistencyCheck(n_ataLine_from_pars, pos, mom, 0., 21., pars_array);
457  // constructor for neutral global parameters
458  NeutralBoundParameters n_ataLine_from_global(tgContext, std::nullopt, pos,
459  mom, 21., sSurface);
460  consistencyCheck(n_ataLine_from_global, pos, mom, 0., 21., pars_array);
461 
462  // check shared ownership of same surface
463  BOOST_CHECK_EQUAL(&ataLine_from_pars.referenceSurface(), sSurface.get());
464  BOOST_CHECK_EQUAL(&ataLine_from_pars.referenceSurface(),
465  &ataLine_from_global.referenceSurface());
466  BOOST_CHECK_EQUAL(&n_ataLine_from_pars.referenceSurface(), sSurface.get());
467  BOOST_CHECK_EQUAL(&n_ataLine_from_pars.referenceSurface(),
468  &n_ataLine_from_global.referenceSurface());
469  BOOST_CHECK_EQUAL(sSurface.use_count(), 5u);
470 }
471 } // namespace Test
472 } // namespace Acts