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#ifdef HEPMC3
40 const HepMC::ConstGenVertexPtr& genVtx = genEvt->vertices().back();
41 size_t nParticles = genVtx->particles_out().size();
42 if (nParticles == 0) {
43 ATH_MSG_ERROR("Truth vertex should have at least one particle!");
44 return StatusCode::FAILURE;
45 }
46 *barcode = HepMC::barcode(genVtx->particles_out().front());
47#else
48 auto genVtx = *(genEvt->vertices_end());
49 size_t nParticles = genVtx->particles_out_size();
50 if (nParticles == 0) {
51 ATH_MSG_ERROR("Truth vertex should have at least one particle!");
52 return StatusCode::FAILURE;
53 }
54 *barcode = HepMC::barcode(*(genVtx->particles_out_const_begin()));
55#endif
56
57 ATH_MSG_DEBUG("Reference barcode: " << *barcode);
58
59 return StatusCode::SUCCESS;
60
61}
62
63
64StatusCode HitsTruthRelinkBase::getReferenceId(const EventContext &ctx, int *id) const
65{
67 if (!inputCollection.isValid()) {
68 ATH_MSG_ERROR("Could not get input truth collection " << inputCollection.name() << " from store " << inputCollection.store());
69 return StatusCode::FAILURE;
70 }
71 ATH_MSG_DEBUG("Found input truth collection " << inputCollection.name() << " in store " << inputCollection.store());
72 int barcode{0};
73 const HepMC::GenEvent *genEvt = *(inputCollection->begin());
74
75 size_t nVertices = genEvt->vertices_size();
76 if (nVertices == 0) {
77 ATH_MSG_ERROR("Truth collection should have at least one vertex!");
78 return StatusCode::FAILURE;
79 }
80#ifdef HEPMC3
81 const HepMC::ConstGenVertexPtr& genVtx = genEvt->vertices().back();
82 size_t nParticles = genVtx->particles_out().size();
83 if (nParticles == 0) {
84 ATH_MSG_ERROR("Truth vertex should have at least one particle!");
85 return StatusCode::FAILURE;
86 }
87 *id = HepMC::uniqueID(genVtx->particles_out().front());
88 barcode = HepMC::barcode(genVtx->particles_out().front());
89#else
90 auto genVtx = *(genEvt->vertices_end());
91 size_t nParticles = genVtx->particles_out_size();
92 if (nParticles == 0) {
93 ATH_MSG_ERROR("Truth vertex should have at least one particle!");
94 return StatusCode::FAILURE;
95 }
96 *id = HepMC::uniqueID(*(genVtx->particles_out_const_begin()));
97 barcode = HepMC::barcode(*(genVtx->particles_out_const_begin()));
98#endif
99
100 ATH_MSG_DEBUG("Reference id: " << *id);
101 ATH_MSG_DEBUG("Reference barcode: " << barcode);
102
103 return StatusCode::SUCCESS;
104
105}
106
107HepMcParticleLink HitsTruthRelinkBase::updatedLink(const EventContext &ctx, const HepMcParticleLink& oldLink, int referenceId, int /*pdgId*/) const {
108 ATH_MSG_DEBUG ("oldLink.id() = " << oldLink.id());
109 int currentId{};
110 // Hits previously linked to truth particles should now be linked to the reference truthParticle
111 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
112 currentId = referenceId;
113 }
114 // TODO test using the ConstGenParticlePtr directly in the HepMcParticleLink constructor
116 if (currentId != 0) {
118 }
119 return newLink;
120}
#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:16
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
const HepMC::GenVertex * ConstGenVertexPtr
Definition GenVertex.h:60