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/single3D.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 
0019 // GTest include
0020 #include <gtest/gtest.h>
0021 
0022 using namespace detray;
0023 
0024 using test_algebra = test::algebra;
0025 using scalar = test::scalar;
0026 using point3 = test::point3;
0027 
0028 constexpr scalar tol{1e-7f};
0029 
0030 /// This tests the basic functionality of a single value mask (index 0)
0031 GTEST_TEST(detray_masks, single3_0) {
0032   static_assert(concepts::shape<single3D<>, test_algebra>);
0033 
0034   point3 p3_in = {0.5f, -9.f, 0.f};
0035   point3 p3_edge = {1.f, 9.3f, 2.f};
0036   point3 p3_out = {1.5f, -9.8f, 8.f};
0037 
0038   constexpr scalar h0{1.f * unit<scalar>::mm};
0039   mask<single3D<>, test_algebra> m1_0{0u, -h0, h0};
0040 
0041   ASSERT_NEAR(m1_0[single3D<>::e_lower], -h0, tol);
0042   ASSERT_NEAR(m1_0[single3D<>::e_upper], h0, tol);
0043 
0044   ASSERT_TRUE(m1_0.is_inside(p3_in));
0045   ASSERT_TRUE(m1_0.is_inside(p3_edge));
0046   ASSERT_FALSE(m1_0.is_inside(p3_out));
0047   // Move outside point inside using a tolerance - take t0 not t1
0048   ASSERT_TRUE(m1_0.is_inside(p3_out, 0.6f));
0049 
0050   // Check the measure
0051   EXPECT_NEAR(m1_0.measure(), 2.f * unit<scalar>::mm2, tol);
0052 
0053   // Check bounding box
0054   constexpr scalar envelope{0.01f};
0055   const auto loc_bounds = m1_0.local_min_bounds(envelope);
0056   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_x], -(h0 + envelope), tol);
0057   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_y], -envelope, tol);
0058   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_z], -envelope, tol);
0059   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_x], (h0 + envelope), tol);
0060   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_y], envelope, tol);
0061   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_z], envelope, tol);
0062 
0063   const auto centroid = m1_0.centroid();
0064   ASSERT_NEAR(centroid[0], 0.f, tol);
0065   ASSERT_NEAR(centroid[1], 0.f, tol);
0066   ASSERT_NEAR(centroid[2], 0.f, tol);
0067 }
0068 
0069 /// This tests the basic functionality of a single value mask (index 1)
0070 GTEST_TEST(detray_masks, single3_1) {
0071   static_assert(concepts::shape<single3D<1>, test_algebra>);
0072 
0073   point3 p3_in = {0.5f, -9.f, 0.f};
0074   point3 p3_edge = {1.f, 9.3f, 2.f};
0075   point3 p3_out = {1.5f, -9.8f, 8.f};
0076 
0077   constexpr scalar h1{9.3f * unit<scalar>::mm};
0078   mask<single3D<1>, test_algebra> m1_1{0u, -h1, h1};
0079 
0080   ASSERT_NEAR(m1_1[single3D<>::e_lower], -h1, tol);
0081   ASSERT_NEAR(m1_1[single3D<>::e_upper], h1, tol);
0082 
0083   ASSERT_TRUE(m1_1.is_inside(p3_in));
0084   ASSERT_TRUE(m1_1.is_inside(p3_edge));
0085   ASSERT_FALSE(m1_1.is_inside(p3_out));
0086   // Move outside point inside using a tolerance - take t1 not t1
0087   ASSERT_TRUE(m1_1.is_inside(p3_out, 0.6f));
0088 
0089   // Check the measure
0090   EXPECT_NEAR(m1_1.measure(), 18.6f * unit<scalar>::mm2, tol);
0091 
0092   // Check bounding box
0093   constexpr scalar envelope{0.01f};
0094   const auto loc_bounds = m1_1.local_min_bounds(envelope);
0095   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_x], -envelope, tol);
0096   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_y], -(h1 + envelope), tol);
0097   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_z], -envelope, tol);
0098   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_x], envelope, tol);
0099   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_y], (h1 + envelope), tol);
0100   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_z], envelope, tol);
0101 
0102   const auto centroid = m1_1.centroid();
0103   ASSERT_NEAR(centroid[0], 0.f, tol);
0104   ASSERT_NEAR(centroid[1], 0.f, tol);
0105   ASSERT_NEAR(centroid[2], 0.f, tol);
0106 }
0107 
0108 /// This tests the basic functionality of a single value mask (index 2)
0109 GTEST_TEST(detray_masks, single3_2) {
0110   static_assert(concepts::shape<single3D<2>, test_algebra>);
0111 
0112   point3 p3_in = {0.5f, -9.f, 0.f};
0113   point3 p3_edge = {1.f, 9.3f, 2.f};
0114   point3 p3_out = {1.5f, -9.8f, 8.f};
0115 
0116   constexpr scalar h2{2.f * unit<scalar>::mm};
0117   mask<single3D<2>, test_algebra> m1_2{0u, -h2, h2};
0118 
0119   ASSERT_NEAR(m1_2[single3D<>::e_lower], -h2, tol);
0120   ASSERT_NEAR(m1_2[single3D<>::e_upper], h2, tol);
0121 
0122   ASSERT_TRUE(m1_2.is_inside(p3_in));
0123   ASSERT_TRUE(m1_2.is_inside(p3_edge));
0124   ASSERT_FALSE(m1_2.is_inside(p3_out));
0125   // Move outside point inside using a tolerance - take t1 not t1
0126   ASSERT_TRUE(m1_2.is_inside(p3_out, 6.1f));
0127 
0128   // Check the measure
0129   EXPECT_NEAR(m1_2.measure(), 4.f * unit<scalar>::mm2, tol);
0130 
0131   // Check bounding box
0132   constexpr scalar envelope{0.01f};
0133   const auto loc_bounds = m1_2.local_min_bounds(envelope);
0134   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_x], -envelope, tol);
0135   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_y], -envelope, tol);
0136   ASSERT_NEAR(loc_bounds[cuboid3D::e_min_z], -(h2 + envelope), tol);
0137   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_x], envelope, tol);
0138   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_y], envelope, tol);
0139   ASSERT_NEAR(loc_bounds[cuboid3D::e_max_z], (h2 + envelope), tol);
0140 
0141   const auto centroid = m1_2.centroid();
0142   ASSERT_NEAR(centroid[0], 0.f, tol);
0143   ASSERT_NEAR(centroid[1], 0.f, tol);
0144   ASSERT_NEAR(centroid[2], 0.f, tol);
0145 }