Start position with n-tuple

I am simulating beam on to polystyrene tube.
If I generate the beam a random position in xy plane and random angle, how can I output them in the n-tuple? (x0,y0, and angle)

Are you using your own PrimaryGeneratorAction or some other utilities(like the GPS) ? This may make the solution different (*).

But to make the solution general, you can create a UserTrackingAction. In the PreUserTrackingAction(const G4Track* track) the “track” is the one that will start its tracking. This track can be a primary track, from the generator, or a secondary (or a secondary of secondary…). To check if this comes from your generator, check the track ParentID, if 0, this is a fresh track from your generator.

Then from track, you can access the three vector of the momentum, and collect the information you need.

To store in a ntuple, you then have to look at basic examples, to see how to use the analysis package.


(*) If you’re using a PrimaryGeneratorAction, you can add your code to collect information in GeneratePrimaries().

Thank you for your answer. I solved this problem in another way.