ATLAS Offline Software
xAODParticleDecayFilter.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 
7 xAODParticleDecayFilter::xAODParticleDecayFilter(const std::string &name, ISvcLocator *pSvcLocator)
8  : GenFilter(name, pSvcLocator)
9 {
10 }
11 
13 {
14  ATH_MSG_INFO("xAODParticleDecayFilter::filterInitialize()");
15 
16  // initialize the ReadHandleKey
17  ATH_CHECK(m_truthEventsKey.initialize());
18 
19  return StatusCode::SUCCESS;
20 }
21 
23 {
24  ATH_MSG_INFO("xAODParticleDecayFilter::filterFinalize()");
25  return StatusCode::SUCCESS;
26 }
27 
29 {
30 
31  ATH_MSG_DEBUG("xAODParticleDecayFilter::filterEvent()");
32 
33  //Create child targets - a map of pdgId along with how many particles
34  //with that pdgId that we want
35  std::map<int, unsigned int> childTargets;
36 
37  //loop over children pdgId and setup counters for each particle type
38  for (auto childPdgId : m_pdgIdChildren.value())
39  {
40  //for charged parents we don't check the charge of children, in order to support both possible conjugate decay modes
41  if (!m_checkCharge) childPdgId = std::abs(childPdgId);
42  if (childTargets.end() != childTargets.find(childPdgId)) childTargets[childPdgId] += 1;
43  else childTargets[childPdgId] = 1;
44  }
45 
46  ATH_MSG_DEBUG("xAODParticleDecayFilter::filterEvent()");
47 // Retrieve TruthGen container from xAOD Gen slimmer, contains all particles witout barcode_zero and
48 // duplicated barcode ones
49  const xAOD::TruthParticleContainer* xTruthParticleContainer;
50  if (evtStore()->retrieve(xTruthParticleContainer, "TruthGen").isFailure()) {
51  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthGen" << " found in StoreGate!");
52  return StatusCode::FAILURE;
53  }
54 
55  // Loop over all particles in the event
56  unsigned int nPart = xTruthParticleContainer->size();
57  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
58  const xAOD::TruthParticle* particle = (*xTruthParticleContainer)[iPart];
59 
60  ATH_MSG_DEBUG("pdg code of this particle in the event is " << particle->pdgId() << " with status " << particle->status());
61  //maps with key pdgId and value of number of particles with that pdgId
62  std::map<int, unsigned int> childCounters;
63  //counter for any children not in the specified list of children
64  int nonListValue = -999;
65  childCounters[nonListValue] = 0;
66 
67  //loop over children pdgId and setup counters for each particle type
68  for (auto childPdgId : m_pdgIdChildren.value()) childCounters[childPdgId] = 0;
69 
70  // check if the parent particle id is found
71  if (std::abs(particle->pdgId()) == static_cast<int>(m_pdgIdParent))
72  {
73  const xAOD::TruthVertex *decayVtx = particle->decayVtx();
74  ATH_MSG_DEBUG("Number of children is " << decayVtx->nOutgoingParticles());
75  //loop over children and count number of particles with each pdgId
76  int outgoing_particles = decayVtx->nOutgoingParticles();
77  for (int part = 0; part < outgoing_particles; part++)
78  {
79  const xAOD::TruthParticle *thisChild = decayVtx->outgoingParticle(part);
80  int childPdgId = thisChild->pdg_id();
81  if (!m_checkCharge) childPdgId = std::abs(childPdgId);
82  ATH_MSG_DEBUG("Child " << thisChild);
83  if (childTargets.end() != childTargets.find(childPdgId)) childCounters[childPdgId] += 1;
84  else childCounters[nonListValue] += 1;
85  }
86 
87  //check if the targeted number of children of each type have been found
88  if (std::all_of(childTargets.begin(), childTargets.end(), [&](const std::pair<unsigned int, unsigned int> &p) { return p.second == childCounters[p.first]; }) && childCounters[nonListValue] == 0)
89  {
90  ATH_MSG_DEBUG("Filter passed");
91  setFilterPassed(true);
92  return StatusCode::SUCCESS;
93  }
94  } // end if particle has parent pdg id
95  } // end loop over particles
96 
97 
98  // if we get here, no particle was found with the required set of children
99  setFilterPassed(false);
100  return StatusCode::SUCCESS;
101 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::TruthVertex_v1::nOutgoingParticles
size_t nOutgoingParticles() const
Get the number of outgoing particles.
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
xAODParticleDecayFilter::xAODParticleDecayFilter
xAODParticleDecayFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODParticleDecayFilter.cxx:7
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAODParticleDecayFilter::filterEvent
StatusCode filterEvent() override
Definition: xAODParticleDecayFilter.cxx:28
xAOD::TruthParticle_v1::pdg_id
int pdg_id() const
PDG ID code.
Definition: TruthParticle_v1.h:56
xAODParticleDecayFilter::filterFinalize
StatusCode filterFinalize() override
Definition: xAODParticleDecayFilter.cxx:22
xAODParticleDecayFilter::filterInitialize
StatusCode filterInitialize() override
Definition: xAODParticleDecayFilter.cxx:12
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODParticleDecayFilter::m_truthEventsKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventsKey
ReadHandle for the TruthEvents.
Definition: xAODParticleDecayFilter.h:32
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAODParticleDecayFilter::m_pdgIdParent
Gaudi::Property< unsigned int > m_pdgIdParent
Particle ID of parent particle.
Definition: xAODParticleDecayFilter.h:35
xAODParticleDecayFilter::m_checkCharge
Gaudi::Property< bool > m_checkCharge
Toggle whether we check the charge of children particles.
Definition: xAODParticleDecayFilter.h:41
xAODParticleDecayFilter.h
xAODParticleDecayFilter::m_pdgIdChildren
Gaudi::Property< std::vector< int > > m_pdgIdChildren
Particle IDs of children of parent particle.
Definition: xAODParticleDecayFilter.h:38
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::TruthVertex_v1::outgoingParticle
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
Definition: TruthVertex_v1.cxx:121