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_toy_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/types.hpp"
0018 #include "detray/test/framework/whiteboard.hpp"
0019 
0020 // Vecmem include(s)
0021 #include <vecmem/memory/cuda/device_memory_resource.hpp>
0022 #include <vecmem/memory/host_memory_resource.hpp>
0023 #include <vecmem/utils/cuda/copy.hpp>
0024 
0025 // GTest include
0026 #include <gtest/gtest.h>
0027 
0028 // System include(s)
0029 #include <limits>
0030 
0031 using namespace detray;
0032 
0033 int main(int argc, char **argv) {
0034   using namespace detray;
0035 
0036   // Filter out the google test flags
0037   ::testing::InitGoogleTest(&argc, argv);
0038 
0039   using toy_detector_t = detector<test::toy_metadata>;
0040   using test_algebra = typename toy_detector_t::algebra_type;
0041   using scalar = dscalar<test_algebra>;
0042 
0043   /// Set a consistent minimum step size across all tests
0044   const float min_stepsize{stepping::config{}.min_stepsize};
0045 
0046   /// Vecmem memory resource for the device allocations
0047   vecmem::cuda::device_memory_resource dev_mr{};
0048 
0049   //
0050   // Toy detector configuration
0051   //
0052   toy_det_config<scalar> toy_cfg{};
0053   toy_cfg.n_brl_layers(4u).n_edc_layers(7u);
0054 
0055   // Build the geometry
0056   vecmem::host_memory_resource host_mr;
0057   auto [toy_det, toy_names] =
0058       build_toy_detector<test_algebra>(host_mr, toy_cfg);
0059 
0060   auto white_board = std::make_shared<test::whiteboard>();
0061   toy_detector_t::geometry_context ctx{};
0062 
0063   // Navigation link consistency, discovered by ray intersection
0064   test::ray_scan<toy_detector_t>::config cfg_ray_scan{};
0065   cfg_ray_scan.name("toy_detector_ray_scan_for_cuda");
0066   cfg_ray_scan.track_generator().n_tracks(10000u);
0067   cfg_ray_scan.overlaps_tol(min_stepsize);
0068 
0069   test::register_checks<test::ray_scan>(toy_det, toy_names, cfg_ray_scan, ctx,
0070                                         white_board);
0071 
0072   // Comparison of straight line navigation with ray scan
0073   detray::cuda::straight_line_navigation<toy_detector_t>::config cfg_str_nav{};
0074   cfg_str_nav.name("toy_detector_straight_line_navigation_cuda");
0075   cfg_str_nav.n_tracks(cfg_ray_scan.track_generator().n_tracks());
0076   cfg_str_nav.propagation().stepping.min_stepsize = min_stepsize;
0077   cfg_str_nav.propagation().navigation.estimate_scattering_noise = false;
0078   cfg_str_nav.propagation().navigation.search_window = {3u, 3u};
0079   cfg_str_nav.propagation().navigation.intersection.min_mask_tolerance =
0080       static_cast<float>(cfg_ray_scan.mask_tolerance());
0081   cfg_str_nav.propagation().navigation.intersection.max_mask_tolerance =
0082       static_cast<float>(cfg_ray_scan.mask_tolerance());
0083 
0084   test::register_checks<detray::cuda::straight_line_navigation>(
0085       toy_det, toy_names, cfg_str_nav, ctx, white_board);
0086 
0087   // Navigation link consistency, discovered by helix intersection
0088   test::helix_scan<toy_detector_t>::config cfg_hel_scan{};
0089   cfg_hel_scan.name("toy_detector_helix_scan_for_cuda");
0090   // Let the Newton algorithm dynamically choose tol. based on approx. error
0091   cfg_hel_scan.mask_tolerance(detray::detail::invalid_value<scalar>());
0092   // Run only 1000 track in double precision in the CI (time limit)
0093   if constexpr (std::same_as<scalar, double>) {
0094     cfg_hel_scan.track_generator().n_tracks(1000u);
0095   } else {
0096     cfg_hel_scan.track_generator().n_tracks(10000u);
0097   }
0098   cfg_hel_scan.overlaps_tol(min_stepsize);
0099   cfg_hel_scan.track_generator().randomize_charge(true);
0100   cfg_hel_scan.track_generator().eta_range(-4.f, 4.f);
0101   cfg_hel_scan.track_generator().p_T(1.f * unit<scalar>::GeV);
0102 
0103   test::register_checks<test::helix_scan>(toy_det, toy_names, cfg_hel_scan, ctx,
0104                                           white_board);
0105 
0106   // Comparison of navigation in a constant B-field with helix
0107   detray::cuda::helix_navigation<toy_detector_t>::config cfg_hel_nav{};
0108   cfg_hel_nav.name("toy_detector_helix_navigation_cuda");
0109   cfg_hel_nav.n_tracks(cfg_hel_scan.track_generator().n_tracks());
0110   cfg_hel_nav.propagation().stepping.min_stepsize = min_stepsize;
0111   cfg_hel_nav.propagation().navigation.estimate_scattering_noise = false;
0112   cfg_hel_nav.propagation().navigation.search_window = {3u, 3u};
0113 
0114   test::register_checks<detray::cuda::helix_navigation>(
0115       toy_det, toy_names, cfg_hel_nav, ctx, white_board);
0116 
0117   // Run the material validation - Material Maps
0118   test::material_scan<toy_detector_t>::config mat_scan_cfg{};
0119   mat_scan_cfg.name("toy_detector_material_scan_for_cuda");
0120   mat_scan_cfg.track_generator().uniform_eta(true).eta_range(-4.f, 4.f);
0121   mat_scan_cfg.track_generator().phi_steps(100).eta_steps(100);
0122   mat_scan_cfg.overlaps_tol(min_stepsize);
0123 
0124   // Record the material using a ray scan
0125   test::register_checks<test::material_scan>(toy_det, toy_names, mat_scan_cfg,
0126                                              ctx, white_board);
0127 
0128   // Now trace the material during navigation and compare
0129   detray::cuda::material_validation<toy_detector_t>::config mat_val_cfg{};
0130   mat_val_cfg.name("toy_detector_material_validaiton_cuda");
0131   mat_val_cfg.device_mr(&dev_mr);
0132   mat_val_cfg.tol(1e-5f);  // < Reduce tolerance for single precision tests
0133   mat_val_cfg.propagation() = cfg_str_nav.propagation();
0134   mat_val_cfg.propagation().stepping.min_stepsize = min_stepsize;
0135 
0136   test::register_checks<detray::cuda::material_validation>(
0137       toy_det, toy_names, mat_val_cfg, ctx, white_board);
0138 
0139   // Run the material validation - Homogeneous material
0140   toy_cfg.use_material_maps(false);
0141 
0142   auto [toy_det_hom_mat, toy_names_hom_mat] =
0143       build_toy_detector<test_algebra>(host_mr, toy_cfg);
0144   toy_names_hom_mat.set_detector_name(toy_names_hom_mat.get_detector_name() +
0145                                       "_hom_material");
0146 
0147   // Record the material using a ray scan
0148   mat_scan_cfg.name("toy_detector_hom_material_scan_for_cuda");
0149   test::register_checks<test::material_scan>(toy_det_hom_mat, toy_names_hom_mat,
0150                                              mat_scan_cfg, ctx, white_board);
0151 
0152   // Now trace the material during navigation and compare
0153   mat_val_cfg.name("toy_detector_hom_material_validaiton_cuda");
0154   test::register_checks<detray::cuda::material_validation>(
0155       toy_det_hom_mat, toy_names_hom_mat, mat_val_cfg, ctx, white_board);
0156 
0157   // Run the checks
0158   return RUN_ALL_TESTS();
0159 }