#include "FCALPrimaryGeneratorAction.hh" #include "FCALPrimaryGeneratorMessenger.hh" #include "G4Event.hh" #include "G4ParticleGun.hh" #include "G4ParticleTable.hh" #include "G4ParticleDefinition.hh" FCALPrimaryGeneratorAction::FCALPrimaryGeneratorAction() { generator_Messenger = new FCALPrimaryGeneratorMessenger(this); // G4ThreeVector gun_Position(0.1*cm, 0.1*cm, -36.*cm); // the position of the particle gun G4ThreeVector gun_Position(0.1*cm, 0.1*cm, -14.*cm); G4ThreeVector momentum_Direction(0, 0, 1); // the momentum direction of incident particles G4ThreeVector particle_Polarization(0, 0, 0); // set the particle polarization particle_Energy = 5.*GeV; // set the particle energy G4int n_Incident_Particles = 1; // set the number of incident particles particle_Gun = new G4ParticleGun(n_Incident_Particles); // generate an object of G4ParticleGun G4ParticleTable* particle_Table = G4ParticleTable::GetParticleTable(); G4ParticleDefinition* particle = particle_Table->FindParticle("gamma"); particle_Gun->SetParticleDefinition(particle); // This command should appear first. particle_Gun->SetParticleMomentumDirection(momentum_Direction); particle_Gun->SetParticleTime(0.*ns); particle_Gun->SetParticleEnergy(particle_Energy); particle_Gun->SetParticlePosition(gun_Position); particle_Gun->SetParticlePolarization(particle_Polarization); } FCALPrimaryGeneratorAction::~FCALPrimaryGeneratorAction() { delete generator_Messenger; delete particle_Gun; } void FCALPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) { particle_Gun->GeneratePrimaryVertex(anEvent); // generate the particle } void FCALPrimaryGeneratorAction::setParticleEnergy(G4double new_Value) { particle_Energy = new_Value; particle_Gun->SetParticleEnergy(particle_Energy); } void FCALPrimaryGeneratorAction::setGunPosition(G4ThreeVector new_Value) { G4ThreeVector gun_Position = new_Value; particle_Gun->SetParticlePosition(gun_Position); }