EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JacobianTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JacobianTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-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/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
25 
26 namespace bdata = boost::unit_test::data;
27 namespace tt = boost::test_tools;
28 using namespace Acts::UnitLiterals;
29 
30 namespace Acts {
31 namespace Test {
32 
33 using BFieldType = ConstantBField;
34 using EigenStepperType = EigenStepper<BFieldType>;
37 
38 // Create a test context
41 
49 Transform3D createCylindricTransform(const Vector3D& nposition, double angleX,
50  double angleY) {
51  Transform3D ctransform;
52  ctransform.setIdentity();
53  ctransform.pretranslate(nposition);
54  ctransform.prerotate(AngleAxis3D(angleX, Vector3D::UnitX()));
55  ctransform.prerotate(AngleAxis3D(angleY, Vector3D::UnitY()));
56  return ctransform;
57 }
58 
67  const Vector3D& nnormal, double angleT,
68  double angleU) {
69  // the rotation of the destination surface
70  Vector3D T = nnormal.normalized();
71  Vector3D U = std::abs(T.dot(Vector3D::UnitZ())) < 0.99
72  ? Vector3D::UnitZ().cross(T).normalized()
73  : Vector3D::UnitX().cross(T).normalized();
74  Vector3D V = T.cross(U);
75  // that's the plane curvilinear Rotation
76  RotationMatrix3D curvilinearRotation;
77  curvilinearRotation.col(0) = U;
78  curvilinearRotation.col(1) = V;
79  curvilinearRotation.col(2) = T;
80  // curvilinear surfaces are boundless
81  Transform3D ctransform{curvilinearRotation};
82  ctransform.pretranslate(nposition);
83  ctransform.prerotate(AngleAxis3D(angleT, T));
84  ctransform.prerotate(AngleAxis3D(angleU, U));
85  //
86  return ctransform;
87 }
88 
105 
106 BoundToFreeMatrix convertToMatrix(const std::array<double, 60> P) {
107  // initialize to zero
108  BoundToFreeMatrix jMatrix = BoundToFreeMatrix::Zero();
109  for (size_t j = 0; j < eBoundSize; ++j) {
110  for (size_t i = 0; i < eFreeSize; ++i) {
111  size_t ijc = eFreeSize + j * eFreeSize + i;
112  jMatrix(i, j) = P[ijc];
113  }
114  }
115  return jMatrix;
116 }
117 
123 template <typename Parameters>
124 void testJacobianToGlobal(const Parameters& pars) {
125  // Jacobian creation for Propagator/Steppers
126  // a) ATLAS stepper
127  AtlasStepperType::State astepState(tgContext, mfContext, pars);
128  // b) Eigen stepper
129  EigenStepperType::State estepState(tgContext, mfContext, pars);
130 
131  // create the matrices
132  auto asMatrix = convertToMatrix(astepState.pVector);
133 
134  // cross comparison checks
135  CHECK_CLOSE_OR_SMALL(asMatrix, estepState.jacToGlobal, 1e-6, 1e-9);
136 }
137 
139 BOOST_AUTO_TEST_CASE(JacobianCurvilinearToGlobalTest) {
140  // Create curvilinear parameters
141  Covariance cov;
142  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
143  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
144  CurvilinearTrackParameters curvilinear(
145  Vector4D(341., 412., 93., 0.), Vector3D(1.2, 8.3, 0.45), 10.0, 1, cov);
146 
147  // run the test
148  testJacobianToGlobal(curvilinear);
149 }
150 
152 BOOST_AUTO_TEST_CASE(JacobianCylinderToGlobalTest) {
153  // the cylinder transform and surface
154  auto cTransform = createCylindricTransform({10., -5., 0.}, 0.004, 0.03);
155  auto cSurface = Surface::makeShared<CylinderSurface>(cTransform, 200., 1000.);
156 
157  Covariance cov;
158  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
159  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
160 
161  BoundVector pars;
162  pars << 182.34, -82., 0.134, 0.85, 1. / (100_GeV), 0;
163 
164  BoundTrackParameters atCylinder(cSurface, std::move(pars), std::move(cov));
165 
166  // run the test
167  testJacobianToGlobal(atCylinder);
168 }
169 
171 BOOST_AUTO_TEST_CASE(JacobianDiscToGlobalTest) {
172  // the disc transform and surface
173  auto dTransform = createPlanarTransform(
174  {10., -5., 0.}, Vector3D(0.23, 0.07, 1.).normalized(), 0.004, 0.03);
175  auto dSurface = Surface::makeShared<DiscSurface>(dTransform, 200., 1000.);
176 
177  Covariance cov;
178  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
179  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
180 
181  BoundVector pars;
182  pars << 192.34, 1.823, 0.734, 0.235, 1. / (100_GeV), 0;
183 
184  BoundTrackParameters atDisc(dSurface, std::move(pars), std::move(cov));
185 
186  // run the test
187  testJacobianToGlobal(atDisc);
188 }
189 
191 BOOST_AUTO_TEST_CASE(JacobianPlaneToGlobalTest) {
192  // Let's create a surface somewhere in space
193  Vector3D sPosition(3421., 112., 893.);
194  Vector3D sNormal = Vector3D(1.2, -0.3, 0.05).normalized();
195 
196  // Create a surface & parameters with covariance on the surface
197  auto pSurface = Surface::makeShared<PlaneSurface>(sPosition, sNormal);
198 
199  Covariance cov;
200  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
201  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
202 
203  BoundVector pars;
204  pars << 12.34, -8722., 2.134, 0.85, 1. / (100_GeV), 0;
205 
206  BoundTrackParameters atPlane(pSurface, std::move(pars), std::move(cov));
207 
208  // run the test
209  testJacobianToGlobal(atPlane);
210 }
211 
213 BOOST_AUTO_TEST_CASE(JacobianPerigeeToGlobalTest) {
214  // Create a surface & parameters with covariance on the surface
215  auto pSurface = Surface::makeShared<PerigeeSurface>(Vector3D({0., 0., 0.}));
216 
217  Covariance cov;
218  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
219  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
220  BoundVector pars;
221  pars << -3.34, -822., -0.734, 0.85, 1. / (100_GeV), 0;
222 
223  BoundTrackParameters perigee(pSurface, std::move(pars), std::move(cov));
224 
225  // run the test
226  testJacobianToGlobal(perigee);
227 }
228 
230 BOOST_AUTO_TEST_CASE(JacobianStrawToGlobalTest) {
231  // Create a surface & parameters with covariance on the surface
232  auto sTransform = createCylindricTransform({1019., -52., 382.}, 0.4, -0.3);
233  auto sSurface = Surface::makeShared<StrawSurface>(sTransform, 10., 1000.);
234 
235  Covariance cov;
236  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
237  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
238 
239  BoundVector pars;
240  pars << -8.34, 812., 0.734, 0.25, 1. / (100_GeV), 0;
241 
242  BoundTrackParameters atStraw(sSurface, std::move(pars), std::move(cov));
243 
244  // run the test
245  testJacobianToGlobal(atStraw);
246 }
247 
248 } // namespace Test
249 } // namespace Acts