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 // Detray include(s)
0010 #include "detray/navigation/accelerators/brute_force.hpp"
0011 
0012 #include "detray/navigation/accelerators/concepts.hpp"
0013 #include "detray/tracks/ray.hpp"
0014 
0015 // Detray test include(s)
0016 #include "detray/test/common/build_toy_detector.hpp"
0017 #include "detray/test/framework/types.hpp"
0018 #include "detray/test/utils/planes_along_direction.hpp"
0019 
0020 // Vecmem include(s)
0021 #include <vecmem/memory/host_memory_resource.hpp>
0022 
0023 // GTest include(s)
0024 #include <gtest/gtest.h>
0025 
0026 using namespace detray;
0027 
0028 namespace {
0029 
0030 vecmem::host_memory_resource host_mr;
0031 
0032 // Algebra definitions
0033 using scalar = test::scalar;
0034 using vector3 = test::vector3;
0035 
0036 /// A functor that performs some tests on a neighborhood of surfaces in a volume
0037 struct neighbor_visit_test {
0038   /// Test the volume links
0039   template <typename surfaces_descriptor_t>
0040   DETRAY_HOST_DEVICE void operator()(const surfaces_descriptor_t& sf,
0041                                      const dindex test_vol_idx) const {
0042     EXPECT_EQ(sf.volume(), test_vol_idx)
0043         << " surface identifier found: " << sf.identifier();
0044   }
0045 
0046   /// Test the volume links
0047   DETRAY_HOST_DEVICE void operator()(const dindex& vol_index,
0048                                      const dindex test_vol_idx) const {
0049     EXPECT_EQ(vol_index, test_vol_idx) << " volume index found: " << vol_index;
0050   }
0051 };
0052 
0053 }  // anonymous namespace
0054 
0055 /// Test retrieval of surface from collection using brute force searching
0056 GTEST_TEST(detray_acceleration_structures, brute_force_collection) {
0057   // Where to place the surfaces
0058   dvector<scalar> distances1{0.f, 10.0f, 20.0f, 40.0f, 80.0f, 100.0f};
0059   dvector<scalar> distances2{30.0f, 230.0f, 240.0f, 250.0f};
0060   dvector<scalar> distances3{0.1f, 5.0f, 50.0f, 500.0f, 5000.0f, 50000.0f};
0061   // surface direction
0062   vector3 direction{0.f, 0.f, 1.f};
0063 
0064   auto [surfaces1, transforms1] =
0065       test::planes_along_direction(distances1, direction);
0066   auto [surfaces2, transforms2] =
0067       test::planes_along_direction(distances2, direction);
0068   auto [surfaces3, transforms3] =
0069       test::planes_along_direction(distances3, direction);
0070 
0071   using brute_force_coll_t =
0072       brute_force_collection<typename decltype(surfaces1)::value_type>;
0073 
0074   brute_force_coll_t sf_collection(&host_mr);
0075 
0076   static_assert(
0077       concepts::surface_accelerator<typename brute_force_coll_t::value_type>);
0078 
0079   // Check a few basics
0080   ASSERT_TRUE(sf_collection.empty());
0081 
0082   sf_collection.push_back(surfaces1);
0083   EXPECT_EQ(sf_collection.size(), 1UL);
0084   sf_collection.push_back(surfaces2);
0085   EXPECT_EQ(sf_collection.size(), 2UL);
0086   sf_collection.push_back(surfaces3);
0087   EXPECT_EQ(sf_collection.size(), 3UL);
0088 
0089   ASSERT_FALSE(sf_collection.empty());
0090   ASSERT_EQ(sf_collection.all().size(),
0091             distances1.size() + distances2.size() + distances3.size());
0092 
0093   // Check a single brute force finder
0094   EXPECT_EQ(sf_collection[0].size(), distances1.size());
0095   EXPECT_EQ(sf_collection[1].size(), distances2.size());
0096   EXPECT_EQ(sf_collection[2].size(), distances3.size());
0097 
0098   // Check the 'all' interface
0099   EXPECT_EQ(sf_collection[0].all().size(), distances1.size());
0100   EXPECT_EQ(sf_collection[1].all().size(), distances2.size());
0101   EXPECT_EQ(sf_collection[2].all().size(), distances3.size());
0102 
0103   // Check the test surfaces
0104   for (const auto& sf : sf_collection[1].all()) {
0105     EXPECT_EQ(sf.volume(), 0UL);
0106     EXPECT_EQ(sf.id(), surface_id::e_sensitive);
0107     EXPECT_FALSE(sf.is_portal());
0108   }
0109 }
0110 
0111 /// Integration test for the retrieval of surfaces in a volume during local
0112 /// navigation
0113 GTEST_TEST(detray_acceleration_structures, brute_force_search) {
0114   const auto [det, names] = build_toy_detector<test::algebra>(host_mr);
0115 
0116   using detector_t = decltype(det);
0117   using context_t = detector_t::geometry_context;
0118   using object_id = typename detector_t::volume_type::object_id;
0119 
0120   context_t ctx{};
0121 
0122   constexpr detray::search_window<dindex, 2> win_size{0u, 0u};
0123 
0124   // Now run a brute force surface search in the first barrel layer
0125   dindex test_vol_idx{7UL};
0126   const auto vol = tracking_volume{det, test_vol_idx};
0127 
0128   // track in x-direction
0129   detail::ray<typename detector_t::algebra_type> trk({0.f, 0.f, 0.f}, 0.f,
0130                                                      {1.f, 0.f, 0.f}, -1.f);
0131 
0132   vol.template visit_neighborhood<object_id::e_portal, neighbor_visit_test>(
0133       trk, win_size, ctx, test_vol_idx);
0134 }