ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExUCN.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ExUCN.cc
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 //
29 //
30 //
31 //
32 //
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35 
36 #ifndef WIN32
37 #include <unistd.h>
38 #endif
39 
40 #include "G4Types.hh"
41 
42 #include "ExUCNPhysicsList.hh"
45 
46 #ifdef G4MULTITHREADED
47 #include "G4MTRunManager.hh"
48 #else
49 #include "G4RunManager.hh"
50 #endif
51 
52 #include "G4UImanager.hh"
53 #include "G4UIcommand.hh"
54 
55 #include "Randomize.hh"
56 
57 #include "G4VisExecutive.hh"
58 #include "G4UIExecutive.hh"
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
62 namespace {
63  void PrintUsage() {
64  G4cerr << " Usage: " << G4endl;
65  G4cerr << " ExUCN [-m macro ] [-u UIsession] [-t nThreads] [-r seed] "
66  << G4endl;
67  G4cerr << " note: -t option is available only for multi-threaded mode."
68  << G4endl;
69  }
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
74 int main(int argc,char** argv)
75 {
76  // Evaluate arguments
77  //
78  if ( argc > 9 ) {
79  PrintUsage();
80  return 1;
81  }
82 
83  G4String macro;
85 #ifdef G4MULTITHREADED
86  G4int nThreads = 0;
87 #endif
88 
89  G4long myseed = 1234;
90  for ( G4int i=1; i<argc; i=i+2 ) {
91  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
92  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
93  else if ( G4String(argv[i]) == "-r" ) myseed = atoi(argv[i+1]);
94 #ifdef G4MULTITHREADED
95  else if ( G4String(argv[i]) == "-t" ) {
96  nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
97  }
98 #endif
99  else {
100  PrintUsage();
101  return 1;
102  }
103  }
104 
105  // Instantiate G4UIExecutive if interactive mode
106  G4UIExecutive* ui = nullptr;
107  if ( argc == 1 ) {
108  ui = new G4UIExecutive(argc, argv);
109  }
110 
111  // Choose the Random engine
112  //
113  G4Random::setTheEngine(new CLHEP::RanecuEngine);
114 
115  // Construct the default run manager
116  //
117 #ifdef G4MULTITHREADED
118  G4MTRunManager * runManager = new G4MTRunManager;
119  if ( nThreads > 0 ) runManager->SetNumberOfThreads(nThreads);
120 #else
121  G4RunManager * runManager = new G4RunManager;
122 #endif
123 
124  // Seed the random number generator manually
125  G4Random::setTheSeed(myseed);
126 
127  // Set mandatory initialization classes
128  //
129  // Detector construction
131  // Physics list
132  runManager->SetUserInitialization(new ExUCNPhysicsList());
133  // User action initialization
135 
136  // Initialize G4 kernel
137  //
138  runManager->Initialize();
139 
140  // Initialize visualization
141  //
142  G4VisManager* visManager = new G4VisExecutive;
143  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
144  // G4VisManager* visManager = new G4VisExecutive("Quiet");
145  visManager->Initialize();
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  UImanager->ApplyCommand("/control/execute vis.mac");
159  if (ui->IsGUI())
160  UImanager->ApplyCommand("/control/execute gui.mac");
161  ui->SessionStart();
162  delete ui;
163  }
164 
165  // Job termination
166  // Free the store: user actions, physics_list and detector_description are
167  // owned and deleted by the run manager, so they should not
168  // be deleted in the main() program !
169 
170  delete visManager;
171  delete runManager;
172 
173  return 0;
174 }
175 
176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......