ATLAS Offline Software
xAODDecaysFinalStateFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // GeneratorFilters/DecaysFinalStateFilter
6 //
7 // Picks events with a given number of quarks, leptons and neutrinos from
8 // decays of a list of specified resonances (e.g. W, Z, ...).
9 // Will work only if resonances are explicitly included in event record.
10 //
11 // Examples:
12 //
13 // topAlg.DecaysFinalStateFilter.PDGAllowedParents = [ 23 ]
14 // topAlg.DecaysFinalStateFilter.NQuarks = 2
15 // topAlg.DecaysFinalStateFilter.NChargedLeptons = 2
16 // -> picks semileptonic ZZ decays
17 //
18 // topAlg.DecaysFinalStateFilter.PDGAllowedParents = [ 23, 24, -24 ]
19 // topAlg.DecaysFinalStateFilter.NQuarks = 2
20 // topAlg.DecaysFinalStateFilter.NChargedLeptons = 2
21 // -> allows W(qq)Z(ll) and Z(qq)Z(ll)
22 //
23 // Requirements can be put on each lepton flavor individually or on charged
24 // leptons inclusively. To put requirements on a single lepton flavor, set
25 // the corresponding property while leaving the properties for the other
26 // lepton flavors as well as ChargedLeptons as their default values.
27 //
28 // Authors:
29 // Kerim Suruliz Nov 2014
30 // Frank Siegert Nov 2014
31 // Jason Veatch Nov 2023
32 
34 //#include "GaudiKernel/MsgStream.h"
35 #include <cmath>
36 
37 
38 xAODDecaysFinalStateFilter::xAODDecaysFinalStateFilter(const std::string& name, ISvcLocator* pSvcLocator)
39  : GenFilter(name,pSvcLocator)
40 {
41  declareProperty("PDGAllowedParents", m_PDGAllowedParents);
42 
43  declareProperty("NQuarks", m_NQuarks = -1);
44  declareProperty("NElectrons", m_NElectrons = -1);
45  declareProperty("NMuons", m_NMuons = -1);
46  declareProperty("NTaus", m_NTaus = -1);
47  declareProperty("NChargedLeptons", m_NChargedLeptons = -1);
48  declareProperty("NNeutrinos", m_NNeutrinos = -1);
49  declareProperty("NPhotons", m_NPhotons = -1);
50 
51  declareProperty("MinNQuarks", m_MinNQuarks = 0);
52  declareProperty("MinNElectrons", m_MinNElectrons = 0);
53  declareProperty("MinNMuons", m_MinNMuons = 0);
54  declareProperty("MinNTaus", m_MinNTaus = 0);
55  declareProperty("MinNChargedLeptons", m_MinNChargedLeptons = 0);
56  declareProperty("MinNNeutrinos", m_MinNNeutrinos = 0);
57  declareProperty("MinNPhotons", m_MinNPhotons = 0);
58 }
59 
60 
62  int nElectrons = 0;
63  int nMuons = 0;
64  int nTaus = 0;
65  int nChargedLeptons = 0;
66  int nQuarks = 0;
67  int nNeutrinos = 0;
68  int nPhotons = 0;
69 
70 // Retrieve TruthGen container from xAOD Gen slimmer, contains all particles witout barcode_zero and
71 // duplicated barcode ones
72  const xAOD::TruthParticleContainer* xTruthParticleContainer;
73  if (evtStore()->retrieve(xTruthParticleContainer, "TruthGen").isFailure()) {
74  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthGen" << " found in StoreGate!");
75  return StatusCode::FAILURE;
76  }
77 
78 
79  // Loop over all particles in the event and build up the grid
80  unsigned int nPart = xTruthParticleContainer->size();
81  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
82  const xAOD::TruthParticle* part = (*xTruthParticleContainer)[iPart];
83 
84  // look only at the allowed parents (e.g. W, Z)
85  bool allowedParent = false;
86  for (size_t i=0; i<m_PDGAllowedParents.size(); ++i) {
87  if ( part->pdgId() == m_PDGAllowedParents[i]) allowedParent = true;
88  }
89  if (!allowedParent) continue;
90 
91  if (!part->decayVtx()) continue;
92  const xAOD::TruthVertex* decayVertex = part->decayVtx();
93  int num_outgoing_particles = decayVertex->nOutgoingParticles();
94 
95  for (int iOutPart = 0; iOutPart< num_outgoing_particles; iOutPart++) {
96  const xAOD::TruthParticle* out_part = decayVertex->outgoingParticle(iOutPart);
97  int apid = std::abs(out_part->pdgId());
98  if (apid == 1 || apid == 2 || apid == 3 || apid == 4 || apid ==5) nQuarks++;
99  if (apid == 11) { nElectrons++; nChargedLeptons++; }
100  if (apid == 13) { nMuons++; nChargedLeptons++; }
101  if (apid == 15) { nTaus++; nChargedLeptons++; }
102  if (apid == 12 || apid == 14 || apid == 16) nNeutrinos++;
103  if (apid == 22) nPhotons++;
104  }
105 
106  }//loop over TruthParticles
107 
108 
109  if (nQuarks < m_MinNQuarks || (m_NQuarks != -1 && nQuarks != m_NQuarks)) {
110  setFilterPassed(false);
111  }
112  else if (nElectrons < m_MinNElectrons || (m_NElectrons != -1 && nElectrons != m_NElectrons)) {
113  setFilterPassed(false);
114  }
115  else if (nMuons < m_MinNMuons || (m_NMuons != -1 && nMuons != m_NMuons)) {
116  setFilterPassed(false);
117  }
118  else if (nTaus < m_MinNTaus || (m_NTaus != -1 && nTaus != m_NTaus)) {
119  setFilterPassed(false);
120  }
121  else if (nChargedLeptons < m_MinNChargedLeptons || (m_NChargedLeptons != -1 && nChargedLeptons != m_NChargedLeptons)) {
122  setFilterPassed(false);
123  }
124  else if (nNeutrinos < m_MinNNeutrinos || (m_NNeutrinos != -1 && nNeutrinos != m_NNeutrinos)) {
125  setFilterPassed(false);
126  }
127  else if (nPhotons < m_MinNPhotons || (m_NPhotons != -1 && nPhotons != m_NPhotons)) {
128  setFilterPassed(false);
129  }
130  else {
131  setFilterPassed(true);
132  }
133  return StatusCode::SUCCESS;
134 }
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.
xAODDecaysFinalStateFilter::m_MinNChargedLeptons
int m_MinNChargedLeptons
Definition: xAODDecaysFinalStateFilter.h:60
xAODDecaysFinalStateFilter::m_MinNQuarks
int m_MinNQuarks
Definition: xAODDecaysFinalStateFilter.h:60
xAODDecaysFinalStateFilter::m_NPhotons
int m_NPhotons
Definition: xAODDecaysFinalStateFilter.h:56
xAODDecaysFinalStateFilter::m_MinNNeutrinos
int m_MinNNeutrinos
Definition: xAODDecaysFinalStateFilter.h:60
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAODDecaysFinalStateFilter::m_NElectrons
int m_NElectrons
Definition: xAODDecaysFinalStateFilter.h:56
xAODDecaysFinalStateFilter::xAODDecaysFinalStateFilter
xAODDecaysFinalStateFilter(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: xAODDecaysFinalStateFilter.cxx:38
xAODDecaysFinalStateFilter::m_MinNPhotons
int m_MinNPhotons
Definition: xAODDecaysFinalStateFilter.h:60
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
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:41
xAODDecaysFinalStateFilter.h
xAODDecaysFinalStateFilter::m_MinNTaus
int m_MinNTaus
Definition: xAODDecaysFinalStateFilter.h:60
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAODDecaysFinalStateFilter::m_NNeutrinos
int m_NNeutrinos
Definition: xAODDecaysFinalStateFilter.h:56
xAODDecaysFinalStateFilter::m_NQuarks
int m_NQuarks
Definition: xAODDecaysFinalStateFilter.h:56
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
xAODDecaysFinalStateFilter::m_MinNMuons
int m_MinNMuons
Definition: xAODDecaysFinalStateFilter.h:60
xAODDecaysFinalStateFilter::m_NTaus
int m_NTaus
Definition: xAODDecaysFinalStateFilter.h:56
xAODDecaysFinalStateFilter::m_PDGAllowedParents
std::vector< int > m_PDGAllowedParents
Definition: xAODDecaysFinalStateFilter.h:52
xAODDecaysFinalStateFilter::filterEvent
virtual StatusCode filterEvent()
Do the filtering.
Definition: xAODDecaysFinalStateFilter.cxx:61
xAODDecaysFinalStateFilter::m_NChargedLeptons
int m_NChargedLeptons
Definition: xAODDecaysFinalStateFilter.h:56
xAODDecaysFinalStateFilter::m_MinNElectrons
int m_MinNElectrons
Definition: xAODDecaysFinalStateFilter.h:60
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
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
xAODDecaysFinalStateFilter::m_NMuons
int m_NMuons
Definition: xAODDecaysFinalStateFilter.h:56