ATLAS Offline Software
xAODFourLeptonMassFilter.cxx
Go to the documentation of this file.
1 
2 /*
3 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 */
6 
7 #include "GaudiKernel/PhysicalConstants.h"
12 
14  ISvcLocator* pSvcLocator)
15  : GenFilter(name, pSvcLocator) {}
17  ATH_MSG_DEBUG("MinPt " << m_minPt);
18  ATH_MSG_DEBUG("MaxEta " << m_maxEta);
19  ATH_MSG_DEBUG("MinMass1 " << m_minMass1);
20  ATH_MSG_DEBUG("MaxMass1 " << m_maxMass1);
21  ATH_MSG_DEBUG("MinMass2 " << m_minMass2);
22  ATH_MSG_DEBUG("MaxMass2 " << m_maxMass2);
23  ATH_MSG_DEBUG("AllowElecMu " << m_allowElecMu);
24  ATH_MSG_DEBUG("AllowSameCharge " << m_allowSameCharge);
26  return StatusCode::SUCCESS;
27 }
29  // Retrieve TruthLightLepton container from xAOD LightLepton slimmer, contains
30  // (electrons and muons ) particles
31 
32  const EventContext& context = Gaudi::Hive::currentContext();
34  xTruthParticleContainerReadHandle(
36  if (!xTruthParticleContainerReadHandle.isValid()) {
37  ATH_MSG_ERROR("Could not retrieve xAOD::TruthParticleContainer with key:"
39 
40  return StatusCode::FAILURE;
41  }
42 
43  unsigned int nParticles = xTruthParticleContainerReadHandle->size();
44  // loop over all particles
45  for (unsigned int iPart = 0; iPart < nParticles; ++iPart) {
46  const xAOD::TruthParticle* lightLeptonParticle =
47  (*xTruthParticleContainerReadHandle)[iPart];
48  int pdgId1 = lightLeptonParticle->pdgId();
49  if (!MC::isStable(lightLeptonParticle))
50  continue;
51  // Pick electrons or muons with Pt > m_inPt and |eta| < m_maxEta
52  if (!(lightLeptonParticle->isElectron() || lightLeptonParticle->isMuon()))
53  continue;
54  if (lightLeptonParticle->pt() < m_minPt ||
55  lightLeptonParticle->abseta() > m_maxEta)
56 
57  continue;
58  // loop over all remaining particles in the event
59  for (unsigned int iPart2 = iPart + 1; iPart2 < nParticles; ++iPart2) {
60  const xAOD::TruthParticle* lightLeptonParticle2 =
61  (*xTruthParticleContainerReadHandle)[iPart2];
62  int pdgId2 = lightLeptonParticle2->pdgId();
63  if ( !MC::isStable(lightLeptonParticle) || iPart == iPart2)
64  continue;
65  // Pick electrons or muons with Pt > m_inPt and |eta| < m_maxEta
66  if (!(lightLeptonParticle2->isElectron() ||
67  lightLeptonParticle2->isMuon()))
68  continue;
69  if (lightLeptonParticle2->pt() < m_minPt ||
70  lightLeptonParticle2->abseta() > m_maxEta)
71  continue;
72  // Loop over all remaining particles in the event
73  for (unsigned int iPart3 = iPart2 + 1; iPart3 < nParticles; ++iPart3) {
74  const xAOD::TruthParticle* lightLeptonParticle3 =
75  (*xTruthParticleContainerReadHandle)[iPart3];
76  int pdgId3 = lightLeptonParticle3->pdgId();
77  if (!MC::isStable(lightLeptonParticle) || iPart == iPart3 ||
78  iPart2 == iPart3)
79  continue;
80  // Pick electrons or muons with Pt > m_inPt and |eta| < m_maxEta
81  if (!(lightLeptonParticle3->isElectron() ||
82  lightLeptonParticle3->isMuon()))
83  continue;
84  if (lightLeptonParticle3->pt() < m_minPt ||
85  lightLeptonParticle3->abseta() > m_maxEta)
86  continue;
87  // Loop over all remaining particles in the event
88  for (unsigned int iPart4 = iPart3 + 1; iPart4 < nParticles; ++iPart4) {
89  const xAOD::TruthParticle* lightLeptonParticle4 =
90  (*xTruthParticleContainerReadHandle)[iPart4];
91  int pdgId4 = lightLeptonParticle4->pdgId();
92  if (!MC::isStable(lightLeptonParticle) || iPart == iPart4 ||
93  iPart2 == iPart4 || iPart3 == iPart4)
94  continue;
95  // Pick electrons or muons with Pt > m_inPt and |eta| < m_maxEta
96  if (!(lightLeptonParticle4->isElectron() ||
97  lightLeptonParticle4->isMuon()))
98  continue;
99  if (lightLeptonParticle4->pt() < m_minPt ||
100  lightLeptonParticle4->abseta() > m_maxEta)
101  continue;
102  decltype(lightLeptonParticle) apitr[4] = {
103  lightLeptonParticle, lightLeptonParticle2, lightLeptonParticle3,
104  lightLeptonParticle4};
105  int pdgIds[4] = {pdgId1, pdgId2, pdgId3, pdgId4};
106  for (int ii = 0; ii < 4; ii++) {
107  for (int jj = 0; jj < 4; jj++) {
108  if (jj == ii)
109  continue;
110  for (int kk = 0; kk < 4; kk++) {
111  if (kk == jj || kk == ii)
112  continue;
113  for (int ll = 0; ll < 4; ll++) {
114  if (ll == kk || ll == jj || ll == ii)
115  continue;
116  if (!m_allowElecMu &&
117  (std::abs(pdgIds[ii]) != std::abs(pdgIds[jj]) ||
118  std::abs(pdgIds[kk]) != std::abs(pdgIds[ll])))
119  continue;
120  if (!m_allowSameCharge && (pdgIds[ii] * pdgIds[jj] > 0. ||
121  pdgIds[kk] * pdgIds[ll] > 0.))
122  continue;
123  // Leading dilepton pair
124  HepMC::FourVector vec(
125  ((apitr[ii]))->px() + ((apitr[jj]))->px(),
126  ((apitr[ii]))->py() + ((apitr[jj]))->py(),
127  ((apitr[ii]))->pz() + ((apitr[jj]))->pz(),
128  ((apitr[ii]))->e() + ((apitr[jj]))->e());
129  double invMass1 = vec.m();
130  if (invMass1 < m_minMass1 || invMass1 > m_maxMass1)
131  continue;
132  ATH_MSG_DEBUG("PASSED FILTER1 " << invMass1);
133  // Sub-leading dilepton pair
134  HepMC::FourVector vec2(
135  ((apitr[kk]))->px() + ((apitr[ll]))->px(),
136  ((apitr[kk]))->py() + ((apitr[ll]))->py(),
137  ((apitr[kk]))->pz() + ((apitr[ll]))->pz(),
138  ((apitr[kk]))->e() + ((apitr[ll]))->e());
139  double invMass2 = vec2.m();
140  if (invMass2 < m_minMass2 || invMass2 > m_maxMass2)
141  continue;
142  ATH_MSG_DEBUG("PASSED FILTER2 " << invMass2);
143  return StatusCode::SUCCESS;
144  }
145  }
146  }
147  }
148  }
149  }
150  }
151  }
152  setFilterPassed(false);
153  return StatusCode::SUCCESS;
154 }
D3PDMakerTestInstan::vec2
std::vector< D3PDTest::MyVec2 > vec2
Definition: D3PDMakerTestDict.h:14
xAODFourLeptonMassFilter::m_maxMass2
Gaudi::Property< double > m_maxMass2
Definition: xAODFourLeptonMassFilter.h:35
test_pyathena.px
px
Definition: test_pyathena.py:18
xAOD::TruthParticle_v1::isElectron
bool isElectron() const
Whether the particle is an electron (or positron)
xAODFourLeptonMassFilter::m_maxEta
Gaudi::Property< double > m_maxEta
Definition: xAODFourLeptonMassFilter.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODFourLeptonMassFilter::m_maxMass1
Gaudi::Property< double > m_maxMass1
Definition: xAODFourLeptonMassFilter.h:33
xAODFourLeptonMassFilter::filterInitialize
virtual StatusCode filterInitialize() override
Definition: xAODFourLeptonMassFilter.cxx:16
TruthParticleContainer.h
xAODFourLeptonMassFilter::xAODFourLeptonMassFilter
xAODFourLeptonMassFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODFourLeptonMassFilter.cxx:13
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
xAODFourLeptonMassFilter.h
TruthParticleAuxContainer.h
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
python.changerun.kk
list kk
Definition: changerun.py:41
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAODFourLeptonMassFilter::m_minPt
Gaudi::Property< double > m_minPt
Definition: xAODFourLeptonMassFilter.h: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
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
xAODFourLeptonMassFilter::m_minMass2
Gaudi::Property< double > m_minMass2
Definition: xAODFourLeptonMassFilter.h:34
xAODFourLeptonMassFilter::m_allowElecMu
Gaudi::Property< bool > m_allowElecMu
Definition: xAODFourLeptonMassFilter.h:36
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Amg::py
@ py
Definition: GeoPrimitives.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::TruthParticle_v1::isMuon
bool isMuon() const
Whether the particle is a muon (or antimuon)
xAODFourLeptonMassFilter::m_xaodTruthParticleContainerNameLightLeptonKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNameLightLeptonKey
Definition: xAODFourLeptonMassFilter.h:41
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
xAODFourLeptonMassFilter::m_allowSameCharge
Gaudi::Property< bool > m_allowSameCharge
Definition: xAODFourLeptonMassFilter.h:37
xAODFourLeptonMassFilter::filterEvent
virtual StatusCode filterEvent() override
Definition: xAODFourLeptonMassFilter.cxx:28
TruthParticle.h
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.
HepMCHelpers.h
xAODFourLeptonMassFilter::m_minMass1
Gaudi::Property< double > m_minMass1
Definition: xAODFourLeptonMassFilter.h:32
xAOD::TruthParticle_v1::abseta
double abseta() const
The absolute pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:218
DiTauMassTools::TauTypes::ll
@ ll
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:49