4949#include < VecGeom/navigation/VNavigator.h>
5050#include < VecGeom/volumes/LogicalVolume.h>
5151#include < mutex>
52+ // The BVH navigator of the VNavigator family, which Geant4 navigation needs on every volume.
53+ #if __has_include(<VecGeom/navigation/BVHNavigatorV.h>)
54+ #define O2_VECGEOM_HAS_BVH_VNAVIGATOR
55+ #include < VecGeom/navigation/BVHNavigatorV.h>
56+ #include < VecGeom/navigation/BVHLevelLocator.h>
57+ #include < VecGeom/navigation/BVHSafetyEstimator.h>
58+ #include < VecGeom/navigation/SimpleSafetyEstimator.h>
59+ #endif
5260#endif
5361
5462using namespace o2 ::detectors;
@@ -574,15 +582,22 @@ bool usesBvhAcceleration(vecgeom::LogicalVolume const* vol)
574582// / process, the first time the VecGeom backend is requested. Not part of loadGeometry(),
575583// / which every job calls regardless of whether it ever uses the VecGeom backend.
576584void ensureVecGeomWorldBuilt ()
585+ {
586+ GeometryManager::buildVecGeomGeometry (true );
587+ }
588+ } // namespace
589+
590+ void GeometryManager::buildVecGeomGeometry (bool flattenAssemblies)
577591{
578592 static std::once_flag onceFlag;
579- std::call_once (onceFlag, []() {
593+ std::call_once (onceFlag, [flattenAssemblies ]() {
580594 if (!gGeoManager ) {
581595 LOG (fatal) << " Cannot build VecGeom geometry: no TGeo geometry loaded (call GeometryManager::loadGeometry() first)" ;
582596 }
583597 // Translate geometry and material pointers, then build acceleration structures.
584598 tgeo2vecgeom::RootGeoManager::Instance ().SetMaterialConversionHook ([](TGeoMaterial const * m) { return (void *)m; });
585- tgeo2vecgeom::RootGeoManager::Instance ().SetFlattenAssemblies (true );
599+ LOG (info) << " VecGeom conversion: flattenAssemblies=" << flattenAssemblies;
600+ tgeo2vecgeom::RootGeoManager::Instance ().SetFlattenAssemblies (flattenAssemblies);
586601 tgeo2vecgeom::RootGeoManager::Instance ().LoadRootGeometry ();
587602
588603 // Acceleration structures must be built before the navigators/locators reference them.
@@ -593,15 +608,28 @@ void ensureVecGeomWorldBuilt()
593608 // Builds a BVH per logical volume.
594609 vecgeom::BVHManager::Init ();
595610
596- // For each logical volume, set both a navigator (used for ComputeStep) and a matched
597- // level locator (used for point relocation after a boundary crossing via GlobalLocator).
611+ // For each logical volume, set a navigator (used for ComputeStep), a matched level locator
612+ // (used for point relocation after a boundary crossing via GlobalLocator) and, where the
613+ // VNavigator family is complete, the safety estimator LogicalVolume::GetSafetyEstimator()
614+ // hands out, which is separate from the one a navigator uses internally.
598615 for (auto & lvol : vecgeom::GeoManager::Instance ().GetLogicalVolumesMap ()) {
599616 auto * vol = lvol.second ;
600617 if (!usesBvhAcceleration (vol)) {
601618 vol->SetNavigator (vecgeom::NewSimpleNavigator<>::Instance ());
619+ #ifdef O2_VECGEOM_HAS_BVH_VNAVIGATOR
620+ vol->SetLevelLocator (vol->ContainsAssembly () ? vecgeom::SimpleAssemblyLevelLocator::GetInstance ()
621+ : vecgeom::SimpleLevelLocator::GetInstance ());
622+ vol->SetSafetyEstimator (vecgeom::SimpleSafetyEstimator::Instance ());
623+ #else
602624 vol->SetLevelLocator (vecgeom::SimpleLevelLocator::GetInstance ());
625+ #endif
603626 } else {
604- #if VECGEOM_VERSION >= 0x020000
627+ #if defined(O2_VECGEOM_HAS_BVH_VNAVIGATOR)
628+ vol->SetNavigator (vecgeom::BVHNavigatorV<>::Instance ());
629+ vol->SetLevelLocator (vol->ContainsAssembly () ? vecgeom::BVHAssemblyAwareLevelLocator::GetInstance ()
630+ : vecgeom::BVHLevelLocator::GetInstance ());
631+ vol->SetSafetyEstimator (vecgeom::BVHSafetyEstimator::Instance ());
632+ #elif VECGEOM_VERSION >= 0x020000
605633 // VecGeom 2 turned BVHNavigator into a plain class with static entry points instead of a
606634 // VNavigator singleton, so there is nothing to attach: vecGeomMaterialBudget() calls it
607635 // directly.
@@ -627,7 +655,6 @@ void ensureVecGeomWorldBuilt()
627655 }
628656 });
629657}
630- } // namespace
631658
632659// _____________________________________________________________________________________
633660o2::base::MatBudget GeometryManager::vecGeomMaterialBudget (float x0, float y0, float z0, float x1, float y1, float z1)
0 commit comments