Back to home page

EIC code displayed by LXR

 
 

    


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

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