File indexing completed on 2025-02-27 09:18:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 #include "G4SystemOfUnits.hh"
0042 #include "IORTPrimaryGeneratorAction.hh"
0043 #include "IORTPrimaryGeneratorMessenger.hh"
0044
0045 #include "globals.hh"
0046 #include "G4Event.hh"
0047 #include "G4ParticleGun.hh"
0048 #include "G4ParticleTable.hh"
0049 #include "G4ParticleDefinition.hh"
0050 #include "Randomize.hh"
0051
0052 IORTPrimaryGeneratorAction::IORTPrimaryGeneratorAction()
0053 {
0054
0055 gunMessenger = new IORTPrimaryGeneratorMessenger(this);
0056
0057 particleGun = new G4ParticleGun();
0058
0059 SetDefaultPrimaryParticle();
0060 }
0061
0062 IORTPrimaryGeneratorAction::~IORTPrimaryGeneratorAction()
0063 {
0064 delete particleGun;
0065
0066 delete gunMessenger;
0067 }
0068
0069 void IORTPrimaryGeneratorAction::SetDefaultPrimaryParticle()
0070 {
0071
0072
0073
0074
0075
0076 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0077 G4ParticleDefinition* particle = particleTable -> FindParticle("e-");
0078 particleGun -> SetParticleDefinition(particle);
0079
0080
0081
0082
0083 G4double defaultMeanKineticEnergy = 10.0 *CLHEP::MeV;
0084 meanKineticEnergy = defaultMeanKineticEnergy;
0085
0086 G4double defaultsigmaEnergy = 100.0 *CLHEP::keV;
0087 sigmaEnergy = defaultsigmaEnergy;
0088
0089
0090
0091
0092 G4double defaultX0 = -862.817 *CLHEP::mm;
0093 X0 = defaultX0;
0094
0095 G4double defaultY0 = 0.0 *CLHEP::mm;
0096 Y0 = defaultY0;
0097
0098 G4double defaultZ0 = 0.0 *CLHEP::mm;
0099 Z0 = defaultZ0;
0100
0101 G4double defaultsigmaY = 1. *CLHEP::mm;
0102 sigmaY = defaultsigmaY;
0103
0104 G4double defaultsigmaZ = 1. *CLHEP::mm;
0105 sigmaZ = defaultsigmaZ;
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 G4double defaultTheta = 6.0 *CLHEP::deg;
0119 Theta = defaultTheta;
0120
0121 }
0122
0123 void IORTPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0124 {
0125
0126
0127
0128
0129
0130
0131
0132 G4double x = X0;
0133 G4double y = Y0;
0134 G4double z = Z0;
0135
0136 if ( sigmaY > 0.0 )
0137 {
0138 y += G4RandGauss::shoot( Y0, sigmaY );
0139 }
0140
0141 if ( sigmaZ > 0.0 )
0142 {
0143 z += G4RandGauss::shoot( Z0, sigmaZ );
0144 }
0145
0146 particleGun -> SetParticlePosition(G4ThreeVector( x , y , z ) );
0147
0148
0149
0150
0151
0152 G4double kineticEnergy = G4RandGauss::shoot( meanKineticEnergy, sigmaEnergy );
0153 particleGun -> SetParticleEnergy ( kineticEnergy );
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 G4double Mx;
0178 G4double My;
0179 G4double Mz;
0180 G4double condizione;
0181
0182 while (true) {
0183
0184
0185
0186
0187
0188 Mx = CLHEP::RandFlat::shoot(0.7,1);
0189 My = CLHEP::RandFlat::shoot(-0.3,0.3);
0190 Mz = CLHEP::RandFlat::shoot(-0.3,0.3);
0191
0192 condizione = std::sqrt(Mx*Mx + My*My + Mz*Mz);
0193
0194
0195 if (condizione < 1) {
0196 Mx = Mx/condizione;
0197 My = My/condizione;
0198 Mz = Mz/condizione;
0199
0200
0201 if (Mx > std::cos(Theta)) {
0202 break;
0203 }
0204 }
0205 }
0206
0207
0208 particleGun -> SetParticleMomentumDirection( G4ThreeVector(Mx,My,Mz) );
0209
0210
0211
0212 particleGun -> GeneratePrimaryVertex( anEvent );
0213 }
0214
0215 void IORTPrimaryGeneratorAction::SetmeanKineticEnergy (G4double val )
0216 {
0217 meanKineticEnergy = val;
0218 G4cout << "The mean Kinetic energy of the incident beam has been changed to (MeV):"
0219 << meanKineticEnergy/MeV << G4endl;
0220 }
0221
0222 void IORTPrimaryGeneratorAction::SetsigmaEnergy (G4double val )
0223 {
0224 sigmaEnergy = val;
0225 G4cout << "The sigma of the kinetic energy of the incident beam has been changed to (MeV):"
0226 << sigmaEnergy/MeV << G4endl;
0227 }
0228
0229 void IORTPrimaryGeneratorAction::SetXposition (G4double val )
0230 { X0 = val;}
0231
0232 void IORTPrimaryGeneratorAction::SetYposition (G4double val )
0233 { Y0 = val;}
0234
0235 void IORTPrimaryGeneratorAction::SetZposition (G4double val )
0236 { Z0 = val;}
0237
0238 void IORTPrimaryGeneratorAction::SetsigmaY (G4double val )
0239 { sigmaY = val;}
0240
0241 void IORTPrimaryGeneratorAction::SetsigmaZ (G4double val )
0242 { sigmaZ = val;}
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252 void IORTPrimaryGeneratorAction::SetTheta (G4double val )
0253 { Theta = val;}
0254
0255
0256 G4double IORTPrimaryGeneratorAction::GetmeanKineticEnergy(void)
0257 { return meanKineticEnergy;}
0258