ATLAS Offline Software
Loading...
Searching...
No Matches
xAODTruthParticleSlimmerLightLepton.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
10
11#include "GaudiKernel/MsgStream.h"
12#include "GaudiKernel/DataSvc.h"
13#include "GaudiKernel/PhysicalConstants.h"
14
18
21
23
25 : AthReentrantAlgorithm(name, svcLoc)
26{
27}
28
35
36StatusCode xAODTruthParticleSlimmerLightLepton::execute(const EventContext& context) const
37{
38 // If the containers already exists then assume that nothing needs to be done
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
83 if (MC::isStable(particle) && (MC::isElectron(particle) || MC::isMuon(particle)) )
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
ATLAS-specific HepMC functions.
An algorithm that can be simultaneously executed in multiple threads.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
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< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNameLightLeptonKey
The key for the output xAOD truth containers.
SG::ReadHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerNameReadHandleKey
virtual StatusCode initialize()
Function initialising the algorithm.
virtual StatusCode execute(const EventContext &context) const
Function executing the algorithm.
xAODTruthParticleSlimmerLightLepton(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
bool isElectron(const T &p)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isMuon(const T &p)
TruthParticle_v1 TruthParticle
Typedef to implementation.