Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-05 08:39:07

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/vg/VecgeomParams.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <string>
0010 #include <unordered_map>
0011 #include <vector>
0012 
0013 #include "corecel/Types.hh"
0014 #include "corecel/cont/LabelIdMultiMap.hh"
0015 #include "corecel/data/ParamsDataInterface.hh"
0016 #include "geocel/BoundingBox.hh"
0017 #include "geocel/GeoParamsInterface.hh"
0018 #include "geocel/Types.hh"
0019 #include "geocel/inp/Model.hh"
0020 
0021 #include "VecgeomData.hh"
0022 
0023 class G4VPhysicalVolume;
0024 
0025 namespace celeritas
0026 {
0027 //---------------------------------------------------------------------------//
0028 /*!
0029  * Shared model parameters for a VecGeom geometry.
0030  *
0031  * The model defines the shapes, volumes, etc.
0032  */
0033 class VecgeomParams final : public GeoParamsInterface,
0034                             public ParamsDataInterface<VecgeomParamsData>
0035 {
0036   public:
0037     // Whether surface tracking is being used
0038     static bool use_surface_tracking();
0039 
0040     // Whether VecGeom GDML is being used to load the geometry
0041     static bool use_vgdml();
0042 
0043     // Construct from a GDML filename
0044     explicit VecgeomParams(std::string const& gdml_filename);
0045 
0046     // Create a VecGeom model from a pre-existing Geant4 geometry
0047     explicit VecgeomParams(G4VPhysicalVolume const* world);
0048 
0049     // Clean up VecGeom on destruction
0050     ~VecgeomParams() final;
0051 
0052     //! Whether safety distance calculations are accurate and precise
0053     bool supports_safety() const final { return true; }
0054 
0055     //! Outer bounding box of geometry
0056     BBox const& bbox() const final { return bbox_; }
0057 
0058     //! Maximum nested geometry depth
0059     //! \todo move to VolumeParams
0060     LevelId::size_type max_depth() const final { return host_ref_.max_depth; }
0061 
0062     // Create model parameters corresponding to our internal representation
0063     inp::Model make_model_input() const final;
0064 
0065     //// VOLUMES ////
0066 
0067     // Get volume metadata
0068     inline VolumeMap const& volumes() const final;
0069 
0070     // Get (physical) volume instance metadata
0071     inline VolInstanceMap const& volume_instances() const final;
0072 
0073     // Get the volume ID corresponding to a Geant4 logical volume
0074     VolumeId find_volume(G4LogicalVolume const* volume) const final;
0075 
0076     // Get the Geant4 physical volume corresponding to a volume instance ID
0077     GeantPhysicalInstance id_to_geant(VolumeInstanceId vol_id) const final;
0078 
0079     // DEPRECATED
0080     using GeoParamsInterface::find_volume;
0081 
0082     //// DATA ACCESS ////
0083 
0084     //! Access geometry data on host
0085     HostRef const& host_ref() const final { return host_ref_; }
0086 
0087     //! Access geometry data on device
0088     DeviceRef const& device_ref() const final { return device_ref_; }
0089 
0090   private:
0091     //// DATA ////
0092 
0093     // Host metadata/access
0094     LabelIdMultiMap<VolumeId> volumes_;
0095     VolInstanceMap vol_instances_;
0096     std::unordered_map<G4LogicalVolume const*, VolumeId> g4log_volid_map_;
0097     std::vector<G4VPhysicalVolume const*> g4_pv_map_;
0098 
0099     BBox bbox_;
0100 
0101     // Host/device storage and reference
0102     HostRef host_ref_;
0103     DeviceRef device_ref_;
0104 
0105     // If VGDML is unavailable and Geant4 is, we load and
0106     bool loaded_geant4_gdml_{false};
0107 
0108     //// HELPER FUNCTIONS ////
0109 
0110     // Construct VecGeom tracking data and copy to GPU
0111     void build_volumes_vgdml(std::string const& filename);
0112     void build_volumes_geant4(G4VPhysicalVolume const* world);
0113     void build_tracking();
0114     void build_surface_tracking();
0115     void build_volume_tracking();
0116 
0117     // Construct host/device Celeritas data
0118     void build_data();
0119     // Construct labels and other host-only metadata
0120     void build_metadata();
0121 };
0122 
0123 //---------------------------------------------------------------------------//
0124 /*!
0125  * Get volume metadata.
0126  */
0127 auto VecgeomParams::volumes() const -> VolumeMap const&
0128 {
0129     return volumes_;
0130 }
0131 
0132 //---------------------------------------------------------------------------//
0133 /*!
0134  * Get volume instance metadata.
0135  *
0136  * Volume instances correspond directly to Geant4 physical volumes.
0137  */
0138 auto VecgeomParams::volume_instances() const -> VolInstanceMap const&
0139 {
0140     return vol_instances_;
0141 }
0142 
0143 //---------------------------------------------------------------------------//
0144 }  // namespace celeritas