File indexing completed on 2025-01-18 09:16:09
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 #include "PrimaryGeneratorAction.hh"
0031
0032 #include "PrimaryGeneratorMessenger.hh"
0033 #include "DetectorConstruction.hh"
0034
0035 #include "G4SystemOfUnits.hh"
0036 #include "G4Event.hh"
0037 #include "G4ParticleGun.hh"
0038 #include "G4ParticleTable.hh"
0039 #include "G4ParticleDefinition.hh"
0040 #include "Randomize.hh"
0041
0042
0043
0044 PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* det)
0045 :Detector(det)
0046 {
0047 G4int n_particle = 1;
0048 particleGun = new G4ParticleGun(n_particle);
0049 SetDefaultKinematic();
0050 beam = 0.*mm;
0051
0052
0053 gunMessenger = new PrimaryGeneratorMessenger(this);
0054 }
0055
0056
0057
0058 PrimaryGeneratorAction::~PrimaryGeneratorAction()
0059 {
0060 delete particleGun;
0061 delete gunMessenger;
0062 }
0063
0064
0065
0066 void PrimaryGeneratorAction::SetDefaultKinematic()
0067 {
0068 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0069 G4String particleName;
0070 G4ParticleDefinition* particle
0071 = particleTable->FindParticle(particleName="e-");
0072 particleGun->SetParticleDefinition(particle);
0073 particleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
0074 particleGun->SetParticleEnergy(1.*GeV);
0075 G4double position = -0.5*(Detector->GetWorldSizeX());
0076 particleGun->SetParticlePosition(G4ThreeVector(position,0.*mm,0.*mm));
0077 }
0078
0079
0080
0081 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0082 {
0083
0084
0085
0086
0087 if (beam > 0.)
0088 {
0089 G4ThreeVector position = particleGun->GetParticlePosition();
0090 G4double maxYZ = 0.49*(Detector->GetCalorSizeYZ());
0091 G4double x0 = position.x();
0092 G4double y0 = position.y() + (G4UniformRand()-0.5)*beam;
0093 G4double z0 = position.z() + (G4UniformRand()-0.5)*beam;
0094 if (std::abs(y0) > maxYZ) y0 = maxYZ;
0095 if (std::abs(z0) > maxYZ) z0 = maxYZ;
0096 particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
0097 particleGun->GeneratePrimaryVertex(anEvent);
0098 particleGun->SetParticlePosition(position);
0099 }
0100 else particleGun->GeneratePrimaryVertex(anEvent);
0101 }
0102
0103
0104