00001 //! \file 00002 //! 00003 //! Source file containing the main program for the OLYMPUS Monte Carlo. 00004 //! 00005 //! The main program initialises the OLYMPUS detector, event generator 00006 //! and physics classes. It then starts the GEANT4 kernel and executes 00007 //! either a batch macro file given on the command line or a default 00008 //! visualisation macro file based on environmental variables for running 00009 //! interactively. 00010 //! 00011 //! \author D.K. Hasell 00012 //! \version 1.0 00013 //! \date 2010-09-01 00014 //! 00015 //! \ingroup control 00016 00017 // Include the GEANT4 header files referenced in this file. 00018 00019 #include "globals.hh" 00020 00021 #include "G4RunManager.hh" 00022 #include "G4UImanager.hh" 00023 #include "G4VisExecutive.hh" 00024 #include "G4UIsession.hh" 00025 #include "G4UIQt.hh" 00026 #include "G4UIXm.hh" 00027 #include "G4UIXaw.hh" 00028 #include "G4UIterminal.hh" 00029 #include "G4UItcsh.hh" 00030 00031 // Include the user header files referenced in this file. 00032 00033 #include "Detector.h" 00034 #include "Physics.h" 00035 #include "Generator.h" 00036 #include "RunAction.h" 00037 #include "EventAction.h" 00038 00039 // Use the standard namespace. 00040 00041 using namespace std; 00042 00043 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+**** 00044 00045 //! Main program for the GEANT4 simulation of the OLYMPUS experiment. 00046 //! 00047 //! The main program receives the command line arguments \a argc and \a argv. 00048 //! - If the command line contains only the program name (i.e. OLYMPUS) then 00049 //! a default visualisation macro file is executed and then control is 00050 //! returned to the user for interactive operation of the program. 00051 //! - If the command line contains more than just the program name then the 00052 //! second argument is taken to be the name of a macro file which is 00053 //! executed in batch mode. 00054 //! 00055 //! \param[in] argc - the number of words on the command line including the 00056 //! command itself. 00057 //! \param[in] argv - an array of character arrays giving the command line 00058 //! arguments. 00059 //! \return returns the integer 0 on successful completion. 00060 00061 int main( int argc, char** argv ) { 00062 00063 // Construct the default run manager. 00064 00065 G4RunManager * runManager = new G4RunManager; 00066 00067 // Set mandatory initialization class for detector. 00068 00069 runManager->SetUserInitialization( new Detector ); 00070 00071 // Set mandatory initialization class for physics. 00072 00073 runManager->SetUserInitialization( new Physics ); 00074 00075 // Set mandatory user action class for event generator. 00076 00077 runManager->SetUserAction( new Generator ); 00078 00079 // Set the optional user run action class. 00080 00081 runManager->SetUserAction( new RunAction ); 00082 00083 // Set the optional user event action class. 00084 00085 runManager->SetUserAction( new EventAction ); 00086 00087 // Initialize GEANT4 kernel. 00088 00089 runManager->Initialize(); 00090 00091 // Get pointer to the UI manager. 00092 00093 G4UImanager * UI = G4UImanager::GetUIpointer(); 00094 00095 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+**** 00096 00097 // If command line contains only the program name run interactively. 00098 00099 if ( argc == 1 ) { 00100 00101 // Create and initialise a visulaisation manager. 00102 00103 G4VisManager * visManager = new G4VisExecutive; 00104 visManager->Initialize(); 00105 00106 // Define a session to run interactively based on environment variables. 00107 00108 //#if defined G4UI_USE_QT 00109 // G4UIsession * session = new G4UIQt( argc, argv ); 00110 #if defined G4UI_USE_XM 00111 G4UIsession * session = new G4UIXm( argc, argv ); 00112 #elif defined G4UI_USE_XAW 00113 G4UIsession * session = new G4UIXaw( argc, argv ); 00114 #elif defined G4UI_USE_TCSH 00115 G4UIsession * session = new G4UIterminal( new G4UItcsh ); 00116 #else 00117 G4UIsession * session = new G4UIterminal(); 00118 #endif 00119 00120 // Execute a startup macro depending on environment variables and start 00121 // the session. 00122 00123 //#if defined G4VIS_USE_OPENGLQT 00124 // UI->ApplyCommand( "/control/execute macros/QT_Init.mac" ); 00125 #if defined G4VIS_USE_OPENGLXM 00126 UI->ApplyCommand( "/control/execute macros/XM_Init.mac" ); 00127 #elif defined G4VIS_USE_OPENGLX 00128 UI->ApplyCommand( "/control/execute macros/X_Init.mac" ); 00129 #endif 00130 00131 session->SessionStart(); 00132 00133 // End interactive session. 00134 00135 delete session; 00136 delete visManager; 00137 00138 } 00139 00140 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+**** 00141 00142 // If command line contains a command file execute it in batch mode. 00143 00144 else { 00145 00146 // Print the commands in the command file as they are executed. 00147 00148 UI->ApplyCommand( "/control/verbose 2" ); 00149 00150 // Execute the Batch command file provided on the command line. 00151 00152 G4String command = "/control/execute "; 00153 G4String file = argv[1]; 00154 00155 UI->ApplyCommand( command + file ); 00156 00157 } 00158 00159 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+**** 00160 00161 // End the session 00162 00163 delete runManager; 00164 00165 // That's All Folks ! 00166 00167 return 0; 00168 00169 }