Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:16:19

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/GeantGeoUtils.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <iosfwd>
0010 #include <string>
0011 #include <unordered_set>
0012 
0013 #include "corecel/Config.hh"
0014 
0015 #include "corecel/Assert.hh"
0016 #include "corecel/cont/Span.hh"
0017 #include "corecel/io/Label.hh"
0018 
0019 //---------------------------------------------------------------------------//
0020 // Forward declarations
0021 class G4LogicalVolume;
0022 class G4VPhysicalVolume;
0023 class G4Navigator;
0024 class G4NavigationHistory;
0025 
0026 #if CELERITAS_GEANT4_VERSION >= 0x0b0200
0027 // Geant4 11.2 removed G4VTouchable
0028 class G4TouchableHistory;
0029 #else
0030 class G4VTouchable;
0031 #endif
0032 
0033 namespace celeritas
0034 {
0035 struct GeantPhysicalInstance;
0036 //---------------------------------------------------------------------------//
0037 #if CELERITAS_GEANT4_VERSION >= 0x0b0200
0038 //! Version-independent typedef to Geant4 touchable history
0039 using GeantTouchableBase = G4TouchableHistory;
0040 #else
0041 using GeantTouchableBase = G4VTouchable;
0042 #endif
0043 
0044 //---------------------------------------------------------------------------//
0045 //! Wrap around a touchable to get a descriptive output.
0046 struct PrintableNavHistory
0047 {
0048     G4NavigationHistory const* nav{nullptr};
0049 };
0050 
0051 //---------------------------------------------------------------------------//
0052 //! Wrap around a G4LogicalVolume to get a descriptive output.
0053 struct PrintableLV
0054 {
0055     G4LogicalVolume const* lv{nullptr};
0056 };
0057 
0058 // Print detailed information about the touchable history.
0059 std::ostream& operator<<(std::ostream&, PrintableNavHistory const&);
0060 
0061 // Print the logical volume name, ID, and address.
0062 std::ostream& operator<<(std::ostream&, PrintableLV const&);
0063 
0064 //---------------------------------------------------------------------------//
0065 // FREE FUNCTIONS
0066 //---------------------------------------------------------------------------//
0067 // Write a GDML file to the given filename
0068 void save_gdml(G4VPhysicalVolume const* world, std::string const& out_filename);
0069 
0070 //---------------------------------------------------------------------------//
0071 // Reset all Geant4 geometry stores if *not* using RunManager
0072 void reset_geant_geometry();
0073 
0074 //---------------------------------------------------------------------------//
0075 // Get a view to the Geant4 LV store
0076 Span<G4LogicalVolume*> geant_logical_volumes();
0077 
0078 //---------------------------------------------------------------------------//
0079 // Get the world volume if the geometry has been set up
0080 G4VPhysicalVolume const* geant_world_volume();
0081 
0082 //---------------------------------------------------------------------------//
0083 // Whether the volume is a replica/parameterization
0084 bool is_replica(G4VPhysicalVolume const&);
0085 
0086 //---------------------------------------------------------------------------//
0087 // Find Geant4 logical volumes corresponding to a list of names
0088 std::unordered_set<G4LogicalVolume const*>
0089     find_geant_volumes(std::unordered_set<std::string>);
0090 
0091 // Get a reproducible vector of LV instance ID -> label from the given world
0092 std::vector<Label> make_logical_vol_labels(G4VPhysicalVolume const& world);
0093 
0094 // Get a reproducible vector of PV instance ID -> label from the given world
0095 std::vector<Label> make_physical_vol_labels(G4VPhysicalVolume const& world);
0096 
0097 //---------------------------------------------------------------------------//
0098 // Update a nav history to match the given volume instance stack
0099 void set_history(Span<GeantPhysicalInstance const> stack,
0100                  G4NavigationHistory* nav);
0101 
0102 //---------------------------------------------------------------------------//
0103 // INLINE DEFINITIONS
0104 //---------------------------------------------------------------------------//
0105 #if !CELERITAS_USE_GEANT4
0106 inline void reset_geant_geometry()
0107 {
0108     CELER_NOT_CONFIGURED("Geant4");
0109 }
0110 
0111 inline Span<G4LogicalVolume*> geant_logical_volumes()
0112 {
0113     CELER_NOT_CONFIGURED("Geant4");
0114 }
0115 
0116 inline std::unordered_set<G4LogicalVolume const*>
0117 find_geant_volumes(std::unordered_set<std::string>)
0118 {
0119     CELER_NOT_CONFIGURED("Geant4");
0120 }
0121 
0122 inline std::ostream& operator<<(std::ostream&, PrintableNavHistory const&)
0123 {
0124     CELER_NOT_CONFIGURED("Geant4");
0125 }
0126 
0127 inline std::ostream& operator<<(std::ostream&, PrintableLV const&)
0128 {
0129     CELER_NOT_CONFIGURED("Geant4");
0130 }
0131 
0132 inline bool is_replica(G4VPhysicalVolume const&)
0133 {
0134     CELER_NOT_CONFIGURED("Geant4");
0135 }
0136 
0137 #endif
0138 
0139 //---------------------------------------------------------------------------//
0140 }  // namespace celeritas