ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::TruthLinkRepointTool Class Reference

#include <TruthLinkRepointTool.h>

Inheritance diagram for DerivationFramework::TruthLinkRepointTool:
Collaboration diagram for DerivationFramework::TruthLinkRepointTool:

Public Member Functions

virtual StatusCode initialize () override final
virtual StatusCode addBranches (const EventContext &ctx) const override final

Static Private Member Functions

static int find_match (const xAOD::TruthParticle *p, const xAOD::TruthParticleContainer *c)

Private Attributes

SG::ReadHandleKey< xAOD::IParticleContainerm_recoKey
 Parameter: input collection key.
SG::WriteDecorHandleKey< xAOD::IParticleContainerm_decorKey {this, "OutputDecoration", m_recoKey, "TruthLink", "Name of the output decoration on the reco object"}
 Parameter: output decoration.
SG::ReadHandleKeyArray< xAOD::TruthParticleContainerm_targetKeys {this, "TargetCollections", {"TruthMuons","TruthPhotons","TruthElectrons"}, "Name of target truth collections"}
 Parameter: target collection.

Detailed Description

Definition at line 23 of file TruthLinkRepointTool.h.

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::TruthLinkRepointTool::addBranches ( const EventContext & ctx) const
finaloverridevirtual

Definition at line 31 of file TruthLinkRepointTool.cxx.

31 {
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) {
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}
#define ATH_MSG_FATAL(x)
static int find_match(const xAOD::TruthParticle *p, const xAOD::TruthParticleContainer *c)
SG::ReadHandleKey< xAOD::IParticleContainer > m_recoKey
Parameter: input collection key.
SG::ReadHandleKeyArray< xAOD::TruthParticleContainer > m_targetKeys
Parameter: target collection.
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decorKey
Parameter: output decoration.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
str index
Definition DeMoScan.py:362
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.

◆ find_match()

int DerivationFramework::TruthLinkRepointTool::find_match ( const xAOD::TruthParticle * p,
const xAOD::TruthParticleContainer * c )
staticprivate

Definition at line 69 of file TruthLinkRepointTool.cxx.

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}
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.

◆ initialize()

StatusCode DerivationFramework::TruthLinkRepointTool::initialize ( )
finaloverridevirtual

Definition at line 23 of file TruthLinkRepointTool.cxx.

23 {
24 ATH_CHECK(m_recoKey.initialize());
25 ATH_CHECK(m_targetKeys.initialize());
26 ATH_CHECK(m_decorKey.initialize());
27 return StatusCode::SUCCESS;
28}
#define ATH_CHECK
Evaluate an expression and check for errors.

Member Data Documentation

◆ m_decorKey

SG::WriteDecorHandleKey<xAOD::IParticleContainer> DerivationFramework::TruthLinkRepointTool::m_decorKey {this, "OutputDecoration", m_recoKey, "TruthLink", "Name of the output decoration on the reco object"}
private

Parameter: output decoration.

Definition at line 36 of file TruthLinkRepointTool.h.

36{this, "OutputDecoration", m_recoKey, "TruthLink", "Name of the output decoration on the reco object"};

◆ m_recoKey

SG::ReadHandleKey<xAOD::IParticleContainer> DerivationFramework::TruthLinkRepointTool::m_recoKey
private
Initial value:
{this,"RecoCollection", "Muons",
"Name of reco collection for decoration"}

Parameter: input collection key.

Definition at line 33 of file TruthLinkRepointTool.h.

33 {this,"RecoCollection", "Muons",
34 "Name of reco collection for decoration"};

◆ m_targetKeys

SG::ReadHandleKeyArray<xAOD::TruthParticleContainer> DerivationFramework::TruthLinkRepointTool::m_targetKeys {this, "TargetCollections", {"TruthMuons","TruthPhotons","TruthElectrons"}, "Name of target truth collections"}
private

Parameter: target collection.

Definition at line 38 of file TruthLinkRepointTool.h.

38{this, "TargetCollections", {"TruthMuons","TruthPhotons","TruthElectrons"}, "Name of target truth collections"};

The documentation for this class was generated from the following files: