LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
field04.cc File Reference

Main program of the field/field04 example. More...

#include <unistd.h>
#include "G4Types.hh"
#include "F04SteppingVerbose.hh"
#include "G4RunManager.hh"
#include "F04PhysicsList.hh"
#include "F04DetectorConstruction.hh"
#include "F04ActionInitialization.hh"
#include "G4UImanager.hh"
#include "Randomize.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Main program of the field/field04 example.

Definition in file field04.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 80 of file field04.cc.

References PrintUsage().

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
123  G4VSteppingVerbose::SetInstance(new F04SteppingVerbose);
124  G4RunManager * runManager = new G4RunManager;
125 #endif
126 
127  G4Random::setTheSeed(randomSeed);
128 
129  // Set mandatory initialization classes
130  //
131  // Detector construction
132  F04DetectorConstruction* detector = new F04DetectorConstruction();
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 }
void PrintUsage()