Geant4  10.00.p01
XrayFluoSimulation.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 //
27 // $Id: XrayFluoSimulation.cc
28 //
29 // Author: Elena Guardincerri
30 //
31 // History:
32 // -----------
33 // 28 Nov 2001 Elena Guardincerri Created
34 // 24 Ago 2002 Splitted in a separet class Alfonso Mantero
35 // 18 Jan 2011 adapted to new deexcitation design
36 //
37 // -------------------------------------------------------------------
38 #include "G4RunManager.hh"
39 #include "G4UImanager.hh"
40 #include "Randomize.hh"
41 #ifdef G4VIS_USE
42 #include "G4VisExecutive.hh"
43 #endif
44 #ifdef G4UI_USE
45 #include "G4UIExecutive.hh"
46 #endif
50 #include "XrayFluoPhysicsList.hh"
54 #include "XrayFluoRunAction.hh"
55 #include "XrayFluoEventAction.hh"
58 #include "XrayFluoSimulation.hh"
59 #ifdef G4ANALYSIS_USE
61 #endif
62 using namespace CLHEP;
63 
65 
66 { }
67 
69 
70 { }
71 
72 void XrayFluoSimulation::RunSimulation(int argc,char* argv[])
73 {
74 
75  // choose the Random engine
76  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
77  CLHEP::HepRandom::setTheSeed(dir);
78 
79  //XrayFluo Verbose output class
81 
82  // Construct the default run manager
83  G4RunManager * runManager = new G4RunManager;
84 
85  // set mandatory initialization
86 
87  XrayFluoPhysicsList* xrayList = new XrayFluoPhysicsList();
88 
89  // chosing Geometry setup
90 
91  G4int geometryNumber = 0;
92 
93  if (argc == 3){
94  geometryNumber = atoi(argv[2]);
95 
96  }
97  while ( (geometryNumber != 1) && (geometryNumber !=2) && (geometryNumber !=3) && (geometryNumber !=4)) {
98  G4cout << "Please Select Simulation Geometrical Set-Up: "<< G4endl;
99  G4cout << "1 - Test Beam" << G4endl;
100  G4cout << "2 - Infinite Plane" << G4endl;
101  G4cout << "3 - Planet and Sun"<< G4endl;
102  G4cout << "4 - Phase-Space Production"<< G4endl;
103 
104 
105  G4cin >> geometryNumber;
106  }
107 
108  XrayFluoDetectorConstruction* testBeamDetector = 0;
109  XrayFluoPlaneDetectorConstruction* planeDetector = 0;
110  XrayFluoMercuryDetectorConstruction* mercuryDetector = 0;
111 
112 
113 
114  if (geometryNumber == 1 || geometryNumber == 4) {
115  testBeamDetector = XrayFluoDetectorConstruction::GetInstance();
116  if (geometryNumber == 4) {
117  testBeamDetector->PhaseSpaceOn();
118  }
119  runManager->SetUserInitialization(testBeamDetector);
120  }
121  else if (geometryNumber == 2) {
123  runManager->SetUserInitialization(planeDetector);
124  }
125  else if (geometryNumber == 3) {
127  runManager->SetUserInitialization(mercuryDetector);
128  }
129 
130 
131  runManager->SetUserInitialization(xrayList);
132 
133 #ifdef G4VIS_USE
134  //visualization manager
135  G4VisManager* visManager = new G4VisExecutive;
136  visManager->Initialize();
137 #endif
138 
139 #ifdef G4ANALYSIS_USE
140  // set analysis to have the messenger running...
141  XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
142 #endif
143  XrayFluoEventAction* eventAction = 0;
144  XrayFluoRunAction* runAction = new XrayFluoRunAction();
146 
147 
148  //Selecting the PrimaryGenerator depending upon Geometry setup selected
149 
150  if (geometryNumber == 1 || geometryNumber == 4) {
151  if (geometryNumber == 4) {
152 #ifdef G4ANALYSIS_USE
153  analysis->PhaseSpaceOn();
154  analysis->CreatePersistency();
155 #endif
156  }
157  eventAction = new XrayFluoEventAction(testBeamDetector);
158  runManager->SetUserAction(new XrayFluoPrimaryGeneratorAction(testBeamDetector));
159  }
160 
161  else if (geometryNumber == 2) {
162  eventAction = new XrayFluoEventAction(planeDetector);
163  runManager->SetUserAction(new XrayFluoPlanePrimaryGeneratorAction(planeDetector));
164  }
165 
166  else if (geometryNumber == 3) {
167  stepAction->SetMercuryFlag(true);
168  eventAction = new XrayFluoEventAction(mercuryDetector);
169  runManager->SetUserAction(new XrayFluoMercuryPrimaryGeneratorAction(mercuryDetector));
170  }
171 
172  runManager->SetUserAction(eventAction);
173  runManager->SetUserAction(runAction);
174  runManager->SetUserAction(stepAction);
175 
176  //Initialize G4 kernel
177  //runManager->Initialize();
178 
179  // get the pointer to the User Interface manager
180  G4UImanager* UImanager = G4UImanager::GetUIpointer();
181 
182  if (getenv("G4VIS_USE")) {
183  UImanager->ApplyCommand("/control/execute vis.mac");
184  }
185 
186  if (argc == 1) // Define UI session for interactive mode.
187  {
188  UImanager->ApplyCommand("/control/execute initInter.mac");
189 #ifdef G4UI_USE
190  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
191 
192  if (ui->IsGUI())
193  UImanager->ApplyCommand("/control/execute gui.mac");
194  ui->SessionStart();
195  delete ui;
196 #endif
197  }
198  else // Batch mode
199  {
200  G4String command = "/control/execute ";
201  G4String fileName = argv[1];
202  UImanager->ApplyCommand(command+fileName);
203  }
204 
205  // job termination
206 
207 #ifdef G4VIS_USE
208  delete visManager;
209  G4cout << "visManager deleted"<< G4endl;
210 #endif
211 
212 // if (testBeamDetector) delete testBeamDetector;
213 // if (planeDetector) delete planeDetector;
214 // if (mercuryDetector) delete mercuryDetector;
215 
216 
217  delete runManager;
218 
219 
220 
221 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
XrayFluoSimulation(G4int seed)
int G4int
Definition: G4Types.hh:78
static XrayFluoDetectorConstruction * GetInstance()
static XrayFluoMercuryDetectorConstruction * GetInstance()
static XrayFluoPlaneDetectorConstruction * GetInstance()
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
#define G4cin
Definition: G4ios.hh:60
G4GLOB_DLL std::ostream G4cout
void Initialize()
static void SetInstance(G4VSteppingVerbose *Instance)
void RunSimulation(int argc, char *argv[])
#define G4endl
Definition: G4ios.hh:61
G4bool IsGUI() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
virtual void SetUserAction(G4UserRunAction *userAction)