Track ID of the secondary electrons was 0

I want to count the TrackID of the electron created by the photon emitted, but I found that the TrackID of the electron are all 0, I think it’s a mistake somewhere. By the way, I also output it’s parentID, it’s name and it’s energy , and it works well.

I hope someone can tell me why, I also write the details in my code, thank you very much!

Here is my code
SteppingAction.cc (5.2 KB)

_Geant4 Version:_11.2.1
_Operating System:_GNU ld (GNU Binutils) 2.37
_Compiler/Version:_11.2.0
_CMake Version:_GNU Make 4.3


It might be worthwhile to try passing the secondaries vector to your TrackingAction and trying to record their track IDs in the PostUserTrackingAction instead.

It is possible that the trackID isn’t zero but merely casting an undefined variable.
Really you want to use

G4TrackVector* secondaries = fpTrackingManager->GimmeSecondaries();
size_t nSeco = secondaries->size();

if (nSeco > 0){
     for(size_t i=0; i < nSeco; i++) {
             // (*secondaries)[i] is the secondaries of the current track
             // your code here
          }
}

This might be hard to chase avoid double counting/pointless CPU time checking sets in the stepping action. @ctwhite is right that this is better to handle in the PostUserTrackingAction and it will be significantly faster since it will check once and only once.