Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:12:20

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file geocel/vg/VecgeomParams.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <string>
0011 #include <unordered_map>
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();
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     int max_depth() const { return host_ref_.max_depth; }
0059 
0060     //// VOLUMES ////
0061 
0062     //! Number of volumes
0063     VolumeId::size_type num_volumes() const final
0064     {
0065         return vol_labels_.size();
0066     }
0067 
0068     // Get the label for a placed volume ID
0069     Label const& id_to_label(VolumeId vol_id) const final;
0070 
0071     //! \cond
0072     using GeoParamsInterface::find_volume;
0073     //! \endcond
0074 
0075     // Get the volume ID corresponding to a unique label name
0076     VolumeId find_volume(std::string const& name) const final;
0077 
0078     // Get the volume ID corresponding to a unique label
0079     VolumeId find_volume(Label const& label) const final;
0080 
0081     // Get the volume ID corresponding to a Geant4 logical volume
0082     VolumeId find_volume(G4LogicalVolume const* volume) const final;
0083 
0084     // Get zero or more volume IDs corresponding to a name
0085     SpanConstVolumeId find_volumes(std::string const& name) const final;
0086 
0087     //// DATA ACCESS ////
0088 
0089     //! Access geometry data on host
0090     HostRef const& host_ref() const final { return host_ref_; }
0091 
0092     //! Access geometry data on device
0093     DeviceRef const& device_ref() const final { return device_ref_; }
0094 
0095   private:
0096     //// DATA ////
0097 
0098     // Host metadata/access
0099     LabelIdMultiMap<VolumeId> vol_labels_;
0100     std::unordered_map<G4LogicalVolume const*, VolumeId> g4log_volid_map_;
0101 
0102     BBox bbox_;
0103 
0104     // Host/device storage and reference
0105     HostRef host_ref_;
0106     DeviceRef device_ref_;
0107 
0108     // If VGDML is unavailable and Geant4 is, we load and
0109     bool loaded_geant4_gdml_{false};
0110 
0111     //// HELPER FUNCTIONS ////
0112 
0113     // Construct VecGeom tracking data and copy to GPU
0114     void build_volumes_vgdml(std::string const& filename);
0115     void build_volumes_geant4(G4VPhysicalVolume const* world);
0116     void build_tracking();
0117     void build_surface_tracking();
0118     void build_volume_tracking();
0119 
0120     // Construct host/device Celeritas data
0121     void build_data();
0122     // Construct labels and other host-only metadata
0123     void build_metadata();
0124 };
0125 
0126 //---------------------------------------------------------------------------//
0127 }  // namespace celeritas