Why it always shows me 10e+9?


I want to output energy of particle emitted by particlegun. But it always give me 10e+9.

I write this code in runaction.

This will give you the energy that you have set in your primary generator action class.
Please check there that what is the energy you have set for particle gun in that class.
This will show the output here if you do G4cout.
Hope this will help you !
priyanshu

I know. But I did not set it as 1000MeV. I set it as different energy. But it always give me this. I did not set 1000MeV in particlegun.

in the snippet you postet, it looks to me as if you create a new G4ParticleGun, and immediately afterwards query for GetParticleEnergy(). Where exactly do you specify the different energy?
I don’t know for sure, but I would not be surprised if that 1GeV is some sort of an initial value…

fyi: I think that particle source definition (new G4ParticleGun, in your example) belongs in the class that refers to G4VUserPrimaryGeneratorAction. Check the examples for inspiration, e.g.: examples/basic/B1/src/B1PrimaryGeneratorAction.cc · geant4-10.7-release · geant4 / geant4 · GitLab

I specified different energy in .mac file.