Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wls.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 //
28 //
29 //
30 //
31 //
32 // --------------------------------------------------------------
33 // GEANT 4 - Example wls
34 //
35 // --------------------------------------------------------------
36 // Comments
37 //
38 //
39 // --------------------------------------------------------------
40 
41 #ifndef WIN32
42 #include <unistd.h>
43 #endif
44 
45 #include "G4RunManager.hh"
46 #include "G4UImanager.hh"
47 
48 #include "Randomize.hh"
49 
50 #include "WLSPhysicsList.hh"
53 
54 #include "WLSRunAction.hh"
55 #include "WLSEventAction.hh"
56 #include "WLSTrackingAction.hh"
57 #include "WLSSteppingAction.hh"
58 #include "WLSStackingAction.hh"
59 #include "WLSSteppingVerbose.hh"
60 
61 #ifdef G4VIS_USE
62 #include "G4VisExecutive.hh"
63 #endif
64 
65 #ifdef G4UI_USE
66 #include "G4UIExecutive.hh"
67 #endif
68 
69 // argc holds the number of arguments (including the name) on the command line
70 // -> it is ONE when only the name is given !!!
71 // argv[0] is always the name of the program
72 // argv[1] points to the first argument, and so on
73 
74 int main(int argc,char** argv)
75 {
76  G4String physName = "QGSP_BERT_EMV";
77 
78  G4int seed = 123;
79  if (argc > 2) seed = atoi(argv[argc-1]);
80 
81  // Choose the Random engine
82 
85 
86 #ifndef WIN32
87  G4int c = 0;
88  while ((c=getopt(argc,argv,"p")) != -1)
89  {
90  switch (c)
91  {
92  case 'p':
93  physName = optarg;
94  G4cout << "Physics List used is " << physName << G4endl;
95  break;
96  case ':': /* -p without operand */
97  fprintf(stderr,
98  "Option -%c requires an operand\n", optopt);
99  break;
100  case '?':
101  fprintf(stderr,
102  "Unrecognised option: -%c\n", optopt);
103  }
104  }
105 #endif
106 
107  // My Verbose output class
108 
110 
111  // Construct the default run manager
112 
113  G4RunManager * runManager = new G4RunManager;
114 
115  // Set mandatory initialization classes
116 
118 
119  runManager->SetUserInitialization(detector);
120 
121  runManager->SetUserInitialization(new WLSPhysicsList(physName));
122 
123 #ifdef G4VIS_USE
124 
125  // visualization manager
126 
127  G4VisManager* visManager = new G4VisExecutive();
128  visManager->Initialize();
129 
130 #endif
131 
132  // Set mandatory user action class
133 
134  runManager->SetUserAction( new WLSPrimaryGeneratorAction(detector) );
135 
136  WLSRunAction* runAction = new WLSRunAction();
137  WLSEventAction* eventAction = new WLSEventAction(runAction);
138 
139  runManager->SetUserAction(runAction);
140  runManager->SetUserAction(eventAction);
141  runManager->SetUserAction( new WLSTrackingAction() );
142  runManager->SetUserAction( new WLSSteppingAction(detector) );
143  runManager->SetUserAction( new WLSStackingAction() );
144 
145  // Get the pointer to the User Interface manager
146 
147  G4UImanager * UImanager = G4UImanager::GetUIpointer();
148 
149 #ifndef WIN32
150  G4int optmax = argc;
151  if (argc > 2) { optmax = optmax-1; }
152 
153  if (optind < optmax)
154  {
155  G4String command = "/control/execute ";
156  for ( ; optind < optmax; optind++)
157  {
158  G4String macroFilename = argv[optind];
159  UImanager->ApplyCommand(command+macroFilename);
160  }
161  }
162 #else // Simple UI for Windows runs, no possibility of additional arguments
163  if (argc!=1)
164  {
165  G4String command = "/control/execute ";
166  G4String fileName = argv[1];
167  UImanager->ApplyCommand(command+fileName);
168  }
169 #endif
170  else {
171  // Define (G)UI terminal for interactive mode
172 #ifdef G4UI_USE
173  G4UIExecutive * ui = new G4UIExecutive(argc,argv);
174 #ifdef G4VIS_USE
175  UImanager->ApplyCommand("/control/execute init.in");
176 #endif
177  ui->SessionStart();
178  delete ui;
179 #endif
180  }
181 
182  // job termination
183 
184 #ifdef G4VIS_USE
185  delete visManager;
186 #endif
187  delete runManager;
188 
189  return 0;
190 }