Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
xAODTruthParticleSlimmerGen.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 #include "AthLinks/ElementLink.h"
7 
9 
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/DataSvc.h"
12 #include "GaudiKernel/PhysicalConstants.h"
13 
17 
19 
21 
23 
24 xAODTruthParticleSlimmerGen::xAODTruthParticleSlimmerGen(const std::string &name, ISvcLocator *svcLoc)
25  : AthAlgorithm(name, svcLoc)
26 {
27 }
28 
30 {
32  ATH_MSG_INFO("xAOD output TruthParticleContainerGen name = " << m_xaodTruthParticleContainerNameGen.key());
34  ATH_CHECK(m_classif.retrieve());
35 
36  return StatusCode::SUCCESS;
37 }
38 
40 {
41  const EventContext& ctx = Gaudi::Hive::currentContext(); // As not re-entrant
42  // Create new output container
44  ATH_CHECK(xTruthParticleContainerGen.record(std::make_unique<xAOD::TruthParticleContainer>(),
45  std::make_unique<xAOD::TruthParticleAuxContainer>()));
46  ATH_MSG_INFO("Recorded TruthParticleContainerGen with key: " << m_xaodTruthParticleContainerNameGen.key());
47 
48  // Retrieve full TruthEventContainer container
50  if ( !xTruthEventContainer.isValid() )
51  {
52  ATH_MSG_ERROR("No TruthEvent collection with name " << m_xaodTruthEventContainerName << " found in StoreGate!");
53  return StatusCode::FAILURE;
54  }
55 
56  // Loop over full TruthParticle container
58  for (itr = xTruthEventContainer->begin(); itr!=xTruthEventContainer->end(); ++itr) {
59 
60  unsigned int nPart = (*itr)->nTruthParticles();
61  std::vector<int> uniqueID_list;
62  int zero_uniqueID=0;
63  int dup_uniqueID=0;
64 
65  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
66  const xAOD::TruthParticle* theParticle = (*itr)->truthParticle(iPart);
67 
68  const int my_uniqueID = HepMC::uniqueID(theParticle);
69  if (my_uniqueID == HepMC::UNDEFINED_ID ) {
70  zero_uniqueID++;
71  continue;
72  }
73  bool found = false;
74  if (uniqueID_list.size() > 0){
75  found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
76  if(found) {
77  dup_uniqueID++;
78  continue;}
79  }
80  uniqueID_list.push_back(my_uniqueID);
81 
82 
83 
84  xAOD::TruthParticle *xTruthParticle = new xAOD::TruthParticle();
85  xTruthParticleContainerGen->push_back( xTruthParticle );
86  // Fill with numerical content
87  *xTruthParticle=*theParticle;
88 
89  }
90  if (zero_uniqueID != 0 || dup_uniqueID != 0) ATH_MSG_INFO("Found " << zero_uniqueID << " uniqueID=0 particles and " << dup_uniqueID << " duplicated");
91  }
92 
93  return StatusCode::SUCCESS;
94 }
95 
96 
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
xAODTruthParticleSlimmerGen.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TruthParticleContainer.h
xAODTruthParticleSlimmerGen::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: xAODTruthParticleSlimmerGen.cxx:39
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
xAODTruthParticleSlimmerGen::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: xAODTruthParticleSlimmerGen.cxx:29
xAODTruthParticleSlimmerGen::m_xaodTruthEventContainerName
SG::ReadHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerName
Definition: xAODTruthParticleSlimmerGen.h:33
TruthParticleAuxContainer.h
IMCTruthClassifier.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:56
xAODTruthParticleSlimmerGen::xAODTruthParticleSlimmerGen
xAODTruthParticleSlimmerGen(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: xAODTruthParticleSlimmerGen.cxx:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAODTruthParticleSlimmerGen::m_xaodTruthParticleContainerNameGen
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNameGen
The key for the output xAOD truth containers.
Definition: xAODTruthParticleSlimmerGen.h:32
xAODTruthParticleSlimmerGen::m_classif
PublicToolHandle< IMCTruthClassifier > m_classif
Definition: xAODTruthParticleSlimmerGen.h:35
TruthParticle.h
HepMCHelpers.h