void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent){//this function is called at the begining of ecah event//更详细的粒子源定义,如果不需要可以不填写
fParticleGun->GeneratePrimaryVertex(anEvent);}
#include"Randomize.hh"// THE MOST IMPORTANT ONE// uniform random number in [0,1]
G4double u =G4UniformRand();// other distributions
G4double uGauss = G4RandGauss::shoot(mu,sigma);
G4double uExpo = G4RandExponential::shoot(mean);
G4double uFlat = G4RandFlat::shoot(a, b);
符合各种标准分布的随机数抽样描述在Randomize.hh
示例
//圆形面源均匀分布。无分散,即方向沿z方向
G4double size =1* mm;//源半径
G4double r = size *(G4UniformRand());
G4double theta =2.*3.14159265*G4UniformRand();
G4double x0 = r *cos(theta);
G4double y0 = r *sin(theta);
G4double z0 =-10.*mm;
fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));