ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkMCTruth
src
TruthLinkRepointTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// TruthLinkRepointTool.cxx
7
// Truth links on some objects point to the main truth particle
8
// container, or to some other container that won't be saved in the
9
// output derivation. This re-points the links from the old
10
// container to the new container (and serves as a chance to clean
11
// up / harmonize the names of the decorations).
12
13
#include "
TruthLinkRepointTool.h
"
14
#include "
xAODMuon/MuonContainer.h
"
15
#include "
xAODEgamma/ElectronContainer.h
"
16
#include "
xAODEgamma/PhotonContainer.h
"
17
#include "
xAODTruth/xAODTruthHelpers.h
"
18
#include "
xAODTruth/TruthParticleContainer.h
"
19
#include "
StoreGate/ReadHandle.h
"
20
21
#include "
TruthUtils/MagicNumbers.h
"
22
23
StatusCode
DerivationFramework::TruthLinkRepointTool::initialize
(){
24
ATH_CHECK
(
m_recoKey
.initialize());
25
ATH_CHECK
(
m_targetKeys
.initialize());
26
ATH_CHECK
(
m_decorKey
.initialize());
27
return
StatusCode::SUCCESS;
28
}
29
30
// Function to do dressing, implements interface in IAugmentationTool
31
StatusCode
DerivationFramework::TruthLinkRepointTool::addBranches
(
const
EventContext& ctx)
const
{
32
// Retrieve the truth collections
33
std::vector<const xAOD::TruthParticleContainer*> targets{};
34
targets.reserve(
m_targetKeys
.size());
35
36
SG::WriteDecorHandle<xAOD::IParticleContainer, ElementLink<xAOD::TruthParticleContainer>
>
37
output_decorator (
m_decorKey
, ctx);
38
39
for
(
const
SG::ReadHandleKey<xAOD::TruthParticleContainer>
& key :
m_targetKeys
) {
40
SG::ReadHandle<xAOD::TruthParticleContainer>
readHandle{key, ctx};
41
if
(!readHandle.
isValid
()) {
42
ATH_MSG_FATAL
(
"Failed to retrieve "
<<key.fullKey());
43
return
StatusCode::FAILURE;
44
}
45
targets.emplace_back(readHandle.
cptr
());
46
}
47
48
49
SG::ReadHandle<xAOD::IParticleContainer>
inputCont{
m_recoKey
, ctx};
50
if
(!inputCont.
isValid
()) {
51
ATH_MSG_FATAL
(
"Failed to retrieve "
<<
m_recoKey
.fullKey());
52
return
StatusCode::FAILURE;
53
}
54
for
(
const
xAOD::IParticle
* input : *inputCont) {
55
const
xAOD::TruthParticle
* truthPart =
xAOD::TruthHelpers::getTruthParticle
(*input);
56
output_decorator(*input) =
ElementLink<xAOD::TruthParticleContainer>
{};
57
for
(
const
xAOD::TruthParticleContainer
* target : targets) {
58
int
index
=
find_match
(truthPart, target);
59
60
if
(
index
>=0) output_decorator(*input) =
ElementLink<xAOD::TruthParticleContainer>
(*target,
index
);
61
62
}
63
}
64
65
return
StatusCode::SUCCESS;
66
}
67
68
// Find a match by unique ID in a different container
69
int
DerivationFramework::TruthLinkRepointTool::find_match
(
const
xAOD::TruthParticle
* p,
const
xAOD::TruthParticleContainer
* c)
70
{
71
// See if it's already gone
72
if
(!p)
return
-1;
73
// Look through the mini-collection
74
for
(
int
i=0;i<int(c->size());++i){
75
if
(c->at(i) &&
HepMC::is_same_particle
(p,c->at(i)))
return
i;
76
}
77
// Note: just fine if it wasn't in the mini-collection
78
return
-1;
79
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ElectronContainer.h
PhotonContainer.h
MuonContainer.h
TruthParticleContainer.h
MagicNumbers.h
ReadHandle.h
Handle class for reading from StoreGate.
TruthLinkRepointTool.h
DerivationFramework::TruthLinkRepointTool::find_match
static int find_match(const xAOD::TruthParticle *p, const xAOD::TruthParticleContainer *c)
Definition
TruthLinkRepointTool.cxx:69
DerivationFramework::TruthLinkRepointTool::m_recoKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_recoKey
Parameter: input collection key.
Definition
TruthLinkRepointTool.h:33
DerivationFramework::TruthLinkRepointTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition
TruthLinkRepointTool.cxx:31
DerivationFramework::TruthLinkRepointTool::m_targetKeys
SG::ReadHandleKeyArray< xAOD::TruthParticleContainer > m_targetKeys
Parameter: target collection.
Definition
TruthLinkRepointTool.h:38
DerivationFramework::TruthLinkRepointTool::initialize
virtual StatusCode initialize() override final
Definition
TruthLinkRepointTool.cxx:23
DerivationFramework::TruthLinkRepointTool::m_decorKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decorKey
Parameter: output decoration.
Definition
TruthLinkRepointTool.h:36
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition
StoreGate/StoreGate/ReadHandleKey.h:40
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
HepMC::is_same_particle
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
Definition
MagicNumbers.h:334
index
Definition
index.py:1
xAOD::TruthHelpers::getTruthParticle
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any).
Definition
xAODTruthHelpers.cxx:25
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
xAODTruthHelpers.h
Generated on
for ATLAS Offline Software by
1.17.0