Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-20 08:00:07

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 "ActsTests/CommonHelpers/FloatComparisons.hpp"
0014 
0015 #include <algorithm>
0016 #include <cmath>
0017 #include <numbers>
0018 #include <utility>
0019 
0020 using namespace Acts;
0021 
0022 namespace ActsTests {
0023 
0024 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0025 
0026 /// Test for rotation matrix and calculation of derivative of rotated x/y/z axis
0027 /// w.r.t. rotation parameters
0028 BOOST_AUTO_TEST_CASE(alignment_helper_test) {
0029   // (a) Test with non-identity rotation matrix
0030   // Rotation angle parameters
0031   const double alpha = std::numbers::pi;
0032   const double beta = 0.;
0033   const double gamma = std::numbers::pi / 2.;
0034   // rotation around x axis
0035   AngleAxis3 rotX(alpha, Vector3(1., 0., 0.));
0036   // rotation around y axis
0037   AngleAxis3 rotY(beta, Vector3(0., 1., 0.));
0038   // rotation around z axis
0039   AngleAxis3 rotZ(gamma, Vector3(0., 0., 1.));
0040   double sz = std::sin(gamma);
0041   double cz = std::cos(gamma);
0042   double sy = std::sin(beta);
0043   double cy = std::cos(beta);
0044   double sx = std::sin(alpha);
0045   double cx = std::cos(alpha);
0046 
0047   // Calculate the expected rotation matrix for rotZ * rotY * rotX,
0048   // (i.e. first rotation around x axis, then y axis, last z axis):
0049   // [ cz*cy  cz*sy*sx-cx*sz  sz*sx+cz*cx*sy ]
0050   // [ cy*sz  cz*cx+sz*sy*sx  cx*sz*sy-cz*sx ]
0051   // [ -sy    cy*sx           cy*cx          ]
0052   RotationMatrix3 expRot = RotationMatrix3::Zero();
0053   expRot.col(0) = Vector3(cz * cy, cy * sz, -sy);
0054   expRot.col(1) =
0055       Vector3(cz * sy * sx - cx * sz, cz * cx + sz * sy * sx, cy * sx);
0056   expRot.col(2) =
0057       Vector3(sz * sx + cz * cx * sy, cx * sz * sy - cz * sx, cy * cx);
0058 
0059   // Calculate the expected derivative of local x axis to its rotation
0060   RotationMatrix3 expRotToXAxis = RotationMatrix3::Zero();
0061   expRotToXAxis.col(0) = expRot * Vector3(0, 0, 0);
0062   expRotToXAxis.col(1) = expRot * Vector3(0, 0, -1);
0063   expRotToXAxis.col(2) = expRot * Vector3(0, 1, 0);
0064 
0065   // Calculate the expected derivative of local y axis to its rotation
0066   RotationMatrix3 expRotToYAxis = RotationMatrix3::Zero();
0067   expRotToYAxis.col(0) = expRot * Vector3(0, 0, 1);
0068   expRotToYAxis.col(1) = expRot * Vector3(0, 0, 0);
0069   expRotToYAxis.col(2) = expRot * Vector3(-1, 0, 0);
0070 
0071   // Calculate the expected derivative of local z axis to its rotation
0072   RotationMatrix3 expRotToZAxis = RotationMatrix3::Zero();
0073   expRotToZAxis.col(0) = expRot * Vector3(0, -1, 0);
0074   expRotToZAxis.col(1) = expRot * Vector3(1, 0, 0);
0075   expRotToZAxis.col(2) = expRot * Vector3(0, 0, 0);
0076 
0077   // Construct a transform
0078   Translation3 translation(Vector3(0., 0., 0.));
0079   Transform3 transform(translation);
0080   // Rotation with rotZ * rotY * rotX
0081   transform *= rotZ;
0082   transform *= rotY;
0083   transform *= rotX;
0084   // Get the rotation of the transform
0085   const auto rotation = transform.rotation();
0086 
0087   // Check if the rotation matrix is as expected
0088   CHECK_CLOSE_ABS(rotation, expRot, 1e-15);
0089 
0090   // Call the alignment helper to calculate the derivative of local frame axes
0091   // w.r.t its rotation
0092   const auto& [rotToLocalXAxis, rotToLocalYAxis, rotToLocalZAxis] =
0093       detail::rotationToLocalAxesDerivative(rotation);
0094 
0095   // Check if the derivative for local x axis is as expected
0096   CHECK_CLOSE_ABS(rotToLocalXAxis, expRotToXAxis, 1e-15);
0097 
0098   // Check if the derivative for local y axis is as expected
0099   CHECK_CLOSE_ABS(rotToLocalYAxis, expRotToYAxis, 1e-15);
0100 
0101   // Check if the derivative for local z axis is as expected
0102   CHECK_CLOSE_ABS(rotToLocalZAxis, expRotToZAxis, 1e-15);
0103 
0104   // (b) Test with identity rotation matrix
0105   RotationMatrix3 iRotation = RotationMatrix3::Identity();
0106 
0107   // Call the alignment helper to calculate the derivative of local frame axes
0108   // w.r.t its rotation
0109   const auto& [irotToLocalXAxis, irotToLocalYAxis, irotToLocalZAxis] =
0110       detail::rotationToLocalAxesDerivative(iRotation);
0111 
0112   // The expected derivatives
0113   expRotToXAxis << 0, 0, 0, 0, 0, 1, 0, -1, 0;
0114   expRotToYAxis << 0, 0, -1, 0, 0, 0, 1, 0, 0;
0115   expRotToZAxis << 0, 1, 0, -1, 0, 0, 0, 0, 0;
0116 
0117   // Check if the derivative for local x axis is as expected
0118   CHECK_CLOSE_ABS(irotToLocalXAxis, expRotToXAxis, 1e-15);
0119 
0120   // Check if the derivative for local y axis is as expected
0121   CHECK_CLOSE_ABS(irotToLocalYAxis, expRotToYAxis, 1e-15);
0122 
0123   // Check if the derivative for local z axis is as expected
0124   CHECK_CLOSE_ABS(irotToLocalZAxis, expRotToZAxis, 1e-15);
0125 }
0126 
0127 BOOST_AUTO_TEST_SUITE_END()
0128 
0129 }  // namespace ActsTests