ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
field04.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file field04.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 // GEANT 4 - Example F04
34 //
35 // --------------------------------------------------------------
36 // Comments
37 //
38 //
39 // --------------------------------------------------------------
40 
41 #ifndef WIN32
42 #include <unistd.h>
43 #endif
44 
45 #include "G4Types.hh"
46 
47 #ifdef G4MULTITHREADED
48 #include "G4MTRunManager.hh"
49 #else
50 #include "F04SteppingVerbose.hh"
51 #include "G4RunManager.hh"
52 #endif
53 
54 #include "F04PhysicsList.hh"
56 
58 
59 #include "G4UImanager.hh"
60 
61 #include "Randomize.hh"
62 
63 #include "G4VisExecutive.hh"
64 #include "G4UIExecutive.hh"
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
68 namespace {
69  void PrintUsage() {
70  G4cerr << " Usage: " << G4endl;
71  G4cerr << " field04 [-m macro ] [-p physicsList] [-r randomSeed] [-s preinit|idle]"
72  << G4endl;
73  }
74 }
75 
76 
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
80 int main(int argc,char** argv)
81 {
82  // Evaluate arguments
83  // argc holds the number of arguments (including the name) on the command line
84  // -> it is ONE when only the name is given !!!
85  // argv[0] is always the name of the program
86  // argv[1] points to the first argument, and so on
87  //
88  if ( argc > 7 ) {
89  PrintUsage();
90  return 1;
91  }
92 
93  G4String macro;
94  G4String physicsList = "QGSP_BERT";
95  G4int randomSeed = 1234;
96  G4String startPhase = "idle";
97  for ( G4int i=1; i<argc; i=i+2 ) {
98  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
99  else if ( G4String(argv[i]) == "-r" ) randomSeed = atoi(argv[i+1]);
100  else if ( G4String(argv[i]) == "-p" ) physicsList = argv[i+1];
101  else if ( G4String(argv[i]) == "-s" ) startPhase = argv[i+1];
102  else {
103  PrintUsage();
104  return 1;
105  }
106  }
107 
108  // Instantiate G4UIExecutive if there are no arguments (interactive mode)
109  G4UIExecutive* ui = nullptr;
110  if ( ! macro.size() ) {
111  ui = new G4UIExecutive(argc, argv);
112  }
113 
114  // Choose the Random engine
115  //
116  G4Random::setTheEngine(new CLHEP::RanecuEngine);
117 
118  // Construct the default run manager
119  //
120 #ifdef G4MULTITHREADED
121  G4MTRunManager * runManager = new G4MTRunManager;
122 #else
124  G4RunManager * runManager = new G4RunManager;
125 #endif
126 
127  G4Random::setTheSeed(randomSeed);
128 
129  // Set mandatory initialization classes
130  //
131  // Detector construction
133  runManager->SetUserInitialization(detector);
134  // Physics list
135  runManager->SetUserInitialization(new F04PhysicsList(physicsList));
136  // User action initialization
137  runManager->SetUserInitialization(new F04ActionInitialization(detector));
138 
139  // Initialize G4 kernel
140  //
141  //runManager->Initialize();
142 
143  // Initialize visualization
144  //
145  G4VisManager* visManager = new G4VisExecutive;
146  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
147  // G4VisManager* visManager = new G4VisExecutive("Quiet");
148  visManager->Initialize();
149 
150  // Get the pointer to the User Interface manager
151  //
152  G4UImanager* UImanager = G4UImanager::GetUIpointer();
153 
154  // Process macro or start UI session
155  //
156  if ( macro.size() ) {
157  // batch mode
158  G4String command = "/control/execute ";
159  UImanager->ApplyCommand(command+macro);
160  }
161  else {
162  // interactive mode : define UI session
163  if ( startPhase == "preinit" ) {
164  // start in PreInit> phase if requested
165  G4cout << "At the prompt, issue commands to set up detector & field, then:"
166  << G4endl;
167  G4cout << "/run/initialize" << G4endl;
168  G4cout << "Then if you want a viewer:"<< G4endl;
169  G4cout << "/control/execute vis.mac" << G4endl;
170  G4cout << "Then: " << G4endl;
171  G4cout << "/run/beamOn … etc." << G4endl;
172  } else {
173  // perform initialization and draw geometry
174  UImanager->ApplyCommand("/control/execute init_vis.mac");
175  }
176  if (ui->IsGUI()) {
177  UImanager->ApplyCommand("/control/execute gui.mac");
178  }
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
186  // be deleted in the main() program !
187 
188  delete visManager;
189  delete runManager;
190 
191  return 0;
192 }
193 
194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......