Back to home page

EIC code displayed by LXR

 
 

    


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

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/mask.hpp"
0011 #include "detray/geometry/shapes/concentric_cylinder2D.hpp"
0012 #include "detray/geometry/shapes/cylinder2D.hpp"
0013 #include "detray/geometry/surface_descriptor.hpp"
0014 #include "detray/navigation/intersection/ray_intersector.hpp"
0015 #include "detray/tracks/ray.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 // System include(s)
0024 #include <limits>
0025 
0026 using namespace detray;
0027 
0028 namespace {
0029 
0030 // Three-dimensional definitions
0031 using test_algebra = test::algebra;
0032 using transform3_t = test::transform3;
0033 using vector3 = test::vector3;
0034 using point3 = test::point3;
0035 using scalar = test::scalar;
0036 using ray_t = detray::detail::ray<test_algebra>;
0037 
0038 constexpr scalar not_defined = std::numeric_limits<scalar>::max();
0039 constexpr scalar tol{1e-5f};
0040 
0041 const scalar r{4.f};
0042 const scalar hz{10.f};
0043 
0044 }  // anonymous namespace
0045 
0046 // This checks both solutions of a ray-cylinder intersection
0047 GTEST_TEST(detray_intersection, translated_cylinder) {
0048   // Create a translated cylinder and test untersection
0049   const transform3_t shifted(vector3{3.f, 2.f, 10.f});
0050   ray_intersector<cylinder2D, test_algebra, true> ci;
0051 
0052   // Test ray
0053   const point3 ori = {3.f, 2.f, 5.f};
0054   const point3 dir = {1.f, 0.f, 0.f};
0055   ray_t ray(ori, 0.f, dir, 0.f);
0056 
0057   // Intersect:
0058   mask<cylinder2D, test_algebra, std::uint_least16_t> cylinder{0u, r, -hz, hz};
0059   const auto hits_bound =
0060       ci(ray, surface_descriptor<>{}, cylinder, shifted, tol, -not_defined);
0061 
0062   // first intersection lies behind the track
0063   EXPECT_TRUE(hits_bound[0].is_inside());
0064   ASSERT_FALSE(hits_bound[0].is_along());
0065 
0066   const auto global0 = cylinder.to_global_frame(shifted, hits_bound[0].local());
0067   EXPECT_NEAR(global0[0], -1.f, tol);
0068   EXPECT_NEAR(global0[1], 2.f, tol);
0069   EXPECT_NEAR(global0[2], 5.f, tol);
0070 
0071   ASSERT_TRUE(hits_bound[0].local()[0] != not_defined &&
0072               hits_bound[0].local()[1] != not_defined);
0073   // p2[0] = r * phi : 180deg in the opposite direction with r = 4
0074   EXPECT_NEAR(hits_bound[0].local()[0], 4.f * constant<scalar>::pi, tol);
0075   EXPECT_NEAR(hits_bound[0].local()[1], -5., tol);
0076 
0077   // second intersection lies in front of the track
0078   EXPECT_TRUE(hits_bound[1].is_inside());
0079   EXPECT_TRUE(hits_bound[1].is_along());
0080 
0081   const auto global1 = cylinder.to_global_frame(shifted, hits_bound[1].local());
0082   EXPECT_NEAR(global1[0], 7.f, tol);
0083   EXPECT_NEAR(global1[1], 2.f, tol);
0084   EXPECT_NEAR(global1[2], 5.f, tol);
0085 
0086   ASSERT_TRUE(hits_bound[1].local()[0] != not_defined &&
0087               hits_bound[1].local()[1] != not_defined);
0088   EXPECT_NEAR(hits_bound[1].local()[0], 0.f, tol);
0089   EXPECT_NEAR(hits_bound[1].local()[1], -5.f, tol);
0090 }
0091 
0092 // This checks the solution of a ray-cylinder portal intersection against
0093 // those obtained from the general cylinder intersector.
0094 GTEST_TEST(detray_intersection, cylinder_portal) {
0095   // Test ray
0096   const point3 ori = {1.f, 0.5f, 1.f};
0097   const point3 dir = vector::normalize(vector3{1.f, 1.f, 1.f});
0098   const ray_t ray(ori, 0.f, dir, 0.f);
0099 
0100   // Create a concentric cylinder and test intersection
0101   const transform3_t identity{};
0102   mask<concentric_cylinder2D, test_algebra, std::uint_least16_t> cylinder{
0103       0u, r, -hz, hz};
0104 
0105   ray_intersector<cylinder2D, test_algebra, true> ci;
0106   ray_intersector<concentric_cylinder2D, test_algebra, true> cpi;
0107 
0108   // Intersect
0109   const auto hits_cylindrical =
0110       ci(ray, surface_descriptor<>{}, cylinder, identity, tol);
0111   const auto hit_cocylindrical =
0112       cpi(ray, surface_descriptor<>{}, cylinder, identity, tol);
0113 
0114   ASSERT_TRUE(hits_cylindrical[1].is_inside());
0115   ASSERT_TRUE(hit_cocylindrical.is_inside());
0116   ASSERT_TRUE(hits_cylindrical[1].is_along());
0117   ASSERT_TRUE(hit_cocylindrical.is_along());
0118 
0119   const auto global0 =
0120       cylinder.to_global_frame(identity, hits_cylindrical[1].local());
0121   const auto global1 =
0122       cylinder.to_global_frame(identity, hit_cocylindrical.local());
0123   EXPECT_NEAR(vector::perp(global0), r, tol);
0124   EXPECT_NEAR(vector::perp(global1), r, tol);
0125 
0126   EXPECT_NEAR(global0[0], global1[0], tol);
0127   EXPECT_NEAR(global0[1], global1[1], tol);
0128   EXPECT_NEAR(global0[2], global1[2], tol);
0129   ASSERT_TRUE(hits_cylindrical[1].local()[0] != not_defined &&
0130               hits_cylindrical[1].local()[1] != not_defined);
0131   ASSERT_TRUE(hit_cocylindrical.local()[0] != not_defined &&
0132               hit_cocylindrical.local()[1] != not_defined);
0133   EXPECT_NEAR(hits_cylindrical[1].local()[0], hit_cocylindrical.local()[0],
0134               tol);
0135   EXPECT_NEAR(hits_cylindrical[1].local()[1], hit_cocylindrical.local()[1],
0136               tol);
0137 }