ATLAS Offline Software
xAODTruthParticleSlimmerLightLepton.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "AthLinks/ElementLink.h"
7 
10 
11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/DataSvc.h"
13 #include "GaudiKernel/PhysicalConstants.h"
14 
18 
19 #include "xAODTruth/TruthEvent.h"
21 
23 
25  : AthReentrantAlgorithm(name, svcLoc)
26 {
27 }
28 
30 {
33  return StatusCode::SUCCESS;
34 }
35 
36 StatusCode xAODTruthParticleSlimmerLightLepton::execute(const EventContext& context) const
37 {
38  // If the containers already exists then assume that nothing needs to be done
39  if (evtStore()->contains<xAOD::TruthParticleContainer>(m_xaodTruthParticleContainerNameLightLeptonKey.key()))
40  {
41  ATH_MSG_WARNING("xAOD LightLeptons Truth Particles are already available in the event");
42  return StatusCode::SUCCESS;
43  }
44 
45  // Create new output container
47  ATH_CHECK(xTruthParticleContainerLightLepton.record(std::make_unique<xAOD::TruthParticleContainer>(), std::make_unique<xAOD::TruthParticleAuxContainer>()));
48 
50  if (!xTruthEventContainerReadHandle.isValid()) {
51  ATH_MSG_ERROR("Could not retrieve xAOD::TruthEventContainer with key:" <<
53  return StatusCode::FAILURE;
54  }
55 
57  for (itr = xTruthEventContainerReadHandle->begin(); itr!=xTruthEventContainerReadHandle->end(); ++itr) {
58 
59  unsigned int nPart = (*itr)->nTruthParticles();
60  std::vector<int> uniqueID_list;
61  int zero_uniqueID=0;
62  int dup_uniqueID=0;
63 
64  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
65  const xAOD::TruthParticle* particle = (*itr)->truthParticle(iPart);
66 
67  int my_uniqueID = HepMC::uniqueID(particle);
68  if ( my_uniqueID == HepMC::UNDEFINED_ID ) {
69  zero_uniqueID++;
70  continue;
71  }
72  bool found = false;
73  if (uniqueID_list.size() > 0){
74  found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
75  if(found) {
76  dup_uniqueID++;
77  continue;}
78  }
79  uniqueID_list.push_back(my_uniqueID);
80 
81 
82  //Save stable Electrons & Muons
84  {
85  xAOD::TruthParticle *xTruthParticle = new xAOD::TruthParticle();
86  xTruthParticleContainerLightLepton->push_back( xTruthParticle );
87 
88  // Fill with numerical content
89  *xTruthParticle=*particle;
90  }
91  if (zero_uniqueID != 0 || dup_uniqueID != 0) ATH_MSG_INFO("Found " << zero_uniqueID << " uniqueID 0 particles and " <<dup_uniqueID << "duplicated");
92  }
93 
94  }
95 
96  return StatusCode::SUCCESS;
97 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
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
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TruthParticleContainer.h
xAODTruthParticleSlimmerLightLepton::m_xaodTruthParticleContainerNameLightLeptonKey
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNameLightLeptonKey
Definition: xAODTruthParticleSlimmerLightLepton.h:37
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAODTruthParticleSlimmerLightLepton.h
TruthParticleAuxContainer.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAODTruthParticleSlimmerLightLepton::xAODTruthParticleSlimmerLightLepton
xAODTruthParticleSlimmerLightLepton(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: xAODTruthParticleSlimmerLightLepton.cxx:24
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
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::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:56
xAODTruthParticleSlimmerLightLepton::m_xaodTruthEventContainerNameReadHandleKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerNameReadHandleKey
The key for the output xAOD truth containers.
Definition: xAODTruthParticleSlimmerLightLepton.h:35
xAODTruthParticleSlimmerLightLepton::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: xAODTruthParticleSlimmerLightLepton.cxx:29
xAODTruthParticleSlimmerLightLepton::execute
virtual StatusCode execute(const EventContext &context) const
Function executing the algorithm.
Definition: xAODTruthParticleSlimmerLightLepton.cxx:36
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition: HepMCHelpers.h:45
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TruthParticle.h
TruthEventContainer.h
HepMCHelpers.h
TruthEvent.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
isMuon
bool isMuon(const T &p)
Definition: AtlasPID.h:170