ATLAS Offline Software
ParticleDecayFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 ParticleDecayFilter::ParticleDecayFilter(const std::string& name, ISvcLocator* pSvcLocator)
8  : GenFilter(name, pSvcLocator)
9 {
10 
11 }
12 
14 {
15  ATH_MSG_INFO("ParticleDecayFilter::filterInitialize()");
16 
17  // initialize the ReadHandleKey
18  ATH_CHECK( m_truthEventsKey.initialize() );
19 
20  return StatusCode::SUCCESS;
21 }
22 
24 {
25  ATH_MSG_INFO("ParticleDecayFilter::filterFinalize()");
26  return StatusCode::SUCCESS;
27 }
28 
29 
31 
32  ATH_MSG_DEBUG("ParticleDecayFilter::filterEvent()");
33 
34  //Create child targets - a map of pdgId along with how many particles
35  //with that pdgId that we want
36  std::map<int, unsigned int> childTargets;
37 
38  //loop over children pdgId and setup counters for each particle type
39  for (auto childPdgId : m_pdgIdChildren.value()){
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  //loop over truth events
48  for (truthEvent = events()->begin(); truthEvent != events()->end(); ++truthEvent){
49 
50  // get the truth particles
51  const HepMC::GenEvent* genEvent = (*truthEvent);
52 
53  // loop over all particles
54  for (auto particle : *genEvent){
55  ATH_MSG_DEBUG("particle in the event is " << particle);
56 
57  //maps with key pdgId and value of number of particles with that pdgId
58  std::map<int, unsigned int> childCounters;
59  //counter for any children not in the specified list of children
60  int nonListValue = -999;
61  childCounters[nonListValue]= 0;
62 
63  //loop over children pdgId and setup counters for each particle type
64  for (auto childPdgId : m_pdgIdChildren.value()) childCounters[childPdgId] = 0;
65 
66  // check if the parent particle id is found
67  if (std::abs(particle->pdg_id()) == static_cast<int>(m_pdgIdParent)){
68  const HepMC::ConstGenVertexPtr& decayVtx = particle->end_vertex();
69  ATH_MSG_DEBUG("Number of children is " << decayVtx->particles_out_size());
70  //loop over children and count number of particles with each pdgId
71  for(auto thisChild: *decayVtx) {
72  int childPdgId = thisChild->pdg_id();
73  if (!m_checkCharge) childPdgId = std::abs(childPdgId);
74  ATH_MSG_DEBUG("Child " << thisChild);
75  if (childTargets.end() != childTargets.find(childPdgId)) childCounters[childPdgId] += 1;
76  else childCounters[nonListValue] += 1;
77  }
78 
79  //check if the targeted number of children of each type have been found
80  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){
81  ATH_MSG_DEBUG("Filter passed");
82  setFilterPassed(true);
83  return StatusCode::SUCCESS;
84  }
85  }// end if particle has parent pdg id
86  }// end loop over particles
87  }//loop over truth events
88 
89  // if we get here, no particle was found with the required set of children
90  setFilterPassed(false);
91  return StatusCode::SUCCESS;
92 }
ParticleDecayFilter::m_checkCharge
Gaudi::Property< bool > m_checkCharge
Toggle whether we check the charge of children particles.
Definition: ParticleDecayFilter.h:41
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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
ParticleDecayFilter.h
ParticleDecayFilter::filterEvent
StatusCode filterEvent()
Definition: ParticleDecayFilter.cxx:30
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
ParticleDecayFilter::ParticleDecayFilter
ParticleDecayFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ParticleDecayFilter.cxx:7
ParticleDecayFilter::m_truthEventsKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventsKey
ReadHandle for the TruthEvents.
Definition: ParticleDecayFilter.h:32
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ParticleDecayFilter::m_pdgIdChildren
Gaudi::Property< std::vector< int > > m_pdgIdChildren
Particle IDs of children of parent particle.
Definition: ParticleDecayFilter.h:38
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
ParticleDecayFilter::m_pdgIdParent
Gaudi::Property< unsigned int > m_pdgIdParent
Particle ID of parent particle.
Definition: ParticleDecayFilter.h:35
ParticleDecayFilter::filterFinalize
StatusCode filterFinalize()
Definition: ParticleDecayFilter.cxx:23
ParticleDecayFilter::filterInitialize
StatusCode filterInitialize()
Definition: ParticleDecayFilter.cxx:13