ATLAS Offline Software
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"
9 #include "StoreGate/ReadHandle.h"
10 #include "StoreGate/WriteHandle.h"
12 
13 #include "RedoTruthLinksAlg.h"
14 
15 
16 using namespace std;
17 
18 namespace xAODMaker {
19 
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
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
RedoTruthLinksAlg.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAODMaker
Definition: StoreGateSvc.h:70
std::stable_sort
void stable_sort(std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, std::reverse_iterator< DataModel_detail::iterator< DVL > > end, Compare comp)
Specialization of stable_sort for DataVector/List.
Definition: DVL_algorithms.h:711
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
WriteHandle.h
Handle class for recording to StoreGate.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
xAOD::TruthEvent_v1
Class describing a signal truth event in the MC record.
Definition: TruthEvent_v1.h:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:28
MagicNumbers.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
ReadHandle.h
Handle class for reading from StoreGate.
TruthEventContainer.h
TruthEvent.h