Loading...
Searching...
No Matches
field06.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 field/field06/field06.cc
28/// \brief Main program of the field/field06 example
29//
30//
31//
32//
33//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35
36#ifndef WIN32
37#include <unistd.h>
38#endif
39
40#include "G4Types.hh"
41
42#include "F06PhysicsList.hh"
43#include "G4Transportation.hh"
44
47
48#include "G4RunManagerFactory.hh"
49
50#include "G4UImanager.hh"
51#include "G4UIcommand.hh"
52
53#include "Randomize.hh"
54
55#include "G4VisExecutive.hh"
56#include "G4UIExecutive.hh"
57
58//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59namespace {
60 void PrintUsage() {
61 G4cerr << " Usage: " << G4endl;
62 G4cerr << " field06 [-m macro ] [-u UIsession] [-t nThreads] [-r randomSeed] "
63 << G4endl;
64 G4cerr << " note: -t option is available only for multi-threaded mode."
65 << G4endl;
66 }
67}
68
69//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70
71int main(int argc,char** argv)
72{
73 // Evaluate arguments
74 //
75 if ( argc > 9 ) {
76 PrintUsage();
77 return 1;
78 }
79
80 G4String macro;
81 G4String session;
82 G4int nThreads = 0;
83
84 G4long randomSeed = 1234;
85 for ( G4int i=1; i<argc; i=i+2 ) {
86 if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
87 else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
88 else if ( G4String(argv[i]) == "-r" ) randomSeed = atoi(argv[i+1]);
89 else if ( G4String(argv[i]) == "-t" ) {
90 nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
91 }
92 else {
93 PrintUsage();
94 return 1;
95 }
96 }
97
98 // Instantiate G4UIExecutive for interactive mode
99 G4UIExecutive* ui = nullptr;
100 if ( macro.size() == 0 ) {
101 ui = new G4UIExecutive(argc, argv, session);
102 }
103
104 // Choose the Random engine
105 //
106 G4Random::setTheEngine(new CLHEP::RanecuEngine);
107
108 // Construct the default run manager
109 //
110 auto* runManager = G4RunManagerFactory::CreateRunManager();
111 if ( nThreads > 0 ) runManager->SetNumberOfThreads(nThreads);
112
113 // Seed the random number generator manually
114 G4Random::setTheSeed(randomSeed);
115
116 // Set mandatory initialization classes
117 //
118 // Detector construction
119 runManager->SetUserInitialization(new F06DetectorConstruction());
120 // Physics list
121 runManager->SetUserInitialization(new F06PhysicsList());
122
123 // Ensure that Transportation considers gravity fields.
124 G4Transportation::EnableGravity(true);
125
126 // User action initialization
127 runManager->SetUserInitialization(new F06ActionInitialization());
128
129 // Initialize visualization
130 //
131 G4VisManager* visManager = new G4VisExecutive;
132 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
133 // G4VisManager* visManager = new G4VisExecutive("Quiet");
134 visManager->Initialize();
135
136 // Get the pointer to the User Interface manager
137 //
138 G4UImanager* UImanager = G4UImanager::GetUIpointer();
139
140 if ( !ui ) {
141 // batch mode
142 G4String command = "/control/execute ";
143 UImanager->ApplyCommand(command+macro);
144 }
145 else
146 {
147 UImanager->ApplyCommand("/control/execute init_vis.mac");
148 if (ui->IsGUI())
149 UImanager->ApplyCommand("/control/execute gui.mac");
150 ui->SessionStart();
151 delete ui;
152 }
153
154 // Job termination
155 // Free the store: user actions, physics_list and detector_description are
156 // owned and deleted by the run manager, so they should not
157 // be deleted in the main() program !
158
159 delete visManager;
160 delete runManager;
161
162 return 0;
163}
164
165//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Definition of the F06ActionInitialization class.
Definition of the F06DetectorConstruction class.
Definition of the F06PhysicsList class.
Action initialization class.
void PrintUsage()
int main()
Definition testCommon.cc:47

Applications | User Support | Publications | Collaboration