There is some difference when I using GPS and ParticleGun

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version:11.3.2
Operating System:linux
Compiler/Version:gcc9
CMake Version:cmake 3.16


Dear G4expert:

There is some difference when I used the GPS and ParticleGun to sumulate neutron capture ,I found that the quantity of capture atom is quiet different , the quantity of using ParticleGun is twice as GPS.Of course the particle source conditions are same.

Particle source is set as isotropic mono neutron

Hi Tang yi

ParticleGun and GPS have some commands in common, and if you use only those commands the results should be the same. But the ParticleGun does not have any commands for “isotropic mono neutron” so I am not surprised the results are different.

John

Thank you for your reply.The ParticleGun does not have any commands for “isotropic mono neutron” so I wrote the code myself to implement this feature.

Mmm. Perhaps you should let us see your code. For example, an isotropic distribution is uniform in cos(theta), not theta. To be safe, use G4RandomDirection.

Thank you for your reply.ok,This is my code.

Please read the guidance above. Screenshots of text are not useful.

ok,I have changed.

G4double z=4UniformRand()*length-length*/2.0;*

G4double *phi=2**CLHEP::pi *G4UniformRand();

G4double x=radius *std::cos(phi);

G4double y=radius *std::sin(phi);
fParticleGun->SetParticlePosition(G4ThreeVector(x,y,z));
G4double costheta=2.G4UniformRand()-1;

G4double sintheta=std::sqrt(1.-costhetacostheta);

G4double phi2=2.*CLHEP::pi *G4UniformRand();

G4double dx=sintheta *std::cos(phi2);

G4double dy=sintheta * std::sin(phi2);

G4double dz = costheta;

fParticleGun->SetParticleMomentumDirection(G4ThreeVector(dx, dy, dz));

Looks OK. Did it make any difference?

Actually, apologies, I meant to recommend G4RandomDirection

fParticleGun->SetParticleMomentumDirection(G4RandomDirrection);

is all that’s needed for direction.

fParticleGun->SetParticleMomentumDirection(G4RandomDirection());

Thank you .Do I just change this?

For goodness sake, just try it and tell us if it works!!

OK,thank you. I will have a try.