00001 // 00002 // $Id: PrimaryGeneratorAction.cc 168 2008-09-16 13:23:52Z maire $ 00003 // 00004 // 00005 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00006 00007 #include "PrimaryGeneratorAction.hh" 00008 00009 #include "DetectorConstruction.hh" 00010 #include "PrimaryGeneratorMessenger.hh" 00011 00012 #include "G4Event.hh" 00013 #include "G4ParticleGun.hh" 00014 #include "G4ParticleTable.hh" 00015 #include "G4ParticleDefinition.hh" 00016 00017 #include "Randomize.hh" 00018 00019 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00020 00021 PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* det) 00022 :m_detector(det) 00023 { 00024 m_particleGun = new G4ParticleGun(1); 00025 G4ParticleDefinition* particle 00026 = G4ParticleTable::GetParticleTable()->FindParticle("proton"); 00027 m_particleGun->SetParticleDefinition(particle); 00028 m_particleGun->SetParticleEnergy(500*MeV); 00029 00030 m_rndmFlag = "on"; 00031 00032 //create a messenger for this class 00033 m_gunMessenger = new PrimaryGeneratorMessenger(this); 00034 } 00035 00036 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00037 00038 PrimaryGeneratorAction::~PrimaryGeneratorAction() 00039 { 00040 delete m_particleGun; 00041 delete m_gunMessenger; 00042 } 00043 00044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00045 00046 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 00047 { 00048 //this function is called at the begining of event 00049 // 00050 G4double y0 = (m_detector->GetWorldSizeXY())*0.5; 00051 G4double x0 = 0., z0 = 0.; 00052 if (m_rndmFlag == "on") { 00053 x0 = (m_detector->GetWorldSizeXY())*(G4UniformRand()-0.5); 00054 z0 = (m_detector->GetWorldSizeZ()) *(G4UniformRand()-0.5); 00055 } 00056 00057 m_particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); 00058 m_particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,-1.,0.)); 00059 m_particleGun->GeneratePrimaryVertex(anEvent); 00060 } 00061 00062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00063