Loading...
Searching...
No Matches
exampleVecGeomNav.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// Author: J. Apostolakis, S. Wenzel, 2018-2021
27//
28// Started from FullCMS Geant4 application by Mihaly Novak (2017)
29//---------------------------------------------------------------------
30
31#include <iostream>
32#include <iomanip>
33
34#include "G4RunManager.hh"
35#include "G4RunManagerFactory.hh"
36
37#include "G4UImanager.hh"
38#include "G4UIsession.hh"
39#include "G4UIterminal.hh"
40
41#include "G4VModularPhysicsList.hh"
42#include "FTFP_BERT.hh"
43#include "G4StepLimiterPhysics.hh"
44
45#include "Randomize.hh"
46
50
51// For interactivity
52#include "G4UIExecutive.hh"
53#include "G4VisExecutive.hh"
54
55static G4bool parUseVecGeom = true;
56static G4bool parCompareG4 = false;
57static G4bool parInteractive = false;
58static std::string parMacroFileName = "";
59static std::string parGDMLFile = "TestNTST.gdml";
60
61void GetInputArguments(int argc, char** argv);
62void PrintUsage();
63
64int main(int argc, char** argv) {
65 //
66 // get input arguments
67 GetInputArguments(argc, argv);
68 G4cout<< " ========== Running exampleVecGeomNav ================ " << G4endl
69 << " GDML geometry file = " << parGDMLFile << G4endl
70 << " Geant4 macro = " << parMacroFileName << G4endl
71 << " Use VecGeom (VG) navigation = " << parUseVecGeom << G4endl
72 << " Compare G4 vs VG navigation = " << parCompareG4 << G4endl
73 << " ===================================================== " << G4endl;
74
75 // Use custom stepping verbosity
76 G4VSteppingVerbose::SetInstance( new VG01SteppingVerboseWithDir() );
77
78 // Construct the run manager
79 //
80 G4RunManager* runManager
81 = G4RunManagerFactory::CreateRunManager( G4RunManagerType::Serial);
82 // or G4RunManagerType::Default to get Task or Multithreading
83
84 // set mandatory initialization classes
85 //
86 // 1. Detector construction
87 //
91 runManager->SetUserInitialization(detector);
92
93 // 2. Physics list
94 //
95 G4VModularPhysicsList* physicsList = new FTFP_BERT;
96 physicsList->RegisterPhysics(new G4StepLimiterPhysics());
97 runManager->SetUserInitialization(physicsList);
98
99 // 3. User action
100 //
101 runManager->SetUserInitialization(new VG01ActionInitialization());
102
103 // 4. Run the simulation in batch mode, except if macroFile == "-"
104 //
105 G4UImanager* UImgr = G4UImanager::GetUIpointer();
106 G4String command = "/control/execute ";
107 if( parMacroFileName != "-")
108 UImgr->ApplyCommand(command+parMacroFileName);
109
110 // 5. Run the simulation in Interactive mode if requested ( flag: -i )
111 //
112 if( parInteractive )
113 {
114 G4UIExecutive* uiExec = 0;
115 uiExec = new G4UIExecutive(argc, argv);
116
117 // Initialize visualization
118 //
119 G4VisManager* visManager = new G4VisExecutive;
120 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
121 // G4VisManager* visManager = new G4VisExecutive("Quiet");
122 visManager->Initialize();
123
124 // UImgr->ApplyCommand("/control/execute init_vis.mac");
125
126 // interactive mode
127 uiExec->SessionStart();
128
129 // Cleanup
130 delete uiExec;
131 delete visManager;
132 }
133 else
134 {
135
136 // Print out the final random number - for batch only runs
137 G4cout << G4endl
138 << " ================================================================= " << G4endl
139 << " Final random number = " << G4UniformRand() << G4endl
140 << " ================================================================= " << G4endl
141 << G4endl;
142 }
143 //
144
145 // Delete the RunManager
146 delete runManager;
147 return 0;
148}
149
150void horizontal_line(char c)
151{
152 std::cout <<"\n " << std::setw(100) << std::setfill(c)
153 << "" << std::setfill(' ') << std::endl;
154}
155
157 horizontal_line('=');
158 std::cout << " Geant4 application to demonstrate interface to VecGeom Navigation. \n"
159 << std::endl
160 << " Two modes: \n\n"
161 << " * 1 parameter this is treated as Geant4 macro file \n"
162 << " \n"
163 << " * Multiple Parameters: \n"
164 << " at least one of the following: \n"
165 << " -m : the standard Geant4 macro file \n"
166 << " -i : interactive (after batch, if any) \n"
167 << " optionally one of the following: \n"
168 << " -v : flag ==> run using VecGeom navigation (default). \n"
169 << " -o : flag ==> run using Geant4 navigation. \n"
170 << " -c : flag ==> compare VecGeom and Geant4 navigation"
171 << " (and report differences.) \n"
172 << " and other(s): \n"
173 << " -g : GDML file with geometry \n"
174 << "\n"
175 << std::endl;
176 horizontal_line('=');
177}
178
179void GetInputArguments(int argc, char** argv) {
180 // process arguments
181 if (argc == 1) {
182 PrintUsage();
183 exit(0);
184 }
185 if (argc == 2) {
186 parMacroFileName = argv[1];
187 G4cout << " argc = 2 -- Filename = " << parMacroFileName << G4endl;
188 return;
189 }
190
191 // Adapted from examples/basic/B4/exampleB4a.cc
192 for ( G4int i=1; i<argc; ++i ) {
193 if ( G4String(argv[i]) == "-m" ) {
194 if( ++i < argc ) {
195 parMacroFileName = argv[i];
196 G4cout << " arg-parsing: Macro file name= " << parMacroFileName << G4endl;
197 }
198 else{
199 G4cerr << " Parse Error: '-m' cannot be last argument. Use it : -m <filename>" << G4endl;
200 PrintUsage();
201 exit(1);
202 }
203 }
204 else if ( G4String(argv[i]) == "-g" ) {
205 if( ++i < argc ) { parGDMLFile = argv[i];
206 G4cout << " arg-parsing: GDML file name= " << parGDMLFile << G4endl;
207 }
208 else{
209 G4cerr << " Parse Error: '-m' cannot be last argument. Use it : -m <filename>" << G4endl;
210 PrintUsage();
211 exit(1);
212 }
213 }
214 else if ( G4String(argv[i]) == "-v" ) { parUseVecGeom = true; }
215 else if ( G4String(argv[i]) == "-o" ) { parUseVecGeom = false; }
216 else if ( G4String(argv[i]) == "-c" ) { parCompareG4 = true; parUseVecGeom= true; }
217 else {
218 G4cerr << " Unknown argument : " << argv[i] << G4endl;
219 PrintUsage();
220 exit(1);
221 }
222 }
223
224 // check if mandatory Geant4 macro file was provided
225 if (parMacroFileName=="" && !parInteractive ) {
226 G4cerr << " *** ERROR : either interactive mode or a Geant4 macro file is required. "
227 << G4endl;
228 PrintUsage();
229 exit(-1);
230 }
231}
Definition of the VG01ActionInitialization class.
Definition of the VG01DetectorConstruction class.
Definition of the VG01SteppingVerboseWithDir class.
Action initialization class.
void SetGDMLFileName(const G4String &gdmlfile)
static G4bool parUseVecGeom
void horizontal_line(char c)
static G4bool parInteractive
static G4bool parCompareG4
static std::string parGDMLFile
void PrintUsage()
void GetInputArguments(int argc, char **argv)
static std::string parMacroFileName
int main()
Definition testCommon.cc:47

Applications | User Support | Publications | Collaboration