File indexing completed on 2026-05-27 07:24:00
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/definitions/math.hpp"
0015 #include "detray/definitions/navigation.hpp"
0016 #include "detray/definitions/units.hpp"
0017 #include "detray/geometry/surface.hpp"
0018 #include "detray/navigation/navigation_config.hpp"
0019
0020
0021 #include <iomanip>
0022 #include <sstream>
0023 #include <string>
0024
0025 namespace detray::navigation {
0026
0027
0028 template <typename state_type>
0029 DETRAY_HOST inline std::string print_state(const state_type &state) {
0030 using detector_t = typename state_type::detector_type;
0031 using scalar_t = typename detector_t::scalar_type;
0032
0033
0034 std::stringstream debug_stream{};
0035
0036 constexpr int cw{20};
0037
0038 debug_stream << std::left << std::setw(cw) << "Volume:" << state.volume()
0039 << std::endl;
0040
0041 debug_stream << std::setw(cw) << std::boolalpha
0042 << "is alive:" << state.is_alive() << std::endl;
0043 debug_stream << std::noboolalpha;
0044
0045
0046 debug_stream << std::setw(cw) << "direction:";
0047 debug_stream << state.direction() << std::endl;
0048
0049
0050 debug_stream << std::setw(cw) << "status:";
0051 debug_stream << state.status() << std::endl;
0052
0053
0054 debug_stream << std::setw(cw) << "trust:";
0055 debug_stream << state.trust_level() << std::endl;
0056
0057
0058 debug_stream << std::setw(cw) << "No. reachable:" << state.n_candidates()
0059 << std::endl;
0060
0061
0062 debug_stream << std::setw(cw) << "current object:";
0063 if (state.is_on_surface()) {
0064
0065 debug_stream << state.geometry_identifier() << std::endl;
0066 } else if (state.status() == status::e_exit) {
0067 debug_stream << "exited" << std::endl;
0068 } else {
0069 debug_stream << "undefined" << std::endl;
0070 }
0071
0072
0073 if (!state.candidates().empty()) {
0074 debug_stream << std::setw(cw) << "next object:";
0075 if (state.n_candidates() == 0u) {
0076 debug_stream << "exhausted" << std::endl;
0077 } else {
0078 debug_stream << state.next_surface().identifier() << std::endl;
0079 }
0080 }
0081
0082
0083 debug_stream << std::setw(cw) << "distance to next:";
0084 if (!state.cache_exhausted() && state.is_on_surface()) {
0085 debug_stream << "on obj (within tol)" << std::endl;
0086 } else if (state.cache_exhausted()) {
0087 debug_stream << "no target" << std::endl;
0088 } else {
0089 debug_stream << state() / detray::unit<scalar_t>::mm << " mm" << std::endl;
0090 }
0091
0092
0093 debug_stream << std::setw(cw) << "ext. mask tol.:"
0094 << state.external_tol() / detray::unit<scalar_t>::mm << " mm"
0095 << std::endl;
0096
0097 return debug_stream.str();
0098 }
0099
0100
0101
0102
0103
0104
0105
0106 template <typename state_type, concepts::point3D point3_t,
0107 concepts::vector3D vector3_t>
0108 DETRAY_HOST inline std::string print_candidates(const state_type &state,
0109 const navigation::config &cfg,
0110 const point3_t &track_pos,
0111 const vector3_t &track_dir) {
0112 using detector_t = typename state_type::detector_type;
0113 using geo_ctx_t = typename detector_t::geometry_context;
0114 using scalar_t = typename detector_t::scalar_type;
0115
0116
0117 std::stringstream debug_stream{};
0118
0119 constexpr int cw{20};
0120
0121 debug_stream << std::left << std::setw(cw) << "Overstep tol.:"
0122 << cfg.intersection.overstep_tolerance /
0123 detray::unit<scalar_t>::um
0124 << " um" << std::endl;
0125
0126 debug_stream << std::setw(cw) << "Track:"
0127 << "pos: [r = " << vector::perp(track_pos)
0128 << ", z = " << track_pos[2] << "]," << std::endl;
0129
0130 debug_stream << std::setw(cw) << " "
0131 << "dir: [" << track_dir[0] << ", " << track_dir[1] << ", "
0132 << track_dir[2] << "]" << std::endl;
0133
0134 debug_stream << "Surface candidates: " << std::endl;
0135
0136 for (const auto &sf_cand : state) {
0137 debug_stream << std::left << std::setw(6) << "-> " << sf_cand;
0138
0139 assert(!sf_cand.surface().identifier().is_invalid());
0140
0141
0142 if constexpr (state_type::value_type::contains_pos()) {
0143 const auto &local = sf_cand.local();
0144 if (!sf_cand.surface().identifier().is_invalid()) {
0145 point3_t pos = geometry::surface{state.detector(), sf_cand.surface()}
0146 .local_to_global(geo_ctx_t{}, local, track_dir);
0147 debug_stream << " glob: [r = " << vector::perp(pos)
0148 << ", z = " << pos[2] << "]" << std::endl;
0149 } else {
0150 debug_stream << "Invalid identifier" << std::endl;
0151 }
0152 } else {
0153 debug_stream << std::endl;
0154 }
0155 }
0156
0157 return debug_stream.str();
0158 }
0159
0160 }