Geant4  10.00.p02
field04.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 // $Id: field04.cc 79251 2014-02-20 16:16:23Z gcosmo $
27 //
30 //
31 //
32 // --------------------------------------------------------------
33 //
34 // GEANT 4 - Example F04
35 //
36 // --------------------------------------------------------------
37 // Comments
38 //
39 //
40 // --------------------------------------------------------------
41 
42 #ifndef WIN32
43 #include <unistd.h>
44 #endif
45 
46 #ifdef G4MULTITHREADED
47 #include "G4MTRunManager.hh"
48 #else
49 #include "F04SteppingVerbose.hh"
50 #include "G4RunManager.hh"
51 #endif
52 
53 #include "F04PhysicsList.hh"
55 
57 
58 #include "G4UImanager.hh"
59 
60 #include "Randomize.hh"
61 
62 #ifdef G4VIS_USE
63 #include "G4VisExecutive.hh"
64 #endif
65 
66 #ifdef G4UI_USE
67 #include "G4UIExecutive.hh"
68 #endif
69 
70 // argc holds the number of arguments (including the name) on the command line
71 // -> it is ONE when only the name is given !!!
72 // argv[0] is always the name of the program
73 // argv[1] points to the first argument, and so on
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
77 int main(int argc,char** argv)
78 {
79  // Choose the Random engine
80  //
81  G4Random::setTheEngine(new CLHEP::RanecuEngine);
82 
83  G4int myseed = 1234;
84  if (argc > 2) myseed = atoi(argv[argc-1]);
85 
86  // Construct the default run manager
87  //
88 #ifdef G4MULTITHREADED
89  G4MTRunManager * runManager = new G4MTRunManager;
90 #else
92  G4RunManager * runManager = new G4RunManager;
93 #endif
94 
95  G4Random::setTheSeed(myseed);
96 
97  G4String physicsList = "QGSP_BERT";
98 
99 #ifndef WIN32
100  G4int c = 0;
101  while ((c=getopt(argc,argv,"p")) != -1)
102  {
103  switch (c)
104  {
105  case 'p':
106  physicsList = optarg;
107  G4cout << "Physics List used is " << physicsList << G4endl;
108  break;
109  case ':': /* -p without operand */
110  fprintf(stderr,"Option -%c requires an operand\n", optopt);
111  break;
112  case '?':
113  fprintf(stderr,"Unrecognised option: -%c\n", optopt);
114  }
115  }
116 #endif
117 
118  // Set mandatory initialization classes
119  //
120  // Detector construction
122  runManager->SetUserInitialization(detector);
123  // Physics list
124  runManager->SetUserInitialization(new F04PhysicsList(physicsList));
125  // User action initialization
126  runManager->SetUserInitialization(new F04ActionInitialization(detector));
127 
128  // Initialize G4 kernel
129  //
130  //runManager->Initialize();
131 
132 #ifdef G4VIS_USE
133  // Initialize visualization
134  //
135  G4VisManager* visManager = new G4VisExecutive;
136  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
137  // G4VisManager* visManager = new G4VisExecutive("Quiet");
138  visManager->Initialize();
139 #endif
140 
141  // Get the pointer to the User Interface manager
142  //
143  G4UImanager* UImanager = G4UImanager::GetUIpointer();
144 
145 #ifndef WIN32
146  G4int optmax = argc;
147  if (argc > 2) { optmax = optmax-1; }
148 
149  if (optind < optmax)
150  {
151  G4String command = "/control/execute ";
152  for ( ; optind < optmax; optind++)
153  {
154  G4String macroFilename = argv[optind];
155  UImanager->ApplyCommand(command+macroFilename);
156  }
157  }
158 #else // Simple UI for Windows runs, no possibility of additional arguments
159  if (argc!=1) // batch mode
160  {
161  G4String command = "/control/execute ";
162  G4String fileName = argv[1];
163  UImanager->ApplyCommand(command+fileName);
164  }
165 #endif
166  else
167  {
168  // Define (G)UI terminal for interactive mode
169 #ifdef G4UI_USE
170  G4UIExecutive * ui = new G4UIExecutive(argc,argv);
171 #ifdef G4VIS_USE
172 // UImanager->ApplyCommand("/control/execute vis.mac");
173  G4cout << "At the prompt, issue commands to set up detector & field, then:"
174  << G4endl;
175  G4cout << "/run/initialize" << G4endl;
176  G4cout << "Then if you want a viewer:"<< G4endl;
177  G4cout << "/control/execute vis.mac" << G4endl;
178  G4cout << "Then: " << G4endl;
179  G4cout << "/run/beamOn … etc." << G4endl;
180 #endif
181  if (ui->IsGUI())
182  UImanager->ApplyCommand("/control/execute gui.mac");
183  ui->SessionStart();
184  delete ui;
185 #endif
186  }
187 
188  // Job termination
189  // Free the store: user actions, physics_list and detector_description are
190  // owned and deleted by the run manager, so they should not
191  // be deleted in the main() program !
192 
193 #ifdef G4VIS_USE
194  delete visManager;
195 #endif
196  delete runManager;
197 
198  return 0;
199 }
200 
201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Action initialization class.
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
int main(int argc, char **argv)
Definition: field04.cc:77
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
Definition of the F04SteppingVerbose class.
Definition of the F04DetectorConstruction class.
G4GLOB_DLL std::ostream G4cout
Definition of the F04PhysicsList class.
void Initialize()
static void SetInstance(G4VSteppingVerbose *Instance)
#define G4endl
Definition: G4ios.hh:61
Definition of the F04ActionInitialization class.
G4bool IsGUI() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432