Get particle type in event action when using multiple sources

I simulated a PET scanner in which I placed two point sources.
In my macro file, I created now two different sources: one FDG source and one Na source:

/gps/ion 9 18 0 0 # F-18
/gps/energy 0
/gps/pos/type Volume
/gps/pos/shape Cylinder
/gps/pos/centre 6 10 0
/gps/pos/radius 1 mm
/gps/pos/halfz 0 mm
/gps/ang/type iso
/gps/source/add 5
/gps/particle ion
/gps/ion 11 22 0 0 # Na22
/gps/energy 0 keV
/gps/pos/type Volume
/gps/pos/shape Cylinder
/gps/pos/centre 0 0 0
/gps/pos/radius 1 mm
/gps/ang/type iso

When I run my program with this macro, I get correct results (I can reconstruct my image and obtain the sources at the right position).
However, in my event action file I would need to know which source is at the moment ‘active’. So from each source the current event is coming from. Is there a possibility to do so?

Thanks in advance,

Elisabeth

Yes. From the G4Event* argument, you can get the G4PrimaryVertex that was created, and within that, access the G4PrimaryParticle list that was generated. With your GPS setup, you’ll only have a single vertex and single particle, which makes the access easy. Look at the .hh files for the classes to see what functions to call.

One note. I don’t remember off hand whether the BeginOfEventAction() is called after, or before, the PrimaryGenerator. If it’s called before, then you would have to put your “source identification” code into EndOfEventAction().

Thanks a lot for the suggestions! It works :slight_smile: