ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
Tools
McEventCollectionFilter
src
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
5
#include "
HitsTruthRelinkBase.h
"
6
#include "
TruthUtils/MagicNumbers.h
"
7
8
HitsTruthRelinkBase::HitsTruthRelinkBase
(
const
std::string &name, ISvcLocator *pSvcLocator)
9
:
AthReentrantAlgorithm
(name, pSvcLocator)
10
{
11
}
12
13
14
StatusCode
HitsTruthRelinkBase::initialize
()
15
{
16
// Check and initialize keys
17
ATH_CHECK
(
m_inputTruthCollectionKey
.initialize() );
18
ATH_MSG_VERBOSE
(
"Initialized ReadHandleKey: "
<<
m_inputTruthCollectionKey
);
19
return
StatusCode::SUCCESS;
20
}
21
22
23
StatusCode
HitsTruthRelinkBase::getReferenceBarcode
(
const
EventContext &ctx,
int
*barcode)
const
24
{
25
SG::ReadHandle<McEventCollection>
inputCollection(
m_inputTruthCollectionKey
, ctx);
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
53
StatusCode
HitsTruthRelinkBase::getReferenceId
(
const
EventContext &ctx,
int
*
id
)
const
54
{
55
SG::ReadHandle<McEventCollection>
inputCollection(
m_inputTruthCollectionKey
, ctx);
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
85
HepMcParticleLink
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
93
HepMcParticleLink
newLink(currentId, oldLink.
eventIndex
(),
HepMcParticleLink::IS_EVENTNUM
,
HepMcParticleLink::IS_ID
, ctx);
94
if
(currentId != 0) {
95
newLink.
setTruthSuppressionType
(
EBC_PU_SUPPRESSED
);
96
}
97
return
newLink;
98
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
HitsTruthRelinkBase.h
MagicNumbers.h
EBC_PU_SUPPRESSED
@ EBC_PU_SUPPRESSED
Definition
MagicNumbers.h:31
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
HepMcParticleLink
a link optimized in size for a GenParticle in a McEventCollection
Definition
HepMcParticleLink.h:72
HepMcParticleLink::IS_EVENTNUM
@ IS_EVENTNUM
Definition
HepMcParticleLink.h:79
HepMcParticleLink::id
int id() const
Return the id of the target particle.
Definition
HepMcParticleLink.cxx:283
HepMcParticleLink::IS_ID
@ IS_ID
Definition
HepMcParticleLink.h:84
HepMcParticleLink::eventIndex
index_type eventIndex() const
Return the event number of the referenced GenEvent.
Definition
HepMcParticleLink.cxx:337
HepMcParticleLink::setTruthSuppressionType
void setTruthSuppressionType(EBC_SUPPRESSED_TRUTH truthSupp)
Return whether the truth particle has been suppressed.
HitsTruthRelinkBase::initialize
virtual StatusCode initialize() override
Definition
HitsTruthRelinkBase.cxx:14
HitsTruthRelinkBase::getReferenceBarcode
StatusCode getReferenceBarcode(const EventContext &ctx, int *barcode) const
Definition
HitsTruthRelinkBase.cxx:23
HitsTruthRelinkBase::m_inputTruthCollectionKey
SG::ReadHandleKey< McEventCollection > m_inputTruthCollectionKey
Definition
HitsTruthRelinkBase.h:26
HitsTruthRelinkBase::updatedLink
virtual HepMcParticleLink updatedLink(const EventContext &ctx, const HepMcParticleLink &oldLink, int referenceId, int pdgID=0) const
Definition
HitsTruthRelinkBase.cxx:85
HitsTruthRelinkBase::getReferenceId
StatusCode getReferenceId(const EventContext &ctx, int *id) const
Definition
HitsTruthRelinkBase.cxx:53
HitsTruthRelinkBase::HitsTruthRelinkBase
HitsTruthRelinkBase(const std::string &name, ISvcLocator *pSvcLocator)
Definition
HitsTruthRelinkBase.cxx:8
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition
StoreGate/src/VarHandleBase.cxx:382
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition
AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
HepMC::barcode
int barcode(const T *p)
Definition
Barcode.h:15
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:89
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition
MagicNumbers.h:57
HepMC::ConstGenVertexPtr
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition
GenVertex.h:24
HepMC::GenEvent
HepMC3::GenEvent GenEvent
Definition
GenEvent.h:39
Generated on
for ATLAS Offline Software by
1.17.0