File indexing completed on 2026-04-17 07:52:14
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 #include "PrimaryGeneratorAction.hh"
0034
0035 #include "G4RunManager.hh"
0036 #include "G4Event.hh"
0037
0038 #include "G4ParticleTable.hh"
0039 #include "G4ParticleDefinition.hh"
0040
0041 #include "Randomize.hh"
0042
0043 #include "G4GeneralParticleSource.hh"
0044 #include "G4ParticleGun.hh"
0045
0046 #include "G4PhysicalConstants.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "globals.hh"
0049
0050
0051
0052 PrimaryGeneratorAction::PrimaryGeneratorAction()
0053 {
0054
0055
0056
0057 fMessenger = new PrimaryGeneratorActionMessenger(this);
0058
0059
0060 G4int n_particle = 1;
0061 fGun = new G4ParticleGun(n_particle);
0062
0063
0064 fGPS = new G4GeneralParticleSource();
0065
0066
0067 G4ParticleDefinition* particle =
0068 G4ParticleTable::GetParticleTable()->FindParticle(fType);
0069
0070
0071
0072 fGPS->SetParticleDefinition(particle);
0073
0074 G4SPSPosDistribution* vPosDist =
0075 fGPS->GetCurrentSource()->GetPosDist();
0076 vPosDist->SetPosDisType("Plane");
0077 vPosDist->SetPosDisShape("Circle");
0078 vPosDist->SetRadius(0.5*CLHEP::mm);
0079 vPosDist->SetCentreCoords(G4ThreeVector(0., 0., -5*CLHEP::cm));
0080
0081 G4SPSAngDistribution* vAngDist =
0082 fGPS->GetCurrentSource()->GetAngDist();
0083 vAngDist->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));
0084
0085 G4SPSEneDistribution* vEneDist =
0086 fGPS->GetCurrentSource()->GetEneDist();
0087 vEneDist->SetEnergyDisType("Mono");
0088 vEneDist->SetMonoEnergy(fEnergy);
0089
0090
0091 fGun->SetParticleDefinition(particle);
0092 fGun->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));
0093 fGun->SetParticleEnergy(fEnergy);
0094 }
0095
0096
0097
0098 PrimaryGeneratorAction::~PrimaryGeneratorAction()
0099 {
0100 delete fGPS;
0101 delete fGun;
0102 }
0103
0104
0105
0106 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0107 {
0108 if (fUseGPS) {
0109 fGPS->GeneratePrimaryVertex(anEvent);
0110 } else {
0111
0112 G4double x = G4RandGauss::shoot(fX, fSigmaX);
0113 G4double y = G4RandGauss::shoot(fY, fSigmaY);
0114 G4double z = G4RandGauss::shoot(fZ, fSigmaZ);
0115 fGun->SetParticlePosition(G4ThreeVector(x, y, z));
0116
0117
0118 G4double t = fT;
0119 if (fSigmaT != 0 && fSigmaZ == 0) {
0120 t = G4RandGauss::shoot(fT, fSigmaT);
0121 }
0122 fGun->SetParticleTime(t);
0123
0124
0125 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0126 fGun->SetParticleDefinition(particleTable->FindParticle(fType));
0127
0128
0129 G4double K = G4RandGauss::shoot(fEnergy, fEnergy*fRelSigmaEnergy);
0130 fGun->SetParticleEnergy(K);
0131
0132
0133 G4double xp = G4RandGauss::shoot(fXp, fSigmaXp);
0134 G4double yp = G4RandGauss::shoot(fYp, fSigmaYp);
0135 fGun->SetParticleMomentumDirection(G4ThreeVector(xp, yp, 1.));
0136
0137
0138 fGun->GeneratePrimaryVertex(anEvent);
0139 }
0140 }
0141
0142
0143