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/definitions/units.hpp"
0011 #include "detray/navigation/caching_navigator.hpp"
0012 #include "detray/navigation/intersection/intersection.hpp"
0013 #include "detray/propagator/actor_chain.hpp"
0014 #include "detray/propagator/line_stepper.hpp"
0015 #include "detray/propagator/propagator.hpp"
0016 #include "detray/tracks/ray.hpp"
0017 #include "detray/tracks/tracks.hpp"
0018 
0019 // Detray test include(s)
0020 #include "detray/test/common/build_toy_detector.hpp"
0021 #include "detray/test/common/track_generators.hpp"
0022 #include "detray/test/utils/inspectors.hpp"
0023 #include "detray/test/validation/detector_scanner.hpp"
0024 
0025 // Example linear algebra plugin: std::array
0026 #include "detray/tutorial/types.hpp"
0027 
0028 // Vecmem include(s)
0029 #include <vecmem/memory/host_memory_resource.hpp>
0030 
0031 // System include(s)
0032 #include <sstream>
0033 
0034 /// Run the navigation through the toy detector including a detailed record
0035 /// of the encountered surfaces (using the navigation inspectors)
0036 int main() {
0037   // Toy detector
0038   using metadata_t = detray::tutorial::toy_metadata;
0039   using toy_detector_t = detray::detector<metadata_t>;
0040   using algebra_t = typename toy_detector_t::algebra_type;
0041 
0042   /// Type that holds the intersection information
0043   using intersection_t =
0044       detray::intersection2D<typename toy_detector_t::surface_type, algebra_t,
0045                              detray::intersection::contains_pos>;
0046 
0047   /// Inspector that records all encountered surfaces
0048   using object_tracer_t = detray::navigation::object_tracer<
0049       intersection_t, detray::dvector, detray::navigation::status::e_on_object,
0050       detray::navigation::status::e_on_portal>;
0051 
0052   /// Inspector that prints the navigator state from within the navigator's
0053   /// method calls (cannot be done with an actor)
0054   using nav_print_inspector_t = detray::navigation::print_inspector;
0055 
0056   /// Aggregation of multiple inspectors
0057   using inspector_t =
0058       detray::aggregate_inspector<object_tracer_t, nav_print_inspector_t>;
0059   /// How many intersections to cache during navigation
0060   constexpr std::size_t cache_size{detray::navigation::default_cache_size};
0061 
0062   // Navigation with inspection
0063   using navigator_t = detray::caching_navigator<toy_detector_t, cache_size,
0064                                                 inspector_t, intersection_t>;
0065   // Line stepper
0066   using stepper_t = detray::line_stepper<algebra_t>;
0067   // Propagator with empty actor chain
0068   using propagator_t =
0069       detray::propagator<stepper_t, navigator_t, detray::actor_chain<>>;
0070 
0071   std::clog << "Navigation Instepction "
0072                "Tutorial\n===============================\n\n";
0073 
0074   vecmem::host_memory_resource host_mr;
0075 
0076   const auto [det, names] = detray::build_toy_detector<algebra_t>(host_mr);
0077 
0078   typename toy_detector_t::geometry_context gctx{};
0079 
0080   // Build the propagator
0081   detray::propagation::config prop_cfg{};
0082   propagator_t prop{prop_cfg};
0083 
0084   std::clog << prop_cfg;
0085 
0086   // Track generation config
0087   // Trivial example: Single track escapes through beampipe
0088   using ray_type = detray::detail::ray<algebra_t>;
0089   constexpr std::size_t theta_steps{1};
0090   constexpr std::size_t phi_steps{1};
0091 
0092   // Iterate through uniformly distributed momentum directions
0093   for (const auto ray :
0094        detray::uniform_track_generator<ray_type>(phi_steps, theta_steps)) {
0095     // Shoot ray through the detector and record all surface intersections
0096     const auto intersection_trace =
0097         detray::detector_scanner::run<detray::ray_scan>(gctx, det, ray);
0098 
0099     // Now follow that ray with the same track and check, if we find
0100     // the same volumes and distances along the way
0101     detray::free_track_parameters<algebra_t> track(ray.pos(), 0.f, ray.dir(),
0102                                                    -1.f);
0103     propagator_t::state propagation(track, det, prop_cfg.context);
0104 
0105     // Run the actual propagation
0106     prop.propagate(propagation);
0107 
0108     // Retrieve navigation information
0109     auto &inspector = propagation.navigation().inspector();
0110     auto &obj_tracer = inspector.template get<object_tracer_t>();
0111     auto &debug_printer = inspector.template get<nav_print_inspector_t>();
0112 
0113     std::cout << "\nNavigation Debug Output:\n----------------------------\n\n"
0114               << debug_printer.to_string();
0115 
0116     // Compare ray trace to object tracer
0117     std::stringstream debug_stream;
0118     for (std::size_t intr_idx = 1u; intr_idx < intersection_trace.size();
0119          ++intr_idx) {
0120       debug_stream << "-------Intersection trace\n"
0121                    << "Volume: " << intersection_trace[intr_idx].vol_idx
0122                    << "\n\nray gun: "
0123                    << intersection_trace[intr_idx].intersection;
0124       // Object tracer does not save extra intersection at origin
0125       debug_stream << "\n\nnavig.:  " << obj_tracer[intr_idx - 1u].intersection;
0126     }
0127     std::clog << debug_stream.str() << std::endl;
0128 
0129     // Compare intersection records
0130     //
0131     // [...]
0132     //
0133   }
0134 }