Geant4  10.00.p03
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 68006 2013-03-13 11:26: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 #include "G4EmUserPhysics.hh"
60 
61 #include "RunAction.hh"
62 #include "EventAction.hh"
63 #include "StackingAction.hh"
64 
65 #ifdef G4VIS_USE
66 #include "G4VisExecutive.hh"
67 #endif
68 
69 #ifdef G4UI_USE
70 #include "G4UIExecutive.hh"
71 #endif
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
75 int main(int argc,char** argv) {
76 
77  //choose the Random engine
78  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
79 
80  //Construct the default run manager
81  G4RunManager * runManager = new G4RunManager();
82 
83  //set mandatory initialization classes
85 
86  G4PhysListFactory factory;
87  G4VModularPhysicsList* phys = 0;
88  PhysicsListMessenger* mess = 0;
89  G4String physName = "";
90 
91  // Physics List name defined via 3nd argument
92  if (argc==3) { physName = argv[2]; }
93 
94  // Physics List name defined via environment variable
95  if("" == physName) {
96  char* path = getenv("PHYSLIST");
97  if (path) { physName = G4String(path); }
98  }
99 
100  // reference PhysicsList via its name
101  if("" != physName && factory.IsReferencePhysList(physName)) {
102  phys = factory.GetReferencePhysList(physName);
103 
104  // added extra EM options
105  phys->RegisterPhysics(new G4EmUserPhysics(1));
106 
107  // instantiated messenger
108  mess = new PhysicsListMessenger();
109  }
110 
111  // local Physics List
112  if(!phys) { phys = new PhysicsList(); }
113 
114  // define physics
115  runManager->SetUserInitialization(phys);
116  runManager->SetUserAction(new PrimaryGeneratorAction());
117 
118  //set user action classes
119  runManager->SetUserAction(new RunAction());
120  runManager->SetUserAction(new EventAction());
121  runManager->SetUserAction(new StackingAction());
122 
123  //get the pointer to the User Interface manager
124  G4UImanager* UImanager = G4UImanager::GetUIpointer();
125 #ifdef G4VIS_USE
126  G4VisManager* visManager = 0;
127 #endif
128 
129  if (argc==1) // Define UI terminal for interactive mode
130  {
131 #ifdef G4VIS_USE
132  //visualization manager
133  visManager = new G4VisExecutive;
134  visManager->Initialize();
135 #endif
136 #ifdef G4UI_USE
137  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
138  ui->SessionStart();
139  delete ui;
140 #endif
141  }
142  else // Batch mode
143  {
144  G4String command = "/control/execute ";
145  G4String fileName = argv[1];
146  UImanager->ApplyCommand(command+fileName);
147  }
148 
149  //job termination
150 #ifdef G4VIS_USE
151  delete visManager;
152 #endif
153  delete runManager;
154  delete mess;
155 
156  return 0;
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void RegisterPhysics(G4VPhysicsConstructor *)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4VModularPhysicsList * GetReferencePhysList(const G4String &)
G4bool IsReferencePhysList(const G4String &)
Definition of the G4EmUserPhysics class.
void Initialize()
Detector construction class to demonstrate various ways of placement.
int main(int argc, char **argv)
Definition: Hadr01.cc:75
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432
virtual void SetUserAction(G4UserRunAction *userAction)