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/line2D.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 point2 = test::point2;
0026 using point3 = test::point3;
0027 using vector3 = test::vector3;
0028 using transform3 = test::transform3;
0029 
0030 constexpr scalar isclose{1e-5f};
0031 
0032 GTEST_TEST(detray_coordinates, line2D_case1) {
0033   // Preparation work
0034   vector3 z = {1.f, 1.f, 1.f};
0035   z = vector::normalize(z);
0036   vector3 x = {1.f, 0.f, -1.f};
0037   x = vector::normalize(x);
0038   const point3 t = {0.f, 0.f, 0.f};
0039   const transform3 trf(t, z, x);
0040   const point3 global1 = {1.f, 1.5f, 0.5f};
0041   const vector3 mom = {0.f, 1.f, 1.f};
0042   const vector3 d = vector::normalize(mom);
0043 
0044   const line2D<test_algebra> l2;
0045 
0046   static_assert(concepts::coordinate_frame<line2D<test_algebra>>);
0047   static_assert(concepts::line_frame<line2D<test_algebra>>);
0048 
0049   // Global to local transformation
0050   const point3 local = l2.global_to_local_3D(trf, global1, d);
0051 
0052   // Check if the local position is correct
0053   ASSERT_NEAR(local[0], -constant<scalar>::inv_sqrt2, isclose);
0054   ASSERT_NEAR(local[1], std::sqrt(3.f), isclose);
0055 
0056   // Local to global transformation
0057   const point3 global2 = l2.local_to_global(trf, local);
0058 
0059   // Check if the same global position is obtained
0060   ASSERT_NEAR(global1[0], global2[0], isclose);
0061   ASSERT_NEAR(global1[1], global2[1], isclose);
0062   ASSERT_NEAR(global1[2], global2[2], isclose);
0063 
0064   // Normal vector
0065   const vector3 n = l2.normal(trf);
0066   ASSERT_NEAR(n[0], z[0], isclose);
0067   ASSERT_NEAR(n[1], z[1], isclose);
0068   ASSERT_NEAR(n[2], z[2], isclose);
0069 }
0070 
0071 GTEST_TEST(detray_coordinates, line2D_case2) {
0072   // Preparation work
0073   vector3 z = {1.f, 2.f, 3.f};
0074   z = vector::normalize(z);
0075   vector3 x = {2.f, -4.f, 2.f};
0076   x = vector::normalize(x);
0077   const point3 t = {0.f, 0.f, 0.f};
0078   const transform3 trf(t, z, x);
0079   const point2 local1 = {1.f, 2.f};
0080   const vector3 mom = {1.f, 6.f, -2.f};
0081   const vector3 d = vector::normalize(mom);
0082   struct dummy_mask {
0083   } mask;
0084 
0085   const line2D<test_algebra> l2;
0086 
0087   static_assert(concepts::coordinate_frame<line2D<test_algebra>>);
0088   static_assert(concepts::line_frame<line2D<test_algebra>>);
0089 
0090   // local to global transformation
0091   const point3 global = l2.local_to_global(trf, mask, local1, d);
0092 
0093   // global to local transform
0094   const point3 local2 = l2.global_to_local_3D(trf, global, d);
0095 
0096   // Check if the same local position is obtained
0097   ASSERT_NEAR(local1[0], local2[0], isclose);
0098   ASSERT_NEAR(local1[1], local2[1], isclose);
0099 }