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