Energy deposit by the secondary particle

Hi Dear Geant4 User!
I tried to simulate the x-ray fluorescence process in Geant4. I’d the energy deposit by the primary particle (source) to the sample, and my huge problem is to know how to get or see the energy deposit by the secondary particle to the detector (the main x-ray fluorescence process) ? any idea about ?
thank for your help

You can query parent ID of the track.

// query for primary particle
if (track->GetParentID() == 0){

}

and particle type from “track->GetDefinition()”