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/shapes/ring2D.hpp"
0011 
0012 #include "detray/definitions/units.hpp"
0013 #include "detray/geometry/concepts.hpp"
0014 #include "detray/geometry/mask.hpp"
0015 
0016 // Detray test include(s)
0017 #include "detray/test/framework/types.hpp"
0018 #include "detray/test/utils/ratio_test.hpp"
0019 
0020 // GTest include
0021 #include <gtest/gtest.h>
0022 
0023 using namespace detray;
0024 
0025 using test_algebra = test::algebra;
0026 using scalar = test::scalar;
0027 using point3 = test::point3;
0028 
0029 constexpr scalar tol{1e-5f};
0030 
0031 /// This tests the basic functionality of a ring
0032 GTEST_TEST(detray_masks, ring2D) {
0033   static_assert(concepts::shape<ring2D, test_algebra>);
0034   static_assert(concepts::planar_shape<ring2D, test_algebra>);
0035 
0036   point3 p2_pl_in = {0.5f, -2.f, 0.f};
0037   point3 p2_pl_edge = {0.f, 3.5f, 0.f};
0038   point3 p2_pl_out = {3.6f, 5.f, 0.f};
0039 
0040   constexpr scalar inner_r{0.f * unit<scalar>::mm};
0041   constexpr scalar outer_r{3.5f * unit<scalar>::mm};
0042 
0043   mask<ring2D, test_algebra> r2{0u, inner_r, outer_r};
0044 
0045   ASSERT_NEAR(r2[ring2D::e_inner_r], 0.f, tol);
0046   ASSERT_NEAR(r2[ring2D::e_outer_r], 3.5f, tol);
0047 
0048   ASSERT_TRUE(r2.is_inside(p2_pl_in));
0049   ASSERT_TRUE(r2.is_inside(p2_pl_edge));
0050   ASSERT_FALSE(r2.is_inside(p2_pl_out));
0051   // Move outside point inside using a tolerance
0052   ASSERT_TRUE(r2.is_inside(p2_pl_out, 1.2f));
0053 
0054   // Check area
0055   const scalar a{r2.area()};
0056   EXPECT_NEAR(a, 38.4845100065f * unit<scalar>::mm2, tol);
0057   ASSERT_EQ(a, r2.measure());
0058 
0059   // Check bounding box
0060   constexpr scalar envelope{0.01f};
0061   const auto loc_bounds = r2.local_min_bounds(envelope);
0062   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_x], -(outer_r + envelope), tol);
0063   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_y], -(outer_r + envelope), tol);
0064   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_z], -envelope, tol);
0065   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_x], (outer_r + envelope), tol);
0066   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_y], (outer_r + envelope), tol);
0067   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_z], envelope, tol);
0068 
0069   const auto centroid = r2.centroid();
0070   ASSERT_NEAR(centroid[0], 0.f, tol);
0071   ASSERT_NEAR(centroid[1], 0.f, tol);
0072   ASSERT_NEAR(centroid[2], 0.f, tol);
0073 }
0074 
0075 /// This tests the inside/outside method of the mask
0076 GTEST_TEST(detray_masks, ring2D_ratio_test) {
0077   struct mask_check {
0078     bool operator()(const point3 &p, const mask<ring2D, test_algebra> &r,
0079                     const test::transform3 &trf, const scalar t) {
0080       return r.is_inside(trf, p, t);
0081     }
0082   };
0083 
0084   constexpr mask<ring2D, test_algebra> r{0u, 2.f, 5.f};
0085 
0086   constexpr scalar t{0.f};
0087   const test::transform3 trf{};
0088   constexpr scalar size{10.f * unit<scalar>::mm};
0089   const auto n_points{static_cast<std::size_t>(std::pow(500, 3))};
0090 
0091   // x- and y-coordinates yield a valid local position on the underlying plane
0092   std::vector<point3> points =
0093       test::generate_regular_points<cuboid3D>(n_points, {size});
0094 
0095   scalar ratio = test::ratio_test<mask_check>(points, r, trf, t);
0096 
0097   const scalar area{r.measure()};
0098   const scalar world{size * size};
0099 
0100   ASSERT_NEAR(ratio, area / world, 0.001f);
0101 }