ATLAS Offline Software
Loading...
Searching...
No Matches
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
12
13#include "RedoTruthLinksAlg.h"
14
15
16using namespace std;
17
18namespace xAODMaker {
19
21
22 // initialize handles
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
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::WriteHandleKey< xAODTruthParticleLinkVector > m_truthLinkContainerKey
The key for the output xAOD truth containers.
virtual StatusCode initialize() override
Function initialising the algorithm.
SG::ReadHandleKey< xAOD::TruthEventContainer > m_linksOnlyTruthEventContainerKey
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
int uniqueID(const T &p)
STL namespace.
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition TruthEvent.h:17