ATLAS Offline Software
xAODDiLeptonMassFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/PhysicalConstants.h"
8 
9 xAODDiLeptonMassFilter::xAODDiLeptonMassFilter(const std::string& name, ISvcLocator* pSvcLocator)
10  : GenFilter(name,pSvcLocator)
11  , m_AthenaCalls(0)
12 {
13  declareProperty("MinPt", m_minPt = 5000.);
14  declareProperty("MaxEta", m_maxEta = 5.0);
15  declareProperty("MinMass", m_minMass = 1000); // To avoid fsr etc
16  declareProperty("MaxMass", m_maxMass = 14000000);
17  declareProperty("MinDilepPt", m_minDilepPt = -1.);
18  declareProperty("AllowElecMu", m_allowElecMu = false);
19  declareProperty("AllowSameCharge", m_allowSameCharge = true);
20 }
21 
22 
24  m_AthenaCalls = 0;
25  ATH_MSG_DEBUG("MinPt " << m_minPt);
26  ATH_MSG_DEBUG("MaxEta " << m_maxEta);
27  ATH_MSG_DEBUG("MinMass " << m_minMass);
28  ATH_MSG_DEBUG("MaxMass " << m_maxMass);
29  ATH_MSG_DEBUG("MinDileptPt " << m_minDilepPt);
30  ATH_MSG_DEBUG("AllowElecMu " << m_allowElecMu);
31  ATH_MSG_DEBUG("AllowSameCharge " << m_allowSameCharge);
32  return StatusCode::SUCCESS;
33 }
34 
37  "\n########## xAODDiLeptonMassFilter Statistics ##########\n" <<
38  "Filter has the following parameters:\n" <<
39  " Minimum pT (GeV) : " << m_minPt / Gaudi::Units::GeV << "\n" <<
40  " Maximum eta : " << m_maxEta << "\n" <<
41  " Mass range : (" << m_minMass << ", " << m_maxMass << ")\n" <<
42  " Dilepton pT (GeV) : " << m_minDilepPt << "\n" <<
43  " Allow el+mu : " << m_allowElecMu << "\n" <<
44  " Allow same-sign : " << m_allowSameCharge << "\n"
45  );
46 
47  if (m_AthenaCalls == 0) {
48  ATH_MSG_DEBUG("xAODDiLeptonMassFilter filter is not interfaced/called.");
49  } else {
51  "\nAfter the filtering you have " << m_nPass << " events passing.\n" <<
52  "xAODDiLeptonMassFilter efficiency = " << m_nPass << " / " << m_AthenaCalls <<
53  " (Accepted/Generated) = " << m_nPass / (double)(m_AthenaCalls) << "\n" <<
54  "########## xAODDiLeptonMassFilter finished ##########\n"
55  );
56  }
57 
58  return StatusCode::SUCCESS;
59 }
60 
61 
63  // Retrieve TruthLightLepton container from xAOD LightLepton slimmer, contains (electrons and muons ) particles
64  const xAOD::TruthParticleContainer* xTruthParticleContainer;
65  if (evtStore()->retrieve(xTruthParticleContainer, "TruthLightLeptons").isFailure()) {
66  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthLightLepton" << " found in StoreGate!");
67  return StatusCode::FAILURE;
68  }
69 
70 
71  unsigned int nParticles = xTruthParticleContainer->size();
72  //loop over all particles
73  for (unsigned int iPart=0; iPart<nParticles; ++iPart) {
74  const xAOD::TruthParticle* lightLeptonParticle = (*xTruthParticleContainer)[iPart];
75  int pdgId1 = lightLeptonParticle->pdgId();
76  if (!MC::isStable(lightLeptonParticle)) continue;
77 
78  // Pick electrons or muons with Pt > m_inPt and |eta| < m_maxEta
79  if (std::abs(pdgId1) == 11 || std::abs(pdgId1) == 13) {
80  if (lightLeptonParticle->pt() >= m_minPt && std::abs(lightLeptonParticle->eta()) <= m_maxEta){
81  //loop over all remaining particles in the event
82 
83  for(unsigned int iPart2=iPart + 1; iPart2<nParticles; ++iPart2) {
84  const xAOD::TruthParticle* lightLeptonParticle2 = (*xTruthParticleContainer)[iPart2];
85  int pdgId2 = lightLeptonParticle2->pdgId();
86  if( !MC::isStable(lightLeptonParticle) || iPart == iPart2) continue;
87 
88  // Pick electrons or muons with Pt > m_inPt and |eta| < m_maxEta
89  // If m_allowSameChagrge is not true only pick those with opposite charge to the first particle
90  // If m_allowElecMu is true allow also Z -> emu compinations (with charge requirements as above)
91  if ((m_allowSameCharge && (std::abs(pdgId2) == std::abs(pdgId1) || (m_allowElecMu && (std::abs(pdgId2) == 11 || std::abs(pdgId2) == 13) ) ) ) ||
92  (!m_allowSameCharge && (pdgId2 == -1*pdgId1 || (m_allowElecMu && (pdgId2 == (pdgId1 < 0 ? 1 : -1) * 11 || (pdgId1 < 0 ? 1 : -1) * pdgId2 == 13) ) ) ) ) {
93  if (lightLeptonParticle2->pt() >= m_minPt && std::abs(lightLeptonParticle2->eta()) <= m_maxEta){
94  // Calculate invariant mass and apply cut
95  HepMC::FourVector vec(lightLeptonParticle->px() + lightLeptonParticle2->px(),
96  lightLeptonParticle->py() + lightLeptonParticle2->py(),
97  lightLeptonParticle->pz() + lightLeptonParticle2->pz(),
98  lightLeptonParticle->e() + lightLeptonParticle2->e());
99 
100  double invMass = vec.m();
101  double dilepPt = vec.perp();
102 
103  if (m_minMass < invMass && invMass < m_maxMass && dilepPt > m_minDilepPt) {
104  ATH_MSG_DEBUG("PASSED FILTER");
105  return StatusCode::SUCCESS;
106  }
107  }
108  }
109 
110  }
111 
112  }
113  }
114 
115  }
116 
117  setFilterPassed(false);
118  return StatusCode::SUCCESS;
119 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
P4Helpers::invMass
double invMass(const I4Momentum &pA, const I4Momentum &pB)
invariant mass from two I4momentum references
Definition: P4Helpers.h:239
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::TruthParticle_v1::pz
float pz() const
The z component of the particle's momentum.
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAODDiLeptonMassFilter::m_maxMass
double m_maxMass
Definition: xAODDiLeptonMassFilter.h:34
xAODDiLeptonMassFilter::m_minPt
double m_minPt
Definition: xAODDiLeptonMassFilter.h:31
xAOD::TruthParticle_v1::px
float px() const
The x component of the particle's momentum.
xAODDiLeptonMassFilter::xAODDiLeptonMassFilter
xAODDiLeptonMassFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODDiLeptonMassFilter.cxx:9
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
xAOD::TruthParticle_v1::py
float py() const
The y component of the particle's momentum.
xAODDiLeptonMassFilter::m_maxEta
double m_maxEta
Definition: xAODDiLeptonMassFilter.h:32
xAODDiLeptonMassFilter::m_allowSameCharge
bool m_allowSameCharge
Definition: xAODDiLeptonMassFilter.h:37
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
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.
xAODDiLeptonMassFilter::m_minMass
double m_minMass
Definition: xAODDiLeptonMassFilter.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
xAODDiLeptonMassFilter::m_allowElecMu
bool m_allowElecMu
Definition: xAODDiLeptonMassFilter.h:36
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAODDiLeptonMassFilter::filterEvent
virtual StatusCode filterEvent()
Definition: xAODDiLeptonMassFilter.cxx:62
xAODDiLeptonMassFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: xAODDiLeptonMassFilter.cxx:23
xAODDiLeptonMassFilter::m_minDilepPt
double m_minDilepPt
Definition: xAODDiLeptonMassFilter.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
GenFilter::m_nPass
int m_nPass
Definition: GenFilter.h:65
xAODDiLeptonMassFilter::m_AthenaCalls
int m_AthenaCalls
Definition: xAODDiLeptonMassFilter.h:38
xAOD::TruthParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:174
xAODDiLeptonMassFilter.h
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.
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAODDiLeptonMassFilter::filterFinalize
virtual StatusCode filterFinalize()
Definition: xAODDiLeptonMassFilter.cxx:35
HepMCHelpers.h