]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TGeant4/TG4RunManager.cxx
Bugfix in AliPoints2Memory
[u/mrichter/AliRoot.git] / TGeant4 / TG4RunManager.cxx
index ff8fd70d4e2ac9a92a59f5164b9329d98bc3cb70..c368938ddbcd322daa0fc273a58654eb0e66f827 100644 (file)
@@ -1,19 +1,23 @@
 // $Id$
 // Category: run
 //
+// Author: I. Hrivnacova
+//
+// Class TG4RunManager
+// -------------------
 // See the class description in the header file.
 
 #include "TG4RunManager.h"
-#include "TG4RunMessenger.h"
 #include "TG4VRunConfiguration.h"
-#include "TGeant4.h"
 #include "TG4Globals.h"
 #include "TG4GeometryManager.h"
+#include "TG4GeometryServices.h"
+#include "TG4SDManager.h"
+#include "TG4SDServices.h"
 #include "TG4PhysicsManager.h"
-//#include "TG4StepManager.h"
+#include "TG4G3PhysicsManager.h"
 
 #include <G4RunManager.hh>
-#include <G4StateManager.hh>
 #include <G4UIsession.hh>
 #include <G4UImanager.hh>
 #include <G4UIterminal.hh>
 #ifdef G4UI_USE_GAG
 #include <G4UIGAG.hh>
 #endif
-#include <globals.hh>
+#ifdef G4UI_USE_TCSH
+#include "G4UItcsh.hh" 
+#endif
 
-#include <TRint.h>
 #include <TROOT.h> 
+#include <TRint.h>
 #include <TCint.h> 
 
 TG4RunManager* TG4RunManager::fgInstance = 0;
 
+//_____________________________________________________________________________
 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration, 
                              int argc, char** argv)              
-  : fRunConfiguration(runConfiguration),
+  : TG4Verbose("runManager"),
+    fMessenger(this),
+    fRunConfiguration(runConfiguration),
     fGeantUISession(0),
     fRootUISession(0),
     fRootUIOwner(false),
     fARGC(argc),
-    fARGV(argv)
-  
+    fARGV(argv)  
 {
 // 
   if (fgInstance) {
     TG4Globals::Exception(
       "TG4RunManager: attempt to create two instances of singleton.");
-  };
+  }
       
   if (!fRunConfiguration) {
     TG4Globals::Exception(
       "TG4RunManager: attempt to create instance without runConfiguration.");
-  };
+  }
       
   fgInstance = this;
   
   // create and configure geant4 run manager
   fRunManager =  new G4RunManager();
   fRunConfiguration->ConfigureRunManager(fRunManager);
-  // add verbose level
-  //G4cout << "G4RunManager has been created." << endl;
+
+  if (VerboseLevel() > 1) {
+    G4cout << "G4RunManager has been created." << G4endl;
+  }  
 
   // create geant4 UI
   CreateGeantUI();
@@ -68,13 +78,13 @@ TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration,
 
   // create root UI
   CreateRootUI();
-
-  // messenger
-  fMessenger = new TG4RunMessenger(this);
 }
 
+//_____________________________________________________________________________
 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
-  : fRunConfiguration(runConfiguration),
+  : TG4Verbose("runManager"),
+    fMessenger(this),
+    fRunConfiguration(runConfiguration),
     fGeantUISession(0),
     fRootUISession(0),
     fRootUIOwner(false),
@@ -86,12 +96,12 @@ TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
   if (fgInstance) {
     TG4Globals::Exception(
       "TG4RunManager: attempt to create two instances of singleton.");
-  };
+  }
       
   if (!fRunConfiguration) {
     TG4Globals::Exception(
       "TG4RunManager: attempt to create instance without runConfiguration.");
-  };
+  }
       
   fgInstance = this;
   
@@ -105,8 +115,10 @@ TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
   // create and configure geant4 run manager
   fRunManager =  new G4RunManager();
   fRunConfiguration->ConfigureRunManager(fRunManager);
-  // add verbose level
-  //G4cout << "G4RunManager has been created." << endl;
+
+  if (VerboseLevel() > 1) {
+    G4cout << "G4RunManager has been created." << G4endl;
+  }  
 
   // create geant4 UI
   CreateGeantUI();
@@ -115,32 +127,36 @@ TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
 
   // create root UI
   CreateRootUI();
-
-  // messenger
-  fMessenger = new TG4RunMessenger(this);
 }
 
-TG4RunManager::TG4RunManager() {
+//_____________________________________________________________________________
+TG4RunManager::TG4RunManager()
+  : TG4Verbose("runManager"),
+    fMessenger(this) {
 //
 }
 
-TG4RunManager::TG4RunManager(const TG4RunManager& right) {
+//_____________________________________________________________________________
+TG4RunManager::TG4RunManager(const TG4RunManager& right) 
+  : TG4Verbose("runManager"),
+    fMessenger(this) {
 // 
   TG4Globals::Exception(
     "Attempt to copy TG4RunManager singleton.");
 }
 
+//_____________________________________________________________________________
 TG4RunManager::~TG4RunManager() {
 //  
   delete fRunConfiguration;
   delete fRunManager;
   delete fGeantUISession;
   if (fRootUIOwner) delete fRootUISession;
-  delete fMessenger;
 }
 
 // operators
 
+//_____________________________________________________________________________
 TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
 {
   // check assignement to self
@@ -154,6 +170,7 @@ TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
 
 // private methods
 
+//_____________________________________________________________________________
 void TG4RunManager::CreateGeantUI()
 {
 // Creates interactive Geant4.
@@ -166,8 +183,12 @@ void TG4RunManager::CreateGeantUI()
     if (fARGC == 1) {
 #ifdef G4UI_USE_GAG
       fGeantUISession = new G4UIGAG();
-#else      
+#else
+ #ifdef G4UI_USE_TCSH
+      fGeantUISession = new G4UIterminal(new G4UItcsh);      
+ #else
       fGeantUISession = new G4UIterminal(); 
+ #endif    
 #endif      
     }  
     else if (strcmp (fARGV[1], "dumb") == 0) {
@@ -199,6 +220,7 @@ void TG4RunManager::CreateGeantUI()
   }
 }
 
+//_____________________________________________________________________________
 void TG4RunManager::CreateRootUI()
 {
 // Creates interactive Root.
@@ -216,20 +238,51 @@ void TG4RunManager::CreateRootUI()
 
 // public methods
 
+//_____________________________________________________________________________
 void TG4RunManager::Initialize()
 {
 // Initializes G4.
 // ---
 
+  // create physics constructor
+  // (this operation has to precede the "Init" phase)
+  TG4PhysicsManager::Instance()->CreatePhysicsConstructors();
+
   // initialize Geant4 
   fRunManager->Initialize();
   
+  // initialize SD manager
+  TG4SDManager::Instance()->Initialize();
+}
+
+//_____________________________________________________________________________
+void TG4RunManager::LateInitialize()
+{
+// Finishes initialization of G4 after the AliRoot initialization
+// is finished. 
+// ---
+
+  // set user limits
+  TG4GeometryManager::Instance()
+    ->SetUserLimits(*TG4G3PhysicsManager::Instance()->GetCutVector(),
+                    *TG4G3PhysicsManager::Instance()->GetControlVector());
+
+  // final clear of G3toG4 objects
+  TG4GeometryManager::Instance()->ClearG3TablesFinal();
+      
   // activate/inactivate physics processes
-  // (this operation is not allowed in "Init" phase)
-  TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
-  physicsManager->SetProcessActivation();
+  TG4PhysicsManager::Instance()->SetProcessActivation();
+
+  // print statistics
+  TG4GeometryServices::Instance()->PrintStatistics(true, false);  
+  TG4SDServices::Instance()->PrintStatistics(false, true);  
+
+  if (VerboseLevel() > 2) {
+    TG4GeometryServices::Instance()->PrintLogicalVolumeStore();  
+  }
 }
 
+//_____________________________________________________________________________
 void TG4RunManager::ProcessEvent()
 {
 // Not yet implemented.
@@ -238,6 +291,7 @@ void TG4RunManager::ProcessEvent()
   TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
 }
     
+//_____________________________________________________________________________
 void TG4RunManager::ProcessRun(G4int nofEvents)
 {
 // Processes Geant4 run.
@@ -246,6 +300,7 @@ void TG4RunManager::ProcessRun(G4int nofEvents)
   fRunManager->BeamOn(nofEvents); 
 }
     
+//_____________________________________________________________________________
 void TG4RunManager::StartGeantUI()
 { 
 // Starts interactive/batch Geant4.
@@ -254,9 +309,9 @@ void TG4RunManager::StartGeantUI()
   if (!fGeantUISession) CreateGeantUI();
   if (fGeantUISession) {  
     // interactive session
-    G4cout << "Welcome back in Geant4" << endl;
+    G4cout << "Welcome back in Geant4" << G4endl;
     fGeantUISession->SessionStart();
-    G4cout << "Welcome back in Root" << endl;  
+    G4cout << "Welcome back in Root" << G4endl;  
   }
   else {
     // execute Geant4 macro if file is specified as an argument 
@@ -265,6 +320,7 @@ void TG4RunManager::StartGeantUI()
   }
 }
 
+//_____________________________________________________________________________
 void TG4RunManager::StartRootUI()
 {
 // Starts interactive Root.
@@ -272,12 +328,13 @@ void TG4RunManager::StartRootUI()
 
   if (!fRootUISession) CreateRootUI();
   if (fRootUISession) { 
-    G4cout << "Welcome back in Root" << endl;
+    G4cout << "Welcome back in Root" << G4endl;
     fRootUISession->Run(kTRUE);
-    G4cout << "Welcome back in Geant4" << endl;  
+    G4cout << "Welcome back in Geant4" << G4endl;  
   }
 }
  
+//_____________________________________________________________________________
 void TG4RunManager::ProcessGeantMacro(G4String macroName)
 {
 // Processes Geant4 macro.
@@ -287,6 +344,7 @@ void TG4RunManager::ProcessGeantMacro(G4String macroName)
   ProcessGeantCommand(command);
 }
  
+//_____________________________________________________________________________
 void TG4RunManager::ProcessRootMacro(G4String macroName)
 {
 // Processes Root macro.
@@ -303,6 +361,7 @@ void TG4RunManager::ProcessRootMacro(G4String macroName)
   gInterpreter->ProcessLine(macroFunction);
 }
  
+//_____________________________________________________________________________
 void TG4RunManager::ProcessGeantCommand(G4String command)
 {
 // Processes Geant4 command.
@@ -312,6 +371,7 @@ void TG4RunManager::ProcessGeantCommand(G4String command)
   pUI->ApplyCommand(command);
 }
 
+//_____________________________________________________________________________
 void TG4RunManager::ProcessRootCommand(G4String command)
 {
 // Processes Root command.
@@ -320,16 +380,18 @@ void TG4RunManager::ProcessRootCommand(G4String command)
   gInterpreter->ProcessLine(command);
 }
 
+//_____________________________________________________________________________
 void TG4RunManager::UseG3Defaults() 
 {
 // Controls G3 defaults usage.
 // ---
 
   TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
-  TG4PhysicsManager::Instance()->SetG3DefaultCuts();
-  TG4PhysicsManager::Instance()->SetG3DefaultProcesses();
+  TG4G3PhysicsManager::Instance()->SetG3DefaultCuts();
+  TG4G3PhysicsManager::Instance()->SetG3DefaultControls();
 }
 
+//_____________________________________________________________________________
 Int_t TG4RunManager::CurrentEvent() const
 {
 // Returns the number of the current event.