Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleB4a.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 //
26 // $Id$
27 //
30 
31 #include "B4DetectorConstruction.hh"
32 #include "B4PrimaryGeneratorAction.hh"
33 #include "B4RunAction.hh"
34 #include "B4aEventAction.hh"
35 #include "B4aSteppingAction.hh"
36 
37 #include "G4RunManager.hh"
38 #include "G4UImanager.hh"
39 #include "FTFP_BERT.hh"
40 
41 #include "Randomize.hh"
42 
43 #ifdef G4VIS_USE
44 #include "G4VisExecutive.hh"
45 #endif
46 
47 #ifdef G4UI_USE
48 #include "G4UIExecutive.hh"
49 #endif
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
53 namespace {
54  void PrintUsage() {
55  G4cerr << " Usage: " << G4endl;
56  G4cerr << " exampleB4a [-m macro ] [-u UIsession]" << G4endl;
57  }
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
62 int main(int argc,char** argv)
63 {
64  // Evaluate arguments
65  //
66  if ( argc > 5 ) {
67  PrintUsage();
68  return 1;
69  }
70 
71  G4String macro;
72  G4String session;
73  for ( G4int i=1; i<argc; i=i+2 ) {
74  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
75  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
76  else {
77  PrintUsage();
78  return 1;
79  }
80  }
81 
82  // Choose the Random engine
83  //
85 
86  // Construct the default run manager
87  //
88  G4RunManager * runManager = new G4RunManager;
89 
90  // Set mandatory initialization classes
91  //
92  B4DetectorConstruction* detConstruction = new B4DetectorConstruction();
93  runManager->SetUserInitialization(detConstruction);
94 
95  G4VModularPhysicsList* physicsList = new FTFP_BERT;
96  runManager->SetUserInitialization(physicsList);
97 
98  // Set user action classes
99  //
100  runManager->SetUserAction(new B4PrimaryGeneratorAction);
101  //
102  runManager->SetUserAction(new B4RunAction());
103  //
104  B4aEventAction* eventAction = new B4aEventAction();
105  runManager->SetUserAction(eventAction);
106  //
107  B4aSteppingAction* steppingAction
108  = new B4aSteppingAction(detConstruction, eventAction);
109  runManager->SetUserAction(steppingAction);
110 
111  // Initialize G4 kernel
112  //
113  runManager->Initialize();
114 
115 #ifdef G4VIS_USE
116  // Initialize visualization
117  G4VisManager* visManager = new G4VisExecutive;
118  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
119  // G4VisManager* visManager = new G4VisExecutive("Quiet");
120  visManager->Initialize();
121 #endif
122 
123  // Get the pointer to the User Interface manager
124  G4UImanager* UImanager = G4UImanager::GetUIpointer();
125 
126  if ( macro.size() ) {
127  // batch mode
128  G4String command = "/control/execute ";
129  UImanager->ApplyCommand(command+macro);
130  }
131  else {
132  // interactive mode : define UI session
133 #ifdef G4UI_USE
134  G4UIExecutive* ui = new G4UIExecutive(argc, argv, session);
135 #ifdef G4VIS_USE
136  UImanager->ApplyCommand("/control/execute init_vis.mac");
137 #else
138  UImanager->ApplyCommand("/control/execute init.mac");
139 #endif
140  if (ui->IsGUI())
141  UImanager->ApplyCommand("/control/execute gui.mac");
142  ui->SessionStart();
143  delete ui;
144 #endif
145  }
146 
147  // Job termination
148  // Free the store: user actions, physics_list and detector_description are
149  // owned and deleted by the run manager, so they should not be deleted
150  // in the main() program !
151 
152 #ifdef G4VIS_USE
153  delete visManager;
154 #endif
155  delete runManager;
156 
157  return 0;
158 }
159 
160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....