Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:27

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2023-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Project include(s).
0009 #include "tests/test_detectors.hpp"
0010 #include "traccc/cuda/seeding/silicon_pixel_spacepoint_formation_algorithm.hpp"
0011 #include "traccc/definitions/common.hpp"
0012 #include "traccc/edm/spacepoint_collection.hpp"
0013 #include "traccc/geometry/detector.hpp"
0014 
0015 // VecMem include(s).
0016 #include <vecmem/memory/cuda/device_memory_resource.hpp>
0017 #include <vecmem/memory/cuda/host_memory_resource.hpp>
0018 #include <vecmem/memory/cuda/managed_memory_resource.hpp>
0019 #include <vecmem/memory/host_memory_resource.hpp>
0020 #include <vecmem/utils/cuda/async_copy.hpp>
0021 #include <vecmem/utils/cuda/stream_wrapper.hpp>
0022 
0023 // GTest include(s).
0024 #include <gtest/gtest.h>
0025 
0026 using namespace traccc;
0027 
0028 TEST(CUDASpacepointFormation, cuda) {
0029   // Memory resource used by the EDM.
0030   vecmem::cuda::managed_memory_resource mng_mr;
0031   vecmem::cuda::host_memory_resource host_mr;
0032   traccc::memory_resource mr{mng_mr, &host_mr};
0033 
0034   // Cuda stream
0035   vecmem::cuda::stream_wrapper vecmem_stream;
0036   traccc::cuda::stream_wrapper stream{vecmem_stream.stream()};
0037 
0038   // Cuda copy objects
0039   vecmem::cuda::async_copy copy{stream.cudaStream()};
0040 
0041   // Use rectangle surfaces
0042   detray::mask<detray::rectangle2D, traccc::default_algebra> rectangle{
0043       0u, 10000.f * traccc::unit<scalar>::mm,
0044       10000.f * traccc::unit<scalar>::mm};
0045 
0046   // Plane alignment direction (aligned to x-axis)
0047   detray::detail::ray<traccc::default_algebra> traj{
0048       {0, 0, 0}, 0, {1, 0, 0}, -1};
0049 
0050   // Position of planes (in mm unit)
0051   std::vector<scalar> plane_positions = {20.f,  40.f,  60.f,  80.f, 100.f,
0052                                          120.f, 140.f, 160.f, 180.f};
0053 
0054   detray::tel_det_config tel_cfg{rectangle};
0055   tel_cfg.positions(plane_positions);
0056   tel_cfg.pilot_track(traj);
0057 
0058   // Create telescope geometry
0059   auto [det, name_map] = build_telescope_detector(mng_mr, tel_cfg);
0060 
0061   traccc::host_detector host_det;
0062   host_det.set<traccc::telescope_detector>(std::move(det));
0063 
0064   // Surface lookup
0065   auto surfaces = host_det.as<traccc::telescope_detector>().surfaces();
0066 
0067   const traccc::detector_buffer device_det =
0068       traccc::buffer_from_host_detector(host_det, mng_mr, copy);
0069 
0070   // Prepare measurement collection
0071   edm::measurement_collection::host measurements{mng_mr};
0072 
0073   // Add a measurement at the first plane
0074   measurements.push_back({{7.f, 2.f},
0075                           {0.f, 0.f},
0076                           2,
0077                           0.f,
0078                           0.f,
0079                           0u,
0080                           surfaces[0].identifier(),
0081                           {1u, 1u},
0082                           0u});
0083 
0084   // Add a measurement at the last plane
0085   measurements.push_back({{10.f, 15.f},
0086                           {0.f, 0.f},
0087                           2u,
0088                           0.f,
0089                           0.f,
0090                           0u,
0091                           surfaces[8u].identifier(),
0092                           {1u, 1u},
0093                           1u});
0094 
0095   // Run spacepoint formation
0096   traccc::cuda::silicon_pixel_spacepoint_formation_algorithm sp_formation(
0097       mr, copy, stream);
0098   auto spacepoints_buffer =
0099       sp_formation(device_det, vecmem::get_data(measurements));
0100 
0101   edm::spacepoint_collection::device spacepoints(spacepoints_buffer);
0102 
0103   // Check the results
0104   EXPECT_EQ(copy.get_size(spacepoints_buffer), 2u);
0105   std::set<std::array<float, 3u>> test;
0106   test.insert(spacepoints[0].global());
0107   test.insert(spacepoints[1].global());
0108 
0109   std::set<std::array<float, 3u>> ref;
0110   ref.insert({180.f, 10.f, 15.f});
0111   ref.insert({20.f, 7.f, 2.f});
0112 
0113   EXPECT_EQ(test, ref);
0114 }