Loading...
Searching...
No Matches
exampleB4a.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27/// \file exampleB4a.cc
28/// \brief Main program of the B4a example
29
30#include "DetectorConstruction.hh"
31#include "ActionInitialization.hh"
32
33#include "G4RunManagerFactory.hh"
34#include "G4SteppingVerbose.hh"
35#include "G4UIcommand.hh"
36#include "G4UImanager.hh"
37#include "G4UIExecutive.hh"
38#include "G4VisExecutive.hh"
39#include "FTFP_BERT.hh"
40#include "Randomize.hh"
41
42//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43
44namespace {
45 void PrintUsage() {
46 G4cerr << " Usage: " << G4endl;
47 G4cerr << " exampleB4a [-m macro ] [-u UIsession] [-t nThreads] [-vDefault]"
48 << G4endl;
49 G4cerr << " note: -t option is available only for multi-threaded mode."
50 << G4endl;
51 }
52}
53
54//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55
56int main(int argc,char** argv)
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 B4::DetectorConstruction();
118 runManager->SetUserInitialization(detConstruction);
119
120 auto physicsList = new FTFP_BERT;
121 runManager->SetUserInitialization(physicsList);
122
123 auto actionInitialization = new B4a::ActionInitialization(detConstruction);
124 runManager->SetUserInitialization(actionInitialization);
125
126 // Initialize visualization
127 //
128 auto visManager = new G4VisExecutive;
129 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
130 // auto visManager = new G4VisExecutive("Quiet");
131 visManager->Initialize();
132
133 // Get the pointer to the User Interface manager
134 auto UImanager = G4UImanager::GetUIpointer();
135
136 // Process macro or start UI session
137 //
138 if ( macro.size() ) {
139 // batch mode
140 G4String command = "/control/execute ";
141 UImanager->ApplyCommand(command+macro);
142 }
143 else {
144 // interactive mode : define UI session
145 UImanager->ApplyCommand("/control/execute init_vis.mac");
146 if (ui->IsGUI()) {
147 UImanager->ApplyCommand("/control/execute gui.mac");
148 }
149 ui->SessionStart();
150 delete ui;
151 }
152
153 // Job termination
154 // Free the store: user actions, physics_list and detector_description are
155 // owned and deleted by the run manager, so they should not be deleted
156 // in the main() program !
157
158 delete visManager;
159 delete runManager;
160}
161
162//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
Detector construction class to define materials and geometry.
Action initialization class.
void PrintUsage()
int main()
Definition testCommon.cc:47

Applications | User Support | Publications | Collaboration