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: BrachySimulation.cc |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // -------------------------------------------------------------- |
---|
31 | // GEANT 4 - Brachytherapy example |
---|
32 | // -------------------------------------------------------------- |
---|
33 | // |
---|
34 | // Code developed by: S.Guatelli, K. Moscicki |
---|
35 | // |
---|
36 | // |
---|
37 | // ******************************* |
---|
38 | // * * |
---|
39 | // * BrachySimualtion.cc * |
---|
40 | // * * |
---|
41 | // ******************************* |
---|
42 | // |
---|
43 | #include "G4RunManager.hh" |
---|
44 | #include "G4UImanager.hh" |
---|
45 | #include "G4UIterminal.hh" |
---|
46 | #include "G4UItcsh.hh" |
---|
47 | #include "BrachyFactoryIr.hh" |
---|
48 | #ifdef G4UI_USE_XM |
---|
49 | #include "G4UIXm.hh" |
---|
50 | #endif |
---|
51 | |
---|
52 | #ifdef G4VIS_USE |
---|
53 | #include "G4VisExecutive.hh" |
---|
54 | #endif |
---|
55 | |
---|
56 | #include "BrachyEventAction.hh" |
---|
57 | #include "BrachyDetectorConstruction.hh" |
---|
58 | #include "BrachyPhysicsList.hh" |
---|
59 | #include "BrachyPhantomSD.hh" |
---|
60 | #include "BrachyPrimaryGeneratorActionIr.hh" |
---|
61 | #include "G4SDManager.hh" |
---|
62 | #include "BrachyRunAction.hh" |
---|
63 | #include "Randomize.hh" |
---|
64 | #include "G4RunManager.hh" |
---|
65 | #include "G4SDManager.hh" |
---|
66 | #include "G4UImanager.hh" |
---|
67 | #include "G4UImessenger.hh" |
---|
68 | #include "BrachySimulation.hh" |
---|
69 | |
---|
70 | BrachySimulation::BrachySimulation(G4int sd) |
---|
71 | { |
---|
72 | pRunManager = 0; |
---|
73 | seed = sd; |
---|
74 | } |
---|
75 | |
---|
76 | BrachySimulation::~BrachySimulation() |
---|
77 | |
---|
78 | { } |
---|
79 | void BrachySimulation::setSeed(G4int sd) |
---|
80 | { |
---|
81 | seed = sd; |
---|
82 | CLHEP::HepRandom::setTheSeed(seed); |
---|
83 | } |
---|
84 | |
---|
85 | G4bool BrachySimulation::initialize(int ,char** ) |
---|
86 | { |
---|
87 | CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); |
---|
88 | |
---|
89 | G4cout << "G4 initializing" << G4endl; |
---|
90 | |
---|
91 | pRunManager = new G4RunManager; |
---|
92 | |
---|
93 | G4String sensitiveDetectorName = "Phantom"; |
---|
94 | |
---|
95 | BrachyDetectorConstruction *pDetectorConstruction = new BrachyDetectorConstruction(sensitiveDetectorName); |
---|
96 | |
---|
97 | pRunManager -> SetUserInitialization(pDetectorConstruction); |
---|
98 | pRunManager -> SetUserInitialization(new BrachyPhysicsList); |
---|
99 | |
---|
100 | // output environment variables: |
---|
101 | #ifdef G4ANALYSIS_USE |
---|
102 | G4cout << G4endl << G4endl << G4endl |
---|
103 | << " User Environment " << G4endl |
---|
104 | << " Using AIDA 3.2.1 analysis " << G4endl; |
---|
105 | # else |
---|
106 | G4cout << G4endl << G4endl << G4endl |
---|
107 | << " User Environment " << G4endl |
---|
108 | << " G4ANALYSIS_USE environment variable not set, NO ANALYSIS " |
---|
109 | << G4endl; |
---|
110 | #endif |
---|
111 | |
---|
112 | BrachyEventAction *pEventAction = new BrachyEventAction(); |
---|
113 | pRunManager -> SetUserAction(pEventAction ); |
---|
114 | |
---|
115 | BrachyRunAction *pRunAction = new BrachyRunAction(); |
---|
116 | pRunManager -> SetUserAction(pRunAction); |
---|
117 | |
---|
118 | //Initialize G4 kernel |
---|
119 | pRunManager -> Initialize(); |
---|
120 | |
---|
121 | return true; |
---|
122 | } |
---|
123 | void BrachySimulation::executeMacro(std::string macroFileName) |
---|
124 | { |
---|
125 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
126 | |
---|
127 | // Batch mode |
---|
128 | |
---|
129 | std::string fileName = macroFileName; |
---|
130 | G4cout << fileName << " <---------- in batch -----------------" << G4endl; |
---|
131 | G4cout << macroFileName << " executed"<<G4endl; |
---|
132 | |
---|
133 | std::string command = "/control/execute "; |
---|
134 | |
---|
135 | if(!UI) |
---|
136 | G4cout << "FATAL ERROR: UI pointer does not exist" << G4endl; |
---|
137 | else |
---|
138 | UI -> ApplyCommand(command+fileName); |
---|
139 | } |
---|
140 | std::string BrachySimulation::getOutputFilename() |
---|
141 | { |
---|
142 | return "brachytherapy.xml"; |
---|
143 | } |
---|
144 | |
---|
145 | void BrachySimulation::finish() |
---|
146 | { |
---|
147 | delete pRunManager; |
---|
148 | } |
---|
149 | |
---|
150 | //// This is all the application needs to run in parallel mode through DIANE |
---|
151 | extern "C" |
---|
152 | DIANE::IG4Simulation* createG4Simulation(int seed) |
---|
153 | {return new BrachySimulation(seed); } |
---|
154 | /////////// |
---|