12#ifndef O2_SIMSETUP_VECGEOMG4MAP_H_
13#define O2_SIMSETUP_VECGEOMG4MAP_H_
15#include <VecGeom/volumes/PlacedVolume.h>
19#include <unordered_map>
22class G4VPhysicalVolume;
23class TG4RootDetectorConstruction;
44 void build(TG4RootDetectorConstruction
const& dc,
bool flattenAssemblies);
48 G4VPhysicalVolume*
const*
chain(
int vgId,
unsigned&
size)
const
50 if (
static_cast<std::size_t
>(vgId) >= mChainSize.size()) {
54 size = mChainSize[vgId];
55 return mChain.data() + mChainBegin[vgId];
62 vecgeom::VPlacedVolume
const*
toVecGeom(
int g4Id)
const {
return mG4ToVG[g4Id]; }
67 return reinterpret_cast<vecgeom::VPlacedVolume const*
>(std::uintptr_t{1});
71 std::vector<vecgeom::VPlacedVolume const*>
const&
candidates(
int g4Id)
const
73 static const std::vector<vecgeom::VPlacedVolume const*>
empty;
74 const auto it = mAmbiguous.find(g4Id);
75 return it == mAmbiguous.end() ?
empty : it->second;
79 bool chainMatches(vecgeom::VPlacedVolume
const* pv, G4VPhysicalVolume*
const*
first, std::size_t
n)
const
86 for (std::size_t
i = 0;
i <
n; ++
i) {
97 return static_cast<std::size_t
>(vgId) < mChainSize.size() ? mChainSize[vgId] : 0;
101 vecgeom::VPlacedVolume
const*
world()
const {
return mWorld; }
106 std::size_t
size()
const {
return mPairs; }
109 void registerPair(vecgeom::VPlacedVolume
const* parent, vecgeom::VPlacedVolume
const* pv,
110 std::vector<TGeoNode*>
const&
nodes, TG4RootDetectorConstruction
const& dc);
112 std::vector<unsigned> mChainBegin;
113 std::vector<unsigned> mChainSize;
114 std::vector<G4VPhysicalVolume*> mChain;
115 std::vector<vecgeom::VPlacedVolume const*> mG4ToVG;
116 std::unordered_map<int, std::vector<vecgeom::VPlacedVolume const*>> mAmbiguous;
117 vecgeom::VPlacedVolume
const* mWorld =
nullptr;
118 std::size_t mPairs = 0;
119 std::size_t mMispaired = 0;
G4VPhysicalVolume *const * chain(int vgId, unsigned &size) const
static vecgeom::VPlacedVolume const * ambiguous()
Marks a Geant4 volume that several VecGeom placements reach.
std::vector< vecgeom::VPlacedVolume const * > const & candidates(int g4Id) const
The placements that share an ambiguous Geant4 volume, to be told apart by their chains.
void build(TG4RootDetectorConstruction const &dc, bool flattenAssemblies)
unsigned chainSize(int vgId) const
How many Geant4 levels a VecGeom placement accounts for.
vecgeom::VPlacedVolume const * toVecGeom(int g4Id) const
bool chainMatches(vecgeom::VPlacedVolume const *pv, G4VPhysicalVolume *const *first, std::size_t n) const
Whether a placement's chain is exactly the given run of Geant4 volumes.
std::size_t ambiguousCount() const
How many Geant4 volumes share more than one VecGeom placement.
vecgeom::VPlacedVolume const * world() const
The outermost placement, standing for the Geant4 world volume.