File indexing completed on 2026-05-27 07:24:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
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
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
0026 #include "detray/tutorial/types.hpp"
0027
0028
0029 #include <vecmem/memory/host_memory_resource.hpp>
0030
0031
0032 #include <sstream>
0033
0034
0035
0036 int main() {
0037
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
0043 using intersection_t =
0044 detray::intersection2D<typename toy_detector_t::surface_type, algebra_t,
0045 detray::intersection::contains_pos>;
0046
0047
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
0053
0054 using nav_print_inspector_t = detray::navigation::print_inspector;
0055
0056
0057 using inspector_t =
0058 detray::aggregate_inspector<object_tracer_t, nav_print_inspector_t>;
0059
0060 constexpr std::size_t cache_size{detray::navigation::default_cache_size};
0061
0062
0063 using navigator_t = detray::caching_navigator<toy_detector_t, cache_size,
0064 inspector_t, intersection_t>;
0065
0066 using stepper_t = detray::line_stepper<algebra_t>;
0067
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
0081 detray::propagation::config prop_cfg{};
0082 propagator_t prop{prop_cfg};
0083
0084 std::clog << prop_cfg;
0085
0086
0087
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
0093 for (const auto ray :
0094 detray::uniform_track_generator<ray_type>(phi_steps, theta_steps)) {
0095
0096 const auto intersection_trace =
0097 detray::detector_scanner::run<detray::ray_scan>(gctx, det, ray);
0098
0099
0100
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
0106 prop.propagate(propagation);
0107
0108
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
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
0125 debug_stream << "\n\nnavig.: " << obj_tracer[intr_idx - 1u].intersection;
0126 }
0127 std::clog << debug_stream.str() << std::endl;
0128
0129
0130
0131
0132
0133 }
0134 }