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

Main program of the electromagnetic/TestEm3 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 electromagnetic/TestEm3 example.

Definition in file TestEm3.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 53 of file TestEm3.cc.

53  {
54 
55  //detect interactive mode (if no arguments) and define UI session
56  G4UIExecutive* ui = nullptr;
57  if (argc == 1) { ui = new G4UIExecutive(argc,argv); }
58 
59  //choose stepping verbose
60  G4VSteppingVerbose::SetInstance(new SteppingVerbose);
61 
62  // Construct the default run manager
63 #ifdef G4MULTITHREADED
64  G4MTRunManager* runManager = new G4MTRunManager;
65  // Number of threads can be defined via 3rd argument
66  G4int nThreads = 4;
67  if (argc==3) {
68  if(G4String(argv[2]) == "NMAX") {
69  nThreads = G4Threading::G4GetNumberOfCores();
70  } else {
71  nThreads = G4UIcommand::ConvertToInt(argv[2]);
72  }
73  } else if(argc==1) {
74  nThreads = 1;
75  }
76  if (nThreads > 0) { runManager->SetNumberOfThreads(nThreads); }
77  G4cout << "===== TestEm3 is started with "
78  << runManager->GetNumberOfThreads() << " threads =====" << G4endl;
79 #else
80  G4RunManager* runManager = new G4RunManager;
81 #endif
82 
83  //set mandatory initialization classes
85  runManager->SetUserInitialization(detector);
86  runManager->SetUserInitialization(new PhysicsList);
87 
88  //set user action classes
89  runManager->SetUserInitialization(new ActionInitialization(detector));
90 
91  //initialize visualization
92  G4VisManager* visManager = nullptr;
93 
94  //get the pointer to the User Interface manager
95  G4UImanager* UImanager = G4UImanager::GetUIpointer();
96 
97  if (ui) {
98  //interactive mode
99  visManager = new G4VisExecutive();
100  visManager->Initialize();
101  ui->SessionStart();
102  delete ui;
103  } else {
104  //batch mode
105  G4String command = "/control/execute ";
106  G4String fileName = argv[1];
107  UImanager->ApplyCommand(command+fileName);
108  }
109 
110  //job termination
111  delete visManager;
112  delete runManager;
113 }