Celeritas  0.5.0-56+6b053cd
Functions
GeantGeoUtils.cc File Reference
#include "GeantGeoUtils.hh"
#include <algorithm>
#include <iostream>
#include <string>
#include <string_view>
#include <unordered_set>
#include <G4Element.hh>
#include <G4GDMLParser.hh>
#include <G4GDMLWriteStructure.hh>
#include <G4Isotope.hh>
#include <G4LogicalVolume.hh>
#include <G4LogicalVolumeStore.hh>
#include <G4Material.hh>
#include <G4NavigationHistory.hh>
#include <G4PhysicalVolumeStore.hh>
#include <G4ReflectionFactory.hh>
#include <G4RegionStore.hh>
#include <G4SolidStore.hh>
#include <G4Threading.hh>
#include <G4TouchableHistory.hh>
#include <G4TransportationManager.hh>
#include <G4VPhysicalVolume.hh>
#include <G4Version.hh>
#include <G4ios.hh>
#include "corecel/Assert.hh"
#include "corecel/cont/Range.hh"
#include "corecel/io/Join.hh"
#include "corecel/io/Logger.hh"
#include "corecel/io/ScopedStreamRedirect.hh"
#include "corecel/io/ScopedTimeLog.hh"
#include "corecel/sys/ScopedMem.hh"
#include "orange/g4org/Converter.hh"
#include "ScopedGeantExceptionHandler.hh"
#include "ScopedGeantLogger.hh"

Functions

std::ostream & celeritas::operator<< (std::ostream &os, PrintableNavHistory const &pnh)
 Print detailed information about the touchable history. More...
 
std::ostream & celeritas::operator<< (std::ostream &os, PrintableLV const &plv)
 Print the logical volume name, ID, and address.
 
G4VPhysicalVolume * celeritas::load_geant_geometry (std::string const &filename)
 Load a Geant4 geometry, leaving the pointer suffixes intact for VecGeom. More...
 
G4VPhysicalVolume * celeritas::load_geant_geometry_native (std::string const &filename)
 Load a Geant4 geometry, stripping suffixes like a typical Geant4 app. More...
 
void celeritas::write_geant_geometry (G4VPhysicalVolume const *world, std::string const &out_filename)
 Write a GDML file to the given filename.
 
void celeritas::reset_geant_geometry ()
 Reset all Geant4 geometry stores if not using RunManager. More...
 
Span< G4LogicalVolume * > celeritas::geant_logical_volumes ()
 Get a view to the Geant4 LV store. More...
 
G4VPhysicalVolume const * celeritas::geant_world_volume ()
 Get the world volume for the primary geometry. More...
 
std::unordered_set< G4LogicalVolume const * > celeritas::find_geant_volumes (std::unordered_set< std::string > names)
 Find Geant4 logical volumes corresponding to a list of names. More...
 
std::string celeritas::make_gdml_name (G4LogicalVolume const &lv)
 Generate the GDML name for a Geant4 logical volume.
 
void celeritas::set_history (Span< G4VPhysicalVolume const * > stack, G4NavigationHistory *nav)
 Update a nav history to match the given pv stack. More...
 

Function Documentation

◆ find_geant_volumes()

std::unordered_set< G4LogicalVolume const * > celeritas::find_geant_volumes ( std::unordered_set< std::string >  names)
inline

Find Geant4 logical volumes corresponding to a list of names.

If logical volumes with duplicate names are present, they will all show up in the output and a warning will be emitted. If one is missing, a RuntimeError will be raised.

static std::string_view const labels[] = {"Vol1", "Vol2"};
auto vols = find_geant_volumes(make_span(labels));
std::unordered_set< G4LogicalVolume const * > find_geant_volumes(std::unordered_set< std::string > names)
Find Geant4 logical volumes corresponding to a list of names.
Definition: GeantGeoUtils.cc:321
CELER_CONSTEXPR_FUNCTION Span< T, N > make_span(Array< T, N > &x)
Get a mutable fixed-size view to an array.
Definition: Span.hh:200

◆ geant_logical_volumes()

Span< G4LogicalVolume * > celeritas::geant_logical_volumes ( )
inline

Get a view to the Geant4 LV store.

This includes all volumes, potentially null ones as well.

◆ geant_world_volume()

G4VPhysicalVolume const * celeritas::geant_world_volume ( )

Get the world volume for the primary geometry.

Returns
World volume if geometry has been initialized, nullptr otherwise.

◆ load_geant_geometry()

G4VPhysicalVolume * celeritas::load_geant_geometry ( std::string const &  filename)
inline

Load a Geant4 geometry, leaving the pointer suffixes intact for VecGeom.

Do not strip 0x extensions since those are needed to deduplicate complex geometries (e.g. CMS) when loaded separately by VGDML and Geant4. The pointer-based deduplication is handled by the Label and LabelIdMultiMap.

Returns
Geant4-owned world volume

◆ load_geant_geometry_native()

G4VPhysicalVolume * celeritas::load_geant_geometry_native ( std::string const &  filename)
inline

Load a Geant4 geometry, stripping suffixes like a typical Geant4 app.

With this implementation, we let Geant4 strip the uniquifying pointers, which allows our application to construct its own based on the actual in-memory addresses.

Returns
Geant4-owned world volume

◆ operator<<()

std::ostream & celeritas::operator<< ( std::ostream &  os,
PrintableNavHistory const &  pnh 
)

Print detailed information about the touchable history.

For brevity, this does not print the world volume.

◆ reset_geant_geometry()

void celeritas::reset_geant_geometry ( )
inline

Reset all Geant4 geometry stores if not using RunManager.

Use this function if reading geometry and cleaning up without doing any transport in between (useful for geometry conversion testing).

◆ set_history()

void celeritas::set_history ( Span< G4VPhysicalVolume const * >  stack,
G4NavigationHistory *  nav 
)

Update a nav history to match the given pv stack.

Warning
The stack cannot have a parameterized/replicated volume.
Note
The stack should have the same semantics as LevelId, i.e. the initial entry is the "most global" level.