Back to home page

EIC code displayed by LXR

 
 

    


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

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/navigation/volume_graph.hpp"
0011 #include "detray/tracks/ray.hpp"
0012 #include "detray/utils/logging.hpp"
0013 
0014 // Detray test include(s)
0015 #include "detray/test/common/build_toy_detector.hpp"
0016 #include "detray/test/common/track_generators.hpp"
0017 #include "detray/test/utils/hash_tree.hpp"
0018 #include "detray/test/validation/detector_scan_utils.hpp"
0019 #include "detray/test/validation/detector_scanner.hpp"
0020 
0021 // Example linear algebra plugin: std::array
0022 #include "detray/tutorial/types.hpp"
0023 
0024 // Vecmem include(s)
0025 #include <vecmem/memory/host_memory_resource.hpp>
0026 
0027 // System include(s)
0028 #include <iostream>
0029 
0030 // Hash of the "correct" geometry
0031 constexpr std::size_t root_hash = 11359580520962287982ul;
0032 
0033 /// Check a given detecor for consistent linking by shooting rays/helices and
0034 /// recording every intersection with the geometry. This intersection record
0035 /// can then be checked for matching portals at the volume boundary surfaces
0036 /// ( @c trace_intersections ) and checked for a consistent 'path' from volume
0037 /// to volume ( @c check_consistency ). See also documentation in
0038 /// 'tests/common/tools/ray_detector_scan_utils.hpp'.
0039 int main() {
0040   using algebra_t = detray::tutorial::algebra_t;
0041   using scalar = detray::tutorial::scalar;
0042 
0043   // Can also be performed with helices
0044   using ray_t = detray::detail::ray<algebra_t>;
0045 
0046   std::clog << "Ray Scan Tutorial\n=================\n\n";
0047 
0048   // Build the geometry
0049   vecmem::host_memory_resource host_mr;
0050   const auto [det, names] = detray::build_toy_detector<algebra_t>(host_mr);
0051 
0052   // The current geometry context
0053   using detector_t = decltype(det);
0054   const detector_t::geometry_context gctx{};
0055 
0056   // Visualization style to be applied to the SVGs
0057   detray::svgtools::styling::style svg_style =
0058       detray::svgtools::styling::tableau_colorblind::style;
0059 
0060   // Optional: get the volume adjaceny matrix from ray scan
0061   detray::volume_graph graph(det);
0062   const auto &adj_mat = graph.adjacency_matrix();  // < need this for the size
0063   detray::dvector<detray::dindex> adj_mat_scan(adj_mat.size(), 0);
0064 
0065   // Keep track of the objects that have already been seen per volume
0066   std::unordered_set<detray::dindex> obj_hashes = {};
0067 
0068   // Index of the volume that the ray origin lies in
0069   detray::dindex start_index{0u};
0070   std::size_t n_rays{0u};
0071 
0072   // Generate a number of random rays
0073   using generator_t =
0074       detray::detail::random_numbers<scalar,
0075                                      std::uniform_real_distribution<scalar>>;
0076   using ray_generator_t = detray::random_track_generator<ray_t, generator_t>;
0077 
0078   ray_generator_t::configuration cfg{};
0079   cfg.n_tracks(10000).p_T(1.f * detray::unit<scalar>::GeV);
0080 
0081   ray_generator_t ray_generator{cfg};
0082 
0083   // Run the check
0084   DETRAY_INFO_HOST("\nScanning " << det.name(names) << " ("
0085                                  << ray_generator.size() << " rays) ...\n");
0086 
0087   bool success = true;
0088   for (const auto ray : ray_generator) {
0089     // Record all intersections and surfaces along the ray
0090     const auto intersection_trace =
0091         detray::detector_scanner::run<detray::ray_scan>(gctx, det, ray);
0092 
0093     bool check_result = detray::detector_scanner::check_trace<detector_t>(
0094         intersection_trace, start_index, adj_mat_scan, obj_hashes);
0095 
0096     if (!check_result) {
0097       // Empty navigation trace
0098       using intersection_trace_t = decltype(intersection_trace);
0099 
0100       detray::detector_scanner::display_error(
0101           gctx, det, names, "ray_scan_tutorial", ray, intersection_trace,
0102           svg_style, n_rays, ray_generator.size(), intersection_trace_t{});
0103     }
0104     success = success && check_result;
0105 
0106     ++n_rays;
0107   }
0108 
0109   // Check result
0110   DETRAY_INFO_HOST("Ray scan: " << (success ? "OK" : "FAILURE"));
0111 
0112   // Compare the adjacency that was discovered in the ray scan to the hashed
0113   // one for the toy detector.
0114   // The hash tree is still Work in Progress !
0115   auto geo_checker = detray::hash_tree(adj_mat);
0116   const bool check_links = (geo_checker.root() == root_hash);
0117 
0118   DETRAY_INFO_HOST("All links reachable: " << (check_links ? "OK" : "FAILURE"));
0119 }