Geant4  10.03.p02
 All Classes 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
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  // Write these values into the analysis if needed. Have to be written separately on change.
94  setBeamMetaData(meanKineticEnergy, sigmaEnergy);
95 
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  // Increment the event counter
136 
137  // ****************************************
138  // Set the beam angular apread
139  // and spot size
140  // beam spot size
141  // ****************************************
142 
143  // Set the position of the primary particles
144  G4double x = X0;
145  G4double y = Y0;
146  G4double z = Z0;
147 
148  if ( sigmaY > 0.0 )
149  {
150  y += G4RandGauss::shoot( Y0, sigmaY );
151  }
152 
153  if ( sigmaZ > 0.0 )
154  {
155  z += G4RandGauss::shoot( Z0, sigmaZ );
156  }
157 
158  particleGun -> SetParticlePosition(G4ThreeVector( x , y , z ) );
159 
160  // ********************************************
161  // Set the beam energy and energy spread
162  // ********************************************
163 
164  G4double kineticEnergy = G4RandGauss::shoot( meanKineticEnergy, sigmaEnergy );
165  particleGun -> SetParticleEnergy ( kineticEnergy );
166 
167  // Set the direction of the primary particles
168 
169 
170  /*
171  G4double momentumX = 1.0;
172  G4double momentumY = 0.0;
173  G4double momentumZ = 0.0;
174 
175  if ( sigmaMomentumY > 0.0 )
176  {
177  momentumY += G4RandGauss::shoot( 0., sigmaMomentumY );
178  }
179  if ( sigmaMomentumZ > 0.0 )
180  {
181  momentumZ += G4RandGauss::shoot( 0., sigmaMomentumZ );
182  }
183 
184  particleGun -> SetParticleMomentumDirection( G4ThreeVector(momentumX,momentumY,momentumZ) );
185 
186  */
187 
188 
189  G4double Mx;
190  G4double My;
191  G4double Mz;
192  G4double condizione;
193 
194 while (true) {
195 
196  //Mx = CLHEP::RandFlat::shoot(0.9,1);
197  //My = CLHEP::RandFlat::shoot(-0.1,0.1);
198  //Mz = CLHEP::RandFlat::shoot(-0.1,0.1);
199 
200  Mx = CLHEP::RandFlat::shoot(0.7,1);
201  My = CLHEP::RandFlat::shoot(-0.3,0.3); // ranges good for 0<Theta<20
202  Mz = CLHEP::RandFlat::shoot(-0.3,0.3);
203 
204  condizione = std::sqrt(Mx*Mx + My*My + Mz*Mz);
205 
206 
207  if (condizione < 1) {
208  Mx = Mx/condizione;
209  My = My/condizione;
210  Mz = Mz/condizione;
211 
212 
213  if (Mx > std::cos(Theta)) {
214  break;
215  }
216  }
217 }
218 
219 
220  particleGun -> SetParticleMomentumDirection( G4ThreeVector(Mx,My,Mz) );
221 
222 
223  // Generate a primary particle
224  particleGun -> GeneratePrimaryVertex( anEvent );
225 }
226 
228 {
229  meanKineticEnergy = val;
230 
231  // Update the beam-data in the analysis manager
233  setBeamMetaData(meanKineticEnergy, sigmaEnergy);
234 
235 
236 }
237 
239 {
240  sigmaEnergy = val;
241  // Update the sigmaenergy in the metadata.
243  setBeamMetaData(meanKineticEnergy, sigmaEnergy);
244 }
245 
247 { X0 = val;}
248 
250 { Y0 = val;}
251 
253 { Z0 = val;}
254 
256 { sigmaY = val;}
257 
259 { sigmaZ = val;}
260 
261 /*
262 void IORTPrimaryGeneratorAction::SetsigmaMomentumY (G4double val )
263 { sigmaMomentumY = val;}
264 
265 void IORTPrimaryGeneratorAction::SetsigmaMomentumZ (G4double val )
266 { sigmaMomentumZ = val;}
267 */
268 
270 { Theta = val;}
271 
272 
274 { return meanKineticEnergy;}
275 
ThreeVector shoot(const G4int Ap, const G4int Af)
CLHEP::Hep3Vector G4ThreeVector
static constexpr double keV
tuple x
Definition: test.py:50
static double shoot()
Definition: RandFlat.cc:59
static constexpr double mm
Definition: SystemOfUnits.h:95
static constexpr double MeV
static IORTAnalysisManager * GetInstance()
static constexpr double deg
static G4ParticleTable * GetParticleTable()
tuple z
Definition: test.py:28
void startNewEvent()
Tell the analysis manager that a new event is starting.
double G4double
Definition: G4Types.hh:76