Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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"
11 
12 #include "RedoTruthLinksAlg.h"
13 
14 
15 using namespace std;
16 
17 namespace xAODMaker {
18 
20 
21  // initialize handles
22  ATH_CHECK(m_truthLinkContainerKey.initialize());
23  ATH_CHECK(m_linksOnlyTruthEventContainerKey.initialize());
24  ATH_MSG_DEBUG("xAOD linksOnlyTruthEventContainer name = " << m_linksOnlyTruthEventContainerKey.key() );
25  ATH_MSG_DEBUG("xAOD TruthParticleLinksContainer name = " << m_truthLinkContainerKey.key());
26  return StatusCode::SUCCESS;
27  }
28 
29 
30  StatusCode RedoTruthLinksAlg::execute(const EventContext& ctx) const {
31 
32  SG::WriteHandle truthLinkVec{m_truthLinkContainerKey, ctx};
33  ATH_CHECK(truthLinkVec.record(std::make_unique<xAODTruthParticleLinkVector>()));
34 
35 
36  SG::ReadHandle xTruthEventContainer {m_linksOnlyTruthEventContainerKey, ctx};
37  // validity check is only really needed for serial running. Remove when MT is only way.
38  ATH_CHECK(xTruthEventContainer.isValid());
39 
40  // Loop over events and particles
41  for (const xAOD::TruthEvent* evt : *xTruthEventContainer) {
42  for (const auto& par : evt->truthParticleLinks()) {
43  if ( !par.isValid() ) {
44  // This can happen if particles have been thinned.
45  ATH_MSG_VERBOSE("Found invalid particle element link in TruthEvent"); //< @todo Use HepMC evt number?
46  continue;
47  }
48  // Create link between HepMC and xAOD truth
50  truthLinkVec->push_back(std::make_unique<xAODTruthParticleLink>(HepMcParticleLink(HepMC::barcode(*par), 0, HepMcParticleLink::IS_POSITION, HepMcParticleLink::IS_BARCODE), par)); // FIXME is barcode-based - using barcodes until xAOD::TruthParticle::id() is available
51  }
52  }
53 
54  std::stable_sort(truthLinkVec->begin(), truthLinkVec->end(), SortTruthParticleLink());
55  ATH_MSG_VERBOSE("Summarizing truth link size: " << truthLinkVec->size() );
56 
57  return StatusCode::SUCCESS;
58  }
59 } // 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:72
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::barcode
int barcode(const T *p)
Definition: Barcode.h:16
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:29
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
ReadHandle.h
Handle class for reading from StoreGate.
TruthEventContainer.h
TruthEvent.h