Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:23

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 // Project include(s).
0010 #include "detray/propagator/detail/jacobian_line.hpp"
0011 
0012 #include "detray/geometry/mask.hpp"
0013 #include "detray/geometry/shapes/line.hpp"
0014 #include "detray/propagator/detail/jacobian_engine.hpp"
0015 #include "detray/tracks/tracks.hpp"
0016 
0017 // Detray test include(s)
0018 #include "detray/test/framework/types.hpp"
0019 
0020 // GTest include(s).
0021 #include <gtest/gtest.h>
0022 
0023 using namespace detray;
0024 
0025 using test_algebra = test::algebra;
0026 using scalar = test::scalar;
0027 using point2 = test::point2;
0028 using point3 = test::point3;
0029 using vector3 = test::vector3;
0030 using transform3 = test::transform3;
0031 
0032 constexpr scalar isclose{1e-5f};
0033 
0034 const scalar r{2.f};
0035 const scalar hz{50.f};
0036 const mask<line<>, test_algebra> ln{0u, r, hz};
0037 
0038 GTEST_TEST(detray_propagator, jacobian_line2D_case1) {
0039   using jac_engine = detail::jacobian_engine<test_algebra>;
0040   using frame_type = line2D<test_algebra>;
0041 
0042   // Preparation work
0043   vector3 z = {1.f, 1.f, 1.f};
0044   z = vector::normalize(z);
0045   vector3 x = {1.f, 0.f, -1.f};
0046   x = vector::normalize(x);
0047   const point3 t = {0.f, 0.f, 0.f};
0048   const transform3 trf(t, z, x);
0049   const point3 global1 = {1.f, 1.5f, 0.5f};
0050   const vector3 mom = {0.f, 1.f, 1.f};
0051   const scalar time{0.1f};
0052   const scalar charge{-1.f};
0053 
0054   // Free track parameter
0055   const free_track_parameters<test_algebra> free_params(global1, time, mom,
0056                                                         charge);
0057 
0058   const auto bound_vec =
0059       detail::free_to_bound_vector<line2D<test_algebra>>(trf, free_params);
0060   const auto free_params2 = detail::bound_to_free_vector(trf, ln, bound_vec);
0061 
0062   // Check if the bound vector is correct
0063   ASSERT_NEAR(getter::element(bound_vec.bound_local(), e_bound_loc0),
0064               -constant<scalar>::inv_sqrt2, isclose);
0065   ASSERT_NEAR(getter::element(bound_vec.bound_local(), e_bound_loc1),
0066               std::sqrt(3.f), isclose);
0067   ASSERT_NEAR(bound_vec.phi(), constant<scalar>::pi_2, isclose);  // atan(2)
0068   ASSERT_NEAR(bound_vec.theta(), constant<scalar>::pi_4,
0069               isclose);  // atan(sqrt(5)/3)
0070   ASSERT_NEAR(bound_vec.qop(), -constant<scalar>::inv_sqrt2, isclose);
0071   ASSERT_NEAR(bound_vec.time(), 0.1f, isclose);
0072 
0073   // Check if the same free vector is obtained
0074   for (unsigned int i = 0u; i < 8u; i++) {
0075     ASSERT_NEAR(free_params[i], free_params2[i], isclose);
0076   }
0077 
0078   // Test Jacobian transformation
0079   const bound_matrix<test_algebra> J =
0080       jac_engine::free_to_bound_jacobian<frame_type>(trf, free_params) *
0081       jac_engine::bound_to_free_jacobian<frame_type>(trf, ln, bound_vec);
0082 
0083   for (unsigned int i = 0u; i < 6u; i++) {
0084     for (unsigned int j = 0u; j < 6u; j++) {
0085       if (i == j) {
0086         EXPECT_NEAR(getter::element(J, i, j), 1.f, isclose);
0087       } else {
0088         EXPECT_NEAR(getter::element(J, i, j), 0.f, isclose);
0089       }
0090     }
0091   }
0092 }
0093 
0094 GTEST_TEST(detray_propagator, jacobian_line2D_case2) {
0095   using jac_engine = detail::jacobian_engine<test_algebra>;
0096   using frame_type = line2D<test_algebra>;
0097 
0098   // Preparation work
0099   vector3 z = {1.f, 2.f, 3.f};
0100   z = vector::normalize(z);
0101   vector3 x = {2.f, -4.f, 2.f};
0102   x = vector::normalize(x);
0103   const point3 t = {0.f, 0.f, 0.f};
0104   const transform3 trf(t, z, x);
0105   const vector3 mom = {1.f, 6.f, -2.f};
0106   const vector3 d = vector::normalize(mom);
0107   const scalar time{0.1f};
0108   const scalar charge{-1.f};
0109 
0110   const point2 bound1 = {1.f, 2.f};
0111 
0112   const point3 global =
0113       line2D<test_algebra>::local_to_global(trf, ln, bound1, d);
0114 
0115   // Free track parameter
0116   const free_track_parameters<test_algebra> free_params(global, time, mom,
0117                                                         charge);
0118   const auto bound_vec =
0119       detail::free_to_bound_vector<line2D<test_algebra>>(trf, free_params);
0120 
0121   // Test Jacobian transformation
0122   const bound_matrix<test_algebra> J =
0123       jac_engine::free_to_bound_jacobian<frame_type>(trf, free_params) *
0124       jac_engine::bound_to_free_jacobian<frame_type>(trf, ln, bound_vec);
0125 
0126   for (unsigned int i = 0u; i < 6u; i++) {
0127     for (unsigned int j = 0u; j < 6u; j++) {
0128       if (i == j) {
0129         EXPECT_NEAR(getter::element(J, i, j), 1.f, isclose);
0130       } else {
0131         EXPECT_NEAR(getter::element(J, i, j), 0.f, isclose);
0132       }
0133     }
0134   }
0135 }