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_consistency.hpp"
0022 #include "detray/test/cpu/detector_scan.hpp"
0023 #include "detray/test/cpu/navigation_validation.hpp"
0024 #include "detray/test/framework/register_checks.hpp"
0025 #include "detray/test/framework/types.hpp"
0026 #include "detray/test/framework/whiteboard.hpp"
0027 
0028 // Vecmem include(s)
0029 #include <vecmem/memory/host_memory_resource.hpp>
0030 
0031 // GTest include(s)
0032 #include <gtest/gtest.h>
0033 
0034 // Boost
0035 #include "detray/options/boost_program_options.hpp"
0036 
0037 // System include(s)
0038 #include <sstream>
0039 #include <stdexcept>
0040 #include <string>
0041 
0042 namespace po = boost::program_options;
0043 
0044 using namespace detray;
0045 
0046 int main(int argc, char** argv) {
0047   // Use the most general type to be able to read in all detector files
0048   using metadata_t = test::default_metadata;
0049   using detector_t = detector<metadata_t>;
0050   using scalar = dscalar<typename detector_t::algebra_type>;
0051 
0052   // Filter out the google test flags
0053   ::testing::InitGoogleTest(&argc, argv);
0054 
0055   // Specific options for this test
0056   po::options_description desc("\ndetray detector validation options");
0057 
0058   desc.add_options()("write_volume_graph", "Write the volume graph to file")(
0059       "write_scan_data", "Write the ray/helix scan data to file")(
0060       "data_dir", po::value<std::string>()->default_value("./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(false);  // < Don't run consistency check twice
0069   detray::test::consistency_check<detector_t>::config con_chk_cfg{};
0070   detray::test::ray_scan<detector_t>::config ray_scan_cfg{};
0071   detray::test::helix_scan<detector_t>::config hel_scan_cfg{};
0072   detray::test::straight_line_navigation<detector_t>::config str_nav_cfg{};
0073   detray::test::helix_navigation<detector_t>::config hel_nav_cfg{};
0074 
0075   po::variables_map vm = detray::options::parse_options(
0076       desc, argc, argv, reader_cfg, hel_scan_cfg.track_generator(),
0077       hel_nav_cfg.propagation());
0078 
0079   // General options
0080   if (vm.count("write_volume_graph") != 0u) {
0081     con_chk_cfg.write_graph(true);
0082     throw std::invalid_argument("Writing of volume graph not implemented");
0083   }
0084   if (vm.count("write_scan_data") != 0u) {
0085     ray_scan_cfg.write_intersections(true);
0086     hel_scan_cfg.write_intersections(true);
0087   }
0088   if (vm.count("overlaps_tol") != 0u) {
0089     ray_scan_cfg.overlaps_tol(vm["overlaps_tol"].as<float>());
0090     hel_scan_cfg.overlaps_tol(vm["overlaps_tol"].as<float>());
0091   }
0092   const auto data_dir{vm["data_dir"].as<std::string>()};
0093 
0094   // For now: Copy the options to the other tests
0095   ray_scan_cfg.track_generator() = hel_scan_cfg.track_generator();
0096   str_nav_cfg.propagation() = hel_nav_cfg.propagation();
0097   str_nav_cfg.fail_on_diff(false);
0098 
0099   detector_t::geometry_context ctx{};
0100   vecmem::host_memory_resource host_mr;
0101 
0102   const auto [det, names] =
0103       detray::io::read_detector<detector_t>(host_mr, reader_cfg);
0104   const std::string& det_name = det.name(names);
0105 
0106   // Create the whiteboard for data transfer between the steps
0107   auto white_board = std::make_shared<test::whiteboard>();
0108   const std::string file_prefix{data_dir + "/" + det_name};
0109   ray_scan_cfg.name(det_name + "_ray_scan");
0110   ray_scan_cfg.intersection_file(file_prefix + "_ray_scan_intersections");
0111   ray_scan_cfg.track_param_file(file_prefix + "_ray_scan_track_parameters");
0112 
0113   hel_scan_cfg.name(det_name + "_helix_scan");
0114   // Let the Newton algorithm dynamically choose tol. based on approx. error
0115   hel_scan_cfg.mask_tolerance(detray::detail::invalid_value<scalar>());
0116   hel_scan_cfg.intersection_file(file_prefix + "_helix_scan_intersections");
0117   hel_scan_cfg.track_param_file(file_prefix + "_helix_scan_track_parameters");
0118 
0119   // General data consistency of the detector
0120   detray::test::register_checks<detray::test::consistency_check>(
0121       det, names, con_chk_cfg, ctx);
0122 
0123   // Navigation link consistency, discovered by ray intersection
0124   detray::test::register_checks<detray::test::ray_scan>(
0125       det, names, ray_scan_cfg, ctx, white_board);
0126 
0127   // Comparison of straight line navigation with ray scan
0128   str_nav_cfg.name(det_name + "_straight_line_navigation");
0129   // Number of tracks to check
0130   str_nav_cfg.n_tracks(ray_scan_cfg.track_generator().n_tracks());
0131   // Ensure that the same mask tolerance is used
0132   str_nav_cfg.propagation().navigation.intersection.min_mask_tolerance =
0133       static_cast<float>(ray_scan_cfg.mask_tolerance());
0134   str_nav_cfg.propagation().navigation.intersection.max_mask_tolerance =
0135       static_cast<float>(ray_scan_cfg.mask_tolerance());
0136   str_nav_cfg.intersection_file(ray_scan_cfg.intersection_file());
0137   str_nav_cfg.track_param_file(ray_scan_cfg.track_param_file());
0138 
0139   detray::test::register_checks<detray::test::straight_line_navigation>(
0140       det, names, str_nav_cfg, ctx, white_board);
0141 
0142   // Navigation link consistency, discovered by helix intersection
0143   detray::test::register_checks<detray::test::helix_scan>(
0144       det, names, hel_scan_cfg, ctx, white_board);
0145 
0146   // Comparison of navigation in a constant B-field with helix
0147   hel_nav_cfg.name(det_name + "_helix_navigation");
0148   hel_nav_cfg.fail_on_diff(false);
0149   // Number of tracks to check
0150   hel_nav_cfg.n_tracks(hel_scan_cfg.track_generator().n_tracks());
0151   hel_nav_cfg.p_range(hel_scan_cfg.track_generator().mom_range());
0152   hel_nav_cfg.intersection_file(hel_scan_cfg.intersection_file());
0153   hel_nav_cfg.track_param_file(hel_scan_cfg.track_param_file());
0154 
0155   detray::test::register_checks<detray::test::helix_navigation>(
0156       det, names, hel_nav_cfg, ctx, white_board);
0157 
0158   // Run the checks
0159   return RUN_ALL_TESTS();
0160 }