Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:49

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/detail/AlignmentHelper.hpp"
0013 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0014 
0015 #include <algorithm>
0016 #include <cmath>
0017 #include <numbers>
0018 #include <utility>
0019 
0020 namespace Acts::Test {
0021 
0022 /// Test for rotation matrix and calculation of derivative of rotated x/y/z axis
0023 /// w.r.t. rotation parameters
0024 BOOST_AUTO_TEST_CASE(alignment_helper_test) {
0025   // (a) Test with non-identity rotation matrix
0026   // Rotation angle parameters
0027   const double alpha = std::numbers::pi;
0028   const double beta = 0.;
0029   const double gamma = std::numbers::pi / 2.;
0030   // rotation around x axis
0031   AngleAxis3 rotX(alpha, Vector3(1., 0., 0.));
0032   // rotation around y axis
0033   AngleAxis3 rotY(beta, Vector3(0., 1., 0.));
0034   // rotation around z axis
0035   AngleAxis3 rotZ(gamma, Vector3(0., 0., 1.));
0036   double sz = std::sin(gamma);
0037   double cz = std::cos(gamma);
0038   double sy = std::sin(beta);
0039   double cy = std::cos(beta);
0040   double sx = std::sin(alpha);
0041   double cx = std::cos(alpha);
0042 
0043   // Calculate the expected rotation matrix for rotZ * rotY * rotX,
0044   // (i.e. first rotation around x axis, then y axis, last z axis):
0045   // [ cz*cy  cz*sy*sx-cx*sz  sz*sx+cz*cx*sy ]
0046   // [ cy*sz  cz*cx+sz*sy*sx  cx*sz*sy-cz*sx ]
0047   // [ -sy    cy*sx           cy*cx          ]
0048   RotationMatrix3 expRot = RotationMatrix3::Zero();
0049   expRot.col(0) = Vector3(cz * cy, cy * sz, -sy);
0050   expRot.col(1) =
0051       Vector3(cz * sy * sx - cx * sz, cz * cx + sz * sy * sx, cy * sx);
0052   expRot.col(2) =
0053       Vector3(sz * sx + cz * cx * sy, cx * sz * sy - cz * sx, cy * cx);
0054 
0055   // Calculate the expected derivative of local x axis to its rotation
0056   RotationMatrix3 expRotToXAxis = RotationMatrix3::Zero();
0057   expRotToXAxis.col(0) = expRot * Vector3(0, 0, 0);
0058   expRotToXAxis.col(1) = expRot * Vector3(0, 0, -1);
0059   expRotToXAxis.col(2) = expRot * Vector3(0, 1, 0);
0060 
0061   // Calculate the expected derivative of local y axis to its rotation
0062   RotationMatrix3 expRotToYAxis = RotationMatrix3::Zero();
0063   expRotToYAxis.col(0) = expRot * Vector3(0, 0, 1);
0064   expRotToYAxis.col(1) = expRot * Vector3(0, 0, 0);
0065   expRotToYAxis.col(2) = expRot * Vector3(-1, 0, 0);
0066 
0067   // Calculate the expected derivative of local z axis to its rotation
0068   RotationMatrix3 expRotToZAxis = RotationMatrix3::Zero();
0069   expRotToZAxis.col(0) = expRot * Vector3(0, -1, 0);
0070   expRotToZAxis.col(1) = expRot * Vector3(1, 0, 0);
0071   expRotToZAxis.col(2) = expRot * Vector3(0, 0, 0);
0072 
0073   // Construct a transform
0074   Translation3 translation(Vector3(0., 0., 0.));
0075   Transform3 transform(translation);
0076   // Rotation with rotZ * rotY * rotX
0077   transform *= rotZ;
0078   transform *= rotY;
0079   transform *= rotX;
0080   // Get the rotation of the transform
0081   const auto rotation = transform.rotation();
0082 
0083   // Check if the rotation matrix is as expected
0084   CHECK_CLOSE_ABS(rotation, expRot, 1e-15);
0085 
0086   // Call the alignment helper to calculate the derivative of local frame axes
0087   // w.r.t its rotation
0088   const auto& [rotToLocalXAxis, rotToLocalYAxis, rotToLocalZAxis] =
0089       detail::rotationToLocalAxesDerivative(rotation);
0090 
0091   // Check if the derivative for local x axis is as expected
0092   CHECK_CLOSE_ABS(rotToLocalXAxis, expRotToXAxis, 1e-15);
0093 
0094   // Check if the derivative for local y axis is as expected
0095   CHECK_CLOSE_ABS(rotToLocalYAxis, expRotToYAxis, 1e-15);
0096 
0097   // Check if the derivative for local z axis is as expected
0098   CHECK_CLOSE_ABS(rotToLocalZAxis, expRotToZAxis, 1e-15);
0099 
0100   // (b) Test with identity rotation matrix
0101   RotationMatrix3 iRotation = RotationMatrix3::Identity();
0102 
0103   // Call the alignment helper to calculate the derivative of local frame axes
0104   // w.r.t its rotation
0105   const auto& [irotToLocalXAxis, irotToLocalYAxis, irotToLocalZAxis] =
0106       detail::rotationToLocalAxesDerivative(iRotation);
0107 
0108   // The expected derivatives
0109   expRotToXAxis << 0, 0, 0, 0, 0, 1, 0, -1, 0;
0110   expRotToYAxis << 0, 0, -1, 0, 0, 0, 1, 0, 0;
0111   expRotToZAxis << 0, 1, 0, -1, 0, 0, 0, 0, 0;
0112 
0113   // Check if the derivative for local x axis is as expected
0114   CHECK_CLOSE_ABS(irotToLocalXAxis, expRotToXAxis, 1e-15);
0115 
0116   // Check if the derivative for local y axis is as expected
0117   CHECK_CLOSE_ABS(irotToLocalYAxis, expRotToYAxis, 1e-15);
0118 
0119   // Check if the derivative for local z axis is as expected
0120   CHECK_CLOSE_ABS(irotToLocalZAxis, expRotToZAxis, 1e-15);
0121 }
0122 }  // namespace Acts::Test