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