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/test/cpu/material_validation.hpp"
0011 
0012 #include "detray/core/detector.hpp"
0013 #include "detray/definitions/units.hpp"
0014 
0015 // Detray IO include(s)
0016 #include "detray/io/frontend/detector_reader.hpp"
0017 
0018 // Detray test include(s)
0019 #include "detray/options/detector_io_options.hpp"
0020 #include "detray/options/parse_options.hpp"
0021 #include "detray/options/propagation_options.hpp"
0022 #include "detray/options/track_generator_options.hpp"
0023 #include "detray/test/cpu/material_scan.hpp"
0024 #include "detray/test/framework/register_checks.hpp"
0025 #include "detray/test/framework/types.hpp"
0026 
0027 // Vecmem include(s)
0028 #include <vecmem/memory/host_memory_resource.hpp>
0029 
0030 // GTest include(s)
0031 #include <gtest/gtest.h>
0032 
0033 // Boost
0034 #include "detray/options/boost_program_options.hpp"
0035 
0036 // System include(s)
0037 #include <sstream>
0038 #include <stdexcept>
0039 #include <string>
0040 
0041 namespace po = boost::program_options;
0042 
0043 using namespace detray;
0044 
0045 int main(int argc, char **argv) {
0046   // Use the most general type to be able to read in all detector files
0047   using metadata_t = test::default_metadata;
0048   using detector_t = detector<metadata_t>;
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 material validation options");
0055 
0056   desc.add_options()(
0057       "data_dir",
0058       po::value<std::string>()->default_value("./validation_data/material"),
0059       "Directory that contains the data files")(
0060       "material_tol", po::value<float>()->default_value(1.f),
0061       "Tolerance for comparing the material traces [%]")(
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   detray::test::material_validation<detector_t>::config mat_val_cfg{};
0069   test::material_scan<detector_t>::config mat_scan_cfg{};
0070 
0071   po::variables_map vm = detray::options::parse_options(
0072       desc, argc, argv, reader_cfg, mat_scan_cfg.track_generator(),
0073       mat_val_cfg.propagation());
0074 
0075   // General options
0076   if (vm.count("material_tol") != 0u) {
0077     mat_val_cfg.relative_error(vm["material_tol"].as<float>() / 100.f);
0078   }
0079   if (vm.count("overlaps_tol") != 0u) {
0080     mat_scan_cfg.overlaps_tol(vm["overlaps_tol"].as<float>());
0081   }
0082   const auto data_dir{vm["data_dir"].as<std::string>()};
0083 
0084   vecmem::host_memory_resource host_mr;
0085 
0086   const auto [det, names] =
0087       detray::io::read_detector<detector_t>(host_mr, reader_cfg);
0088 
0089   auto white_board = std::make_shared<test::whiteboard>();
0090   detector_t::geometry_context ctx{};
0091 
0092   // Print the detector's material as recorded by a ray scan
0093   mat_scan_cfg.track_generator().uniform_eta(true);
0094   mat_scan_cfg.material_file(data_dir + "/material_scan");
0095 
0096   detray::test::register_checks<test::material_scan>(det, names, mat_scan_cfg,
0097                                                      ctx, white_board);
0098 
0099   // Now trace the material during navigation and compare
0100   mat_val_cfg.material_file(data_dir + "/navigation_material_trace");
0101 
0102   test::register_checks<detray::test::material_validation>(
0103       det, names, mat_val_cfg, ctx, white_board);
0104 
0105   // Run the checks
0106   return RUN_ALL_TESTS();
0107 }