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p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 Wollongong, Australia
 37 //
 38 //   *Corresponding author, email to carlo.casarino@polooncologicocefalu.it
 39 //////////////////////////////////////////////////////////////////////////////////////////////
 40 
 41 #include "G4SystemOfUnits.hh"
 42 #include "IORTPrimaryGeneratorAction.hh"
 43 #include "IORTPrimaryGeneratorMessenger.hh"
 44 
 45 #include "globals.hh"
 46 #include "G4Event.hh"
 47 #include "G4ParticleGun.hh"
 48 #include "G4ParticleTable.hh"
 49 #include "G4ParticleDefinition.hh"
 50 #include "Randomize.hh"
 51   
 52 IORTPrimaryGeneratorAction::IORTPrimaryGeneratorAction()
 53 {
 54   // Define the messenger
 55   gunMessenger = new IORTPrimaryGeneratorMessenger(this);
 56 
 57   particleGun  = new G4ParticleGun();
 58 
 59   SetDefaultPrimaryParticle();  
 60 }  
 61 
 62 IORTPrimaryGeneratorAction::~IORTPrimaryGeneratorAction()
 63 {
 64   delete particleGun;
 65 
 66   delete gunMessenger;
 67 }
 68   
 69 void IORTPrimaryGeneratorAction::SetDefaultPrimaryParticle()
 70 {    
 71   // ****************************
 72   // Default primary particle
 73   // ****************************
 74   
 75   // Define primary particles: electrons // protons
 76   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
 77   G4ParticleDefinition* particle = particleTable -> FindParticle("e-");   // ("proton")
 78   particleGun -> SetParticleDefinition(particle); 
 79 
 80   // Define the energy of primary particles:
 81   // gaussian distribution with mean energy = 10.0 *MeV   
 82   // and sigma = 400.0 *keV
 83   G4double defaultMeanKineticEnergy = 10.0 *CLHEP::MeV;   
 84   meanKineticEnergy = defaultMeanKineticEnergy;
 85 
 86   G4double defaultsigmaEnergy = 100.0 *CLHEP::keV;   
 87   sigmaEnergy = defaultsigmaEnergy;
 88  
 89   // Define the parameters of the initial position: 
 90   // the y, z coordinates have a gaussian distribution 
 91   
 92   G4double defaultX0 = -862.817 *CLHEP::mm;                 
 93   X0 = defaultX0;
 94 
 95   G4double defaultY0 = 0.0 *CLHEP::mm;  
 96   Y0 = defaultY0;
 97 
 98   G4double defaultZ0 = 0.0 *CLHEP::mm;  
 99   Z0 = defaultZ0;
100 
101   G4double defaultsigmaY = 1. *CLHEP::mm;  
102   sigmaY = defaultsigmaY;
103 
104   G4double defaultsigmaZ = 1. *CLHEP::mm;  
105   sigmaZ = defaultsigmaZ;
106 
107   // Define the parameters of the momentum of primary particles: 
108   // The momentum along the y and z axis has a gaussian distribution
109  
110 /* 
111   G4double defaultsigmaMomentumY = 0.0;  
112   sigmaMomentumY = defaultsigmaMomentumY;
113 
114   G4double defaultsigmaMomentumZ = 0.0;  
115   sigmaMomentumZ = defaultsigmaMomentumZ;
116 */
117 
118   G4double defaultTheta = 6.0 *CLHEP::deg;  
119   Theta = defaultTheta;
120 
121 }
122 
123 void IORTPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
124 {
125   // ****************************************
126   // Set the beam angular apread 
127   // and spot size
128   // beam spot size
129   // ****************************************
130 
131   // Set the position of the primary particles
132   G4double x = X0;
133   G4double y = Y0;
134   G4double z = Z0;
135 
136   if ( sigmaY > 0.0 )
137     {
138       y += G4RandGauss::shoot( Y0, sigmaY );
139     }
140  
141   if ( sigmaZ > 0.0 )
142     {
143       z += G4RandGauss::shoot( Z0, sigmaZ );
144     }
145 
146   particleGun -> SetParticlePosition(G4ThreeVector( x , y , z ) );
147  
148   // ********************************************
149   // Set the beam energy and energy spread
150   // ********************************************
151 
152   G4double kineticEnergy = G4RandGauss::shoot( meanKineticEnergy, sigmaEnergy );
153   particleGun -> SetParticleEnergy ( kineticEnergy );
154 
155   // Set the direction of the primary particles  
156   
157 
158   /*                          
159   G4double momentumX = 1.0;
160   G4double momentumY = 0.0;
161   G4double momentumZ = 0.0;
162 
163   if ( sigmaMomentumY  > 0.0 )
164     {
165       momentumY += G4RandGauss::shoot( 0., sigmaMomentumY );
166     }
167   if ( sigmaMomentumZ  > 0.0 )
168     {
169       momentumZ += G4RandGauss::shoot( 0., sigmaMomentumZ );
170     }
171  
172   particleGun -> SetParticleMomentumDirection( G4ThreeVector(momentumX,momentumY,momentumZ) );
173 
174   */
175   
176                
177   G4double Mx;    
178   G4double My;
179   G4double Mz;
180   G4double condizione;
181   
182 while (true)  {
183 
184   //Mx =  CLHEP::RandFlat::shoot(0.9,1);
185   //My =  CLHEP::RandFlat::shoot(-0.1,0.1);
186   //Mz =  CLHEP::RandFlat::shoot(-0.1,0.1);
187 
188   Mx =  CLHEP::RandFlat::shoot(0.7,1);
189   My =  CLHEP::RandFlat::shoot(-0.3,0.3); // ranges good for 0<Theta<20
190   Mz =  CLHEP::RandFlat::shoot(-0.3,0.3);
191 
192   condizione = std::sqrt(Mx*Mx + My*My + Mz*Mz);
193 
194  
195   if (condizione < 1)  {
196     Mx = Mx/condizione;
197     My = My/condizione;
198     Mz = Mz/condizione;
199 
200 
201     if (Mx > std::cos(Theta)) { 
202       break;
203         }
204     }
205 }
206   
207  
208   particleGun -> SetParticleMomentumDirection( G4ThreeVector(Mx,My,Mz) );
209   
210 
211   // Generate a primary particle
212   particleGun -> GeneratePrimaryVertex( anEvent ); 
213 } 
214 
215 void IORTPrimaryGeneratorAction::SetmeanKineticEnergy (G4double val )  
216 {
217   meanKineticEnergy = val;
218   G4cout << "The mean Kinetic energy of the incident beam has been changed to (MeV):" 
219          << meanKineticEnergy/MeV << G4endl; 
220 } 
221 
222 void IORTPrimaryGeneratorAction::SetsigmaEnergy (G4double val )  
223 { 
224  sigmaEnergy = val;
225  G4cout << "The sigma of the kinetic energy of the incident beam has been changed to (MeV):"
226         << sigmaEnergy/MeV << G4endl; 
227 }
228 
229 void IORTPrimaryGeneratorAction::SetXposition (G4double val )  
230 { X0 = val;}
231 
232 void IORTPrimaryGeneratorAction::SetYposition (G4double val )  
233 { Y0 = val;}
234 
235 void IORTPrimaryGeneratorAction::SetZposition (G4double val )  
236 { Z0 = val;}
237 
238 void IORTPrimaryGeneratorAction::SetsigmaY (G4double val )  
239 { sigmaY = val;}
240 
241 void IORTPrimaryGeneratorAction::SetsigmaZ (G4double val )  
242 { sigmaZ = val;}
243 
244 /*
245 void IORTPrimaryGeneratorAction::SetsigmaMomentumY (G4double val )  
246 { sigmaMomentumY = val;}
247 
248 void IORTPrimaryGeneratorAction::SetsigmaMomentumZ (G4double val )  
249 { sigmaMomentumZ = val;}
250 */
251 
252 void IORTPrimaryGeneratorAction::SetTheta (G4double val ) 
253 { Theta = val;}
254 
255 
256 G4double IORTPrimaryGeneratorAction::GetmeanKineticEnergy(void)
257 { return meanKineticEnergy;}
258 
259