Why do the same particle conditions in PrimaryGeneratorAction.cc and .mac file give different results?

Hi!
I’m trying to simulate the gamma production due to neutron activation in carbon. An official project in ./examples/extended/radioactivedecay/Activation was run. I created a C.mac file where the command for setting up the neutron source is:

/gun/particle neutron
/gun/energy 14 meV

And then I got the gamma spectrum:
C.mac.pdf (13.5 KB)

When I comment out these codes in C.mac:
#/gun/particle neutron
#/gun/energy 14 meV
and write the same information in PrimaryGeneratorAction.cc:
void PrimaryGeneratorAction::SetDefaultKinematic()
{
G4ParticleDefinition* particle
= G4ParticleTable::GetParticleTable()->FindParticle(“neutron”);
fParticleGun->SetParticleDefinition(particle);
fParticleGun->SetParticleEnergy(14MeV);
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
G4double position = -0.45
(fDetector->GetWorldSizeX());
fParticleGun->SetParticlePosition(G4ThreeVector(position,0.*cm,0.*cm));
}
I got the gamma spectrum:
CommentOut.pdf (15.3 KB)
I do not know Why the same particle conditions in PrimaryGeneratorAction.cc and .mac file give different results? Are the two ways of setting up particles actually different?
Thank you very much for your help!

If this is a copy-paste of your code, theres a couple syntax issues with the units - your particle energy should be defined as 14*MeV, rather than just 14MeV. Similarly, I would be sure to give your particle position definition a unit e.g. position * cm, rather than leaving it unitless.

Also, in your macro, note that meV (millielectron volts) is different to MeV in your code (megaelectron volts) - make sure to be consistent on which you mean!

Make sure you’ve got the units header included, try these changes and see if it helps?

Dear LEley22,
Thank you for your reply. I conducted a new experiment according to your advice. I did incorrectly set the energy to 14MeV, which should be 0.014eV. As a beginner in nuclear physics and geant4, your reply helps me a lot.

1 Like