Loading...
Searching...
No Matches
Functions
TestEm1.cc File Reference

Main program of the electromagnetic/TestEm1 example. More...

#include "G4Types.hh"
#include "G4RunManagerFactory.hh"
#include "G4UImanager.hh"
#include "G4SteppingVerbose.hh"
#include "Randomize.hh"
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "ActionInitialization.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/TestEm1 example.

Definition in file TestEm1.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 50 of file TestEm1.cc.

50 {
51
52 //detect interactive mode (if no arguments) and define UI session
53 G4UIExecutive* ui = nullptr;
54 if (argc == 1) { ui = new G4UIExecutive(argc,argv); }
55
56 //use G4SteppingVerboseWithUnits
57 G4int precision = 4;
58 G4SteppingVerbose::UseBestUnit(precision);
59
60 //construct the run manager
61 auto runManager = G4RunManagerFactory::CreateRunManager();
62 if (argc==3) {
63 G4int nThreads = G4UIcommand::ConvertToInt(argv[2]);
64 runManager->SetNumberOfThreads(nThreads);
65 }
66
67 //set mandatory initialization classes
69 runManager->SetUserInitialization(det);
70
71 PhysicsList* phys = new PhysicsList(det);
72 runManager->SetUserInitialization(phys);
73
74 //set user action classes
75 runManager->SetUserInitialization(new ActionInitialization(det));
76
77 //initialize visualization
78 G4VisManager* visManager = nullptr;
79
80 //get the pointer to the User Interface manager
81 G4UImanager* UImanager = G4UImanager::GetUIpointer();
82
83 if (ui) {
84 //interactive mode
85 visManager = new G4VisExecutive;
86 visManager->Initialize();
87 ui->SessionStart();
88 delete ui;
89 }
90 else {
91 //batch mode
92 G4String command = "/control/execute ";
93 G4String fileName = argv[1];
94 UImanager->ApplyCommand(command+fileName);
95 }
96
97 //job termination
98 delete visManager;
99 delete runManager;
100}
Action initialization class.