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/definitions/units.hpp"
0011 #include "detray/geometry/volume_descriptor.hpp"
0012 
0013 // Detray test include(s)
0014 #include "detray/test/common/build_toy_detector.hpp"
0015 #include "detray/test/framework/types.hpp"
0016 
0017 // Vecmem include(s)
0018 #include <vecmem/memory/host_memory_resource.hpp>
0019 
0020 // GTest include(s)
0021 #include <gtest/gtest.h>
0022 
0023 // System include(s)
0024 #include <algorithm>
0025 
0026 // TODO: Move these into the test defs
0027 namespace {
0028 
0029 // geo object ids for testing
0030 enum geo_objects : unsigned int {
0031   e_sensitive = 0u,
0032   e_portal = 1u,
0033   e_size = 2u,
0034   e_all = e_size,
0035 };
0036 
0037 // surface finder ids for testing
0038 enum class accel_id : unsigned int {
0039   e_surface_default = 0u,
0040   e_grid = 1u,
0041 };
0042 
0043 }  // namespace
0044 
0045 // This tests the detector volume class and its many links
0046 GTEST_TEST(detray_geometry, volume_descriptor) {
0047   using namespace detray;
0048 
0049   using accel_link_t = dtyped_index<accel_id, dindex>;
0050   using volume_t = volume_descriptor<geo_objects, accel_link_t>;
0051 
0052   // Check construction, setters and getters
0053   volume_t v1(volume_id::e_cylinder);
0054   v1.set_index(12345u);
0055   v1.template set_accel_link<geo_objects::e_portal>(
0056       {accel_id::e_surface_default, 1u});
0057   v1.template set_accel_link<geo_objects::e_sensitive>({accel_id::e_grid, 12u});
0058 
0059   ASSERT_TRUE(v1.id() == volume_id::e_cylinder);
0060   ASSERT_TRUE(v1.index() == 12345u);
0061   ASSERT_TRUE(v1.template accel_link<geo_objects::e_portal>().id() ==
0062               accel_id::e_surface_default);
0063   ASSERT_TRUE(v1.template accel_link<geo_objects::e_portal>().index() == 1u);
0064   ASSERT_TRUE(v1.template accel_link<geo_objects::e_sensitive>().id() ==
0065               accel_id::e_grid);
0066   ASSERT_TRUE(v1.template accel_link<geo_objects::e_sensitive>().index() ==
0067               12u);
0068 
0069   // Check copy constructor
0070   const auto v2 = volume_t(v1);
0071   ASSERT_EQ(v2.id(), volume_id::e_cylinder);
0072   ASSERT_EQ(v2.index(), 12345u);
0073   ASSERT_TRUE(v2.template accel_link<geo_objects::e_portal>().id() ==
0074               accel_id::e_surface_default);
0075   ASSERT_TRUE(v2.template accel_link<geo_objects::e_portal>().index() == 1u);
0076   ASSERT_TRUE(v2.template accel_link<geo_objects::e_sensitive>().id() ==
0077               accel_id::e_grid);
0078   ASSERT_TRUE(v2.template accel_link<geo_objects::e_sensitive>().index() ==
0079               12u);
0080 }
0081 
0082 /// This tests the functionality of a detector volume interface
0083 GTEST_TEST(detray_geometry, tracking_volume) {
0084   using namespace detray;
0085 
0086   using test_algebra = test::algebra;
0087   using scalar = test::scalar;
0088 
0089   constexpr scalar tol{5e-5f};
0090 
0091   vecmem::host_memory_resource host_mr;
0092   const auto [toy_det, names] = build_toy_detector<test_algebra>(host_mr);
0093 
0094   //
0095   // Volume 7 is a barrrel layer with sensitive surfaces
0096   //
0097   const auto vol7 = tracking_volume{toy_det, 7u};
0098 
0099   ASSERT_EQ(vol7.id(), volume_id::e_cylinder) << vol7 << std::endl;
0100   ASSERT_EQ(vol7.index(), 7u) << vol7 << std::endl;
0101   ASSERT_EQ(vol7.name(names), "barrel_7") << vol7 << std::endl;
0102   auto t = vol7.center();
0103   ASSERT_NEAR(t[0], 0.f, tol);
0104   ASSERT_NEAR(t[1], 0.f, tol);
0105   ASSERT_NEAR(t[2], 0.f, tol);
0106   ASSERT_EQ(vol7.surfaces().size(), 228u);
0107 
0108   // Access to all surfaces
0109   std::vector<dindex> sf_indices{};
0110   sf_indices.reserve(vol7.surfaces().size());
0111   for (const auto& sf : vol7.surfaces()) {
0112     sf_indices.push_back(sf.index());
0113   }
0114   auto seq = detray::views::iota(354u, 582u);
0115   EXPECT_TRUE(std::ranges::equal(sf_indices, seq));
0116 
0117   // Access to portals
0118   sf_indices.clear();
0119   for (const auto& pt : vol7.portals()) {
0120     sf_indices.push_back(pt.index());
0121   }
0122   seq = detray::views::iota(578u, 582u);
0123   EXPECT_TRUE(std::ranges::equal(sf_indices, seq));
0124 
0125   // Access to sensitive surfaces
0126   sf_indices.clear();
0127   for (const auto& sens : vol7.template surfaces<surface_id::e_sensitive>()) {
0128     sf_indices.push_back(sens.index());
0129   }
0130   seq = detray::views::iota(354u, 578u);
0131   EXPECT_TRUE(std::ranges::equal(sf_indices, seq));
0132   //
0133   // Volume 5 is negative endcap layer with sensitive surfaces
0134   //
0135   const auto vol5 = tracking_volume{toy_det, 5u};
0136 
0137   ASSERT_EQ(vol5.id(), volume_id::e_cylinder) << vol5 << std::endl;
0138   ASSERT_EQ(vol5.index(), 5u) << vol5 << std::endl;
0139   ASSERT_EQ(vol5.name(names), "endcap_5") << vol5 << std::endl;
0140   t = vol5.center();
0141   ASSERT_NEAR(t[0], 0.f, tol);
0142   ASSERT_NEAR(t[1], 0.f, tol);
0143   ASSERT_NEAR(t[2], -820.f, tol);
0144   ASSERT_EQ(vol5.surfaces().size(), 112u);
0145 
0146   // Access to all surfaces
0147   sf_indices.clear();
0148   for (const auto& sf : vol5.surfaces()) {
0149     sf_indices.push_back(sf.index());
0150   }
0151   seq = detray::views::iota(238u, 350u);
0152   EXPECT_TRUE(std::ranges::equal(sf_indices, seq));
0153 
0154   // Access to portals
0155   sf_indices.clear();
0156   for (const auto& pt : vol5.portals()) {
0157     sf_indices.push_back(pt.index());
0158   }
0159   seq = detray::views::iota(346u, 350u);
0160   EXPECT_TRUE(std::ranges::equal(sf_indices, seq));
0161 
0162   // Access to sensitive surfaces
0163   sf_indices.clear();
0164   for (const auto& sens : vol5.template surfaces<surface_id::e_sensitive>()) {
0165     sf_indices.push_back(sens.index());
0166   }
0167   seq = detray::views::iota(238u, 346u);
0168   EXPECT_TRUE(std::ranges::equal(sf_indices, seq));
0169 
0170   //
0171   // Volume 17 is the positive connector gap
0172   //
0173   const auto vol17 = tracking_volume{toy_det, 17u};
0174 
0175   ASSERT_EQ(vol17.id(), volume_id::e_cylinder) << vol17 << std::endl;
0176   ASSERT_EQ(vol17.index(), 17u) << vol17 << std::endl;
0177   ASSERT_EQ(vol17.name(names), "connector_gap_17") << vol17 << std::endl;
0178   t = vol17.center();
0179   ASSERT_NEAR(t[0], 0.f, tol);
0180   ASSERT_NEAR(t[1], 0.f, tol);
0181   ASSERT_NEAR(t[2], 546.25f, tol);
0182   ASSERT_EQ(vol17.surfaces().size(), 4u);
0183 
0184   // Access to all surfaces
0185   sf_indices.clear();
0186   for (const auto& sf : vol17.surfaces()) {
0187     sf_indices.push_back(sf.index());
0188   }
0189   seq = detray::views::iota(2994u, 2998u);
0190   EXPECT_TRUE(std::ranges::equal(sf_indices, seq));
0191 
0192   // Access to portals
0193   sf_indices.clear();
0194   for (const auto& pt : vol17.portals()) {
0195     sf_indices.push_back(pt.index());
0196   }
0197   EXPECT_TRUE(std::ranges::equal(sf_indices, seq));
0198 
0199   // Access to sensitive surfaces: None in gap volume
0200   sf_indices.clear();
0201   for (const auto& sens : vol17.template surfaces<surface_id::e_sensitive>()) {
0202     sf_indices.push_back(sens.index());
0203   }
0204   EXPECT_TRUE(sf_indices.empty());
0205 }