Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:59

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/definitions/geometry.hpp"
0014 #include "detray/definitions/indexing.hpp"
0015 #include "detray/geometry/identifier.hpp"
0016 
0017 // Sysytem include(s)
0018 #include <memory>
0019 
0020 namespace detray {
0021 
0022 /// Templated surface class for detector surfaces and portals.
0023 ///
0024 /// @note might be holding multiple surfaces in the future
0025 ///
0026 /// @tparam mask_regsitry_t the type collection of masks that can be linked
0027 ///                         to the surface
0028 /// @tparam material_registry_t the type collection of material that can be
0029 ///                             linked to the surface
0030 /// @tparam transform_link_t how to reference the surfaces transforms
0031 template <typename mask_link_t = dtyped_index<dindex, dindex>,
0032           typename material_link_t = dtyped_index<dindex, dindex>,
0033           typename transform_link_t = dindex,
0034           typename navigation_link_t = std::uint_least16_t>
0035 class surface_descriptor {
0036  public:
0037   /// Link type of the mask to a volume.
0038   using navigation_link = navigation_link_t;
0039   // Broadcast the type of links
0040   using transform_link = transform_link_t;
0041   /// might be a single mask, a range of masks or a multiindex in the future
0042   using mask_link = mask_link_t;
0043   using mask_id = typename mask_link::id_type;
0044   using material_link = material_link_t;
0045   using material_id = typename material_link::id_type;
0046 
0047   /// Default constructor
0048   constexpr surface_descriptor() = default;
0049 
0050   /// Constructor with full arguments
0051   ///
0052   /// @param trf the transform for positioning and 3D local frame
0053   /// @param mask the type and index of the mask for this surface
0054   /// @param material the type and index of the material for this surface
0055   /// @param vol the volume this surface belongs to
0056   /// @param src the source object/source link this surface is representing
0057   /// @param sf_id remember whether this is a portal or not
0058   DETRAY_HOST
0059   constexpr surface_descriptor(const transform_link trf, const mask_link mask,
0060                                const material_link material,
0061                                const dindex volume, const surface_id sf_id)
0062       : m_identifier{geometry::identifier{}
0063                          .set_volume(volume)
0064                          .set_id(sf_id)
0065                          .set_transform(trf)},
0066         m_mask(mask),
0067         m_material(material) {}
0068 
0069   /// Equality operator
0070   ///
0071   /// @param rhs is the right hand side to be compared to
0072   DETRAY_HOST_DEVICE
0073   constexpr auto operator==(const surface_descriptor &rhs) const -> bool {
0074     return (m_mask == rhs.m_mask && m_material == rhs.m_material &&
0075             m_identifier == rhs.m_identifier);
0076   }
0077 
0078   /// Sets a new surface identifier
0079   DETRAY_HOST_DEVICE
0080   auto set_identifier(const geometry::identifier geo_id) -> void {
0081     m_identifier = geo_id;
0082   }
0083 
0084   /// @returns the surface identifier
0085   DETRAY_HOST_DEVICE
0086   constexpr auto identifier() const -> geometry::identifier {
0087     return m_identifier;
0088   }
0089 
0090   /// Sets a new surface id (portal/passive/sensitive)
0091   DETRAY_HOST_DEVICE
0092   auto set_id(const surface_id new_id) -> void { m_identifier.set_id(new_id); }
0093 
0094   /// @returns the surface id (sensitive, passive or portal)
0095   DETRAY_HOST_DEVICE
0096   constexpr auto id() const -> surface_id { return m_identifier.id(); }
0097 
0098   /// Sets a new volume link (index in volume collection of detector)
0099   DETRAY_HOST
0100   auto set_volume(const dindex new_idx) -> void {
0101     m_identifier.set_volume(new_idx);
0102   }
0103 
0104   /// @returns the surface id (sensitive, passive or portal)
0105   DETRAY_HOST_DEVICE
0106   constexpr auto volume() const -> dindex { return m_identifier.volume(); }
0107 
0108   /// Sets a new surface index (index in surface collection of surface store)
0109   DETRAY_HOST_DEVICE
0110   auto set_index(const dindex new_idx) -> void {
0111     m_identifier.set_index(new_idx);
0112   }
0113 
0114   /// @returns the surface id (sensitive, passive or portal)
0115   DETRAY_HOST_DEVICE
0116   constexpr auto index() const -> dindex { return m_identifier.index(); }
0117 
0118   /// Update the transform index
0119   ///
0120   /// @param offset update the position when move into new collection
0121   DETRAY_HOST
0122   auto update_transform(dindex offset) -> void {
0123     m_identifier.set_transform(transform() + offset);
0124   }
0125 
0126   /// @return the transform index
0127   DETRAY_HOST_DEVICE
0128   constexpr auto transform() const -> dindex {
0129     return m_identifier.transform();
0130   }
0131 
0132   /// Update the mask link
0133   ///
0134   /// @param offset update the position when move into new collection
0135   DETRAY_HOST
0136   auto update_mask(dindex offset) -> void { m_mask.shift(offset); }
0137 
0138   /// @return the mask link
0139   DETRAY_HOST_DEVICE
0140   constexpr auto mask() const -> const mask_link & { return m_mask; }
0141 
0142   /// Update the material link
0143   ///
0144   /// @param offset update the position when move into new collection
0145   DETRAY_HOST
0146   auto update_material(dindex offset) -> void { m_material.shift(offset); }
0147 
0148   /// Access to the material
0149   DETRAY_HOST_DEVICE
0150   constexpr auto material() -> material_link & { return m_material; }
0151 
0152   /// @return the material link
0153   DETRAY_HOST_DEVICE
0154   constexpr auto material() const -> const material_link & {
0155     return m_material;
0156   }
0157 
0158   /// @returns true if the surface descriptor has a valid material link
0159   DETRAY_HOST_DEVICE
0160   constexpr auto has_material() const -> bool {
0161     return (m_material.id() != material_link::id_type::e_none) &&
0162            !m_material.is_invalid();
0163   }
0164 
0165   /// @returns true if the surface is a sensitive detector module.
0166   DETRAY_HOST_DEVICE
0167   constexpr auto is_sensitive() const -> bool {
0168     return m_identifier.id() == surface_id::e_sensitive;
0169   }
0170 
0171   /// @returns true if the surface is a portal.
0172   DETRAY_HOST_DEVICE
0173   constexpr auto is_portal() const -> bool {
0174     return m_identifier.id() == surface_id::e_portal;
0175   }
0176 
0177   /// @returns true if the surface is a passive detector element.
0178   DETRAY_HOST_DEVICE
0179   constexpr auto is_passive() const -> bool {
0180     return m_identifier.id() == surface_id::e_passive;
0181   }
0182 
0183   /// @returns a string stream that prints the surface details
0184   DETRAY_HOST
0185   friend std::ostream &operator<<(std::ostream &os,
0186                                   const surface_descriptor &sf) {
0187     os << sf.m_identifier;
0188     os << " | mask: " << sf.m_mask;
0189     os << " | mat.: " << sf.m_material;
0190     return os;
0191   }
0192 
0193  private:
0194   geometry::identifier m_identifier{};
0195   mask_link m_mask{};
0196   material_link m_material{};
0197 };
0198 
0199 }  // namespace detray
0200 
0201 namespace std {
0202 
0203 // Specialize std::hash so surface descriptors can be used in STL containers
0204 template <typename mask_link_t, typename material_link_t,
0205           typename transform_link_t, typename navigation_link_t>
0206 struct hash<detray::surface_descriptor<mask_link_t, material_link_t,
0207                                        transform_link_t, navigation_link_t>> {
0208   using descr_t =
0209       detray::surface_descriptor<mask_link_t, material_link_t, transform_link_t,
0210                                  navigation_link_t>;
0211 
0212   auto operator()(const descr_t sf_desc) const noexcept {
0213     return std::hash<detray::geometry::identifier::value_t>()(
0214         sf_desc.identifier().value());
0215   }
0216 };
0217 
0218 }  // namespace std