don’t want to use (slow?) string comparisons, so I tried to compare aStep->GetTrack()->GetParticleDefinition()->GetParticleDefinitionID()
with G4Gamma::Gamma()->GetPDGEncoding()
for incident gamma, this compares 12 == 22 → false
is this expected? Using version 10.7.2
G4ParticleDefintion* pd = aStep->GetTrack()->GetParticleDefinition();
if (pd->GetPDGEncoding() == G4Gamma::Gamma()->GetPDGEncoding())
G4cout << " Hey, I got a gamma!" << G4endl;
From reading G4ParticleDefinition.hh, it looks to me like that “ID” object is some sort of counter into the G4ParticleTable, rather than true particle type identifier:
protected:
inline G4int GetInstanceID() const;
// Returns the instance ID.
G4int g4particleDefinitionInstanceID;
// This field is used as instance ID.
public:
void SetParticleDefinitionID(G4int id=-1);
G4int GetParticleDefinitionID() const;
No problem, I do the same thing all the time. I also realized that my solution above was kind of silly. There’s no reason to dereference the PDs at all; they are guaranteed global singletons. You can match the track to a particular particle type with
if (aStep->GetTrack()->GetParticleDefinition() == G4Gamma::Gamma())