Back to home page

EIC code displayed by LXR

 
 

    


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

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/detail/qualifiers.hpp"
0013 #include "detray/geometry/surface.hpp"
0014 #include "detray/geometry/tracking_volume.hpp"
0015 
0016 // System include(s)
0017 #include <iomanip>
0018 #include <sstream>
0019 #include <string>
0020 
0021 namespace detray::utils {
0022 
0023 namespace detail {
0024 
0025 /// A functor that retrieves an acceleration struct and prints it
0026 struct accelerator_printer {
0027   /// Print an acceleration structure
0028   ///
0029   /// @param accel_coll collection of acceleration structs
0030   /// @param idx the specific grid to be checked
0031   /// @param id type id of the material grid collection
0032   template <typename accel_coll_t, typename index_t>
0033   DETRAY_HOST void operator()(const accel_coll_t &accel_coll, const index_t idx,
0034                               std::stringstream &os) const {
0035     os << accel_coll[idx];
0036   }
0037 };
0038 
0039 /// A functor that retrieves material and prints it
0040 struct material_printer {
0041   /// Print material
0042   ///
0043   /// @param material_coll collection of material
0044   /// @param idx the specific grid to be checked
0045   /// @param id type id of the material grid collection
0046   template <typename material_coll_t, typename index_t>
0047   DETRAY_HOST void operator()(const material_coll_t &material_coll,
0048                               const index_t idx, std::stringstream &os) const {
0049     os << material_coll[idx] << std::endl;
0050   }
0051 };
0052 
0053 }  // namespace detail
0054 
0055 /// Print basic information about the detector @param det
0056 template <typename detector_t>
0057 DETRAY_HOST inline std::string print_detector(
0058     const detector_t &det, const typename detector_t::name_map &names = {}) {
0059   // Gathers navigation information across navigator update calls
0060   std::stringstream debug_stream{};
0061 
0062   debug_stream << std::left << "[>] Detector " << det.name(names) << " has "
0063                << det.volumes().size() << " volumes." << std::endl;
0064 
0065   for (const auto [i, v_desc] : detray::views::enumerate(det.volumes())) {
0066     tracking_volume v{det, v_desc};
0067 
0068     debug_stream << "[>>] Volume " << v.name(names) << std::endl;
0069     debug_stream << v << std::endl;
0070 
0071     debug_stream << "[>>>] Acceleration Structures:" << std::endl;
0072     const auto acc_link = v_desc.accel_link();
0073     for (std::size_t j = 0u; j < acc_link.size(); ++j) {
0074       // An acceleration data structure link was set, but is invalid
0075       if (!acc_link[j].is_invalid_id() && !acc_link[j].is_invalid_index()) {
0076         debug_stream << "Surfaces registered in '" << acc_link[j].id()
0077                      << "':" << std::endl;
0078         det.accelerator_store().template visit<detail::accelerator_printer>(
0079             acc_link[j], debug_stream);
0080       }
0081     }
0082 
0083     debug_stream << "[>>>] Surfaces:" << std::endl;
0084     for (const auto sf_desc : v.template surfaces<>()) {
0085       geometry::surface sf{det, sf_desc};
0086       debug_stream << sf << std::endl;
0087 
0088       // Check the surface material, if present
0089       if (sf.has_material()) {
0090         debug_stream << "[>>>>] Surface material: ";
0091         sf.template visit_material<detail::material_printer>(debug_stream);
0092       }
0093     }
0094 
0095     debug_stream << std::endl;
0096   }
0097 
0098   return debug_stream.str();
0099 }
0100 
0101 }  // namespace detray::utils