Geant4 freezes with particles > 100000

When I simulate more than around 100,000 particles Geant4 will freeze. I’m running it via using

/run/beamOn 100000

and Geant4 will simply freeze then. Are there some options I can use to avoid this?
Maybe running it in batch mode only, or so? Or visualize only each 100th particle or the like?

Certainly for such a large number of events you should disable vis:


Normally we expect users to run a small number of events with vis, enough to check that everything looks OK. Then for production, run in batch. Or if you want to be lazy and run interactively, disable the vis.

If you would like to see every 100th event, there are ways of doing that. You would have to write some code in your EventAction::EndOfEventAction, something like:

  G4EventManager* evMan = G4EventManager::GetEventManager();
  if (evMan->GetConstCurrentEvent()->GetEventID() % 100 == 0) {



Let me know if this works for you.

1 Like

Hi allison,
thank you very much for your input! I would like to test it but it seems I followed an example which doesn’t use EventAction. I can only find RunAction(). I guess my code is quite similar to extended/eventgenerator/particlegun Hence, I’m not sure where to insert the code.
Shall I simply add EventAction() (e.g. from the B-examples) to my code or where exactly could/would I add above lines?
Thanks in advance!

Best, Ben

There must be some sort of “action” in any example because that is the only way to get information out. To do what you want you need EventAction, SteppingAction or a G4VSensitiveDetector::ProcessHits.

But yes, if you really, really want to see every 100th event (but why?), it would be good to add an EventAction. You would add those lines (as I said above) in 'EventAction::EndOfEventAction`.

1 Like