Can I Detect the Particle Type from RunManager?

_Geant4 Version:_11.3.0
_Operating System:_Windows 10
_Compiler/Version:_MSVC 2022
_CMake Version:_3.31.4

I have provided a function in my code below:

G4bool SensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) {
    G4Track *track = aStep->GetTrack();

    G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
    G4StepPoint *postStepPoint = aStep->GetPostStepPoint(); //Issue with charged particles

    G4ThreeVector posParticle = postStepPoint -> GetPosition();

    G4cout << "Particle position " << posParticle << G4endl;

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

    G4AnalysisManager *man = G4AnalysisManager::Instance();
    
    man->FillNtupleIColumn(0, 0, evt); //Everything
    man->FillNtupleDColumn(0, 1, posParticle[0]);
    man->FillNtupleDColumn(0, 2, posParticle[1]);
    man->FillNtupleDColumn(0, 3, posParticle[2]);
    man->AddNtupleRow(0);

    return true;
}

I am curious if anyone can point me to any examples if they exist, is there a way to detect the particle type hitting my sensitive detector? If I need to provide any more code, please let me know.

Thank you

You have access to it in your step object or in the track:

track->GetDynamicParticle()->GetParticleDefinition()->GetParticleName()
1 Like

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