#include "LGPrimaryGeneratorAction.hh" #include "LGPrimaryGeneratorMessenger.hh" #include "G4Event.hh" #include "G4ParticleGun.hh" #include "G4ParticleTable.hh" #include "G4ParticleDefinition.hh" #include LGPrimaryGeneratorAction::LGPrimaryGeneratorAction(G4int randomdir) { generator_Messenger = new LGPrimaryGeneratorMessenger(this); RandomDir = randomdir; RandGen.setTheSeed(38470987038941); // G4ThreeVector gun_Position(0.1*cm, 0.1*cm, -36.*cm); // the position of the particle gun G4ThreeVector gun_Position(0., 0., -60.*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 = 2.76*eV; // 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("opticalphoton"); 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); } LGPrimaryGeneratorAction::~LGPrimaryGeneratorAction() { delete generator_Messenger; delete particle_Gun; } void LGPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) { if (RandomDir) { G4double x = RandGen.flat()*2.5 - 1.25; //G4double y = RandGen.flat()*6.0 - 3.0; G4double y = 0.; G4ThreeVector gun_Position; gun_Position.set(x*cm, y*cm, -60.0*cm); G4double theta = RandGen.flat()*M_PI/2. ; G4double phi = RandGen.flat()*M_PI*2. ; G4double dz = cos(theta); G4double dr = sin(theta); G4double dx = dr*cos(phi); G4double dy = dr*sin(phi); G4ThreeVector gun_Direction; gun_Direction.set(dx, dy, dz); particle_Gun->SetParticlePosition(gun_Position); particle_Gun->SetParticleMomentumDirection(gun_Direction); } particle_Gun->GeneratePrimaryVertex(anEvent); // generate the particle } void LGPrimaryGeneratorAction::setParticleEnergy(G4double new_Value) { particle_Energy = new_Value; particle_Gun->SetParticleEnergy(particle_Energy); } void LGPrimaryGeneratorAction::setGunPosition(G4ThreeVector new_Value) { G4ThreeVector gun_Position = new_Value; particle_Gun->SetParticlePosition(gun_Position); }