21#include "G4PropagatorInField.hh"
22#include "G4RunManager.hh"
23#include "G4TransportationManager.hh"
25#include "TGeoManager.h"
51 fDetConstruction(detConstruction),
55 if (!detConstruction) {
72 G4bool isMaster = !G4Threading::IsWorkerThread();
84 if (!geom)
return NULL;
86 G4bool isMaster = !G4Threading::IsWorkerThread();
87 Printf(
"isMaster=%d", isMaster);
101 G4bool isMaster = !G4Threading::IsWorkerThread();
120 Info(
"ConnectToG4",
"Already connected");
124 Error(
"ConnectToG4",
"No detector construction set !");
130 "ConnectToG4",
"Navigator has to be created befor connecting to G4 !!!");
134 G4RunManager* runManager = G4RunManager::GetRunManager();
136 Error(
"ConnectToG4",
"Unable to connect: G4RunManager not instantiated");
139 G4bool isMaster = !G4Threading::IsWorkerThread();
142 "ROOT detector construction class connected to G4RunManager");
152 Error(
"SetNavigator",
153 "Navigator set after instantiation of G4RunManager. Won't set!!!");
156 G4TransportationManager* trMgr =
157 G4TransportationManager::GetTransportationManager();
159 trMgr->SetNavigatorForTracking(nav);
160 G4FieldManager* fieldMgr =
161 trMgr->GetPropagatorInField()->GetCurrentFieldManager();
162 delete trMgr->GetPropagatorInField();
163 trMgr->SetPropagatorInField(
new G4PropagatorInField(nav, fieldMgr));
164 trMgr->ActivateNavigator(nav);
165 G4EventManager* evtMgr = G4EventManager::GetEventManager();
167 evtMgr->GetTrackingManager()->GetSteppingManager()->SetNavigator(nav);
171 "TG4RootNavigator created and registered to G4TransportationManager");
179 Info(
"Initialize",
"Creating G4 hierarchy ...");
181 if (nthreads > 1) gGeoManager->SetMaxThreads(nthreads);
188 G4ThreeVector point(pt[0], pt[1], pt[2]);
190 G4ThreeVector direction(dir[0], dir[1], dir[2]);
211 G4cout << *history << G4endl;
222 std::function<Bool_t(Int_t)> restoreGeoStateFunction)
Definition of the TG4RootDetectorConstruction and TVirtualUserPostDetConstruction classes.
Definition of the TG4RootNavMgr class.
Definition of the TG4RootNavigator class.
Builder creating a pseudo G4 geometry starting from a TGeo geometry.
void Initialize(TVirtualUserPostDetConstruction *sdinit=0)
Manager class creating a G4Navigator based on a ROOT geometry.
static G4ThreadLocal TG4RootNavMgr * fRootNavMgr
void SetVerboseLevel(Int_t level)
TGeoManager * fGeometry
Pointer to TGeo geometry.
void SetNavigator(TG4RootNavigator *nav)
static TG4RootNavMgr * fgMasterInstance
void SetG4TrackingManager(G4TrackingManager *trackingManager)
Forward current G4TrackingManager.
Bool_t fConnected
Flags connection to G4.
static TG4RootNavMgr * GetMasterInstance()
TG4RootNavigator * fNavigator
G4 navigator working with TGeo.
void PrintG4State() const
void LocateGlobalPointAndSetup(Double_t *pt, Double_t *dir=0)
static TG4RootNavMgr * GetInstance(TGeoManager *geom=0)
void Initialize(TVirtualUserPostDetConstruction *sdinit=0, Int_t nthreads=1)
TG4RootDetectorConstruction * fDetConstruction
void SetGeometryRestoreFunction(std::function< Bool_t(Int_t)> restoreGeoStateFunction)
Forward the given function to the TG4RootNavigator.
GEANT4 navigator using directly a TGeo geometry.
void SetG4TrackingManager(G4TrackingManager *trackingManager)
Set current G4TrackingManager.
G4NavigationHistory * GetHistory()
Return the navigation history.
void SetGeometryRestoreFunction(std::function< Bool_t(Int_t)> restoreGeoStateFunction)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Abstract class for defining links to G4 geometry.