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

Main program of the extensibleFactory example. More...

#include "DetectorConstruction.hh"
#include "ActionInitialization.hh"
#include "PrimaryGeneratorAction.hh"
#include "G4RunManager.hh"
#include "G4PhysListFactoryAlt.hh"
#include "G4PhysListRegistry.hh"
#include "G4PhysicsConstructorFactory.hh"
#include "G4PhysListStamper.hh"
#include "MySpecialPhysList.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

 G4_DECLARE_PHYSLIST_FACTORY (MySpecialPhysList)
 
int main (int argc, char **argv)
 

Detailed Description

Main program of the extensibleFactory example.

Definition in file extensibleFactory.cc.

Function Documentation

G4_DECLARE_PHYSLIST_FACTORY ( MySpecialPhysList  )
int main ( int  argc,
char **  argv 
)

Definition at line 137 of file extensibleFactory.cc.

References PrintUsage(), and session.

138 {
139  // Evaluate arguments
140  //
141  if ( argc > 13 ) {
142  PrintUsage(0);
143  return 1;
144  }
145 
146  G4String macro;
148  G4String physListName;
149  char* physListNameEnv = 0;
150  G4String gdmlFileName;
151 #ifdef G4MULTITHREADED
152  G4int nofThreads = 0;
153 #endif
154  G4int verbosity = 0;
155 
156  for ( G4int i=1; i<argc; i=i+2 ) {
157  G4String g4argv(argv[i]); // convert only once
158  if ( g4argv == "-m" ) macro = argv[i+1];
159  else if ( g4argv == "-u" ) session = argv[i+1];
160  else if ( g4argv == "-p" ) physListName = argv[i+1];
161 #ifdef G4MULTITHREADED
162  else if ( g4argv == "-t" ) {
163  nofThreads = G4UIcommand::ConvertToInt(argv[i+1]);
164  }
165 #endif
166  else if ( g4argv == "-v" || g4argv == "--verbose" ) {
167  ++verbosity; // verbose flag doesn't take an argument
168  --i ; // don't increment argc by two, just the one
169  }
170  else if ( g4argv == "-h" || g4argv == "--help" ) {
171  PrintUsage(verbosity+1);
172  return 1;
173  }
174  else {
175  PrintUsage(0);
176  return 1;
177  }
178  }
179 
180  // Detect interactive mode (if no arguments) and define UI session
181  //
182  G4UIExecutive* ui = 0;
183  if ( ! macro.size() ) {
184  ui = new G4UIExecutive(argc, argv, session);
185  }
186 
187  // Choose the Random engine //choose the Random engine
188  G4Random::setTheEngine(new CLHEP::RanecuEngine());
189 
190  // Construct the run manager
191 #ifdef G4MULTITHREADED
192  G4MTRunManager * runManager = new G4MTRunManager();
193  if ( nofThreads > 0 ) {
194  runManager->SetNumberOfThreads(nofThreads);
195  }
196 #else
197  G4RunManager * runManager = new G4RunManager();
198 #endif
199 
200  // g4alt::G4PhysListFactoryAlt is the extensible factory
201  // including the G4PhysListFactoryAlt.hh header and the line:
202  // using namespace g4alt;
203  // would make this a drop-in replacement, but we'll list the explicit
204  // namespace here just for clarity
205  g4alt::G4PhysListFactory factory;
206  G4VModularPhysicsList* physList = nullptr;
207 
208  // Show how an alternative default list could be set
209  // but set the default to the normal default FTFP_BERT.
210  // This is what is used when no -p flag is given and $PHYSLIST
211  // is not defined in the environment.
212  G4String defaultPhysListName = "FTFP_BERT";
213  if ( verbosity > 0 ) {
214  G4cout << "extensibleFactory: SetDefaultReferencePhysList to '"
215  << defaultPhysListName << "' ('' = system default)"
216  << G4endl << G4endl;
217  }
218  factory.SetDefaultReferencePhysList(defaultPhysListName);
219 
220  // set a short name for G4RadioactiveDecayPhysics
221  G4PhysListRegistry* plreg = G4PhysListRegistry::Instance();
222  plreg->AddPhysicsExtension("RADIO","G4RadioactiveDecayPhysics");
223  plreg->AddPhysicsExtension("MYPHYSICS","MyG4PhysicsPhysics");
224  if ( verbosity > 0 ) {
225  G4cout << "extensibleFactory: adding extensions" << G4endl
226  << " RADIO ===> G4RadioactiveDecayPhysics" << G4endl
227  << " MYPHYSICS ===> MyG4PhysicsPhysics" << G4endl
228  << G4endl;
229  }
230 
231  // Get Reference PhysicsList via its name, or if none given
232  // from environment varialb e$PHYSLIST, with fall back to a default
233  if ( physListName.size() ) {
234  if ( verbosity > 0 ) {
235  G4cout << "extensibleFactory: explicitly using '"
236  << physListName << "'" << G4endl;
237  }
238  physList = factory.GetReferencePhysList(physListName);
239  } else {
240  if ( verbosity > 0 ) {
241  G4cout << "extensibleFactory: no -p flag;"
242  << " using ReferencePhysList() ($PHYSLIST or default)" << G4endl;
243  }
244  physList = factory.ReferencePhysList();
245 
246  if ( ! physList ) {
247  // failed? get what the user set, but we couldn't find
248  physListNameEnv = std::getenv("PHYSLIST");
249  if ( physListNameEnv ) {
250  G4cout << "extensibleFactory: $PHYSLIST="
251  << physListNameEnv << G4endl;
252  }
253  }
254 
255  }
256 
257  // deal with failure to get what the user wanted
258  // print what they _could_ use
259  if ( ! physList ) {
260  G4cerr << "extensibleFactory: PhysicsList '"
261  << ( physListNameEnv ? physListNameEnv : physListName )
262  << "' was not available in g4alt::PhysListFactory." << G4endl;
263  PrintAvailable(verbosity);
264 
265  // if we can't get what the user asked for...
266  // don't go on to use something else, that's confusing
267  G4ExceptionDescription ED;
268  ED << "The factory for the physicslist ["
269  << ( physListNameEnv ? physListNameEnv : physListName )
270  << "] does not exist!"
271  << G4endl;
272  G4Exception("extensibleFactory",
273  "extensibleFactory001", FatalException, ED);
274  exit(42);
275  }
276 
277  // Set mandatory initialization classes
278  runManager->SetUserInitialization(new DetectorConstruction());
279  runManager->SetUserInitialization(physList);
280 
281  // set user action classes
282  ActionInitialization* actinit =
283  new ActionInitialization("extensibleFactory");
284  runManager->SetUserInitialization(actinit);
285 
286 // Initialize visualization
287  G4VisManager* visManager = new G4VisExecutive;
288  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
289  // G4VisManager* visManager = new G4VisExecutive("Quiet");
290  visManager->Initialize();
291 
292  // Get the pointer to the User Interface manager
293  G4UImanager* UImanager = G4UImanager::GetUIpointer();
294 
295  if ( macro.size() ) {
296  // batch mode
297  G4String command = "/control/execute ";
298  UImanager->ApplyCommand(command+macro);
299  }
300  else {
301  // interactive mode : define UI session
302  UImanager->ApplyCommand("/control/execute init_vis.mac");
303  ui->SessionStart();
304  delete ui;
305  }
306 
307  // Job termination
308  // Free the store: user actions, physics_list and detector_description are
309  // owned and deleted by the run manager, so they should not be deleted
310  // in the main() program !
311 
312  delete visManager;
313  delete runManager;
314 }
static G4UIterminal * session
void PrintUsage()