source: trunk/examples/novice/N03/exampleN03.cc @ 1341

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

update ti head

File size: 5.1 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: exampleN03.cc,v 1.37 2009/10/30 15:06:01 allison Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30//
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33
34#include "G4RunManager.hh"
35#include "G4UImanager.hh"
36
37#include "Randomize.hh"
38
39#include "ExN03DetectorConstruction.hh"
40#include "ExN03PhysicsList.hh"
41#include "ExN03PrimaryGeneratorAction.hh"
42#include "ExN03RunAction.hh"
43#include "ExN03EventAction.hh"
44#include "ExN03SteppingAction.hh"
45#include "ExN03SteppingVerbose.hh"
46
47#ifdef G4VIS_USE
48#include "G4VisExecutive.hh"
49#endif
50
51#ifdef G4UI_USE
52#include "G4UIExecutive.hh"
53#endif
54
55#include "qcoreapplication.h"
56
57#define MAC_OSX_APP 1
58
59//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60
61int main(int argc,char** argv)
62{
63  // Choose the Random engine
64  //
65  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
66 
67  // User Verbose output class
68  //
69  G4VSteppingVerbose::SetInstance(new ExN03SteppingVerbose);
70     
71  // Construct the default run manager
72  //
73  G4RunManager * runManager = new G4RunManager;
74
75  // Set mandatory initialization classes
76  //
77  ExN03DetectorConstruction* detector = new ExN03DetectorConstruction;
78  runManager->SetUserInitialization(detector);
79  //
80  G4VUserPhysicsList* physics = new ExN03PhysicsList;
81  runManager->SetUserInitialization(physics);
82   
83  // Set user action classes
84  //
85  G4VUserPrimaryGeneratorAction* gen_action = 
86                          new ExN03PrimaryGeneratorAction(detector);
87  runManager->SetUserAction(gen_action);
88  //
89  ExN03RunAction* run_action = new ExN03RunAction; 
90  runManager->SetUserAction(run_action);
91  //
92  ExN03EventAction* event_action = new ExN03EventAction(run_action);
93  runManager->SetUserAction(event_action);
94  //
95  G4UserSteppingAction* stepping_action =
96                    new ExN03SteppingAction(detector, event_action);
97  runManager->SetUserAction(stepping_action);
98 
99  // Initialize G4 kernel
100  //
101  runManager->Initialize();
102 
103#ifdef G4VIS_USE
104  // Initialize visualization
105  //
106  G4VisManager* visManager = new G4VisExecutive;
107  visManager->Initialize();
108#endif
109 
110  // Get the pointer to the User Interface manager
111  //
112  G4UImanager* UImanager = G4UImanager::GetUIpointer();
113   
114#ifdef MAC_OSX_APP
115  std::string progName = argv[0]; 
116  std::string::size_type pos = progName.find(".app/Contents/MacOS/",0); 
117  if (pos != std::string::npos) { 
118    std::string progDir = progName.substr(0,pos+4); 
119    chdir((progDir+"/Contents/macros").c_str()); 
120    argc = 1; 
121  } 
122#endif
123
124  if (argc!=1)   // batch mode
125    {
126     G4String command = "/control/execute ";
127      G4String fileName = argv[1];
128      UImanager->ApplyCommand(command+fileName);   
129    }
130  else
131    {  // interactive mode : define UI session
132#ifdef G4UI_USE
133      G4UIExecutive* ui = new G4UIExecutive(argc, argv);
134#ifdef G4VIS_USE
135      UImanager->ApplyCommand("/control/execute vis.mac");     
136#endif
137      if (ui->IsGUI())
138        UImanager->ApplyCommand("/control/execute visTutor/gui.mac");     
139      ui->SessionStart();
140      delete ui;
141#endif
142    }
143 
144  // Job termination
145  // Free the store: user actions, physics_list and detector_description are
146  //                 owned and deleted by the run manager, so they should not
147  //                 be deleted in the main() program !
148#ifdef G4VIS_USE
149  delete visManager;
150#endif               
151  delete runManager;
152
153  return 0;
154}
155
156//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.