ATLAS Offline Software
Loading...
Searching...
No Matches
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
20
22
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
31StatusCode 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
37 output_decorator (m_decorKey, ctx);
38
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
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) {
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
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
Handle class for reading from StoreGate.
static int find_match(const xAOD::TruthParticle *p, const xAOD::TruthParticleContainer *c)
SG::ReadHandleKey< xAOD::IParticleContainer > m_recoKey
Parameter: input collection key.
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::ReadHandleKeyArray< xAOD::TruthParticleContainer > m_targetKeys
Parameter: target collection.
virtual StatusCode initialize() override final
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decorKey
Parameter: output decoration.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Handle class for adding a decoration to an object.
Class providing the definition of the 4-vector interface.
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 index.py:1
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any)
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.