Distinguish particles detected

I am currently editing the rdecay01 example so I can detect the gamma particles generated by the decay of Neon-24. The detector is not only counting detections from gammas, but also electrons and neutrinos. I am not sure what I should call in order to get the particle name. I am currently retrieving the copy number of the detector and the event id, and I would like to get the particle id from each hit as well. Thanks!

`G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *R
G4Track *track = aStep->GetTrack();


    G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
    G4StepPoint *postStepPoint = aStep->GetPostStepPoint();

    G4ThreeVector posPhoton = preStepPoint->GetPosition();

    const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();

    G4int copyNo = touchable->GetCopyNumber();

    G4cout << "Copy number: " << copyNo << G4endl;

    G4int evt = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();

    G4cout << "Event id: " << evt << G4endl;

    return true;


This code is a modified version of the tutorial on Physics Matters on Youtube.

Don’t get the name, use the particle definition pointer. Thus:

if (track->GetDefinition() == G4Electron::Definition()) { G4cout << " got an electron!" << G4endl;
if (track->GetDefinition() == G4Gamma::Definition()) { G4cout << " got a photon!" << G4endl;
if (track->GetDefinition() == G4Lambda::Definition()) { G4cout << " got a hyperon!" << G4endl;

and so on. Obviously you need the corresponding #includes for the different particle types.

If you want the particle name, for printing or to put into your N-tuple, G4ParticleDefinition::GetParticleName() is the function.

1 Like

It worked! Thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.