#include "TGeoManager.h"
#include "TG4RootNavigator.h"
#include "TG4RootDetectorConstruction.h"
#include "TG4RootNavMgr.h"
#include "G4RunManager.hh"
#include "G4TransportationManager.hh"
#include "G4PropagatorInField.hh"
ClassImp(TG4RootNavMgr)
TG4RootNavMgr *TG4RootNavMgr::fRootNavMgr = 0;
TG4RootNavMgr::TG4RootNavMgr()
:TObject(),
fGeometry(0),
fNavigator(0),
fDetConstruction(0),
fConnected(kFALSE)
{
}
TG4RootNavMgr::TG4RootNavMgr(TGeoManager *geom)
:TObject(),
fGeometry(0),
fNavigator(0),
fDetConstruction(0),
fConnected(kFALSE)
{
fDetConstruction = new TG4RootDetectorConstruction(geom);
SetNavigator(new TG4RootNavigator);
}
TG4RootNavMgr::~TG4RootNavMgr()
{
if (fDetConstruction) delete fDetConstruction;
fRootNavMgr = 0;
}
TG4RootNavMgr *TG4RootNavMgr::GetInstance(TGeoManager *geom)
{
if (fRootNavMgr) return fRootNavMgr;
if (!geom) return NULL;
fRootNavMgr = new TG4RootNavMgr(geom);
return fRootNavMgr;
}
Bool_t TG4RootNavMgr::ConnectToG4()
{
if (fConnected) {
Info("ConnectToG4", "Already connected");
return kTRUE;
}
if (!fDetConstruction) {
Error("ConnectToG4", "No detector construction set !");
return kFALSE;
}
if (!fNavigator) {
Error("ConnectToG4", "Navigator has to be created befor connecting to G4 !!!");
return kFALSE;
}
G4RunManager *runManager = G4RunManager::GetRunManager();
if (!runManager) {
Error("ConnectToG4", "Unable to connect: G4RunManager not instantiated");
return kFALSE;
}
runManager->SetUserInitialization(fDetConstruction);
Info("ConnectToG4", "ROOT detector construction class connected to G4RunManager");
fConnected = kTRUE;
return kTRUE;
}
void TG4RootNavMgr::SetNavigator(TG4RootNavigator *nav)
{
if (fConnected) {
Error("SetNavigator", "Navigator set after instantiation of G4RunManager. Won't set!!!");
return;
}
G4TransportationManager *trMgr = G4TransportationManager::GetTransportationManager();
trMgr->SetNavigatorForTracking(nav);
G4FieldManager *fieldMgr = trMgr->GetPropagatorInField()->GetCurrentFieldManager();
delete trMgr->GetPropagatorInField();
trMgr->SetPropagatorInField(new G4PropagatorInField(nav, fieldMgr));
trMgr->ActivateNavigator(nav);
fNavigator = nav;
Info("SetNavigator", "TG4RootNavigator created and registered to G4TransportationManager");
}
void TG4RootNavMgr::Initialize(TVirtualUserPostDetConstruction *sdinit)
{
Info("Initialize", "Creating G4 hierarchy ...");
if (fDetConstruction) fDetConstruction->Initialize(sdinit);
}
void TG4RootNavMgr::LocateGlobalPointAndSetup(Double_t *pt, Double_t *dir)
{
G4ThreeVector point(pt[0], pt[1], pt[2]);
G4VPhysicalVolume *pVol = 0;
if (dir) {
G4ThreeVector direction(dir[0], dir[1], dir[2]);
pVol = fNavigator->LocateGlobalPointAndSetup(point, &direction);
} else {
pVol = fNavigator->LocateGlobalPointAndSetup(point);
}
fNavigator->PrintState();
}
void TG4RootNavMgr::SetVerboseLevel(Int_t level)
{
fNavigator->SetVerboseLevel(level);
}
void TG4RootNavMgr::PrintG4State() const
{
G4NavigationHistory *history = fNavigator->GetHistory();
G4cout << *history << G4endl;
}
Last change: Wed Jun 25 08:39:25 2008
Last generated: 2008-06-25 08:39
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.