PDG Encoding wrong for gamma?

Hello,

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

Why aren’t you comparing PDGEncoding with itself?

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;

excellent question! I must have been blind…
thanks for your solution

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())
1 Like

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