ATLAS Offline Software
Loading...
Searching...
No Matches
Event
xAOD
xAODTruthCnv
src
RedoTruthLinksAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
7
#include "
xAODTruth/TruthEvent.h
"
8
#include "
xAODTruth/TruthEventContainer.h
"
9
#include "
StoreGate/ReadHandle.h
"
10
#include "
StoreGate/WriteHandle.h
"
11
#include "
TruthUtils/MagicNumbers.h
"
12
13
#include "
RedoTruthLinksAlg.h
"
14
15
16
using namespace
std
;
17
18
namespace
xAODMaker
{
19
20
StatusCode
RedoTruthLinksAlg::initialize
() {
21
22
// initialize handles
23
ATH_CHECK
(
m_truthLinkContainerKey
.initialize());
24
ATH_CHECK
(
m_linksOnlyTruthEventContainerKey
.initialize());
25
ATH_MSG_DEBUG
(
"xAOD linksOnlyTruthEventContainer name = "
<<
m_linksOnlyTruthEventContainerKey
.key() );
26
ATH_MSG_DEBUG
(
"xAOD TruthParticleLinksContainer name = "
<<
m_truthLinkContainerKey
.key());
27
return
StatusCode::SUCCESS;
28
}
29
30
31
StatusCode
RedoTruthLinksAlg::execute
(
const
EventContext& ctx)
const
{
32
33
SG::WriteHandle
truthLinkVec{
m_truthLinkContainerKey
, ctx};
34
ATH_CHECK
(truthLinkVec.
record
(std::make_unique<xAODTruthParticleLinkVector>()));
35
36
37
SG::ReadHandle
xTruthEventContainer {
m_linksOnlyTruthEventContainerKey
, ctx};
38
// validity check is only really needed for serial running. Remove when MT is only way.
39
ATH_CHECK
(xTruthEventContainer.
isValid
());
40
41
// Loop over events and particles
42
for
(
const
xAOD::TruthEvent
* evt : *xTruthEventContainer) {
43
for
(
const
auto
& par : evt->truthParticleLinks()) {
44
if
( !par.isValid() ) {
45
// This can happen if particles have been thinned.
46
ATH_MSG_VERBOSE
(
"Found invalid particle element link in TruthEvent"
);
//< @todo Use HepMC evt number?
47
continue
;
48
}
49
// Create link between HepMC and xAOD truth
51
truthLinkVec->push_back(std::make_unique<xAODTruthParticleLink>(
HepMcParticleLink
(
HepMC::uniqueID
(*par), 0,
HepMcParticleLink::IS_POSITION
,
HepMcParticleLink::IS_ID
), par));
52
}
53
}
54
55
std::stable_sort
(truthLinkVec->begin(), truthLinkVec->end(),
SortTruthParticleLink
());
56
ATH_MSG_VERBOSE
(
"Summarizing truth link size: "
<< truthLinkVec->size() );
57
58
return
StatusCode::SUCCESS;
59
}
60
}
// namespace xAODMaker
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
MagicNumbers.h
RedoTruthLinksAlg.h
ReadHandle.h
Handle class for reading from StoreGate.
WriteHandle.h
Handle class for recording to StoreGate.
TruthEventContainer.h
TruthEvent.h
HepMcParticleLink
a link optimized in size for a GenParticle in a McEventCollection
Definition
HepMcParticleLink.h:72
HepMcParticleLink::IS_POSITION
@ IS_POSITION
Definition
HepMcParticleLink.h:80
HepMcParticleLink::IS_ID
@ IS_ID
Definition
HepMcParticleLink.h:84
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAODMaker::RedoTruthLinksAlg::m_truthLinkContainerKey
SG::WriteHandleKey< xAODTruthParticleLinkVector > m_truthLinkContainerKey
The key for the output xAOD truth containers.
Definition
RedoTruthLinksAlg.h:42
xAODMaker::RedoTruthLinksAlg::initialize
virtual StatusCode initialize() override
Function initialising the algorithm.
Definition
RedoTruthLinksAlg.cxx:20
xAODMaker::RedoTruthLinksAlg::m_linksOnlyTruthEventContainerKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_linksOnlyTruthEventContainerKey
Definition
RedoTruthLinksAlg.h:46
xAODMaker::RedoTruthLinksAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
Definition
RedoTruthLinksAlg.cxx:31
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:117
std
STL namespace.
std::stable_sort
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
Definition
DVL_algorithms.h:644
xAODMaker
Definition
StoreGateSvc.h:72
xAOD::TruthEvent
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition
TruthEvent.h:17
SortTruthParticleLink
Definition
xAODTruthParticleLink.h:17
Generated on
for ATLAS Offline Software by
1.14.0