![]() |
Precalibrated Ion Beam Identification Detector Simulation 1.0
A pilot study detector simulation, written in C++ with Geant4.
|
00001 00006 #include "G4RunManager.hh" 00007 #include "G4UImanager.hh" 00008 00009 #include "Randomize.hh" 00010 #include <ctime> 00011 00012 #include "MyPhysicsList.hh" 00013 #include "DetectorConstruction.hh" 00014 #include "PrimaryGeneratorAction.hh" 00015 #include "RunAction.hh" 00016 #include "EventAction.hh" 00017 #include "SteppingAction.hh" 00018 #include "SteppingVerbose.hh" 00019 00020 #ifndef STDIO 00021 #define STDIO //!<Inclusion guard. 00022 #include <stdio.h> 00023 #endif 00024 00025 #ifdef G4VIS_USE //If we're using G4VIS 00026 #include "G4VisExecutive.hh" 00027 #endif 00028 00029 #ifdef G4UI_USE //If we're using G4UI 00030 #include "G4UIExecutive.hh" 00031 #endif 00032 00033 00034 int main(int argc, 00035 char** argv 00036 ); 00037 00038 int main(int argc,char** argv) 00039 { 00040 // Choose the Random engine 00041 // 00042 srand(time(0)); 00043 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); 00044 CLHEP::HepRandom::setTheSeed(rand()%10000+1); 00045 00046 00047 // User Verbose output class 00048 // 00049 G4VSteppingVerbose::SetInstance(new SteppingVerbose); 00050 00051 // Construct the default run manager 00052 // 00053 G4RunManager * runManager = new G4RunManager; 00054 00055 // Set mandatory initialization classes 00056 // 00057 DetectorConstruction* detector = new DetectorConstruction; 00058 runManager->SetUserInitialization(detector); 00059 // 00060 G4VUserPhysicsList* physics = new MyPhysicsList<G4VModularPhysicsList>; 00061 runManager->SetUserInitialization(physics); 00062 00063 // Set user action classes 00064 // 00065 00066 // 00067 RunAction* run_action = new RunAction; 00068 // 00069 00070 00071 PrimaryGeneratorAction * myAction = 00072 new PrimaryGeneratorAction(detector,run_action); 00073 00074 G4VUserPrimaryGeneratorAction* gen_action = myAction; 00075 00076 runManager->SetUserAction(gen_action); 00077 00078 runManager->SetUserAction(run_action); 00079 00080 EventAction* event_action = new EventAction(run_action, detector); 00081 runManager->SetUserAction(event_action); 00082 // 00083 G4UserSteppingAction* stepping_action = 00084 new SteppingAction(detector, event_action); 00085 runManager->SetUserAction(stepping_action); 00086 00087 // Initialize G4 kernel 00088 // 00089 runManager->Initialize(); 00090 00091 myAction->SetParticle(6,17,0.,0.); 00092 00093 #ifdef G4VIS_USE 00094 // Initialize visualization 00095 // 00096 G4VisManager* visManager = new G4VisExecutive; 00097 visManager->Initialize(); 00098 #endif 00099 00100 00101 00102 // Get the pointer to the User Interface manager 00103 // 00104 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 00105 00106 if (argc==2) // batch mode 00107 { 00108 G4String command = "/control/execute "; 00109 G4String fileName = argv[1]; 00110 UImanager->ApplyCommand(command+fileName); 00111 } 00112 else 00113 { // interactive mode : define UI session 00114 #ifdef G4UI_USE 00115 G4UIExecutive* ui = new G4UIExecutive(argc, argv); 00116 #ifdef G4VIS_USE 00117 if(argc<2) 00118 UImanager->ApplyCommand("/control/execute vis.mac"); 00119 else //other init file. 00120 { 00121 G4String command = "/control/execute "; 00122 G4String fileName = argv[1]; 00123 UImanager->ApplyCommand(command+fileName); 00124 } 00125 #endif 00126 if (ui->IsGUI()) 00127 UImanager->ApplyCommand("/control/execute visTutor/gui.mac"); 00128 ui->SessionStart(); 00129 delete ui; 00130 #endif 00131 } 00132 00133 // Job termination 00134 // Free the store: user actions, physics_list and detector_description are 00135 // owned and deleted by the run manager, so they should not 00136 // be deleted in the main() program ! 00137 #ifdef G4VIS_USE 00138 delete visManager; 00139 #endif 00140 delete runManager; 00141 00142 return 0; 00143 } 00144 00145 00146