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

Main program of the eventgenerator/particleGun example. More...

#include "G4Types.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "Randomize.hh"
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "ActionInitialization.hh"
#include "SteppingVerbose.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Main program of the eventgenerator/particleGun example.

Definition in file particleGun.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 55 of file particleGun.cc.

55  {
56 
57  //detect interactive mode (if no arguments) and define UI session
58  G4UIExecutive* ui = 0;
59  if (argc == 1) ui = new G4UIExecutive(argc,argv);
60 
61  //choose the Random engine
62  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
63 
64  // Construct the default run manager
65 #ifdef G4MULTITHREADED
66  G4MTRunManager* runManager = new G4MTRunManager;
67  G4int nThreads = G4Threading::G4GetNumberOfCores();
68  if (argc==3) nThreads = G4UIcommand::ConvertToInt(argv[2]);
69  runManager->SetNumberOfThreads(nThreads);
70 #else
71  //my Verbose output class
72  G4VSteppingVerbose::SetInstance(new SteppingVerbose);
73  G4RunManager* runManager = new G4RunManager;
74 #endif
75 
76  //set mandatory initialization classes
78  runManager->SetUserInitialization(detector);
79  runManager->SetUserInitialization(new PhysicsList);
80 
81  runManager->SetUserInitialization(new ActionInitialization);
82 
83  //initialize visualization
84  G4VisManager* visManager = nullptr;
85 
86  //get the pointer to the User Interface manager
87  G4UImanager* UImanager = G4UImanager::GetUIpointer();
88 
89  if (ui) {
90  //interactive mode
91  visManager = new G4VisExecutive;
92  visManager->Initialize();
93  UImanager->ApplyCommand("/control/execute vis.mac");
94  ui->SessionStart();
95  delete ui;
96  }
97  else {
98  //batch mode
99  G4String command = "/control/execute ";
100  G4String fileName = argv[1];
101  UImanager->ApplyCommand(command+fileName);
102  }
103 
104  //job termination
105  delete visManager;
106  delete runManager;
107 }