EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BoundTrackParametersTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BoundTrackParametersTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2020 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 
23 #include "Acts/Utilities/Units.hpp"
25 
27 
28 namespace {
29 
30 namespace bdata = boost::unit_test::data;
31 using namespace Acts;
32 using namespace Acts::UnitLiterals;
33 using AnyBoundTrackParameters = SingleBoundTrackParameters<AnyCharge>;
34 
35 constexpr auto eps = 8 * std::numeric_limits<BoundScalar>::epsilon();
37 const BoundSymMatrix cov = BoundSymMatrix::Identity();
38 
39 template <typename charge_t>
40 void checkParameters(const SingleBoundTrackParameters<charge_t>& params,
41  double l0, double l1, double time, double phi,
42  double theta, double p, double q, const Vector3D& pos,
43  const Vector3D& unitDir) {
44  const auto qOverP = (q != 0) ? (q / p) : (1 / p);
45  const auto pos4 = VectorHelpers::makeVector4(pos, time);
46 
47  // native values
48  CHECK_CLOSE_OR_SMALL(params.template get<eBoundLoc0>(), l0, eps, eps);
49  CHECK_CLOSE_OR_SMALL(params.template get<eBoundLoc1>(), l1, eps, eps);
50  CHECK_CLOSE_OR_SMALL(params.template get<eBoundTime>(), time, eps, eps);
51  CHECK_CLOSE_OR_SMALL(detail::radian_sym(params.template get<eBoundPhi>()),
52  detail::radian_sym(phi), eps, eps);
53  CHECK_CLOSE_OR_SMALL(params.template get<eBoundTheta>(), theta, eps, eps);
54  CHECK_CLOSE_OR_SMALL(params.template get<eBoundQOverP>(), qOverP, eps, eps);
55  // convenience accessors
58  CHECK_CLOSE_OR_SMALL(params.time(), time, eps, eps);
61  CHECK_CLOSE_OR_SMALL(params.transverseMomentum(), p * std::sin(theta), eps,
62  eps);
63  CHECK_CLOSE_OR_SMALL(params.momentum(), p * unitDir, eps, eps);
64  BOOST_CHECK_EQUAL(params.charge(), q);
65 }
66 
67 void runTest(std::shared_ptr<const Surface> surface, double l0, double l1,
68  double time, double phi, double theta, double p) {
69  // phi is ill-defined in forward/backward tracks
70  phi = ((0 < theta) and (theta < M_PI)) ? phi : 0.0;
71 
72  // global direction for reference
73  const Vector3D dir = makeDirectionUnitFromPhiTheta(phi, theta);
74  // convert local-to-global for reference
75  const Vector2D loc(l0, l1);
76  const Vector3D pos = surface->localToGlobal(geoCtx, loc, dir);
77  // global four-position as input
78  Vector4D pos4;
79  pos4.segment<3>(ePos0) = pos;
80  pos4[eTime] = time;
81 
82  // neutral parameters from local vector
83  {
84  BoundVector vector = BoundVector::Zero();
85  vector[eBoundLoc0] = l0;
86  vector[eBoundLoc1] = l1;
87  vector[eBoundTime] = time;
88  vector[eBoundPhi] = phi;
89  vector[eBoundTheta] = theta;
90  vector[eBoundQOverP] = 1 / p;
91  NeutralBoundTrackParameters params(surface, vector);
92  checkParameters(params, l0, l1, time, phi, theta, p, 0_e, pos, dir);
93  BOOST_CHECK(not params.covariance());
94 
95  // reassign w/ covariance
96  params = NeutralBoundTrackParameters(surface, vector, cov);
97  checkParameters(params, l0, l1, time, phi, theta, p, 0_e, pos, dir);
98  BOOST_CHECK(params.covariance());
99  BOOST_CHECK_EQUAL(params.covariance().value(), cov);
100  }
101  // negative charged parameters from local vector
102  {
103  BoundVector vector = BoundVector::Zero();
104  vector[eBoundLoc0] = l0;
105  vector[eBoundLoc1] = l1;
106  vector[eBoundTime] = time;
107  vector[eBoundPhi] = phi;
108  vector[eBoundTheta] = theta;
109  vector[eBoundQOverP] = -1_e / p;
110  BoundTrackParameters params(surface, vector);
111  checkParameters(params, l0, l1, time, phi, theta, p, -1_e, pos, dir);
112  BOOST_CHECK(not params.covariance());
113 
114  // reassign w/ covariance
115  params = BoundTrackParameters(surface, vector, cov);
116  checkParameters(params, l0, l1, time, phi, theta, p, -1_e, pos, dir);
117  BOOST_CHECK(params.covariance());
118  BOOST_CHECK_EQUAL(params.covariance().value(), cov);
119  }
120  // positive charged parameters from local vector
121  {
122  BoundVector vector = BoundVector::Zero();
123  vector[eBoundLoc0] = l0;
124  vector[eBoundLoc1] = l1;
125  vector[eBoundTime] = time;
126  vector[eBoundPhi] = phi;
127  vector[eBoundTheta] = theta;
128  vector[eBoundQOverP] = 1_e / p;
129  BoundTrackParameters params(surface, vector);
130  checkParameters(params, l0, l1, time, phi, theta, p, 1_e, pos, dir);
131  BOOST_CHECK(not params.covariance());
132 
133  // reassign w/ covariance
134  params = BoundTrackParameters(surface, vector, cov);
135  checkParameters(params, l0, l1, time, phi, theta, p, 1_e, pos, dir);
136  BOOST_CHECK(params.covariance());
137  BOOST_CHECK_EQUAL(params.covariance().value(), cov);
138  }
139  // double-negative charged any parameters from local vector
140  {
141  BoundVector vector = BoundVector::Zero();
142  vector[eBoundLoc0] = l0;
143  vector[eBoundLoc1] = l1;
144  vector[eBoundTime] = time;
145  vector[eBoundPhi] = phi;
146  vector[eBoundTheta] = theta;
147  vector[eBoundQOverP] = -2_e / p;
148  AnyBoundTrackParameters params(surface, vector, -2_e);
149  checkParameters(params, l0, l1, time, phi, theta, p, -2_e, pos, dir);
150  BOOST_CHECK(not params.covariance());
151 
152  // reassign w/ covariance
153  params = AnyBoundTrackParameters(surface, vector, -2_e, cov);
154  checkParameters(params, l0, l1, time, phi, theta, p, -2_e, pos, dir);
155  BOOST_CHECK(params.covariance());
156  BOOST_CHECK_EQUAL(params.covariance().value(), cov);
157  }
158  // neutral parameters from global information
159  {
160  NeutralBoundTrackParameters params(surface, geoCtx, pos4, dir, 1 / p);
161  checkParameters(params, l0, l1, time, phi, theta, p, 0_e, pos, dir);
162  BOOST_CHECK(not params.covariance());
163  }
164  // negative charged parameters from global information
165  {
166  BoundTrackParameters params(surface, geoCtx, pos4, dir, -1_e / p);
167  checkParameters(params, l0, l1, time, phi, theta, p, -1_e, pos, dir);
168  BOOST_CHECK(not params.covariance());
169  }
170  // positive charged parameters from global information
171  {
172  BoundTrackParameters params(surface, geoCtx, pos4, dir, 1_e / p);
173  checkParameters(params, l0, l1, time, phi, theta, p, 1_e, pos, dir);
174  BOOST_CHECK(not params.covariance());
175  }
176  // neutral any parameters from global information
177  {
178  AnyBoundTrackParameters params(surface, geoCtx, pos4, dir, p, 0_e);
179  checkParameters(params, l0, l1, time, phi, theta, p, 0_e, pos, dir);
180  BOOST_CHECK(not params.covariance());
181  }
182  // double-negative any parameters from global information
183  {
184  AnyBoundTrackParameters params(surface, geoCtx, pos4, dir, p, -2_e);
185  checkParameters(params, l0, l1, time, phi, theta, p, -2_e, pos, dir);
186  BOOST_CHECK(not params.covariance());
187  }
188  // triple-positive any parameters from global information
189  {
190  AnyBoundTrackParameters params(surface, geoCtx, pos4, dir, p, 3_e);
191  checkParameters(params, l0, l1, time, phi, theta, p, 3_e, pos, dir);
192  BOOST_CHECK(not params.covariance());
193  }
194 }
195 
196 // different surfaces
197 // parameters must be chosen such that all possible local positions (as defined
198 // in the datasets header) represent valid points on the surface.
199 const auto cones = bdata::make({
200  Surface::makeShared<ConeSurface>(Transform3D::Identity(),
201  0.5 /* opening angle */),
202 });
203 const auto cylinders = bdata::make({
204  Surface::makeShared<CylinderSurface>(Transform3D::Identity(),
205  10.0 /* radius */, 100 /* half z */),
206 });
207 const auto discs = bdata::make({
208  Surface::makeShared<DiscSurface>(Transform3D::Identity(),
209  0 /* radius min */, 100 /* radius max */),
210 });
211 const auto perigees = bdata::make({
212  Surface::makeShared<PerigeeSurface>(Vector3D(0, 0, -1.5)),
213 });
214 const auto planes = bdata::make({
215  Surface::makeShared<PlaneSurface>(Vector3D(1, 2, 3), Vector3D::UnitX()),
216  Surface::makeShared<PlaneSurface>(Vector3D(-2, -3, -4), Vector3D::UnitY()),
217  Surface::makeShared<PlaneSurface>(Vector3D(3, -4, 5), Vector3D::UnitZ()),
218 });
219 const auto straws = bdata::make({
220  Surface::makeShared<StrawSurface>(Transform3D::Identity(), 2.0 /* radius */,
221  200.0 /* half z */),
222 });
223 
224 } // namespace
225 
226 BOOST_AUTO_TEST_SUITE(EventDataBoundTrackParameters)
227 
229  cones* posAngle* posPositiveNonzero* ts* phis* thetas* ps,
230  surface, lphi, lz, time, phi, theta, p) {
231  // TODO extend lz to zero after fixing the transform implementation
232  // local parameter r*phi has limits that depend on the z position
233  const auto r = lz * surface->bounds().tanAlpha();
234  // local coordinates are singular at z = 0 -> normalize local r*phi
235  runTest(surface, (0 < lz) ? (r * lphi) : 0.0, lz, time, phi, theta, p);
236 }
237 
240  cylinders* posSymmetric* posSymmetric* ts* phis* thetas* ps, surface, lrphi,
241  lz, time, phi, theta, p) {
242  runTest(surface, lrphi, lz, time, phi, theta, p);
243 }
244 
246  discs* posPositive* posAngle* ts* phis* thetas* ps,
247  surface, lr, lphi, time, phi, theta, p) {
248  // local coordinates are singular at r = 0 -> normalize local phi
249  runTest(surface, lr, (0 < lr) ? lphi : 0.0, time, phi, theta, p);
250 }
251 
254  perigees* posSymmetric* posSymmetric* ts* phis* thetasNoForwardBackward* ps,
255  surface, d0, z0, time, phi, theta, p) {
256  // TODO extend theta to forward/back extreme cases fixing the transform
257  runTest(surface, d0, z0, time, phi, theta, p);
258 }
259 
261  planes* posSymmetric* posSymmetric* ts* phis* thetas* ps,
262  surface, l0, l1, time, phi, theta, p) {
263  runTest(surface, l0, l1, time, phi, theta, p);
264 }
265 
267  StrawSurface,
268  straws* posPositive* posSymmetric* ts* phis* thetasNoForwardBackward* ps,
269  surface, lr, lz, time, phi, theta, p) {
270  // TODO extend theta to forward/back extreme cases fixing the transform
271  runTest(surface, lr, lz, time, phi, theta, p);
272 }
273 
274 BOOST_AUTO_TEST_SUITE_END()