Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IORTPrimaryGeneratorAction.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 // This is the *BASIC* version of IORT, a Geant4-based application
27 //
28 // Main Authors: G.Russo(a,b), C.Casarino*(c), G.C. Candiano(c), G.A.P. Cirrone(d), F.Romano(d)
29 // Contributor Authors: S.Guatelli(e)
30 // Past Authors: G.Arnetta(c), S.E.Mazzaglia(d)
31 //
32 // (a) Fondazione Istituto San Raffaele G.Giglio, Cefalù, Italy
33 // (b) IBFM-CNR , Segrate (Milano), Italy
34 // (c) LATO (Laboratorio di Tecnologie Oncologiche), Cefalù, Italy
35 // (d) Laboratori Nazionali del Sud of the INFN, Catania, Italy
36 // (e) University of Wallongong, Australia
37 //
38 // *Corresponding author, email to carlo.casarino@polooncologicocefalu.it
39 //////////////////////////////////////////////////////////////////////////////////////////////
40 
42 
45 
46 #include "globals.hh"
47 #include "G4Event.hh"
48 #include "G4ParticleGun.hh"
49 #include "G4ParticleTable.hh"
50 #include "G4ParticleDefinition.hh"
51 #include "Randomize.hh"
52 
53 #include "IORTAnalysisManager.hh"
54 
56 {
57  // Define the messenger
58  gunMessenger = new IORTPrimaryGeneratorMessenger(this);
59 
60  particleGun = new G4ParticleGun();
61 
62  SetDefaultPrimaryParticle();
63 }
64 
66 {
67  delete particleGun;
68 
69  delete gunMessenger;
70 }
71 
72 void IORTPrimaryGeneratorAction::SetDefaultPrimaryParticle()
73 {
74  // ****************************
75  // Default primary particle
76  // ****************************
77 
78  // Define primary particles: electrons // protons
80  G4ParticleDefinition* particle = particleTable -> FindParticle("e-"); // ("proton")
81  particleGun -> SetParticleDefinition(particle);
82 
83  // Define the energy of primary particles:
84  // gaussian distribution with mean energy = 10.0 *MeV
85  // and sigma = 400.0 *keV
86  G4double defaultMeanKineticEnergy = 10.0 *CLHEP::MeV;
87  meanKineticEnergy = defaultMeanKineticEnergy;
88 
89  G4double defaultsigmaEnergy = 100.0 *CLHEP::keV;
90  sigmaEnergy = defaultsigmaEnergy;
91 
92 #ifdef G4ANALYSIS_USE_ROOT
93  // Write these values into the analysis if needed. Have to be written separately on change.
94  IORTAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
95 #endif
96 
97  // Define the parameters of the initial position:
98  // the y, z coordinates have a gaussian distribution
99 
100 
101  G4double defaultX0 = -862.817 *CLHEP::mm;
102  X0 = defaultX0;
103 
104  G4double defaultY0 = 0.0 *CLHEP::mm;
105  Y0 = defaultY0;
106 
107  G4double defaultZ0 = 0.0 *CLHEP::mm;
108  Z0 = defaultZ0;
109 
110  G4double defaultsigmaY = 1. *CLHEP::mm;
111  sigmaY = defaultsigmaY;
112 
113  G4double defaultsigmaZ = 1. *CLHEP::mm;
114  sigmaZ = defaultsigmaZ;
115 
116  // Define the parameters of the momentum of primary particles:
117  // The momentum along the y and z axis has a gaussian distribution
118 
119 /*
120  G4double defaultsigmaMomentumY = 0.0;
121  sigmaMomentumY = defaultsigmaMomentumY;
122 
123  G4double defaultsigmaMomentumZ = 0.0;
124  sigmaMomentumZ = defaultsigmaMomentumZ;
125 */
126 
127  G4double defaultTheta = 6.0 *CLHEP::deg;
128  Theta = defaultTheta;
129 
130 }
131 
133 {
134 #ifdef G4ANALYSIS_USE_ROOT
135  // Increment the event counter
136  IORTAnalysisManager::GetInstance()->startNewEvent();
137 #endif
138 
139  // ****************************************
140  // Set the beam angular apread
141  // and spot size
142  // beam spot size
143  // ****************************************
144 
145  // Set the position of the primary particles
146  G4double x = X0;
147  G4double y = Y0;
148  G4double z = Z0;
149 
150  if ( sigmaY > 0.0 )
151  {
152  y += G4RandGauss::shoot( Y0, sigmaY );
153  }
154 
155  if ( sigmaZ > 0.0 )
156  {
157  z += G4RandGauss::shoot( Z0, sigmaZ );
158  }
159 
160  particleGun -> SetParticlePosition(G4ThreeVector( x , y , z ) );
161 
162  // ********************************************
163  // Set the beam energy and energy spread
164  // ********************************************
165 
166  G4double kineticEnergy = G4RandGauss::shoot( meanKineticEnergy, sigmaEnergy );
167  particleGun -> SetParticleEnergy ( kineticEnergy );
168 
169  // Set the direction of the primary particles
170 
171 
172  /*
173  G4double momentumX = 1.0;
174  G4double momentumY = 0.0;
175  G4double momentumZ = 0.0;
176 
177  if ( sigmaMomentumY > 0.0 )
178  {
179  momentumY += G4RandGauss::shoot( 0., sigmaMomentumY );
180  }
181  if ( sigmaMomentumZ > 0.0 )
182  {
183  momentumZ += G4RandGauss::shoot( 0., sigmaMomentumZ );
184  }
185 
186  particleGun -> SetParticleMomentumDirection( G4ThreeVector(momentumX,momentumY,momentumZ) );
187 
188  */
189 
190 
191  G4double Mx;
192  G4double My;
193  G4double Mz;
194  G4double condizione;
195 
196 while (true) {
197 
198  //Mx = CLHEP::RandFlat::shoot(0.9,1);
199  //My = CLHEP::RandFlat::shoot(-0.1,0.1);
200  //Mz = CLHEP::RandFlat::shoot(-0.1,0.1);
201 
202  Mx = CLHEP::RandFlat::shoot(0.7,1);
203  My = CLHEP::RandFlat::shoot(-0.3,0.3); // ranges good for 0<Theta<20
204  Mz = CLHEP::RandFlat::shoot(-0.3,0.3);
205 
206  condizione = std::sqrt(Mx*Mx + My*My + Mz*Mz);
207 
208 
209  if (condizione < 1) {
210  Mx = Mx/condizione;
211  My = My/condizione;
212  Mz = Mz/condizione;
213 
214 
215  if (Mx > std::cos(Theta)) {
216  break;
217  }
218  }
219 }
220 
221 
222  particleGun -> SetParticleMomentumDirection( G4ThreeVector(Mx,My,Mz) );
223 
224 
225  // Generate a primary particle
226  particleGun -> GeneratePrimaryVertex( anEvent );
227 }
228 
230 {
231  meanKineticEnergy = val;
232 #ifdef G4ANALYSIS_USE_ROOT
233  // Update the beam-data in the analysis manager
234  IORTAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
235 #endif
236 
237 }
238 
240 {
241  sigmaEnergy = val;
242 #ifdef G4ANALYSIS_USE_ROOT
243  // Update the sigmaenergy in the metadata.
244  IORTAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
245 #endif
246 }
247 
249 { X0 = val;}
250 
252 { Y0 = val;}
253 
255 { Z0 = val;}
256 
258 { sigmaY = val;}
259 
261 { sigmaZ = val;}
262 
263 /*
264 void IORTPrimaryGeneratorAction::SetsigmaMomentumY (G4double val )
265 { sigmaMomentumY = val;}
266 
267 void IORTPrimaryGeneratorAction::SetsigmaMomentumZ (G4double val )
268 { sigmaMomentumZ = val;}
269 */
270 
272 { Theta = val;}
273 
274 
276 { return meanKineticEnergy;}
277 
ThreeVector shoot(const G4int Ap, const G4int Af)
CLHEP::Hep3Vector G4ThreeVector
G4double z
Definition: TRTMaterials.hh:39
static double shoot()
Definition: RandFlat.cc:59
static IORTAnalysisManager * GetInstance()
static G4ParticleTable * GetParticleTable()
double G4double
Definition: G4Types.hh:76