source: trunk/examples/extended/field/field04/field04.cc @ 1292

Last change on this file since 1292 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

File size: 5.5 KB
Line 
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// $Id: field04.cc,v 1.11 2009/10/30 10:17:43 allison Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30//
31// --------------------------------------------------------------
32//      GEANT 4 - Example F04
33//
34// --------------------------------------------------------------
35// Comments
36//
37//
38// --------------------------------------------------------------
39
40#ifndef WIN32
41#include <unistd.h>
42#endif
43
44#include "G4RunManager.hh"
45#include "G4UImanager.hh"
46
47#include "Randomize.hh"
48
49#include "F04PhysicsList.hh"
50#include "F04DetectorConstruction.hh"
51#include "F04PrimaryGeneratorAction.hh"
52
53#include "F04RunAction.hh"
54#include "F04EventAction.hh"
55#include "F04TrackingAction.hh"
56#include "F04SteppingAction.hh"
57#include "F04StackingAction.hh"
58#include "F04SteppingVerbose.hh"
59
60#ifdef G4VIS_USE
61#include "G4VisExecutive.hh"
62#endif
63
64#ifdef G4UI_USE
65#include "G4UIExecutive.hh"
66#endif
67
68// argc holds the number of arguments (including the name) on the command line
69// -> it is ONE when only the name is  given !!!
70// argv[0] is always the name of the program
71// argv[1] points to the first argument, and so on
72
73int main(int argc,char** argv) 
74{
75  G4String physicsList = "QGSP_BERT";
76
77  G4int seed = 123;
78  if (argc  > 2) seed = atoi(argv[argc-1]);
79
80  // Choose the Random engine
81
82  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
83  CLHEP::HepRandom::setTheSeed(seed);
84
85#ifndef WIN32
86  G4int c = 0;
87  while ((c=getopt(argc,argv,"p")) != -1)
88  {
89     switch (c)
90     {
91       case 'p':
92         physicsList = optarg;
93         G4cout << "Physics List used is " <<  physicsList << G4endl;
94         break;
95       case ':':       /* -p without operand */
96         fprintf(stderr, 
97                         "Option -%c requires an operand\n", optopt);
98         break;
99       case '?':
100         fprintf(stderr,
101                         "Unrecognised option: -%c\n", optopt);
102     }
103  }
104#endif
105
106  // My Verbose output class
107
108  G4VSteppingVerbose::SetInstance(new F04SteppingVerbose);
109 
110  // Construct the default run manager
111
112  G4RunManager * runManager = new G4RunManager;
113
114  // Set mandatory initialization classes
115
116  F04DetectorConstruction* detector = new F04DetectorConstruction();
117
118  runManager->SetUserInitialization(detector);
119  runManager->SetUserInitialization(new F04PhysicsList(physicsList));
120 
121#ifdef G4VIS_USE
122
123  // visualization manager
124
125  G4VisManager* visManager = new G4VisExecutive();
126  visManager->Initialize();
127
128#endif
129
130  // Set mandatory user action class
131
132  runManager->SetUserAction( new F04PrimaryGeneratorAction(detector) );
133
134  F04RunAction* runAction = new F04RunAction();
135  F04EventAction* eventAction = new F04EventAction(runAction);
136
137  runManager->SetUserAction(runAction);
138  runManager->SetUserAction(eventAction);
139  runManager->SetUserAction( new F04TrackingAction() );
140  runManager->SetUserAction( new F04SteppingAction() );
141  runManager->SetUserAction( new F04StackingAction() );
142
143  // Get the pointer to the User Interface manager
144
145  G4UImanager * UImanager = G4UImanager::GetUIpointer(); 
146
147#ifndef WIN32
148  G4int optmax = argc;
149  if (argc > 2)  { optmax = optmax-1; }
150
151  if (optind < optmax)
152  {
153     G4String command = "/control/execute ";
154     for ( ; optind < optmax; optind++)
155     {
156         G4String macroFilename = argv[optind];
157         UImanager->ApplyCommand(command+macroFilename);
158     }
159  }
160#else  // Simple UI for Windows runs, no possibility of additional arguments
161  if (argc!=1)
162  { 
163     G4String command = "/control/execute ";
164     G4String fileName = argv[1];
165     UImanager->ApplyCommand(command+fileName);
166  }
167#endif
168  else  {
169     // Define (G)UI terminal for interactive mode
170#ifdef G4UI_USE
171     G4UIExecutive * ui = new G4UIExecutive(argc,argv);
172#ifdef G4VIS_USE
173     UImanager->ApplyCommand("/control/execute vis.mac");     
174#endif
175     ui->SessionStart();
176     delete ui;
177#endif
178  }
179
180  // job termination
181
182#ifdef G4VIS_USE
183  delete visManager;
184#endif
185  delete runManager;
186
187  return 0;
188}
Note: See TracBrowser for help on using the repository browser.