Back to home page

EIC code displayed by LXR

 
 

    


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

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/core/detector.hpp"
0011 #include "detray/definitions/units.hpp"
0012 
0013 // Detray IO include(s)
0014 #include "detray/io/frontend/detector_reader.hpp"
0015 
0016 // Detray test include(s)
0017 #include "detray/options/detector_io_options.hpp"
0018 #include "detray/options/parse_options.hpp"
0019 #include "detray/options/propagation_options.hpp"
0020 #include "detray/options/track_generator_options.hpp"
0021 #include "detray/test/cpu/detector_scan.hpp"
0022 #include "detray/test/device/cuda/navigation_validation.hpp"
0023 #include "detray/test/framework/register_checks.hpp"
0024 #include "detray/test/framework/whiteboard.hpp"
0025 
0026 // Vecmem include(s)
0027 #include <vecmem/memory/host_memory_resource.hpp>
0028 
0029 // GTest include(s)
0030 #include <gtest/gtest.h>
0031 
0032 // Boost
0033 #include "detray/options/boost_program_options.hpp"
0034 
0035 // System include(s)
0036 #include <sstream>
0037 #include <stdexcept>
0038 #include <string>
0039 
0040 namespace po = boost::program_options;
0041 
0042 using namespace detray;
0043 
0044 int main(int argc, char** argv) {
0045   // Use the most general type to be able to read in all detector files
0046   using metadata_t = test::default_metadata;
0047   using detector_t = detector<metadata_t>;
0048   using scalar = dscalar<typename detector_t::algebra_type>;
0049 
0050   // Filter out the google test flags
0051   ::testing::InitGoogleTest(&argc, argv);
0052 
0053   // Specific options for this test
0054   po::options_description desc("\ndetray detector CUDA validation options");
0055 
0056   desc.add_options()("write_scan_data",
0057                      "Write the ray/helix scan data to file")(
0058       "data_dir",
0059       boost::program_options::value<std::string>()->default_value(
0060           "./validation_data"),
0061       "Directory that contains the data files")(
0062       "overlaps_tol",
0063       po::value<float>()->default_value(stepping::config{}.min_stepsize),
0064       "Tolerance for considering surfaces to be overlapping [mm]");
0065 
0066   // Configs to be filled
0067   detray::io::detector_reader_config reader_cfg{};
0068   reader_cfg.do_check(true);
0069   detray::test::ray_scan<detector_t>::config ray_scan_cfg{};
0070   detray::test::helix_scan<detector_t>::config hel_scan_cfg{};
0071   detray::cuda::straight_line_navigation<detector_t>::config str_nav_cfg{};
0072   detray::cuda::helix_navigation<detector_t>::config hel_nav_cfg{};
0073 
0074   po::variables_map vm = detray::options::parse_options(
0075       desc, argc, argv, reader_cfg, hel_scan_cfg.track_generator(),
0076       hel_nav_cfg.propagation());
0077 
0078   const auto data_dir{vm["data_dir"].as<std::string>()};
0079 
0080   if (vm.count("overlaps_tol") != 0u) {
0081     ray_scan_cfg.overlaps_tol(vm["overlaps_tol"].as<float>());
0082     hel_scan_cfg.overlaps_tol(vm["overlaps_tol"].as<float>());
0083   }
0084 
0085   // For now: Copy the options to the other tests
0086   ray_scan_cfg.track_generator() = hel_scan_cfg.track_generator();
0087   str_nav_cfg.propagation() = hel_nav_cfg.propagation();
0088   str_nav_cfg.fail_on_diff(false);
0089 
0090   detector_t::geometry_context ctx{};
0091   vecmem::host_memory_resource host_mr;
0092 
0093   const auto [det, names] =
0094       detray::io::read_detector<detector_t>(host_mr, reader_cfg);
0095   const std::string& det_name = det.name(names);
0096 
0097   // Create the whiteboard for data transfer between the steps
0098   auto white_board = std::make_shared<test::whiteboard>();
0099   const std::string file_prefix{data_dir + "/" + det_name};
0100   ray_scan_cfg.name(det_name + "_ray_scan_for_cuda");
0101   ray_scan_cfg.intersection_file(file_prefix + "_ray_scan_intersections");
0102   ray_scan_cfg.track_param_file(file_prefix + "_ray_scan_track_parameters");
0103 
0104   hel_scan_cfg.name(det_name + "_helix_scan_for_cuda");
0105   // Let the Newton algorithm dynamically choose tol. based on approx. error
0106   hel_scan_cfg.mask_tolerance(detray::detail::invalid_value<scalar>());
0107   hel_scan_cfg.intersection_file(file_prefix + "_helix_scan_intersections");
0108   hel_scan_cfg.track_param_file(file_prefix + "_helix_scan_track_parameters");
0109 
0110   // Navigation link consistency, discovered by ray intersection
0111   detray::test::register_checks<detray::test::ray_scan>(
0112       det, names, ray_scan_cfg, ctx, white_board);
0113 
0114   // Comparison of straight line navigation with ray scan
0115   str_nav_cfg.name(det_name + "_straight_line_navigation_cuda");
0116   // Number of tracks to check
0117   str_nav_cfg.n_tracks(ray_scan_cfg.track_generator().n_tracks());
0118   // Ensure that the same mask tolerance is used
0119   str_nav_cfg.propagation().navigation.intersection.min_mask_tolerance =
0120       static_cast<float>(ray_scan_cfg.mask_tolerance());
0121   str_nav_cfg.propagation().navigation.intersection.max_mask_tolerance =
0122       static_cast<float>(ray_scan_cfg.mask_tolerance());
0123   str_nav_cfg.intersection_file(ray_scan_cfg.intersection_file());
0124   str_nav_cfg.track_param_file(ray_scan_cfg.track_param_file());
0125 
0126   detray::test::register_checks<detray::cuda::straight_line_navigation>(
0127       det, names, str_nav_cfg, ctx, white_board);
0128 
0129   // Navigation link consistency, discovered by helix intersection
0130   detray::test::register_checks<detray::test::helix_scan>(
0131       det, names, hel_scan_cfg, ctx, white_board);
0132 
0133   // Comparison of navigation in a constant B-field with helix
0134   hel_nav_cfg.name(det_name + "_helix_navigation_cuda");
0135   hel_nav_cfg.fail_on_diff(false);
0136   // Number of tracks to check
0137   hel_nav_cfg.n_tracks(hel_scan_cfg.track_generator().n_tracks());
0138   hel_nav_cfg.p_range(hel_scan_cfg.track_generator().mom_range());
0139   hel_nav_cfg.intersection_file(hel_scan_cfg.intersection_file());
0140   hel_nav_cfg.track_param_file(hel_scan_cfg.track_param_file());
0141 
0142   detray::test::register_checks<detray::cuda::helix_navigation>(
0143       det, names, hel_nav_cfg, ctx, white_board);
0144 
0145   // Run the checks
0146   return RUN_ALL_TESTS();
0147 }