ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
genericPL.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file genericPL.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 //
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"
48 #include "PrimaryGeneratorAction.hh"
49 
50 #ifdef G4MULTITHREADED
51 #include "G4MTRunManager.hh"
52 #else
53 #include "G4RunManager.hh"
54 #endif
55 
56 #include "G4GenericPhysicsList.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 physListMacro ] [-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 physListMacro;
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" ) physListMacro = 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  // Get the pointer to the User Interface manager
128  G4UImanager* UImanager = G4UImanager::GetUIpointer();
129 
130  // Physics List
131  G4VModularPhysicsList* physList = nullptr;
132  if ( physListMacro.size() ) {
133  // via macro
134  physList = new G4GenericPhysicsList();
135  UImanager->ApplyCommand("/control/execute "+physListMacro);
136  }
137  else {
138  // from vector of physics cobstructor names
139  std::vector<G4String>* myConstructors = new std::vector<G4String>;
140 
141  myConstructors->push_back("G4EmStandardPhysics");
142  myConstructors->push_back("G4EmExtraPhysics");
143  myConstructors->push_back("G4DecayPhysics");
144  myConstructors->push_back("G4HadronElasticPhysics");
145  myConstructors->push_back("G4HadronPhysicsFTFP_BERT");
146  myConstructors->push_back("G4StoppingPhysics");
147  myConstructors->push_back("G4IonPhysics");
148  myConstructors->push_back("G4NeutronTrackingCut");
149 
150  physList = new G4GenericPhysicsList(myConstructors);
151  }
152 
153  // Set mandatory initialization classes
154  runManager->SetUserInitialization(new DetectorConstruction());
155  runManager->SetUserInitialization(physList);
156 
157  // set user action classes
158  runManager->SetUserInitialization(new ActionInitialization("genericPL"));
159 
160  // Initialize visualization
161  G4VisManager* visManager = new G4VisExecutive;
162  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
163  // G4VisManager* visManager = new G4VisExecutive("Quiet");
164  visManager->Initialize();
165 
166  if ( macro.size() ) {
167  // batch mode
168  G4String command = "/control/execute ";
169  UImanager->ApplyCommand(command+macro);
170  }
171  else {
172  // interactive mode : define UI session
173  UImanager->ApplyCommand("/control/execute init_vis.mac");
174  ui->SessionStart();
175  delete ui;
176  }
177 
178  // Job termination
179  // Free the store: user actions, physics_list and detector_description are
180  // owned and deleted by the run manager, so they should not be deleted
181  // in the main() program !
182 
183  delete visManager;
184  delete runManager;
185 }
186 
187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......