Analysis Software
Documentation for sPHENIX simulation 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 
30 
31 #include <algorithm>
32 #include <array>
33 #include <cstddef>
34 #include <memory>
35 #include <optional>
36 #include <type_traits>
37 #include <utility>
38 
39 namespace bdata = boost::unit_test::data;
40 namespace tt = boost::test_tools;
41 using namespace Acts::UnitLiterals;
42 
43 namespace Acts {
44 namespace Test {
45 
46 using BFieldType = ConstantBField;
47 using EigenStepperType = EigenStepper<>;
50 
51 // Create a test context
54 
55 static auto bField = std::make_shared<BFieldType>(Vector3{0, 0, 1_T});
56 
64 Transform3 createCylindricTransform(const Vector3& nposition, double angleX,
65  double angleY) {
66  Transform3 ctransform;
67  ctransform.setIdentity();
68  ctransform.pretranslate(nposition);
69  ctransform.prerotate(AngleAxis3(angleX, Vector3::UnitX()));
70  ctransform.prerotate(AngleAxis3(angleY, Vector3::UnitY()));
71  return ctransform;
72 }
73 
82  const Vector3& nnormal, double angleT,
83  double angleU) {
84  // the rotation of the destination surface
85  Vector3 T = nnormal.normalized();
86  Vector3 U = std::abs(T.dot(Vector3::UnitZ())) < 0.99
87  ? Vector3::UnitZ().cross(T).normalized()
88  : Vector3::UnitX().cross(T).normalized();
89  Vector3 V = T.cross(U);
90  // that's the plane curvilinear Rotation
91  RotationMatrix3 curvilinearRotation;
92  curvilinearRotation.col(0) = U;
93  curvilinearRotation.col(1) = V;
94  curvilinearRotation.col(2) = T;
95  // curvilinear surfaces are boundless
96  Transform3 ctransform{curvilinearRotation};
97  ctransform.pretranslate(nposition);
98  ctransform.prerotate(AngleAxis3(angleT, T));
99  ctransform.prerotate(AngleAxis3(angleU, U));
100  //
101  return ctransform;
102 }
103 
120 
121 BoundToFreeMatrix convertToMatrix(const std::array<double, 60> P) {
122  // initialize to zero
123  BoundToFreeMatrix jMatrix = BoundToFreeMatrix::Zero();
124  for (size_t j = 0; j < eBoundSize; ++j) {
125  for (size_t i = 0; i < eFreeSize; ++i) {
126  size_t ijc = eFreeSize + j * eFreeSize + i;
127  jMatrix(i, j) = P[ijc];
128  }
129  }
130  return jMatrix;
131 }
132 
138 template <typename Parameters>
139 void testJacobianToGlobal(const Parameters& pars) {
140  // Jacobian creation for Propagator/Steppers
141  // a) ATLAS stepper
142  AtlasStepperType::State astepState(tgContext, bField->makeCache(mfContext),
143  pars);
144  // b) Eigen stepper
145  EigenStepperType::State estepState(tgContext, bField->makeCache(mfContext),
146  pars);
147 
148  // create the matrices
149  auto asMatrix = convertToMatrix(astepState.pVector);
150 
151  // cross comparison checks
152  CHECK_CLOSE_OR_SMALL(asMatrix, estepState.jacToGlobal, 1e-6, 1e-9);
153 }
154 
156 BOOST_AUTO_TEST_CASE(JacobianCurvilinearToGlobalTest) {
157  // Create curvilinear parameters
158  Covariance cov;
159  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
160  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
161  CurvilinearTrackParameters curvilinear(Vector4(341., 412., 93., 0.),
162  Vector3(1.2, 8.3, 0.45), 1 / 10.0, cov,
164 
165  // run the test
166  testJacobianToGlobal(curvilinear);
167 }
168 
170 BOOST_AUTO_TEST_CASE(JacobianCylinderToGlobalTest) {
171  // the cylinder transform and surface
172  auto cTransform = createCylindricTransform({10., -5., 0.}, 0.004, 0.03);
173  auto cSurface = Surface::makeShared<CylinderSurface>(cTransform, 200., 1000.);
174 
175  Covariance cov;
176  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
177  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
178 
180  pars << 182.34, -82., 0.134, 0.85, 1. / (100_GeV), 0;
181 
182  BoundTrackParameters atCylinder(cSurface, pars, std::move(cov),
184 
185  // run the test
186  testJacobianToGlobal(atCylinder);
187 }
188 
190 BOOST_AUTO_TEST_CASE(JacobianDiscToGlobalTest) {
191  // the disc transform and surface
192  auto dTransform = createPlanarTransform(
193  {10., -5., 0.}, Vector3(0.23, 0.07, 1.).normalized(), 0.004, 0.03);
194  auto dSurface = Surface::makeShared<DiscSurface>(dTransform, 200., 1000.);
195 
196  Covariance cov;
197  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
198  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
199 
201  pars << 192.34, 1.823, 0.734, 0.235, 1. / (100_GeV), 0;
202 
203  BoundTrackParameters atDisc(dSurface, pars, std::move(cov),
205 
206  // run the test
207  testJacobianToGlobal(atDisc);
208 }
209 
211 BOOST_AUTO_TEST_CASE(JacobianPlaneToGlobalTest) {
212  // Let's create a surface somewhere in space
213  Vector3 sPosition(3421., 112., 893.);
214  Vector3 sNormal = Vector3(1.2, -0.3, 0.05).normalized();
215 
216  // Create a surface & parameters with covariance on the surface
217  auto pSurface = Surface::makeShared<PlaneSurface>(sPosition, sNormal);
218 
219  Covariance cov;
220  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
221  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
222 
224  pars << 12.34, -8722., 2.134, 0.85, 1. / (100_GeV), 0;
225 
226  BoundTrackParameters atPlane(pSurface, pars, std::move(cov),
228 
229  // run the test
230  testJacobianToGlobal(atPlane);
231 }
232 
234 BOOST_AUTO_TEST_CASE(JacobianPerigeeToGlobalTest) {
235  // Create a surface & parameters with covariance on the surface
236  auto pSurface = Surface::makeShared<PerigeeSurface>(Vector3({0., 0., 0.}));
237 
238  Covariance cov;
239  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
240  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
242  pars << -3.34, -822., -0.734, 0.85, 1. / (100_GeV), 0;
243 
244  BoundTrackParameters perigee(pSurface, pars, std::move(cov),
246 
247  // run the test
248  testJacobianToGlobal(perigee);
249 }
250 
252 BOOST_AUTO_TEST_CASE(JacobianStrawToGlobalTest) {
253  // Create a surface & parameters with covariance on the surface
254  auto sTransform = createCylindricTransform({1019., -52., 382.}, 0.4, -0.3);
255  auto sSurface = Surface::makeShared<StrawSurface>(sTransform, 10., 1000.);
256 
257  Covariance cov;
258  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
259  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
260 
262  pars << -8.34, 812., 0.734, 0.25, 1. / (100_GeV), 0;
263 
264  BoundTrackParameters atStraw(sSurface, pars, std::move(cov),
266 
267  // run the test
268  testJacobianToGlobal(atStraw);
269 }
270 
271 } // namespace Test
272 } // namespace Acts