About accessing the energy of the particle

Hello,
I created a code in which I count the total number of particles that deposit some energy > 0 in my detector in order to determine the total detection efficiency.

Now, I want to calculate the ‘full-energy-peak-efficiency’, and I think I need to introduce in my if condition, at the EndOfEventAction, the following: if( fEdep == energy of the photon at the beginning of event), but idk how to access that energy.

The question is, how can I access the energy with which my particle is created?

you can access the primary vertex of each event as described here:

and from there you can access the energy the primary (“the photon at the beginning of the event”) was equipped with.

I just want to count the number of photons that deposit all of their energy per event, in my if condition (line 19). This if only counts the photons that deposit some energy > 0 for now, but i want to count the photons that deposit all their energy.

if the particle is created by a physical process and not as primary, you can get the info from the track, using G4Track::GetVertexKineticEnergy.

https://apc.u-paris.fr/~franco/g4doxy/html/classG4Track.html#92fd0ff1c01b30a98793836851826270

keep in mind that you then need to keep track of the total deposit per track (and not per event) if you want to use this approach. you could use a std::map<G4int, G4double> for the fEdep instead of G4double, and use the TrackID as key.

this would be my approach, maybe there is something more elegant?

1 Like

The particle is generated with a GPS macro file, and I am adding its energy. I generate photons of 1 MeV, and I wanted to put in my if condition to count only if the energy deposited in detector is equal to the energy of my primary particle.