ATLAS Offline Software
Loading...
Searching...
No Matches
HitsTruthRelinkBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8HitsTruthRelinkBase::HitsTruthRelinkBase(const std::string &name, ISvcLocator *pSvcLocator)
9 : AthReentrantAlgorithm(name, pSvcLocator)
10{
11}
12
13
15{
16 // Check and initialize keys
18 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_inputTruthCollectionKey);
19 return StatusCode::SUCCESS;
20}
21
22
23StatusCode HitsTruthRelinkBase::getReferenceBarcode(const EventContext &ctx, int *barcode) const
24{
26 if (!inputCollection.isValid()) {
27 ATH_MSG_ERROR("Could not get input truth collection " << inputCollection.name() << " from store " << inputCollection.store());
28 return StatusCode::FAILURE;
29 }
30 ATH_MSG_DEBUG("Found input truth collection " << inputCollection.name() << " in store " << inputCollection.store());
31
32 const HepMC::GenEvent *genEvt = *(inputCollection->begin());
33
34 size_t nVertices = genEvt->vertices_size();
35 if (nVertices == 0) {
36 ATH_MSG_ERROR("Truth collection should have at least one vertex!");
37 return StatusCode::FAILURE;
38 }
39 const HepMC::ConstGenVertexPtr& genVtx = genEvt->vertices().back();
40 size_t nParticles = genVtx->particles_out().size();
41 if (nParticles == 0) {
42 ATH_MSG_ERROR("Truth vertex should have at least one particle!");
43 return StatusCode::FAILURE;
44 }
45 *barcode = HepMC::barcode(genVtx->particles_out().front());
46 ATH_MSG_DEBUG("Reference barcode: " << *barcode);
47
48 return StatusCode::SUCCESS;
49
50}
51
52
53StatusCode HitsTruthRelinkBase::getReferenceId(const EventContext &ctx, int *id) const
54{
56 if (!inputCollection.isValid()) {
57 ATH_MSG_ERROR("Could not get input truth collection " << inputCollection.name() << " from store " << inputCollection.store());
58 return StatusCode::FAILURE;
59 }
60 ATH_MSG_DEBUG("Found input truth collection " << inputCollection.name() << " in store " << inputCollection.store());
61 int barcode{0};
62 const HepMC::GenEvent *genEvt = *(inputCollection->begin());
63
64 size_t nVertices = genEvt->vertices_size();
65 if (nVertices == 0) {
66 ATH_MSG_ERROR("Truth collection should have at least one vertex!");
67 return StatusCode::FAILURE;
68 }
69 const HepMC::ConstGenVertexPtr& genVtx = genEvt->vertices().back();
70 size_t nParticles = genVtx->particles_out().size();
71 if (nParticles == 0) {
72 ATH_MSG_ERROR("Truth vertex should have at least one particle!");
73 return StatusCode::FAILURE;
74 }
75 *id = HepMC::uniqueID(genVtx->particles_out().front());
76 barcode = HepMC::barcode(genVtx->particles_out().front());
77
78 ATH_MSG_DEBUG("Reference id: " << *id);
79 ATH_MSG_DEBUG("Reference barcode: " << barcode);
80
81 return StatusCode::SUCCESS;
82
83}
84
85HepMcParticleLink HitsTruthRelinkBase::updatedLink(const EventContext &ctx, const HepMcParticleLink& oldLink, int referenceId, int /*pdgId*/) const {
86 ATH_MSG_DEBUG ("oldLink.id() = " << oldLink.id());
87 int currentId{};
88 // Hits previously linked to truth particles should now be linked to the reference truthParticle
89 if ( HepMC::uniqueID(oldLink) != HepMC::UNDEFINED_ID || HepMC::barcode(oldLink) != HepMC::UNDEFINED_ID ) { // FIXME barcode-based for now to work around reading in HepMcParticleLink_p2 based EDM
90 currentId = referenceId;
91 }
92 // TODO test using the ConstGenParticlePtr directly in the HepMcParticleLink constructor
94 if (currentId != 0) {
96 }
97 return newLink;
98}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
@ EBC_PU_SUPPRESSED
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode initialize() override
StatusCode getReferenceBarcode(const EventContext &ctx, int *barcode) const
SG::ReadHandleKey< McEventCollection > m_inputTruthCollectionKey
virtual HepMcParticleLink updatedLink(const EventContext &ctx, const HepMcParticleLink &oldLink, int referenceId, int pdgID=0) const
StatusCode getReferenceId(const EventContext &ctx, int *id) const
HitsTruthRelinkBase(const std::string &name, ISvcLocator *pSvcLocator)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
int barcode(const T *p)
Definition Barcode.h:15
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition GenVertex.h:24
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39