Back to home page

EIC code displayed by LXR

 
 

    


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

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/polar2D.hpp"
0011 
0012 #include "detray/definitions/units.hpp"
0013 #include "detray/geometry/concepts.hpp"
0014 
0015 // Detray test include(s)
0016 #include "detray/test/framework/types.hpp"
0017 
0018 // GTest include(s).
0019 #include <gtest/gtest.h>
0020 
0021 using namespace detray;
0022 
0023 using test_algebra = test::algebra;
0024 using scalar = test::scalar;
0025 using point3 = test::point3;
0026 using vector3 = test::vector3;
0027 using transform3 = test::transform3;
0028 
0029 const scalar isclose{1e-5f};
0030 
0031 // This test polar2D coordinate
0032 GTEST_TEST(detray_coordinates, polar2D) {
0033   // Preparation work
0034   const vector3 z = {0.f, 0.f, 1.f};
0035   const vector3 x = {1.f, 0.f, 0.f};
0036   const point3 t = {2.f, 3.f, 4.f};
0037   const transform3 trf(t, z, x);
0038   const point3 global1 = {4.f, 7.f, 4.f};
0039   const vector3 mom = {1.f, 2.f, 3.f};
0040   const vector3 d = vector::normalize(mom);
0041 
0042   const polar2D<test_algebra> p2;
0043 
0044   static_assert(concepts::coordinate_frame<polar2D<test_algebra>>);
0045   static_assert(concepts::planar_frame<polar2D<test_algebra>>);
0046 
0047   // Global to local transformation
0048   const point3 local = p2.global_to_local_3D(trf, global1, d);
0049 
0050   // Check if the local position is correct
0051   ASSERT_NEAR(local[0], std::sqrt(20.f), isclose);
0052   ASSERT_NEAR(local[1], std::atan2(4.f, 2.f), isclose);
0053 
0054   // Local to global transformation
0055   const point3 global2 = p2.local_to_global(trf, local);
0056 
0057   // Check if the same global position is obtained
0058   ASSERT_NEAR(global1[0], global2[0], isclose);
0059   ASSERT_NEAR(global1[1], global2[1], isclose);
0060   ASSERT_NEAR(global1[2], global2[2], isclose);
0061 
0062   // Normal vector
0063   const vector3 n = p2.normal(trf);
0064   ASSERT_NEAR(n[0], z[0], isclose);
0065   ASSERT_NEAR(n[1], z[1], isclose);
0066   ASSERT_NEAR(n[2], z[2], isclose);
0067 }