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/material_scan.hpp"
0022 #include "detray/test/device/cuda/material_validation.hpp"
0023 #include "detray/test/framework/register_checks.hpp"
0024 
0025 // Vecmem include(s)
0026 #include <vecmem/memory/cuda/device_memory_resource.hpp>
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 
0049   // Filter out the google test flags
0050   ::testing::InitGoogleTest(&argc, argv);
0051 
0052   // Specific options for this test
0053   po::options_description desc("\ndetray CUDA material validation options");
0054 
0055   desc.add_options()(
0056       "data_dir",
0057       po::value<std::string>()->default_value("./validation_data/material"),
0058       "Directory that contains the data files")(
0059       "material_tol", po::value<float>()->default_value(1.f),
0060       "Tolerance for comparing the material traces [%]")(
0061       "overlaps_tol",
0062       po::value<float>()->default_value(stepping::config{}.min_stepsize),
0063       "Tolerance for considering surfaces to be overlapping [mm]");
0064 
0065   // Configs to be filled
0066   detray::io::detector_reader_config reader_cfg{};
0067   detray::test::material_validation<detector_t>::config mat_val_cfg{};
0068   test::material_scan<detector_t>::config mat_scan_cfg{};
0069 
0070   po::variables_map vm = detray::options::parse_options(
0071       desc, argc, argv, reader_cfg, mat_scan_cfg.track_generator(),
0072       mat_val_cfg.propagation());
0073 
0074   // General options
0075   if (vm.count("material_tol") != 0u) {
0076     mat_val_cfg.relative_error(vm["material_tol"].as<float>() / 100.f);
0077   }
0078   if (vm.count("overlaps_tol") != 0u) {
0079     mat_scan_cfg.overlaps_tol(vm["overlaps_tol"].as<float>());
0080   }
0081   const auto data_dir{vm["data_dir"].as<std::string>()};
0082 
0083   /// Vecmem memory resource for the device allocations
0084   vecmem::cuda::device_memory_resource dev_mr{};
0085   vecmem::host_memory_resource host_mr;
0086 
0087   const auto [det, names] =
0088       detray::io::read_detector<detector_t>(host_mr, reader_cfg);
0089 
0090   auto white_board = std::make_shared<test::whiteboard>();
0091   detector_t::geometry_context ctx{};
0092 
0093   // Print the detector's material as recorded by a ray scan
0094   mat_scan_cfg.name("material_scan_for_cuda");
0095   mat_scan_cfg.track_generator().uniform_eta(true);
0096   mat_scan_cfg.material_file(data_dir + "/material_scan_for_cuda");
0097   detray::test::register_checks<test::material_scan>(det, names, mat_scan_cfg,
0098                                                      ctx, white_board);
0099 
0100   // Now trace the material during navigation and compare
0101   mat_val_cfg.name("material_validation_cuda");
0102   mat_val_cfg.material_file(data_dir + "/navigation_material_trace");
0103   mat_val_cfg.device_mr(&dev_mr);
0104 
0105   test::register_checks<detray::cuda::material_validation>(
0106       det, names, mat_val_cfg, ctx, white_board);
0107 
0108   // Run the checks
0109   return RUN_ALL_TESTS();
0110 }