Back to home page

EIC code displayed by LXR

 
 

    


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

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/geometry/coordinates/cylindrical2D.hpp"
0011 
0012 #include "detray/definitions/units.hpp"
0013 #include "detray/geometry/concepts.hpp"
0014 #include "detray/geometry/coordinates/concentric_cylindrical2D.hpp"
0015 
0016 // Detray test include(s)
0017 #include "detray/test/framework/types.hpp"
0018 
0019 // GTest include(s).
0020 #include <gtest/gtest.h>
0021 
0022 // System include(s).
0023 #include <limits>
0024 
0025 using namespace detray;
0026 
0027 using test_algebra = test::algebra;
0028 using scalar = test::scalar;
0029 using point3 = test::point3;
0030 using point2 = test::point2;
0031 using vector3 = test::vector3;
0032 using transform3 = test::transform3;
0033 
0034 constexpr scalar isclose{1e-5f};
0035 
0036 // This test cylindrical2D coordinate
0037 GTEST_TEST(detray_coordinates, cylindrical2D) {
0038   // Preparation work
0039   const vector3 z = {0.f, 0.f, 1.f};
0040   const vector3 x = {1.f, 0.f, 0.f};
0041   const point3 t = {2.f, 3.f, 4.f};
0042   const transform3 trf(t, z, x);
0043   // Global position on surface
0044   const point3 global1 = {3.4142136f, 4.4142136f, 9.f};
0045   const vector3 mom = {1.f, 2.f, 3.f};
0046   const vector3 d = vector::normalize(mom);
0047   const scalar r{2.f};
0048 
0049   const cylindrical2D<test_algebra> c2;
0050 
0051   static_assert(concepts::coordinate_frame<cylindrical2D<test_algebra>>);
0052   static_assert(concepts::cylindrical_frame<cylindrical2D<test_algebra>>);
0053 
0054   // Global to local transformation
0055   const point3 local = c2.global_to_local_3D(trf, global1, d);
0056 
0057   // Check if the local position is correct
0058   ASSERT_NEAR(local[0], r * constant<scalar>::pi_4, isclose);
0059   ASSERT_NEAR(local[1], 5.f, isclose);
0060 
0061   // Local to global transformation
0062   const point3 global2 = c2.local_to_global(trf, local);
0063 
0064   // Check if the same global position is obtained
0065   ASSERT_NEAR(global1[0], global2[0], isclose);
0066   ASSERT_NEAR(global1[1], global2[1], isclose);
0067   ASSERT_NEAR(global1[2], global2[2], isclose);
0068 
0069   // Normal vector
0070   const vector3 n = c2.normal(trf, local);
0071   ASSERT_NEAR(n[0], constant<scalar>::inv_sqrt2, isclose);
0072   ASSERT_NEAR(n[1], constant<scalar>::inv_sqrt2, isclose);
0073   ASSERT_NEAR(n[2], 0.f, isclose);
0074 }
0075 
0076 // This test concentric cylindrical2D coordinate
0077 GTEST_TEST(detray_coordinates, concentric_cylindrical2D) {
0078   const transform3 trf{};
0079   // Global position on surface
0080   const point3 global1 = {constant<scalar>::sqrt2, constant<scalar>::sqrt2,
0081                           static_cast<scalar>(9.f)};
0082   const scalar r{2.f};
0083 
0084   const concentric_cylindrical2D<test_algebra> c2;
0085 
0086   static_assert(
0087       concepts::coordinate_frame<concentric_cylindrical2D<test_algebra>>);
0088 
0089   // Global to local transformation
0090   const point3 local3 = c2.global_to_local_3D(trf, global1, {});
0091   const point2 local2 = c2.global_to_local(trf, global1, {});
0092 
0093   // Check if the local position is correct
0094   ASSERT_NEAR(local3[0], constant<scalar>::pi_4, isclose);
0095   ASSERT_NEAR(local3[1], 9.f, isclose);
0096   ASSERT_NEAR(local3[2], r, isclose);
0097   ASSERT_NEAR(local2[0], constant<scalar>::pi_4, isclose);
0098   ASSERT_NEAR(local2[1], 9.f, isclose);
0099 
0100   // Local to global transformation
0101   const point3 global2 = c2.local_to_global(trf, local3);
0102   // Check if the same global position is obtained
0103   ASSERT_NEAR(global1[0], global2[0], isclose);
0104   ASSERT_NEAR(global1[1], global2[1], isclose);
0105   ASSERT_NEAR(global1[2], global2[2], isclose);
0106 
0107   // Normal vector
0108   const vector3 n = c2.normal(trf, local3);
0109   ASSERT_NEAR(n[0], constant<scalar>::inv_sqrt2, isclose);
0110   ASSERT_NEAR(n[1], constant<scalar>::inv_sqrt2, isclose);
0111   ASSERT_NEAR(n[2], 0.f, isclose);
0112 }