///////////////////////////////////////////////////////////////////////// // G4Tutorial: // // main() function of the Geant4 tutorial example // // ///////////////////////////////////////////////////////////////////////// #include "G4RunManager.hh" #include "G4UImanager.hh" #include "G4UIsession.hh" #include "G4UIterminal.hh" #include "globals.hh" #include "DetectorConstruction.hh" #include "PhysicsList.hh" #include "PrimaryGenerator.hh" #include "UserRunAction.hh" #include "UserEventAction.hh" #include "UserTrackingAction.hh" #ifdef G4VIS_USE #include "G4VisExecutive.hh" #include "G4TrajectoryGenericDrawer.hh" #endif int main(int argc,char** argv) { // As a first step, the Geant4 run manager must be created. The user is // responsible for deleting the run manager instance at the end of the // program. G4RunManager* runManager = new G4RunManager; G4String detectorRegionName = "Detector"; // As a minimum input, the user must provide three classes describing: // A) the detector setup (geometry, materials, ...) // B) the physics setup (physics processes, models, ...) // C) the particle source (initial particle energy, direction, ...) // (see the corresponding implementations for details) // // These classes must be instantiated in the main() function and assigned // to the run manager by using the SetUserInitialization() method of // G4RunManager. // Note: The run manager takes care of deleting the instances of these // classes in the end. DetectorConstruction* detector = new DetectorConstruction(detectorRegionName); runManager -> SetUserInitialization(detector); PhysicsList* physics = new PhysicsList(detectorRegionName); runManager -> SetUserInitialization(physics); PrimaryGenerator* source = new PrimaryGenerator(); runManager -> SetUserAction(source); // Additionally, the user can define certain actions, which are performed // at different levels of the tracking algorithm (track, step) or at the // beginning and/or end of events and runs. These classes are optional, // i.e. they are not required to perform Geant4 simulations. // (see the corresponding implementations for details) // // User defined action classes must be instantiated in the main() function // and must be assigned to the run manager by using the SetUserAction() // method of G4RunManager. // Note: The run manager takes care of deleting the instances of these // classes in the end. UserEventAction* eventAction = new UserEventAction(); runManager -> SetUserAction(eventAction); UserTrackingAction* trackingAction = new UserTrackingAction(); runManager -> SetUserAction(trackingAction); UserRunAction* runAction = new UserRunAction(); runManager -> SetUserAction(runAction); #ifdef G4VIS_USE G4cout << "INFORMATION: Visualisation used." << G4endl; // If visualization is used, the visualization manager (G4VisManager) must be // instantiated and initialized. The user is responsible for deleting the // visualization manager at the end of the program. G4VisManager* visManager = new G4VisExecutive; visManager -> Initialize(); // Additionally, according to the visualization mode, drawers can be assigned // to the visualization manager (in the current example, trajectories are // visualized) G4TrajectoryGenericDrawer* genDrawer = new G4TrajectoryGenericDrawer; visManager -> RegisterModel(genDrawer); #endif G4UImanager * UI = G4UImanager::GetUIpointer(); if(argc == 1) { //Start interactive session (executable without macro) G4cout << "INFORMATION: Interactive commands" << " used to control simulation." << G4endl; G4UIsession *session=new G4UIterminal(); session->SessionStart(); delete session; } else if (argc ==2) { G4String fileName = argv[1]; G4cout << "INFORMATION: Commands in file " << fileName << " used to control simulation." << G4endl; UI -> ApplyCommand("/control/execute " + fileName); } else { G4cerr << "Error. Wrong number of arguments." << G4endl; G4cout << "INFORMATION: Usage " << argv[0] << " [macrofile]" << G4endl; } // Deleting the visualization manager #ifdef G4VIS_USE delete visManager; #endif // The run manager must be deleted at last delete runManager; return 0; }