#include "PrimaryGeneratorAction.hh" #include "G4LogicalVolumeStore.hh" #include "G4LogicalVolume.hh" #include "G4Box.hh" #include "G4RunManager.hh" #include "G4GeneralParticleSource.hh" #include "G4ParticleTable.hh" #include "G4ParticleDefinition.hh" #include "G4SystemOfUnits.hh" #include "Randomize.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... PrimaryGeneratorAction::PrimaryGeneratorAction() : G4VUserPrimaryGeneratorAction(), fGPS(0) { // Initialize the general particle source fGPS = new G4GeneralParticleSource(); // Set the particle type to gamma G4ParticleDefinition* particle = G4ParticleTable::GetParticleTable()->FindParticle("gamma"); fGPS->SetParticleDefinition(particle); // Set the energy of the gamma particles to 511 keV fGPS->GetCurrentSource()->GetEneDist()->SetMonoEnergy(511 * keV); // Set the initial position of the particles (e.g., at the origin) fGPS->SetParticlePosition(G4ThreeVector(0., 0., 0.)); // Optionally, set the direction of the particles (e.g., along the z-axis) fGPS->GetCurrentSource()->GetAngDist()->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.)); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... PrimaryGeneratorAction::~PrimaryGeneratorAction() { delete fGPS; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) { // Generate the primary vertex for the event fGPS->GeneratePrimaryVertex(anEvent); }