ATLAS Offline Software
xAODMultiElecMuTauFilter.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 "CLHEP/Vector/LorentzVector.h"
8 
9 xAODMultiElecMuTauFilter::xAODMultiElecMuTauFilter(const std::string& name, ISvcLocator* pSvcLocator)
10  : GenFilter(name,pSvcLocator)
11 {
12 declareProperty("MinPt", m_minPt = 5000. );
13 declareProperty("MaxEta", m_maxEta = 10.0 );
14 declareProperty("MinVisPtHadTau", m_minVisPtHadTau = 10000.);
15 declareProperty("NLeptons", m_NLeptons = 4 );
16 declareProperty("IncludeHadTaus", m_incHadTau = true );
17 declareProperty("TwoSameSignLightLeptonsOneHadTau", m_TwoSameSignLightLeptonsOneHadTau = false );
18 }
19 
20 
22  int numLeptons = 0;
23  int numLightLeptons = 0;
24  int numHadTaus = 0;
26  if (m_NLeptons!=3) ATH_MSG_ERROR("TwoSameSignLightLeptonsOneHadTau request possible only for NLeptons = 3. Check your jobOptions.");
27  }
28  int charge1 = 0;
29  int charge2 = 0;
30 
31 // Retrieve TruthGen container from xAOD Gen slimmer, contains all particles witout barcode_zero and
32 // duplicated barcode ones
33  const xAOD::TruthParticleContainer* xTruthParticleContainer;
34  if (evtStore()->retrieve(xTruthParticleContainer, "TruthGen").isFailure()) {
35  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthGen" << " found in StoreGate!");
36  return StatusCode::FAILURE;
37  }
38 
39  // Loop over all particles in the event and build up the grid
40  unsigned int nPart = xTruthParticleContainer->size();
41  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
42  const xAOD::TruthParticle* pitr = (*xTruthParticleContainer)[iPart];
43  if (MC::isStable(pitr) && (std::abs(pitr->pdgId()) == 11 || std::abs(pitr->pdgId()) == 13)) {
44  if (pitr->pt() >= m_minPt && std::abs(pitr->eta()) <= m_maxEta) {
45  ATH_MSG_DEBUG("Found lepton" << pitr);
46  numLeptons++;
47  numLightLeptons++;
48  if (numLightLeptons==1) { if (pitr->pdgId() < 0) { charge1 = -1; } else { charge1 = 1; } }
49  if (numLightLeptons==2) { if (pitr->pdgId() < 0) { charge2 = -1; } else { charge2 = 1; } }
50  }
51  continue;
52  }
53  //Look for Hadronic taus (leptonic ones will be saved by above) that have status!=3 and don't decay to another tau (FSR)
54  if (!m_incHadTau) continue;
55  const xAOD::TruthParticle *tau= nullptr;
56  const xAOD::TruthParticle *taunu= nullptr;
57  if (!MC::isTau(pitr) || !MC::isPhysical(pitr)) continue;
58  tau = pitr;
59  if(!tau->decayVtx()) continue;
60  // Loop over children and:
61  // 1. Find if it is hadronic (i.e. no decay lepton).
62  // 2. Veto tau -> tau (FSR)
63  // 3. Store the tau neutino to calculate the visible momentum
64  size_t nout = tau->decayVtx()->nOutgoingParticles();
65  for (unsigned int iChild = 0; iChild < nout; ++iChild) {
66  const xAOD::TruthParticle* citr = tau->decayVtx()->outgoingParticle(iChild);
67  //Ignore tau -> tau (FSR)
68  if (pitr->pdgId() == citr->pdgId()) {
69  ATH_MSG_DEBUG("FSR tau decay. Ignoring!");
70  tau = nullptr;
71  break;
72  }
73  // Ignore leptonic decays
74  if (std::abs(citr->pdgId()) == 13 || std::abs(citr->pdgId()) == 11) {
75  tau = nullptr;
76  break;
77  }
78  // Find tau decay nu
79  if (std::abs(citr->pdgId()) == 16) {
80  taunu = citr;
81  }
82  }
83  if (tau) {
84  // Good hadronic decay
85  CLHEP::HepLorentzVector tauVisMom = CLHEP::HepLorentzVector(tau->px() - taunu->px(),
86  tau->py() - taunu->py(),
87  tau->pz() - taunu->pz(),
88  tau->e() - taunu->e());
89  if (tauVisMom.perp() >= m_minVisPtHadTau && std::abs(tauVisMom.eta()) <= m_maxEta) {
90  ATH_MSG_DEBUG("Found hadronic tau decay" << tau);
91  numLeptons++;
92  numHadTaus++;
93 
94  }
95  }
96  }//loop over TruthParticles
97 
98  bool passed_event = false;
100  if ( ((numLightLeptons+numHadTaus)==numLeptons) && numLightLeptons == 2 && numHadTaus == 1 && charge1==charge2 ) {
101  ATH_MSG_DEBUG("Found " << numLeptons << " Leptons: two same sign ligh leptons + one hadronic tau! Event passed.");
102  passed_event = true;
103  }
104  } else {
105  if ( numLeptons >= m_NLeptons ) {
106  ATH_MSG_DEBUG("Found " << numLeptons << " Leptons. Event passed.");
107  passed_event = true;
108  }
109  }
110  setFilterPassed(passed_event);
111 
112  return StatusCode::SUCCESS;
113 }
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.
xAODMultiElecMuTauFilter::filterEvent
virtual StatusCode filterEvent()
Definition: xAODMultiElecMuTauFilter.cxx:21
xAODMultiElecMuTauFilter::m_maxEta
double m_maxEta
Definition: xAODMultiElecMuTauFilter.h:27
xAOD::TruthParticle_v1::pz
float pz() const
The z component of the particle's momentum.
xAODMultiElecMuTauFilter::m_incHadTau
bool m_incHadTau
Definition: xAODMultiElecMuTauFilter.h:30
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::TruthParticle_v1::px
float px() const
The x component of the particle's momentum.
xAOD::TruthParticle_v1::py
float py() const
The y component of the particle's momentum.
xAODMultiElecMuTauFilter::m_minPt
double m_minPt
Definition: xAODMultiElecMuTauFilter.h:26
MC::isPhysical
bool isPhysical(const T &p)
Definition: HepMCHelpers.h:32
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
xAOD::TruthParticle_v1::e
virtual double e() const override final
The total energy of the particle.
xAODMultiElecMuTauFilter::m_minVisPtHadTau
double m_minVisPtHadTau
Definition: xAODMultiElecMuTauFilter.h:28
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
isTau
bool isTau(const T &p)
Definition: AtlasPID.h:148
xAOD::TruthParticle_v1::decayVtx
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAODMultiElecMuTauFilter::xAODMultiElecMuTauFilter
xAODMultiElecMuTauFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODMultiElecMuTauFilter.cxx:9
xAODMultiElecMuTauFilter::m_TwoSameSignLightLeptonsOneHadTau
bool m_TwoSameSignLightLeptonsOneHadTau
Definition: xAODMultiElecMuTauFilter.h:31
xAOD::TruthParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:174
xAODMultiElecMuTauFilter::m_NLeptons
int m_NLeptons
Definition: xAODMultiElecMuTauFilter.h:29
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
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
xAODMultiElecMuTauFilter.h
HepMCHelpers.h