Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:17

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 test include(s)
0010 #include "detray/test/common/bfield.hpp"
0011 #include "detray/test/common/build_telescope_detector.hpp"
0012 #include "detray/test/cpu/detector_scan.hpp"
0013 #include "detray/test/cpu/material_scan.hpp"
0014 #include "detray/test/device/cuda/material_validation.hpp"
0015 #include "detray/test/device/cuda/navigation_validation.hpp"
0016 #include "detray/test/framework/register_checks.hpp"
0017 #include "detray/test/framework/whiteboard.hpp"
0018 
0019 // Vecmem include(s)
0020 #include <vecmem/memory/cuda/device_memory_resource.hpp>
0021 #include <vecmem/memory/host_memory_resource.hpp>
0022 #include <vecmem/utils/cuda/copy.hpp>
0023 
0024 // GTest include
0025 #include <gtest/gtest.h>
0026 
0027 // System include(s)
0028 #include <limits>
0029 
0030 using namespace detray;
0031 
0032 int main(int argc, char **argv) {
0033   using namespace detray;
0034 
0035   using test_algebra = test::algebra;
0036 
0037   // Filter out the google test flags
0038   ::testing::InitGoogleTest(&argc, argv);
0039 
0040   /// Vecmem memory resource for the device allocations
0041   vecmem::cuda::device_memory_resource dev_mr{};
0042 
0043   //
0044   // Telescope detector configuration
0045   //
0046   using tel_detector_t = detector<test::default_telescope_metadata>;
0047   using scalar = typename tel_detector_t::scalar_type;
0048 
0049   /// Set a consistent minimum step size across all tests
0050   const float min_stepsize{stepping::config{}.min_stepsize};
0051 
0052   tel_det_config<test_algebra, rectangle2D> tel_cfg{20.f * unit<scalar>::mm,
0053                                                     20.f * unit<scalar>::mm};
0054   tel_cfg.n_surfaces(10u)
0055       .length(500.f * unit<scalar>::mm)
0056       .envelope(500.f * unit<scalar>::um);
0057 
0058   vecmem::host_memory_resource host_mr;
0059 
0060   const auto [tel_det, tel_names] =
0061       build_telescope_detector<test_algebra>(host_mr, tel_cfg);
0062 
0063   auto white_board = std::make_shared<test::whiteboard>();
0064   tel_detector_t::geometry_context ctx{};
0065 
0066   // Navigation link consistency, discovered by ray intersection
0067   test::ray_scan<tel_detector_t>::config cfg_ray_scan{};
0068   cfg_ray_scan.name("telescope_detector_ray_scan_for_cuda");
0069   cfg_ray_scan.track_generator().n_tracks(10000u);
0070   cfg_ray_scan.overlaps_tol(min_stepsize);
0071   // The first surface is at z=0, so shift the track origin back
0072   cfg_ray_scan.track_generator().origin(0.f, 0.f, -0.05f * unit<scalar>::mm);
0073   cfg_ray_scan.track_generator().theta_range(0.f,
0074                                              0.25f * constant<scalar>::pi_4);
0075 
0076   test::register_checks<test::ray_scan>(tel_det, tel_names, cfg_ray_scan, ctx,
0077                                         white_board);
0078 
0079   // Comparison of straight line navigation with ray scan
0080   detray::cuda::straight_line_navigation<tel_detector_t>::config cfg_str_nav{};
0081   cfg_str_nav.name("telescope_detector_straight_line_navigation_cuda");
0082   cfg_str_nav.n_tracks(cfg_ray_scan.track_generator().n_tracks());
0083   cfg_str_nav.propagation().stepping.min_stepsize = min_stepsize;
0084   cfg_str_nav.propagation().navigation.estimate_scattering_noise = false;
0085   cfg_str_nav.propagation().navigation.intersection.min_mask_tolerance =
0086       static_cast<float>(cfg_ray_scan.mask_tolerance());
0087   cfg_str_nav.propagation().navigation.intersection.max_mask_tolerance =
0088       static_cast<float>(cfg_ray_scan.mask_tolerance());
0089 
0090   test::register_checks<detray::cuda::straight_line_navigation>(
0091       tel_det, tel_names, cfg_str_nav, ctx, white_board);
0092 
0093   // Navigation link consistency, discovered by helix intersection
0094   test::helix_scan<tel_detector_t>::config cfg_hel_scan{};
0095   cfg_hel_scan.name("telescope_detector_helix_scan_for_cuda");
0096   // Let the Newton algorithm dynamically choose tol. based on approx. error
0097   cfg_hel_scan.mask_tolerance(detray::detail::invalid_value<scalar>());
0098   cfg_hel_scan.track_generator().n_tracks(10000u);
0099   cfg_hel_scan.overlaps_tol(min_stepsize);
0100   cfg_hel_scan.track_generator().p_tot(10.f * unit<scalar>::GeV);
0101   cfg_hel_scan.track_generator().origin(0.f, 0.f, -0.05f * unit<scalar>::mm);
0102   cfg_hel_scan.track_generator().theta_range(0.f,
0103                                              0.25f * constant<scalar>::pi_4);
0104 
0105   test::register_checks<test::helix_scan>(tel_det, tel_names, cfg_hel_scan, ctx,
0106                                           white_board);
0107 
0108   // Comparison of navigation in a constant B-field with helix
0109   detray::cuda::helix_navigation<tel_detector_t>::config cfg_hel_nav{};
0110   cfg_hel_nav.name("telescope_detector_helix_navigation_cuda");
0111   cfg_hel_nav.n_tracks(cfg_hel_scan.track_generator().n_tracks());
0112   cfg_hel_nav.propagation().stepping.min_stepsize = min_stepsize;
0113   cfg_hel_nav.propagation().navigation.estimate_scattering_noise = false;
0114   cfg_hel_nav.propagation().navigation.intersection.overstep_tolerance =
0115       -100.f * unit<float>::um;
0116 
0117   test::register_checks<detray::cuda::helix_navigation>(
0118       tel_det, tel_names, cfg_hel_nav, ctx, white_board);
0119 
0120   // Run the material validation
0121   test::material_scan<tel_detector_t>::config mat_scan_cfg{};
0122   mat_scan_cfg.name("telescope_detector_material_scan_for_cuda");
0123   mat_scan_cfg.track_generator().uniform_eta(true).eta_range(1.f, 6.f);
0124   mat_scan_cfg.track_generator().origin(0.f, 0.f, -0.05f * unit<scalar>::mm);
0125   mat_scan_cfg.track_generator().phi_steps(10).eta_steps(100);
0126   mat_scan_cfg.overlaps_tol(min_stepsize);
0127 
0128   // Record the material using a ray scan
0129   test::register_checks<test::material_scan>(tel_det, tel_names, mat_scan_cfg,
0130                                              ctx, white_board);
0131 
0132   // Now trace the material during navigation and compare
0133   detray::cuda::material_validation<tel_detector_t>::config mat_val_cfg{};
0134   mat_val_cfg.name("telescope_detector_material_validaiton_cuda");
0135   mat_val_cfg.device_mr(&dev_mr);
0136   mat_val_cfg.propagation() = cfg_str_nav.propagation();
0137   mat_val_cfg.propagation().stepping.min_stepsize = min_stepsize;
0138 
0139   test::register_checks<detray::cuda::material_validation>(
0140       tel_det, tel_names, mat_val_cfg, ctx, white_board);
0141 
0142   // Run the checks
0143   return RUN_ALL_TESTS();
0144 }