LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
factory.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 //
31 // -------------------------------------------------------------
32 // GEANT4 Hadr00
33 //
34 // Application demonstrating Geant4 hadronic cross sections
35 //
36 // Author: V.Ivanchenko 20 June 2008
37 //
38 // Modified:
39 //
40 // -------------------------------------------------------------
41 //
42 //
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
46 #include "DetectorConstruction.hh"
47 #include "ActionInitialization.hh"
49 
50 #ifdef G4MULTITHREADED
51 #include "G4MTRunManager.hh"
52 #else
53 #include "G4RunManager.hh"
54 #endif
55 
56 #include "G4PhysListFactory.hh"
57 #include "G4VModularPhysicsList.hh"
58 #include "G4UImanager.hh"
59 #include "Randomize.hh"
60 #include "G4VisExecutive.hh"
61 #include "G4UIExecutive.hh"
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
65 namespace {
66  void PrintUsage() {
67  G4cerr << " Usage: " << G4endl;
68  G4cerr << " factory [-m macro ] [-p physList ] [-u UIsession] [-t nThreads]" << G4endl;
69  G4cerr << " note: -t option is available only for multi-threaded mode." << G4endl;
70  G4cerr << G4endl;
71  }
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
76 int main(int argc,char** argv)
77 {
78  // Evaluate arguments
79  //
80  if ( argc > 9 ) {
81  PrintUsage();
82  return 1;
83  }
84 
85  G4String macro;
87  G4String physListName;
88  G4String gdmlFileName;
89 #ifdef G4MULTITHREADED
90  G4int nofThreads = 0;
91 #endif
92  for ( G4int i=1; i<argc; i=i+2 ) {
93  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
94  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
95  else if ( G4String(argv[i]) == "-p" ) physListName = argv[i+1];
96 #ifdef G4MULTITHREADED
97  else if ( G4String(argv[i]) == "-t" ) {
98  nofThreads = G4UIcommand::ConvertToInt(argv[i+1]);
99  }
100 #endif
101  else {
102  PrintUsage();
103  return 1;
104  }
105  }
106 
107  // Detect interactive mode (if no arguments) and define UI session
108  //
109  G4UIExecutive* ui = 0;
110  if ( ! macro.size() ) {
111  ui = new G4UIExecutive(argc, argv, session);
112  }
113 
114  // Choose the Random engine //choose the Random engine
115  G4Random::setTheEngine(new CLHEP::RanecuEngine());
116 
117  // Construct the run manager
118 #ifdef G4MULTITHREADED
119  G4MTRunManager * runManager = new G4MTRunManager();
120  if ( nofThreads > 0 ) {
121  runManager->SetNumberOfThreads(nofThreads);
122  }
123 #else
124  G4RunManager * runManager = new G4RunManager();
125 #endif
126 
127  // Physics list factory
128  G4PhysListFactory factory;
129  G4VModularPhysicsList* physList = nullptr;
130 
131  // Get physics list name
132  if ( ! physListName.size() ) {
133  // Physics List is defined via environment variable PHYSLIST
134  char* physListNameEnv = std::getenv("PHYSLIST");
135  if ( physListNameEnv ) {
136  physListName = G4String(physListNameEnv);
137  }
138  }
139 
140  // Check if the name is known to the factory
141  if ( physListName.size() && (! factory.IsReferencePhysList(physListName) ) ) {
142  G4cerr << "Physics list " << physListName
143  << " is not available in PhysListFactory." << G4endl;
144  physListName.clear();
145  }
146 
147  // If name is not defined use FTFP_BERT
148  if ( ! physListName.size() ) {
149  physListName = "FTFP_BERT";
150  }
151 
152  // Reference PhysicsList via its name
153  physList = factory.GetReferencePhysList(physListName);
154 
155  // Set mandatory initialization classes
156  runManager->SetUserInitialization(new DetectorConstruction());
157  runManager->SetUserInitialization(physList);
158 
159  // set user action classes
160  runManager->SetUserInitialization(new ActionInitialization("factory"));
161 
162 // Initialize visualization
163  G4VisManager* visManager = new G4VisExecutive;
164  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
165  // G4VisManager* visManager = new G4VisExecutive("Quiet");
166  visManager->Initialize();
167 
168  // Get the pointer to the User Interface manager
169  G4UImanager* UImanager = G4UImanager::GetUIpointer();
170 
171  if ( macro.size() ) {
172  // batch mode
173  G4String command = "/control/execute ";
174  UImanager->ApplyCommand(command+macro);
175  }
176  else {
177  // interactive mode : define UI session
178  UImanager->ApplyCommand("/control/execute init_vis.mac");
179  ui->SessionStart();
180  delete ui;
181  }
182 
183  // Job termination
184  // Free the store: user actions, physics_list and detector_description are
185  // owned and deleted by the run manager, so they should not be deleted
186  // in the main() program !
187 
188  delete visManager;
189  delete runManager;
190 }
191 
192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static G4UIterminal * session
void PrintUsage()
int main(int argc, char **argv)
Definition: factory.cc:76