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_wire_chamber.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   // Filter out the google test flags
0036   ::testing::InitGoogleTest(&argc, argv);
0037 
0038   /// Vecmem memory resource for the device allocations
0039   vecmem::cuda::device_memory_resource dev_mr{};
0040 
0041   //
0042   // Wire Chamber configuration
0043   //
0044   vecmem::host_memory_resource host_mr;
0045 
0046   using metadata_t = test::wire_chamber_metadata;
0047   using test_algebra = metadata_t::algebra_type;
0048   using wire_chamber_t = detector<metadata_t>;
0049   using scalar = typename wire_chamber_t::scalar_type;
0050 
0051   /// Set a consistent minimum step size across all tests
0052   const float min_stepsize{stepping::config{}.min_stepsize};
0053 
0054   wire_chamber_config<scalar> wire_chamber_cfg{};
0055   wire_chamber_cfg.half_z(500.f * unit<scalar>::mm);
0056 
0057   std::clog << wire_chamber_cfg << std::endl;
0058 
0059   auto [det, names] =
0060       build_wire_chamber<test_algebra>(host_mr, wire_chamber_cfg);
0061 
0062   auto white_board = std::make_shared<test::whiteboard>();
0063   wire_chamber_t::geometry_context ctx{};
0064 
0065   // Navigation link consistency, discovered by ray intersection
0066   test::ray_scan<wire_chamber_t>::config cfg_ray_scan{};
0067   cfg_ray_scan.name("wire_chamber_ray_scan_for_cuda");
0068   cfg_ray_scan.track_generator().seed(42u);
0069   cfg_ray_scan.track_generator().n_tracks(10000u);
0070   cfg_ray_scan.overlaps_tol(min_stepsize);
0071 
0072   test::register_checks<test::ray_scan>(det, names, cfg_ray_scan, ctx,
0073                                         white_board);
0074 
0075   // Comparison of straight line navigation with ray scan
0076   detray::cuda::straight_line_navigation<wire_chamber_t>::config cfg_str_nav{};
0077   cfg_str_nav.name("wire_chamber_straight_line_navigation_cuda");
0078   cfg_str_nav.n_tracks(cfg_ray_scan.track_generator().n_tracks());
0079   cfg_str_nav.propagation().stepping.min_stepsize = min_stepsize;
0080   cfg_str_nav.propagation().navigation.estimate_scattering_noise = false;
0081   cfg_str_nav.propagation().navigation.search_window = {3u, 3u};
0082   cfg_str_nav.propagation().navigation.intersection.min_mask_tolerance =
0083       static_cast<float>(cfg_ray_scan.mask_tolerance());
0084   cfg_str_nav.propagation().navigation.intersection.max_mask_tolerance =
0085       static_cast<float>(cfg_ray_scan.mask_tolerance());
0086 
0087   test::register_checks<detray::cuda::straight_line_navigation>(
0088       det, names, cfg_str_nav, ctx, white_board);
0089 
0090   // Navigation link consistency, discovered by helix intersection
0091   test::helix_scan<wire_chamber_t>::config cfg_hel_scan{};
0092   cfg_hel_scan.name("wire_chamber_helix_scan_for_cuda");
0093   // Let the Newton algorithm dynamically choose tol. based on approx. error
0094   cfg_hel_scan.mask_tolerance(detray::detail::invalid_value<scalar>());
0095   // Run only 1000 track in double precision in the CI (time limit)
0096   if constexpr (std::same_as<scalar, double>) {
0097     cfg_hel_scan.track_generator().n_tracks(1000u);
0098   } else {
0099     cfg_hel_scan.track_generator().n_tracks(10000u);
0100   }
0101   cfg_hel_scan.overlaps_tol(min_stepsize);
0102   cfg_hel_scan.track_generator().randomize_charge(true);
0103   cfg_hel_scan.track_generator().eta_range(-1.f, 1.f);
0104   // TODO: Fails for smaller momenta
0105   cfg_hel_scan.track_generator().p_T(4.f * unit<scalar>::GeV);
0106 
0107   test::register_checks<test::helix_scan>(det, names, cfg_hel_scan, ctx,
0108                                           white_board);
0109 
0110   // Comparison of navigation in a constant B-field with helix
0111   detray::cuda::helix_navigation<wire_chamber_t>::config cfg_hel_nav{};
0112   cfg_hel_nav.name("wire_chamber_helix_navigation_cuda");
0113   cfg_hel_nav.n_tracks(cfg_hel_scan.track_generator().n_tracks());
0114   cfg_hel_nav.propagation().stepping.min_stepsize = min_stepsize;
0115   cfg_hel_nav.propagation().navigation.estimate_scattering_noise = false;
0116   cfg_hel_nav.propagation().navigation.intersection.min_mask_tolerance *= 12.f;
0117   cfg_hel_nav.propagation().navigation.search_window = {3u, 3u};
0118 
0119   test::register_checks<detray::cuda::helix_navigation>(det, names, cfg_hel_nav,
0120                                                         ctx, white_board);
0121 
0122   // Run the material validation
0123   test::material_scan<wire_chamber_t>::config mat_scan_cfg{};
0124   mat_scan_cfg.name("wire_chamber_material_scan_for_cuda");
0125   mat_scan_cfg.track_generator().uniform_eta(true).eta_range(-1.f, 1.f);
0126   mat_scan_cfg.track_generator().phi_steps(100).eta_steps(100);
0127   mat_scan_cfg.overlaps_tol(min_stepsize);
0128 
0129   // Record the material using a ray scan
0130   test::register_checks<test::material_scan>(det, names, mat_scan_cfg, ctx,
0131                                              white_board);
0132 
0133   // Now trace the material during navigation and compare
0134   detray::cuda::material_validation<wire_chamber_t>::config mat_val_cfg{};
0135   mat_val_cfg.name("wire_chamber_material_validaiton_cuda");
0136   mat_val_cfg.device_mr(&dev_mr);
0137   // Reduce tolerance for single precision tests
0138   if constexpr (std::is_same_v<scalar, float>) {
0139     mat_val_cfg.relative_error(130.f);
0140   }
0141   mat_val_cfg.propagation() = cfg_str_nav.propagation();
0142   mat_val_cfg.propagation().stepping.min_stepsize = min_stepsize;
0143 
0144   test::register_checks<detray::cuda::material_validation>(
0145       det, names, mat_val_cfg, ctx, white_board);
0146 
0147   // Run the checks
0148   return RUN_ALL_TESTS();
0149 }