ATLAS Offline Software
Loading...
Searching...
No Matches
TrackHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4#include <utility>
5
8#include "G4Track.hh"
12
13namespace
14{
15 HepMC::ConstGenParticlePtr outputAttributionParticle(const TrackInformation* trackInfo)
16 {
17 if (!trackInfo) {
18 return nullptr;
19 }
20 // Output links should remain anchored to the pre-regeneration particle.
21 // Older TrackInformation instances may only have the current particle.
22 HepMC::ConstGenParticlePtr particle = trackInfo->GetGenerationZeroGenParticle();
23 return particle ? particle : trackInfo->GetCurrentGenParticle();
24 }
25}
26
27TrackHelper::TrackHelper(const G4Track* t)
28{
29 G4VUserTrackInformation* userInfo = t ? t->GetUserInformation() : nullptr;
30 m_trackInfo = dynamic_cast<VTrackInformation*>(userInfo);
31}
32
38{
39 if (m_trackInfo==0) return false;
40 return m_trackInfo->GetClassification()==VTrackInformation::Primary;
41}
43{
44 if (m_trackInfo==0) return false;
45 return m_trackInfo->GetClassification()==VTrackInformation::RegeneratedPrimary;
46}
48{
49 if (m_trackInfo==0) return false;
50 return m_trackInfo->GetClassification()==VTrackInformation::RegisteredSecondary;
51}
53{
54 if (m_trackInfo==0) return true;
55 return m_trackInfo->GetClassification()==VTrackInformation::Secondary;
56}
57int TrackHelper::GetBarcode() const // TODO Drop this once UniqueID and Status are used instead
58{
59 if (const TrackInformation* concreteInfo = dynamic_cast<const TrackInformation*>(m_trackInfo)) {
60 HepMC::ConstGenParticlePtr particle = outputAttributionParticle(concreteInfo);
61 return particle ? HepMC::barcode(particle) : 0;
62 }
63 return m_trackInfo ? m_trackInfo->GetParticleBarcode() : 0;
64}
65
67{
68 if (const TrackInformation* concreteInfo = dynamic_cast<const TrackInformation*>(m_trackInfo)) {
69 HepMC::ConstGenParticlePtr particle = outputAttributionParticle(concreteInfo);
70 return particle ? HepMC::uniqueID(particle) : 0;
71 }
72 return m_trackInfo ? m_trackInfo->GetParticleUniqueID() : 0;
73}
74
76{
77 if (const TrackInformation* concreteInfo = dynamic_cast<const TrackInformation*>(m_trackInfo)) {
78 HepMC::ConstGenParticlePtr particle = outputAttributionParticle(concreteInfo);
79 return particle ? particle->status() : 0;
80 }
81 return m_trackInfo ? m_trackInfo->GetParticleStatus() : 0;
82}
83
85{
86 return m_trackInfo ? m_trackInfo->GetPrimaryGenParticle() : nullptr;
87}
88
90{
91 return m_trackInfo ? std::as_const(m_trackInfo)->GetPrimaryGenParticle() : nullptr;
92}
TrackInformation * GetTrackInformation()
Return concrete TrackInformation when callers need fields that are not part of the VTrackInformation ...
TrackHelper(const G4Track *t)
bool IsPrimary() const
VTrackInformation * m_trackInfo
Definition TrackHelper.h:66
bool IsSecondary() const
int GetBarcode() const
Return the truth barcode/id/status used for detector output.
bool IsRegisteredSecondary() const
HepMC::GenParticlePtr GetPrimaryGenParticle()
Return the primary truth particle associated with this track.
bool IsRegeneratedPrimary() const
int GetUniqueID() const
int GetStatus() const
Implementation of VTrackInformation.
Instances of classes derived from this class are attached as UserInformation to G4Tracks.
int barcode(const T *p)
Definition Barcode.h:15
int uniqueID(const T &p)
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses