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

Main program of the physicslists/factory example. More...

#include "DetectorConstruction.hh"
#include "ActionInitialization.hh"
#include "PrimaryGeneratorAction.hh"
#include "G4RunManager.hh"
#include "G4PhysListFactory.hh"
#include "G4VModularPhysicsList.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 physicslists/factory example.

Definition in file factory.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 76 of file factory.cc.

References PrintUsage(), and session.

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 }
static G4UIterminal * session
void PrintUsage()