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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 ]

Diff markup

Differences between /examples/advanced/iort_therapy/src/IORTPrimaryGeneratorAction.cc (Version 11.3.0) and /examples/advanced/iort_therapy/src/IORTPrimaryGeneratorAction.cc (Version 10.5.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // This is the *BASIC* version of IORT, a Gean     26 // This is the *BASIC* version of IORT, a Geant4-based application
 27 //                                                 27 //
 28 // Main Authors: G.Russo(a,b), C.Casarino*(c),     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)              29 // Contributor Authors: S.Guatelli(e)
 30 // Past Authors: G.Arnetta(c), S.E.Mazzaglia(d     30 // Past Authors: G.Arnetta(c), S.E.Mazzaglia(d)
 31 //                                                 31 //    
 32 //   (a) Fondazione Istituto San Raffaele G.Gi     32 //   (a) Fondazione Istituto San Raffaele G.Giglio, Cefalù, Italy
 33 //   (b) IBFM-CNR , Segrate (Milano), Italy        33 //   (b) IBFM-CNR , Segrate (Milano), Italy
 34 //   (c) LATO (Laboratorio di Tecnologie Oncol     34 //   (c) LATO (Laboratorio di Tecnologie Oncologiche), Cefalù, Italy
 35 //   (d) Laboratori Nazionali del Sud of the I     35 //   (d) Laboratori Nazionali del Sud of the INFN, Catania, Italy
 36 //   (e) University of Wollongong, Australia       36 //   (e) University of Wollongong, Australia
 37 //                                                 37 //
 38 //   *Corresponding author, email to carlo.cas     38 //   *Corresponding author, email to carlo.casarino@polooncologicocefalu.it
 39 //////////////////////////////////////////////     39 //////////////////////////////////////////////////////////////////////////////////////////////
 40                                                    40 
 41 #include "G4SystemOfUnits.hh"                      41 #include "G4SystemOfUnits.hh"
 42 #include "IORTPrimaryGeneratorAction.hh"           42 #include "IORTPrimaryGeneratorAction.hh"
 43 #include "IORTPrimaryGeneratorMessenger.hh"        43 #include "IORTPrimaryGeneratorMessenger.hh"
 44                                                    44 
 45 #include "globals.hh"                              45 #include "globals.hh"
 46 #include "G4Event.hh"                              46 #include "G4Event.hh"
 47 #include "G4ParticleGun.hh"                        47 #include "G4ParticleGun.hh"
 48 #include "G4ParticleTable.hh"                      48 #include "G4ParticleTable.hh"
 49 #include "G4ParticleDefinition.hh"                 49 #include "G4ParticleDefinition.hh"
 50 #include "Randomize.hh"                            50 #include "Randomize.hh"
 51                                                    51   
 52 IORTPrimaryGeneratorAction::IORTPrimaryGenerat     52 IORTPrimaryGeneratorAction::IORTPrimaryGeneratorAction()
 53 {                                                  53 {
 54   // Define the messenger                          54   // Define the messenger
 55   gunMessenger = new IORTPrimaryGeneratorMesse     55   gunMessenger = new IORTPrimaryGeneratorMessenger(this);
 56                                                    56 
 57   particleGun  = new G4ParticleGun();              57   particleGun  = new G4ParticleGun();
 58                                                    58 
 59   SetDefaultPrimaryParticle();                     59   SetDefaultPrimaryParticle();  
 60 }                                                  60 }  
 61                                                    61 
 62 IORTPrimaryGeneratorAction::~IORTPrimaryGenera     62 IORTPrimaryGeneratorAction::~IORTPrimaryGeneratorAction()
 63 {                                                  63 {
 64   delete particleGun;                              64   delete particleGun;
 65                                                    65 
 66   delete gunMessenger;                             66   delete gunMessenger;
 67 }                                                  67 }
 68                                                    68   
 69 void IORTPrimaryGeneratorAction::SetDefaultPri     69 void IORTPrimaryGeneratorAction::SetDefaultPrimaryParticle()
 70 {                                                  70 {    
 71   // ****************************                  71   // ****************************
 72   // Default primary particle                      72   // Default primary particle
 73   // ****************************                  73   // ****************************
 74                                                    74   
 75   // Define primary particles: electrons // pr     75   // Define primary particles: electrons // protons
 76   G4ParticleTable* particleTable = G4ParticleT     76   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
 77   G4ParticleDefinition* particle = particleTab     77   G4ParticleDefinition* particle = particleTable -> FindParticle("e-");   // ("proton")
 78   particleGun -> SetParticleDefinition(particl     78   particleGun -> SetParticleDefinition(particle); 
 79                                                    79 
 80   // Define the energy of primary particles:       80   // Define the energy of primary particles:
 81   // gaussian distribution with mean energy =      81   // gaussian distribution with mean energy = 10.0 *MeV   
 82   // and sigma = 400.0 *keV                        82   // and sigma = 400.0 *keV
 83   G4double defaultMeanKineticEnergy = 10.0 *CL     83   G4double defaultMeanKineticEnergy = 10.0 *CLHEP::MeV;   
 84   meanKineticEnergy = defaultMeanKineticEnergy     84   meanKineticEnergy = defaultMeanKineticEnergy;
 85                                                    85 
 86   G4double defaultsigmaEnergy = 100.0 *CLHEP::     86   G4double defaultsigmaEnergy = 100.0 *CLHEP::keV;   
 87   sigmaEnergy = defaultsigmaEnergy;                87   sigmaEnergy = defaultsigmaEnergy;
 88                                                    88  
 89   // Define the parameters of the initial posi     89   // Define the parameters of the initial position: 
 90   // the y, z coordinates have a gaussian dist     90   // the y, z coordinates have a gaussian distribution 
 91                                                    91   
 92   G4double defaultX0 = -862.817 *CLHEP::mm;        92   G4double defaultX0 = -862.817 *CLHEP::mm;                 
 93   X0 = defaultX0;                                  93   X0 = defaultX0;
 94                                                    94 
 95   G4double defaultY0 = 0.0 *CLHEP::mm;             95   G4double defaultY0 = 0.0 *CLHEP::mm;  
 96   Y0 = defaultY0;                                  96   Y0 = defaultY0;
 97                                                    97 
 98   G4double defaultZ0 = 0.0 *CLHEP::mm;             98   G4double defaultZ0 = 0.0 *CLHEP::mm;  
 99   Z0 = defaultZ0;                                  99   Z0 = defaultZ0;
100                                                   100 
101   G4double defaultsigmaY = 1. *CLHEP::mm;         101   G4double defaultsigmaY = 1. *CLHEP::mm;  
102   sigmaY = defaultsigmaY;                         102   sigmaY = defaultsigmaY;
103                                                   103 
104   G4double defaultsigmaZ = 1. *CLHEP::mm;         104   G4double defaultsigmaZ = 1. *CLHEP::mm;  
105   sigmaZ = defaultsigmaZ;                         105   sigmaZ = defaultsigmaZ;
106                                                   106 
107   // Define the parameters of the momentum of     107   // Define the parameters of the momentum of primary particles: 
108   // The momentum along the y and z axis has a    108   // The momentum along the y and z axis has a gaussian distribution
109                                                   109  
110 /*                                                110 /* 
111   G4double defaultsigmaMomentumY = 0.0;           111   G4double defaultsigmaMomentumY = 0.0;  
112   sigmaMomentumY = defaultsigmaMomentumY;         112   sigmaMomentumY = defaultsigmaMomentumY;
113                                                   113 
114   G4double defaultsigmaMomentumZ = 0.0;           114   G4double defaultsigmaMomentumZ = 0.0;  
115   sigmaMomentumZ = defaultsigmaMomentumZ;         115   sigmaMomentumZ = defaultsigmaMomentumZ;
116 */                                                116 */
117                                                   117 
118   G4double defaultTheta = 6.0 *CLHEP::deg;        118   G4double defaultTheta = 6.0 *CLHEP::deg;  
119   Theta = defaultTheta;                           119   Theta = defaultTheta;
120                                                   120 
121 }                                                 121 }
122                                                   122 
123 void IORTPrimaryGeneratorAction::GeneratePrima    123 void IORTPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
124 {                                                 124 {
125   // ****************************************     125   // ****************************************
126   // Set the beam angular apread                  126   // Set the beam angular apread 
127   // and spot size                                127   // and spot size
128   // beam spot size                               128   // beam spot size
129   // ****************************************     129   // ****************************************
130                                                   130 
131   // Set the position of the primary particles    131   // Set the position of the primary particles
132   G4double x = X0;                                132   G4double x = X0;
133   G4double y = Y0;                                133   G4double y = Y0;
134   G4double z = Z0;                                134   G4double z = Z0;
135                                                   135 
136   if ( sigmaY > 0.0 )                             136   if ( sigmaY > 0.0 )
137     {                                             137     {
138       y += G4RandGauss::shoot( Y0, sigmaY );      138       y += G4RandGauss::shoot( Y0, sigmaY );
139     }                                             139     }
140                                                   140  
141   if ( sigmaZ > 0.0 )                             141   if ( sigmaZ > 0.0 )
142     {                                             142     {
143       z += G4RandGauss::shoot( Z0, sigmaZ );      143       z += G4RandGauss::shoot( Z0, sigmaZ );
144     }                                             144     }
145                                                   145 
146   particleGun -> SetParticlePosition(G4ThreeVe    146   particleGun -> SetParticlePosition(G4ThreeVector( x , y , z ) );
147                                                   147  
148   // *****************************************    148   // ********************************************
149   // Set the beam energy and energy spread        149   // Set the beam energy and energy spread
150   // *****************************************    150   // ********************************************
151                                                   151 
152   G4double kineticEnergy = G4RandGauss::shoot(    152   G4double kineticEnergy = G4RandGauss::shoot( meanKineticEnergy, sigmaEnergy );
153   particleGun -> SetParticleEnergy ( kineticEn    153   particleGun -> SetParticleEnergy ( kineticEnergy );
154                                                   154 
155   // Set the direction of the primary particle    155   // Set the direction of the primary particles  
156                                                   156   
157                                                   157 
158   /*                                              158   /*                          
159   G4double momentumX = 1.0;                       159   G4double momentumX = 1.0;
160   G4double momentumY = 0.0;                       160   G4double momentumY = 0.0;
161   G4double momentumZ = 0.0;                       161   G4double momentumZ = 0.0;
162                                                   162 
163   if ( sigmaMomentumY  > 0.0 )                    163   if ( sigmaMomentumY  > 0.0 )
164     {                                             164     {
165       momentumY += G4RandGauss::shoot( 0., sig    165       momentumY += G4RandGauss::shoot( 0., sigmaMomentumY );
166     }                                             166     }
167   if ( sigmaMomentumZ  > 0.0 )                    167   if ( sigmaMomentumZ  > 0.0 )
168     {                                             168     {
169       momentumZ += G4RandGauss::shoot( 0., sig    169       momentumZ += G4RandGauss::shoot( 0., sigmaMomentumZ );
170     }                                             170     }
171                                                   171  
172   particleGun -> SetParticleMomentumDirection(    172   particleGun -> SetParticleMomentumDirection( G4ThreeVector(momentumX,momentumY,momentumZ) );
173                                                   173 
174   */                                              174   */
175                                                   175   
176                                                   176                
177   G4double Mx;                                    177   G4double Mx;    
178   G4double My;                                    178   G4double My;
179   G4double Mz;                                    179   G4double Mz;
180   G4double condizione;                            180   G4double condizione;
181                                                   181   
182 while (true)  {                                   182 while (true)  {
183                                                   183 
184   //Mx =  CLHEP::RandFlat::shoot(0.9,1);          184   //Mx =  CLHEP::RandFlat::shoot(0.9,1);
185   //My =  CLHEP::RandFlat::shoot(-0.1,0.1);       185   //My =  CLHEP::RandFlat::shoot(-0.1,0.1);
186   //Mz =  CLHEP::RandFlat::shoot(-0.1,0.1);       186   //Mz =  CLHEP::RandFlat::shoot(-0.1,0.1);
187                                                   187 
188   Mx =  CLHEP::RandFlat::shoot(0.7,1);            188   Mx =  CLHEP::RandFlat::shoot(0.7,1);
189   My =  CLHEP::RandFlat::shoot(-0.3,0.3); // r    189   My =  CLHEP::RandFlat::shoot(-0.3,0.3); // ranges good for 0<Theta<20
190   Mz =  CLHEP::RandFlat::shoot(-0.3,0.3);         190   Mz =  CLHEP::RandFlat::shoot(-0.3,0.3);
191                                                   191 
192   condizione = std::sqrt(Mx*Mx + My*My + Mz*Mz    192   condizione = std::sqrt(Mx*Mx + My*My + Mz*Mz);
193                                                   193 
194                                                   194  
195   if (condizione < 1)  {                          195   if (condizione < 1)  {
196     Mx = Mx/condizione;                           196     Mx = Mx/condizione;
197     My = My/condizione;                           197     My = My/condizione;
198     Mz = Mz/condizione;                           198     Mz = Mz/condizione;
199                                                   199 
200                                                   200 
201     if (Mx > std::cos(Theta)) {                   201     if (Mx > std::cos(Theta)) { 
202       break;                                      202       break;
203         }                                         203         }
204     }                                             204     }
205 }                                                 205 }
206                                                   206   
207                                                   207  
208   particleGun -> SetParticleMomentumDirection(    208   particleGun -> SetParticleMomentumDirection( G4ThreeVector(Mx,My,Mz) );
209                                                   209   
210                                                   210 
211   // Generate a primary particle                  211   // Generate a primary particle
212   particleGun -> GeneratePrimaryVertex( anEven    212   particleGun -> GeneratePrimaryVertex( anEvent ); 
213 }                                                 213 } 
214                                                   214 
215 void IORTPrimaryGeneratorAction::SetmeanKineti    215 void IORTPrimaryGeneratorAction::SetmeanKineticEnergy (G4double val )  
216 {                                                 216 {
217   meanKineticEnergy = val;                        217   meanKineticEnergy = val;
218   G4cout << "The mean Kinetic energy of the in    218   G4cout << "The mean Kinetic energy of the incident beam has been changed to (MeV):" 
219          << meanKineticEnergy/MeV << G4endl;      219          << meanKineticEnergy/MeV << G4endl; 
220 }                                                 220 } 
221                                                   221 
222 void IORTPrimaryGeneratorAction::SetsigmaEnerg    222 void IORTPrimaryGeneratorAction::SetsigmaEnergy (G4double val )  
223 {                                                 223 { 
224  sigmaEnergy = val;                               224  sigmaEnergy = val;
225  G4cout << "The sigma of the kinetic energy of    225  G4cout << "The sigma of the kinetic energy of the incident beam has been changed to (MeV):"
226         << sigmaEnergy/MeV << G4endl;             226         << sigmaEnergy/MeV << G4endl; 
227 }                                                 227 }
228                                                   228 
229 void IORTPrimaryGeneratorAction::SetXposition     229 void IORTPrimaryGeneratorAction::SetXposition (G4double val )  
230 { X0 = val;}                                      230 { X0 = val;}
231                                                   231 
232 void IORTPrimaryGeneratorAction::SetYposition     232 void IORTPrimaryGeneratorAction::SetYposition (G4double val )  
233 { Y0 = val;}                                      233 { Y0 = val;}
234                                                   234 
235 void IORTPrimaryGeneratorAction::SetZposition     235 void IORTPrimaryGeneratorAction::SetZposition (G4double val )  
236 { Z0 = val;}                                      236 { Z0 = val;}
237                                                   237 
238 void IORTPrimaryGeneratorAction::SetsigmaY (G4    238 void IORTPrimaryGeneratorAction::SetsigmaY (G4double val )  
239 { sigmaY = val;}                                  239 { sigmaY = val;}
240                                                   240 
241 void IORTPrimaryGeneratorAction::SetsigmaZ (G4    241 void IORTPrimaryGeneratorAction::SetsigmaZ (G4double val )  
242 { sigmaZ = val;}                                  242 { sigmaZ = val;}
243                                                   243 
244 /*                                                244 /*
245 void IORTPrimaryGeneratorAction::SetsigmaMomen    245 void IORTPrimaryGeneratorAction::SetsigmaMomentumY (G4double val )  
246 { sigmaMomentumY = val;}                          246 { sigmaMomentumY = val;}
247                                                   247 
248 void IORTPrimaryGeneratorAction::SetsigmaMomen    248 void IORTPrimaryGeneratorAction::SetsigmaMomentumZ (G4double val )  
249 { sigmaMomentumZ = val;}                          249 { sigmaMomentumZ = val;}
250 */                                                250 */
251                                                   251 
252 void IORTPrimaryGeneratorAction::SetTheta (G4d    252 void IORTPrimaryGeneratorAction::SetTheta (G4double val ) 
253 { Theta = val;}                                   253 { Theta = val;}
254                                                   254 
255                                                   255 
256 G4double IORTPrimaryGeneratorAction::GetmeanKi    256 G4double IORTPrimaryGeneratorAction::GetmeanKineticEnergy(void)
257 { return meanKineticEnergy;}                      257 { return meanKineticEnergy;}
258                                                   258 
259                                                   259