Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-10 10:11:50

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file geocel/VolumeParams.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/cont/LabelIdMultiMap.hh"
0010 #include "corecel/cont/Span.hh"
0011 
0012 #include "Types.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace inp
0017 {
0018 struct Volumes;
0019 }
0020 
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Define and manage a hierarchy of volumes and instances thereof.
0024  *
0025  * See the introduction to \rstref{the Geometry API section,api_geometry} for
0026  * a detailed description of volumes in the detector geometry description. This
0027  * class abstracts the graph of volumes, relating \em nodes (VolumeId, aka
0028  * logical volume) to \em edges (VolumeInstanceId, aka physical volume) and
0029  * providing the means to determine the \em path (VolumeUniqueInstanceId, aka
0030  * touchable history) of a track state. In conjunction with \c GeantGeoParams
0031  * this allows conversion between the Celeritas geometry implementation and the
0032  * Geant4 geometry navigation.
0033  *
0034  * \internal Construction requirements:
0035  * - At least one volume must be defined.
0036  * - Material IDs are allowed to be null for testing purposes.
0037  *
0038  * \todo We should be able to easily move the ID-related methods to a
0039  * GPU-friendly view rather than just this metadata class. It's not needed at
0040  * the moment though.
0041  */
0042 class VolumeParams
0043 {
0044   public:
0045     //!@{
0046     //! \name Type aliases
0047     using VolumeMap = LabelIdMultiMap<VolumeId>;
0048     using VolInstMap = LabelIdMultiMap<VolumeInstanceId>;
0049     //!@}
0050 
0051   public:
0052     // Construct from input
0053     explicit VolumeParams(inp::Volumes const&);
0054 
0055     // Construct empty volume params for unit testing: no volumes
0056     VolumeParams();
0057 
0058     //! Empty if no volumes are present (e.g., ORANGE debugging)
0059     bool empty() const { return v_labels_.empty(); }
0060 
0061     //! Number of volumes
0062     VolumeId::size_type num_volumes() const { return v_labels_.size(); }
0063 
0064     //! Number of volume instances
0065     VolumeInstanceId::size_type num_volume_instances() const
0066     {
0067         return vi_labels_.size();
0068     }
0069 
0070     //! Get volume metadata
0071     VolumeMap const& volume_labels() const { return v_labels_; }
0072 
0073     //! Get volume instance metadata
0074     VolInstMap const& volume_instance_labels() const { return vi_labels_; }
0075 
0076     // Find all instances of a volume (incoming edges)
0077     inline Span<VolumeInstanceId const> parents(VolumeId v_id) const;
0078 
0079     // Get the list of daughter volumes (outgoing edges)
0080     inline Span<VolumeInstanceId const> children(VolumeId v_id) const;
0081 
0082     // Get the geometry material of a volume
0083     inline GeoMatId material(VolumeId v_id) const;
0084 
0085     // Get the volume being instantiated (outgoing node)
0086     inline VolumeId volume(VolumeInstanceId vi_id) const;
0087 
0088   private:
0089     VolumeMap v_labels_;
0090     VolInstMap vi_labels_;
0091 
0092     std::vector<std::vector<VolumeInstanceId>> parents_;
0093     std::vector<std::vector<VolumeInstanceId>> children_;
0094     std::vector<GeoMatId> materials_;
0095     std::vector<VolumeId> volumes_;
0096 };
0097 
0098 //---------------------------------------------------------------------------//
0099 // INLINE DEFINITIONS
0100 //---------------------------------------------------------------------------//
0101 /*!
0102  * Find all instances of a volume (incoming edges).
0103  */
0104 Span<VolumeInstanceId const> VolumeParams::parents(VolumeId v_id) const
0105 {
0106     CELER_EXPECT(v_id < parents_.size());
0107     return make_span(parents_[v_id.unchecked_get()]);
0108 }
0109 
0110 //---------------------------------------------------------------------------//
0111 /*!
0112  * Get the list of daughter volumes (outgoing edges).
0113  */
0114 Span<VolumeInstanceId const> VolumeParams::children(VolumeId v_id) const
0115 {
0116     CELER_EXPECT(v_id < children_.size());
0117     return make_span(children_[v_id.unchecked_get()]);
0118 }
0119 
0120 //---------------------------------------------------------------------------//
0121 /*!
0122  * Get the geometry material of a volume.
0123  */
0124 GeoMatId VolumeParams::material(VolumeId v_id) const
0125 {
0126     CELER_EXPECT(v_id < materials_.size());
0127     return materials_[v_id.unchecked_get()];
0128 }
0129 
0130 //---------------------------------------------------------------------------//
0131 /*!
0132  * Get the volume being instantiated (outgoing node).
0133  */
0134 VolumeId VolumeParams::volume(VolumeInstanceId vi_id) const
0135 {
0136     CELER_EXPECT(vi_id < volumes_.size());
0137     return volumes_[vi_id.unchecked_get()];
0138 }
0139 
0140 //---------------------------------------------------------------------------//
0141 }  // namespace celeritas