LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ExUCN.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: ExUCN.cc 75572 2013-11-04 11:46:08Z gcosmo $
27 //
30 //
31 //
32 //
33 //
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 
37 #ifndef WIN32
38 #include <unistd.h>
39 #endif
40 
41 #include "ExUCNPhysicsList.hh"
42 #include "ExUCNDetectorConstruction.hh"
43 #include "ExUCNActionInitialization.hh"
44 
45 #ifdef G4MULTITHREADED
46 #include "G4MTRunManager.hh"
47 #else
48 #include "G4RunManager.hh"
49 #endif
50 
51 #include "G4UImanager.hh"
52 #include "G4UIcommand.hh"
53 
54 #include "Randomize.hh"
55 
56 #ifdef G4VIS_USE
57 #include "G4VisExecutive.hh"
58 #endif
59 
60 #ifdef G4UI_USE
61 #include "G4UIExecutive.hh"
62 #endif
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
66 namespace {
67  void PrintUsage() {
68  G4cerr << " Usage: " << G4endl;
69  G4cerr << " ExUCN [-m macro ] [-u UIsession] [-t nThreads] [-r seed] "
70  << G4endl;
71  G4cerr << " note: -t option is available only for multi-threaded mode."
72  << G4endl;
73  }
74 }
75 
76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
78 int main(int argc,char** argv)
79 {
80  // Evaluate arguments
81  //
82  if ( argc > 9 ) {
83  PrintUsage();
84  return 1;
85  }
86 
87  G4String macro;
89 #ifdef G4MULTITHREADED
90  G4int nThreads = 0;
91 #endif
92 
93  G4long myseed = 1234;
94  for ( G4int i=1; i<argc; i=i+2 ) {
95  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
96  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
97  else if ( G4String(argv[i]) == "-r" ) myseed = atoi(argv[i+1]);
98 #ifdef G4MULTITHREADED
99  else if ( G4String(argv[i]) == "-t" ) {
100  nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
101  }
102 #endif
103  else {
104  PrintUsage();
105  return 1;
106  }
107  }
108 
109  // Choose the Random engine
110  //
111  G4Random::setTheEngine(new CLHEP::RanecuEngine);
112 
113  // Construct the default run manager
114  //
115 #ifdef G4MULTITHREADED
116  G4MTRunManager * runManager = new G4MTRunManager;
117  if ( nThreads > 0 ) runManager->SetNumberOfThreads(nThreads);
118 #else
119  G4RunManager * runManager = new G4RunManager;
120 #endif
121 
122  // Seed the random number generator manually
123  G4Random::setTheSeed(myseed);
124 
125  // Set mandatory initialization classes
126  //
127  // Detector construction
128  runManager->SetUserInitialization(new ExUCNDetectorConstruction());
129  // Physics list
130  runManager->SetUserInitialization(new ExUCNPhysicsList());
131  // User action initialization
132  runManager->SetUserInitialization(new ExUCNActionInitialization());
133 
134  // Initialize G4 kernel
135  //
136  runManager->Initialize();
137 
138 #ifdef G4VIS_USE
139  // Initialize visualization
140  //
141  G4VisManager* visManager = new G4VisExecutive;
142  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
143  // G4VisManager* visManager = new G4VisExecutive("Quiet");
144  visManager->Initialize();
145 #endif
146 
147  // Get the pointer to the User Interface manager
148  //
149  G4UImanager* UImanager = G4UImanager::GetUIpointer();
150 
151  if ( macro.size() ) {
152  // batch mode
153  G4String command = "/control/execute ";
154  UImanager->ApplyCommand(command+macro);
155  }
156  else
157  { // interactive mode : define UI session
158 #ifdef G4UI_USE
159  G4UIExecutive* ui = new G4UIExecutive(argc, argv, session);
160 #ifdef G4VIS_USE
161  UImanager->ApplyCommand("/control/execute vis.mac");
162 #else
163  UImanager->ApplyCommand("/control/execute ExUCN.in");
164 #endif
165  if (ui->IsGUI())
166  UImanager->ApplyCommand("/control/execute gui.mac");
167  ui->SessionStart();
168  delete ui;
169 #endif
170  }
171 
172  // Job termination
173  // Free the store: user actions, physics_list and detector_description are
174  // owned and deleted by the run manager, so they should not
175  // be deleted in the main() program !
176 
177 #ifdef G4VIS_USE
178  delete visManager;
179 #endif
180  delete runManager;
181 
182  return 0;
183 }
184 
185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static G4UIterminal * session
void PrintUsage()
int main(int argc, char **argv)
Definition: ExUCN.cc:78