Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:59:52

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