Give the survived particle set as an input beam

Hello Geant4 experts,

I want to simulate the low probability interaction process with a gaseous target.
To achieve significant interaction statistics, I would like to create an interaction loop when the primary beam output is provided as the beam input afterwards. I know that it could be done with input and output files.

But is there any way to avoid this in favor of better performance?

Any implementation example will be helpful.

Best wishes,

Volodymyr

Hi, I have found a simple solution.

Detector behind the target checks if the particle is primary and resets its initial time and position and randomizes slightly other parameters within a defined distribution.
The number of such rewinds controlled by the counter or if all particles lost the primary status.

Best wishes,

Volodymyr