ECCE @ 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 std::shared_ptr<Transform3D> createCylindricTransform(const Vector3D& nposition,
50  double angleX,
51  double angleY) {
52  Transform3D ctransform;
53  ctransform.setIdentity();
54  ctransform.pretranslate(nposition);
55  ctransform.prerotate(AngleAxis3D(angleX, Vector3D::UnitX()));
56  ctransform.prerotate(AngleAxis3D(angleY, Vector3D::UnitY()));
57  return std::make_shared<Transform3D>(ctransform);
58 }
59 
67 std::shared_ptr<Transform3D> createPlanarTransform(const Vector3D& nposition,
68  const Vector3D& nnormal,
69  double angleT,
70  double angleU) {
71  // the rotation of the destination surface
72  Vector3D T = nnormal.normalized();
73  Vector3D U = std::abs(T.dot(Vector3D::UnitZ())) < 0.99
74  ? Vector3D::UnitZ().cross(T).normalized()
75  : Vector3D::UnitX().cross(T).normalized();
76  Vector3D V = T.cross(U);
77  // that's the plane curvilinear Rotation
78  RotationMatrix3D curvilinearRotation;
79  curvilinearRotation.col(0) = U;
80  curvilinearRotation.col(1) = V;
81  curvilinearRotation.col(2) = T;
82  // curvilinear surfaces are boundless
83  Transform3D ctransform{curvilinearRotation};
84  ctransform.pretranslate(nposition);
85  ctransform.prerotate(AngleAxis3D(angleT, T));
86  ctransform.prerotate(AngleAxis3D(angleU, U));
87  //
88  return std::make_shared<Transform3D>(ctransform);
89 }
90 
107 
108 BoundToFreeMatrix convertToMatrix(const std::array<double, 60> P) {
109  // initialize to zero
110  BoundToFreeMatrix jMatrix = BoundToFreeMatrix::Zero();
111  for (size_t j = 0; j < eBoundParametersSize; ++j) {
112  for (size_t i = 0; i < eFreeParametersSize; ++i) {
113  size_t ijc = eFreeParametersSize + j * eFreeParametersSize + i;
114  jMatrix(i, j) = P[ijc];
115  }
116  }
117  return jMatrix;
118 }
119 
125 template <typename Parameters>
126 void testJacobianToGlobal(const Parameters& pars) {
127  // Jacobian creation for Propagator/Steppers
128  // a) ATLAS stepper
129  AtlasStepperType::State astepState(tgContext, mfContext, pars);
130  // b) Eigen stepper
131  EigenStepperType::State estepState(tgContext, mfContext, pars);
132 
133  // create the matrices
134  auto asMatrix = convertToMatrix(astepState.pVector);
135 
136  // cross comparison checks
137  CHECK_CLOSE_OR_SMALL(asMatrix, estepState.jacToGlobal, 1e-6, 1e-9);
138 }
139 
141 BOOST_AUTO_TEST_CASE(JacobianCurvilinearToGlobalTest) {
142  Covariance cov;
143  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
144  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
145 
146  // Let's create a surface somewhere in space
147  Vector3D pos(341., 412., 93.);
148  Vector3D mom(1.2, 8.3, 0.45);
149  const double q = 1;
150 
151  // Create curvilinear parameters
152  CurvilinearParameters curvilinear(cov, pos, mom, q, 0.);
153 
154  // run the test
155  testJacobianToGlobal(curvilinear);
156 }
157 
159 BOOST_AUTO_TEST_CASE(JacobianCylinderToGlobalTest) {
160  // the cylinder transform and surface
161  auto cTransform = createCylindricTransform({10., -5., 0.}, 0.004, 0.03);
162  auto cSurface = Surface::makeShared<CylinderSurface>(cTransform, 200., 1000.);
163 
164  Covariance cov;
165  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
166  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
167 
168  BoundVector pars;
169  pars << 182.34, -82., 0.134, 0.85, 1. / (100_GeV), 0;
170 
171  BoundParameters atCylinder(tgContext, cov, std::move(pars), cSurface);
172 
173  // run the test
174  testJacobianToGlobal(atCylinder);
175 }
176 
178 BOOST_AUTO_TEST_CASE(JacobianDiscToGlobalTest) {
179  // the disc transform and surface
180  auto dTransform = createPlanarTransform(
181  {10., -5., 0.}, Vector3D(0.23, 0.07, 1.).normalized(), 0.004, 0.03);
182  auto dSurface = Surface::makeShared<DiscSurface>(dTransform, 200., 1000.);
183 
184  Covariance cov;
185  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
186  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
187 
188  BoundVector pars;
189  pars << 192.34, 1.823, 0.734, 0.235, 1. / (100_GeV), 0;
190 
191  BoundParameters atDisc(tgContext, cov, std::move(pars), dSurface);
192 
193  // run the test
194  testJacobianToGlobal(atDisc);
195 }
196 
198 BOOST_AUTO_TEST_CASE(JacobianPlaneToGlobalTest) {
199  // Let's create a surface somewhere in space
200  Vector3D sPosition(3421., 112., 893.);
201  Vector3D sNormal = Vector3D(1.2, -0.3, 0.05).normalized();
202 
203  // Create a surface & parameters with covariance on the surface
204  auto pSurface = Surface::makeShared<PlaneSurface>(sPosition, sNormal);
205 
206  Covariance cov;
207  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
208  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
209 
210  BoundVector pars;
211  pars << 12.34, -8722., 2.134, 0.85, 1. / (100_GeV), 0;
212 
213  BoundParameters atPlane(tgContext, cov, std::move(pars), pSurface);
214 
215  // run the test
216  testJacobianToGlobal(atPlane);
217 }
218 
220 BOOST_AUTO_TEST_CASE(JacobianPerigeeToGlobalTest) {
221  // Create a surface & parameters with covariance on the surface
222  auto pSurface = Surface::makeShared<PerigeeSurface>(Vector3D({0., 0., 0.}));
223 
224  Covariance cov;
225  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
226  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
227  BoundVector pars;
228  pars << -3.34, -822., -0.734, 0.85, 1. / (100_GeV), 0;
229 
230  BoundParameters perigee(tgContext, cov, std::move(pars), pSurface);
231 
232  // run the test
233  testJacobianToGlobal(perigee);
234 }
235 
237 BOOST_AUTO_TEST_CASE(JacobianStrawToGlobalTest) {
238  // Create a surface & parameters with covariance on the surface
239  auto sTransform = createCylindricTransform({1019., -52., 382.}, 0.4, -0.3);
240  auto sSurface = Surface::makeShared<StrawSurface>(sTransform, 10., 1000.);
241 
242  Covariance cov;
243  cov << 10_mm, 0, 0, 0, 0, 0, 0, 10_mm, 0, 0, 0, 0, 0, 0, 0.1, 0, 0, 0, 0, 0,
244  0, 0.1, 0, 0, 0, 0, 0, 0, 1. / (10_GeV), 0, 0, 0, 0, 0, 0, 0;
245 
246  BoundVector pars;
247  pars << -8.34, 812., 0.734, 0.25, 1. / (100_GeV), 0;
248 
249  BoundParameters atStraw(tgContext, cov, std::move(pars), sSurface);
250 
251  // run the test
252  testJacobianToGlobal(atStraw);
253 }
254 
255 } // namespace Test
256 } // namespace Acts