Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-18 08:42:25

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 /** Detray library, part of the ACTS project (R&D line)
0010  *
0011  * (c) 2025 CERN for the benefit of the ACTS project
0012  *
0013  * Mozilla Public License Version 2.0
0014  */
0015 
0016 #pragma once
0017 
0018 // Project include(s)
0019 #include "detray/definitions/detail/qualifiers.hpp"
0020 #include "detray/definitions/geometry.hpp"
0021 #include "detray/definitions/indexing.hpp"
0022 #include "detray/definitions/units.hpp"
0023 #include "detray/geometry/identifier.hpp"
0024 #include "detray/geometry/mask.hpp"
0025 
0026 namespace detray {
0027 
0028 template <typename algebra_t, typename shape_t, typename material_t,
0029           typename nav_link_t>
0030 class external_surface {
0031  public:
0032   using transform3_type = dtransform3D<algebra_t>;
0033   using mask_type = detray::mask<shape_t, algebra_t, nav_link_t>;
0034   using material_type = material_t;
0035   /// Link type of the mask to a volume.
0036   using navigation_link = nav_link_t;
0037 
0038   /// Default constructor
0039   constexpr external_surface() = default;
0040 
0041   /// Constructor with full arguments
0042   ///
0043   /// @param trf the transform for positioning and 3D local frame
0044   /// @param mask the surface mask
0045   /// @param material the surface material
0046   /// @param volume the volume this surface belongs to
0047   /// @param sf_id remember whether this is a portal or not
0048   DETRAY_HOST_DEVICE
0049   constexpr external_surface(const transform3_type& trf, const mask_type& mask,
0050                              const material_type& material, const dindex volume,
0051                              const surface_id sf_id)
0052       : m_transform{trf},
0053         m_mask(mask),
0054         m_material(material),
0055         m_barcode{geometry::identifier{}.set_volume(volume).set_id(sf_id)} {}
0056 
0057   /// Constructor with full arguments - move semantics
0058   ///
0059   /// @param trf the transform for positioning and 3D local frame
0060   /// @param mask the surface mask
0061   /// @param material the surface material
0062   /// @param volume the volume this surface belongs to
0063   /// @param sf_id remember whether this is a portal or not
0064   DETRAY_HOST_DEVICE
0065   constexpr external_surface(transform3_type&& trf, mask_type&& mask,
0066                              material_type&& material, const dindex volume,
0067                              const surface_id sf_id)
0068       : m_transform{std::move(trf)},
0069         m_mask(std::move(mask)),
0070         m_material(std::move(material)),
0071         m_barcode{geometry::identifier{}.set_volume(volume).set_id(sf_id)} {}
0072 
0073   /// Equality operator
0074   ///
0075   /// @param rhs is the right hand side to be compared to
0076   DETRAY_HOST_DEVICE
0077   constexpr auto operator==(const external_surface& rhs) const -> bool {
0078     return (m_barcode == rhs.m_barcode);
0079   }
0080 
0081   /// Sets a new surface barcode
0082   DETRAY_HOST_DEVICE
0083   auto set_barcode(const geometry::identifier bcd) -> void { m_barcode = bcd; }
0084 
0085   /// @returns the surface barcode
0086   DETRAY_HOST_DEVICE
0087   constexpr auto barcode() const -> geometry::identifier { return m_barcode; }
0088 
0089   /// @returns the surface identifier (identifier-era naming)
0090   DETRAY_HOST_DEVICE
0091   constexpr auto identifier() const -> geometry::identifier {
0092     return m_barcode;
0093   }
0094 
0095   /// Explicit conversion for APIs that take geometry::identifier.
0096   DETRAY_HOST_DEVICE
0097   explicit operator geometry::identifier() const { return m_barcode; }
0098 
0099   /// Sets a new surface id (portal/passive/sensitive)
0100   DETRAY_HOST_DEVICE
0101   auto set_id(const surface_id new_id) -> void { m_barcode.set_id(new_id); }
0102 
0103   /// @returns the surface id (sensitive, passive or portal)
0104   DETRAY_HOST_DEVICE
0105   constexpr auto id() const -> surface_id { return m_barcode.id(); }
0106 
0107   /// Sets a new volume link (index in volume collection of detector)
0108   DETRAY_HOST_DEVICE
0109   auto set_volume(const dindex new_idx) -> void {
0110     m_barcode.set_volume(new_idx);
0111   }
0112 
0113   /// @returns the surface id (sensitive, passive or portal)
0114   DETRAY_HOST_DEVICE
0115   constexpr auto volume() const -> dindex { return m_barcode.volume(); }
0116 
0117   /// Sets a new surface index (index in surface collection of surface store)
0118   DETRAY_HOST_DEVICE
0119   auto set_index(const dindex new_idx) -> void { m_barcode.set_index(new_idx); }
0120 
0121   /// @returns the surface id (sensitive, passive or portal)
0122   DETRAY_HOST_DEVICE
0123   constexpr auto index() const -> dindex { return m_barcode.index(); }
0124 
0125   /// Update the transform index
0126   ///
0127   /// @param offset update the position when move into new collection
0128   DETRAY_HOST_DEVICE
0129   void set_transform(const transform3_type& trf) { m_transform = trf; }
0130 
0131   /// @return the transform index
0132   DETRAY_HOST_DEVICE
0133   constexpr auto transform() const -> const transform3_type& {
0134     return m_transform;
0135   }
0136 
0137   /// Update the mask link
0138   ///
0139   /// @param offset update the position when move into new collection
0140   DETRAY_HOST_DEVICE
0141   void set_mask(const mask_type m) { m_mask = m; }
0142 
0143   /// @return the mask - const
0144   DETRAY_HOST_DEVICE
0145   constexpr auto mask() const -> const mask_type& { return m_mask; }
0146 
0147   /// Update the material link
0148   ///
0149   /// @param offset update the position when move into new collection
0150   DETRAY_HOST_DEVICE
0151   void set_material(const material_type& offset) { m_material.shift(offset); }
0152 
0153   /// Access to the material
0154   DETRAY_HOST_DEVICE
0155   constexpr auto material() -> material_type& { return m_material; }
0156 
0157   /// @return the material link
0158   DETRAY_HOST_DEVICE
0159   constexpr auto material() const -> const material_type& { return m_material; }
0160 
0161   /// @returns true if the surface descriptor has a valid material link
0162   DETRAY_HOST_DEVICE
0163   constexpr auto has_material() const -> bool { return false; }
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_barcode.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_barcode.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_barcode.id() == surface_id::e_passive;
0181   }
0182 
0183  private:
0184   /// Surface placement transform and its inverse
0185   transform3_type m_transform{};
0186   /// Surface mask
0187   mask_type m_mask{};
0188   /// Surface material
0189   material_type m_material{};
0190   /// Surface hash
0191   geometry::identifier m_barcode{};
0192 };
0193 
0194 }  // namespace detray