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

Main program of the OpNovice example. More...

#include "G4Types.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "FTFP_BERT.hh"
#include "G4OpticalPhysics.hh"
#include "G4EmStandardPhysics_option4.hh"
#include "OpNoviceDetectorConstruction.hh"
#include "OpNoviceActionInitialization.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 OpNovice example.

Definition in file OpNovice.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 79 of file OpNovice.cc.

References PrintUsage(), and session.

80 {
81  // Evaluate arguments
82  //
83  if ( argc > 9 ) {
84  PrintUsage();
85  return 1;
86  }
87 
88  G4String macro;
90 #ifdef G4MULTITHREADED
91  G4int nThreads = 0;
92 #endif
93 
94  G4long myseed = 345354;
95  for ( G4int i=1; i<argc; i=i+2 ) {
96  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
97  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
98  else if ( G4String(argv[i]) == "-r" ) myseed = atoi(argv[i+1]);
99 #ifdef G4MULTITHREADED
100  else if ( G4String(argv[i]) == "-t" ) {
101  nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
102  }
103 #endif
104  else {
105  PrintUsage();
106  return 1;
107  }
108  }
109 
110  // Instantiate G4UIExecutive if interactive mode
111  G4UIExecutive* ui = nullptr;
112  if ( macro.size() == 0 ) {
113  ui = new G4UIExecutive(argc, argv);
114  }
115 
116  // Choose the Random engine
117  //
118  G4Random::setTheEngine(new CLHEP::RanecuEngine);
119 
120  // Construct the default run manager
121  //
122 #ifdef G4MULTITHREADED
123  G4MTRunManager * runManager = new G4MTRunManager;
124  if ( nThreads > 0 ) runManager->SetNumberOfThreads(nThreads);
125 #else
126  G4RunManager * runManager = new G4RunManager;
127 #endif
128 
129  // Seed the random number generator manually
130  G4Random::setTheSeed(myseed);
131 
132  // Set mandatory initialization classes
133  //
134  // Detector construction
135  runManager-> SetUserInitialization(new OpNoviceDetectorConstruction());
136  // Physics list
137  G4VModularPhysicsList* physicsList = new FTFP_BERT;
138  physicsList->ReplacePhysics(new G4EmStandardPhysics_option4());
139  G4OpticalPhysics* opticalPhysics = new G4OpticalPhysics();
140  physicsList->RegisterPhysics(opticalPhysics);
141  runManager-> SetUserInitialization(physicsList);
142 
143  // User action initialization
144  runManager->SetUserInitialization(new OpNoviceActionInitialization());
145 
146  // Initialize visualization
147  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
148  G4VisManager* visManager = new G4VisExecutive("Quiet");
149  visManager->Initialize();
150 
151  // Get the pointer to the User Interface manager
152  G4UImanager* UImanager = G4UImanager::GetUIpointer();
153 
154  if ( macro.size() ) {
155  // Batch mode
156  G4String command = "/control/execute ";
157  UImanager->ApplyCommand(command+macro);
158  }
159  else // Define UI session for interactive mode
160  {
161  UImanager->ApplyCommand("/control/execute vis.mac");
162  if (ui->IsGUI())
163  UImanager->ApplyCommand("/control/execute gui.mac");
164  ui->SessionStart();
165  delete ui;
166  }
167 
168  // Job termination
169  // Free the store: user actions, physics_list and detector_description are
170  // owned and deleted by the run manager, so they should not
171  // be deleted in the main() program !
172 
173  delete visManager;
174  delete runManager;
175 
176  return 0;
177 }
static G4UIterminal * session
void PrintUsage()