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

Main program of the B4c example. More...

#include "DetectorConstruction.hh"
#include "ActionInitialization.hh"
#include "G4RunManagerFactory.hh"
#include "G4SteppingVerbose.hh"
#include "G4UIcommand.hh"
#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"
#include "FTFP_BERT.hh"
#include "Randomize.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Main program of the B4c example.

Definition in file exampleB4c.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 56 of file exampleB4c.cc.

57{
58 // Evaluate arguments
59 //
60 if ( argc > 7 ) {
61 PrintUsage();
62 return 1;
63 }
64
65 G4String macro;
66 G4String session;
67 G4bool verboseBestUnits = true;
68#ifdef G4MULTITHREADED
69 G4int nThreads = 0;
70#endif
71 for ( G4int i=1; i<argc; i=i+2 ) {
72 if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
73 else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
74#ifdef G4MULTITHREADED
75 else if ( G4String(argv[i]) == "-t" ) {
76 nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
77 }
78#endif
79 else if ( G4String(argv[i]) == "-vDefault" ) {
80 verboseBestUnits = false;
81 --i; // this option is not followed with a parameter
82 }
83 else {
84 PrintUsage();
85 return 1;
86 }
87 }
88
89 // Detect interactive mode (if no macro provided) and define UI session
90 //
91 G4UIExecutive* ui = nullptr;
92 if ( ! macro.size() ) {
93 ui = new G4UIExecutive(argc, argv, session);
94 }
95
96 // Optionally: choose a different Random engine...
97 // G4Random::setTheEngine(new CLHEP::MTwistEngine);
98
99 // Use G4SteppingVerboseWithUnits
100 if ( verboseBestUnits ) {
101 G4int precision = 4;
102 G4SteppingVerbose::UseBestUnit(precision);
103 }
104
105 // Construct the default run manager
106 //
107 auto runManager =
108 G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
109#ifdef G4MULTITHREADED
110 if ( nThreads > 0 ) {
111 runManager->SetNumberOfThreads(nThreads);
112 }
113#endif
114
115 // Set mandatory initialization classes
116 //
117 auto detConstruction = new B4c::DetectorConstruction();
118 runManager->SetUserInitialization(detConstruction);
119
120 auto physicsList = new FTFP_BERT;
121 runManager->SetUserInitialization(physicsList);
122
123 auto actionInitialization = new B4c::ActionInitialization();
124 runManager->SetUserInitialization(actionInitialization);
125
126 // Initialize visualization
127 auto visManager = new G4VisExecutive;
128 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
129 // auto visManager = new G4VisExecutive("Quiet");
130 visManager->Initialize();
131
132 // Get the pointer to the User Interface manager
133 auto UImanager = G4UImanager::GetUIpointer();
134
135 // Process macro or start UI session
136 //
137 if ( macro.size() ) {
138 // batch mode
139 G4String command = "/control/execute ";
140 UImanager->ApplyCommand(command+macro);
141 }
142 else {
143 // interactive mode : define UI session
144 UImanager->ApplyCommand("/control/execute init_vis.mac");
145 if (ui->IsGUI()) {
146 UImanager->ApplyCommand("/control/execute gui.mac");
147 }
148 ui->SessionStart();
149 delete ui;
150 }
151
152 // Job termination
153 // Free the store: user actions, physics_list and detector_description are
154 // owned and deleted by the run manager, so they should not be deleted
155 // in the main() program !
156
157 delete visManager;
158 delete runManager;
159}
Action initialization class.
Detector construction class to define materials and geometry.
void PrintUsage()

Applications | User Support | Publications | Collaboration