Back to home page

EIC code displayed by LXR

 
 

    


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

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 #pragma once
0010 
0011 // Project include(s)
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 // System include(s)
0021 #include <iomanip>
0022 #include <sstream>
0023 #include <string>
0024 
0025 namespace detray::navigation {
0026 
0027 /// Print basic information about the state of a navigation stream @param state
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   // Gathers navigation information across navigator update calls
0034   std::stringstream debug_stream{};
0035   // Column width in output
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   // Navigation direction
0046   debug_stream << std::setw(cw) << "direction:";
0047   debug_stream << state.direction() << std::endl;
0048 
0049   // Navigation status
0050   debug_stream << std::setw(cw) << "status:";
0051   debug_stream << state.status() << std::endl;
0052 
0053   // Navigation trust level
0054   debug_stream << std::setw(cw) << "trust:";
0055   debug_stream << state.trust_level() << std::endl;
0056 
0057   // Number of reachable candidates
0058   debug_stream << std::setw(cw) << "No. reachable:" << state.n_candidates()
0059                << std::endl;
0060 
0061   // Current surface
0062   debug_stream << std::setw(cw) << "current object:";
0063   if (state.is_on_surface()) {
0064     // If "exit" is called twice, the state has been cleared
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   // Next surface
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   // Distance to next
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   // Current external mask tolerance
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 /// Print candidate and configuration information of a navigation state
0101 ///
0102 /// @param state the state object of the navigation stream
0103 /// @param cfg the navigation configuration object
0104 /// @param track_pos the current track position
0105 /// @param track_dir the current track direction
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   // Gathers navigation information across navigator update calls
0117   std::stringstream debug_stream{};
0118   // Column width in output
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     // Use additional debug information that was gathered on the cand.
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 }  // namespace detray::navigation