Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Hadr01.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 // $Id: Hadr01.cc 101216 2016-11-09 13:54:13Z gcosmo $
31 //
32 // -------------------------------------------------------------
33 // GEANT4 Hadr01
34 //
35 // Application demonstrating Geant4 hadronic physics:
36 // beam interaction with a target
37 //
38 // Authors: A.Bagulya, I.Gudowska, V.Ivanchenko, N.Starkov
39 //
40 // Modified:
41 // 29.12.2009 V.Ivanchenko introduced access to reference PhysLists
42 //
43 // -------------------------------------------------------------
44 //
45 //
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 
49 #include "G4RunManager.hh"
50 #include "G4UImanager.hh"
51 #include "Randomize.hh"
52 
53 #include "DetectorConstruction.hh"
54 #include "PhysicsList.hh"
55 #include "G4PhysListFactory.hh"
56 #include "G4VModularPhysicsList.hh"
57 #include "PrimaryGeneratorAction.hh"
58 #include "PhysicsListMessenger.hh"
59 
60 #include "RunAction.hh"
61 #include "EventAction.hh"
62 #include "StackingAction.hh"
63 
64 #ifdef G4VIS_USE
65 #include "G4VisExecutive.hh"
66 #endif
67 
68 #ifdef G4UI_USE
69 #include "G4UIExecutive.hh"
70 #endif
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
74 int main(int argc,char** argv) {
75 
76  //choose the Random engine
78 
79  //Construct the default run manager
80  G4RunManager * runManager = new G4RunManager();
81 
82  //set mandatory initialization classes
84 
85  G4PhysListFactory factory;
86  G4VModularPhysicsList* phys = nullptr;
87  PhysicsListMessenger* mess = nullptr;
88  G4String physName = "";
89 
90  // Physics List name defined via 3nd argument
91  if (argc==3) { physName = argv[2]; }
92 
93  // Physics List name defined via environment variable
94  if("" == physName) {
95  char* path = getenv("PHYSLIST");
96  if (path) { physName = G4String(path); }
97  }
98 
99  // reference PhysicsList via its name
100  if("" != physName && factory.IsReferencePhysList(physName)) {
101  phys = factory.GetReferencePhysList(physName);
102 
103  // instantiated messenger
104  mess = new PhysicsListMessenger();
105  }
106 
107  // local Physics List
108  if(!phys) { phys = new PhysicsList(); }
109 
110  // define physics
111  runManager->SetUserInitialization(phys);
112  runManager->SetUserAction(new PrimaryGeneratorAction());
113 
114  //set user action classes
115  runManager->SetUserAction(new RunAction());
116  runManager->SetUserAction(new EventAction());
117  runManager->SetUserAction(new StackingAction());
118 
119  //get the pointer to the User Interface manager
120  G4UImanager* UImanager = G4UImanager::GetUIpointer();
121 #ifdef G4VIS_USE
122  G4VisManager* visManager = nullptr;
123 #endif
124 
125  if (argc==1) // Define UI terminal for interactive mode
126  {
127 #ifdef G4VIS_USE
128  //visualization manager
129  visManager = new G4VisExecutive;
130  visManager->Initialize();
131 #endif
132 #ifdef G4UI_USE
133  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
134  ui->SessionStart();
135  delete ui;
136 #endif
137  }
138  else // Batch mode
139  {
140  G4String command = "/control/execute ";
141  G4String fileName = argv[1];
142  UImanager->ApplyCommand(command+fileName);
143  }
144 
145  //job termination
146 #ifdef G4VIS_USE
147  delete visManager;
148 #endif
149  delete runManager;
150  delete mess;
151 
152  return 0;
153 }
154 
155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
The primary generator action class with particle gun.
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
int main(int argc, char **argv)
Definition: genwindef.cpp:30
Event action class.
Definition: EventAction.hh:45
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4VModularPhysicsList * GetReferencePhysList(const G4String &)
G4bool IsReferencePhysList(const G4String &)
void Initialize()
Detector construction class to define materials and geometry.
static void setTheEngine(HepRandomEngine *theNewEngine)
Definition: Random.cc:270
Run action class.
Definition: RunAction.hh:45
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
virtual void SetUserAction(G4UserRunAction *userAction)
Physics list class.
Definition: PhysicsList.hh:47