Generate particles with gaussian momentum distribution

_Geant4 Version: 11.2.0
_Operating System: Windows 10 + WSL 2.0
_Compiler/Version: gcc 11.4.0
_CMake Version: 3.22.1

I wish that for each event the particle is generated with a random momentum from a gaussian distribution. Is this a correct way of doing so or should I be using something else like a General Particle Source?

MyPrimaryGenerator::MyPrimaryGenerator() {
    fParticleGun = new G4ParticleGun(1);

    G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();

    G4String particleName = "mu-";
    G4ParticleDefinition *particle = particleTable->FindParticle(particleName);

    G4ThreeVector pos(0., 0., 0.);
    G4ThreeVector mom(0., 0., 1.);

    fParticleGun->SetParticleMomentum(12. * MeV);

    sigma_perc = 0.01;

MyPrimaryGenerator::~MyPrimaryGenerator() { delete fParticleGun; }

void MyPrimaryGenerator::GeneratePrimaries(G4Event *anEvent) {

    G4double momentum = fParticleGun->GetParticleMomentum();
    G4double rand_momentum =
        G4RandGauss::shoot(momentum, sigma_perc * momentum);



The results I’m getting with these method seem very weird to me.

The weird results I was getting were due to the fact that I was using the already defined particle gun momentum as a parameter to de distribution. This was causing the distribution to change for each event in the run. I fixed it by using a constant to save the mean of the distribution.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.