14#include <fairlogger/Logger.h>
31#include "TG4RootDetectorConstruction.h"
32#include "TG4RootNavMgr.h"
34#include "G4EventManager.hh"
35#include "G4FieldManager.hh"
36#include "G4PropagatorInField.hh"
37#include "G4SteppingManager.hh"
38#include "G4TrackingManager.hh"
39#include "G4TransportationManager.hh"
41#include "TMCManager.h"
42#include "TStopwatch.h"
57 if (TMCManager::Instance() !=
nullptr) {
58 LOG(fatal) <<
"G4.navmode=kVecGeom cannot be used with the multi-engine TMCManager: restoring a "
59 "geometry state across engines goes through the TGeo navigator";
62 LOG(fatal) <<
"G4.navmode=kVecGeom cannot be used with GeometryManagerParam.useParallelWorld: VecGeom "
63 "has no equivalent of the TGeo priority world";
65 auto* navMgr = TG4RootNavMgr::GetInstance();
66 if (navMgr ==
nullptr || navMgr->GetDetConstruction() ==
nullptr) {
67 LOG(fatal) <<
"G4.navmode=kVecGeom needs the Geant4 geometry built from TGeo by g4root, which is what "
68 "the geomRoot option provides; no TG4RootNavMgr was found";
70 auto* detConstruction = navMgr->GetDetConstruction();
71 if (!detConstruction->IsConstructed()) {
72 LOG(fatal) <<
"The Geant4 geometry has not been built yet; installVecGeomNavigator must be called after "
73 "the TGeant4 engine has been created";
77 LOG(fatal) <<
"G4.vecgeomNavigator=kRelocating needs G4.vecgeomFlattenAssemblies=true: it enters a daughter by "
78 "locating inside it, which an assembly cannot answer";
83 o2::base::GeometryManager::buildVecGeomGeometry(g4Params.vecgeomFlattenAssemblies);
85 LOG(info) <<
"VecGeom geometry built in " << timer.RealTime() <<
" s";
89 static VecGeomG4Map map;
90 map.build(*detConstruction, g4Params.vecgeomFlattenAssemblies);
92 LOG(info) <<
"VecGeom to Geant4 map built in " << timer.RealTime() <<
" s";
94 if (!g4Params.vecgeomCheckVolumes.empty()) {
95 std::stringstream names(g4Params.vecgeomCheckVolumes);
97 while (std::getline(names,
one,
',')) {
101 if (g4Params.vecgeomCheckRays > 0) {
104 if (g4Params.vecgeomCheckLocation > 0) {
110 LOG(info) <<
"VecGeom navigation: propagating navigator";
111 navigator =
new VecGeomG4PropagatingNavigator(map, g4Params.vecgeomZeroSafety);
113 navigator =
new VecGeomG4Navigator(map, g4Params.vecgeomPushDepth, g4Params.vecgeomZeroSafety);
115 navigator->SetWorldVolume(detConstruction->GetTopPV());
119 auto* trMgr = G4TransportationManager::GetTransportationManager();
120 trMgr->SetNavigatorForTracking(navigator);
121 auto* fieldMgr = trMgr->GetPropagatorInField()->GetCurrentFieldManager();
122 delete trMgr->GetPropagatorInField();
123 trMgr->SetPropagatorInField(
new G4PropagatorInField(navigator, fieldMgr));
124 trMgr->ActivateNavigator(navigator);
125 if (
auto* evtMgr = G4EventManager::GetEventManager()) {
126 evtMgr->GetTrackingManager()->GetSteppingManager()->SetNavigator(navigator);
129 LOG(info) <<
"VecGeom navigator registered with the Geant4 transportation manager";
138 LOG(fatal) <<
"G4.navmode=kVecGeom needs O2 built against TGeo2VecGeom and a VecGeom with the BVH navigator of "
139 "the VNavigator family (BVHNavigatorV), which were not found at configure time";
Definition of the GeometryManager class.
static const G4Params & Instance()
void checkVecGeomRays(std::size_t rays)
bool isVecGeomNavigationAvailable()
void installVecGeomNavigator()
std::size_t checkVecGeomLocation(std::size_t samples)
std::size_t checkVecGeomVolume(const char *name, std::size_t perPlacement, std::size_t maxPlacements)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"