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

Main program of the B4d example. More...

#include "DetectorConstruction.hh"
#include "ActionInitialization.hh"
#include "G4AnalysisManager.hh"
#include "G4RunManagerFactory.hh"
#include "G4SteppingVerbose.hh"
#include "G4TScoreNtupleWriter.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 B4d example.

Definition in file exampleB4d.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 58 of file exampleB4d.cc.

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

Applications | User Support | Publications | Collaboration