ATLAS Offline Software
DiLeptonMassFilter.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 DiLeptonMassFilter::DiLeptonMassFilter(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########## DiLeptonMassFilter 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("DiLeptonMassFilter filter is not interfaced/called.");
49  } else {
51  "\nAfter the filtering you have " << m_nPass << " events passing.\n" <<
52  "DiLeptonMassFilter efficiency = " << m_nPass << " / " << m_AthenaCalls <<
53  " (Accepted/Generated) = " << m_nPass / (double)(m_AthenaCalls) << "\n" <<
54  "########## DiLeptonMassFilter finished ##########\n"
55  );
56  }
57 
58  return StatusCode::SUCCESS;
59 }
60 
61 
64  for (itr = events()->begin(); itr!=events()->end(); ++itr) {
65  m_AthenaCalls++;
66  const HepMC::GenEvent* genEvt = (*itr);
67  // Loop over all particles in the event
68  for (auto pitr1 = HepMC::begin(*genEvt); pitr1!=HepMC::end(*genEvt); ++pitr1 ){
69  int pdgId1((*pitr1)->pdg_id());
70  if(!MC::isStable(*pitr1)) continue;
71 
72  // Pick electrons or muons with Pt > m_inPt and |eta| < m_maxEta
73  if (MC::isElectron(*pitr1) || MC::isMuon(*pitr1)) {
74  if ((*pitr1)->momentum().perp() >= m_minPt && std::abs((*pitr1)->momentum().pseudoRapidity()) <= m_maxEta){
75 
76  // Loop over all remaining particles in the event
77  auto pitr2 = pitr1;
78  pitr2++;
79 
80  for(; pitr2 != HepMC::end(*genEvt); ++pitr2){
81  int pdgId2((*pitr2)->pdg_id());
82  if(!MC::isStable(*pitr2) || pitr1 == pitr2) continue;
83 
84  // Pick electrons or muons with Pt > m_inPt and |eta| < m_maxEta
85  // If m_allowSameChagrge is not true only pick those with opposite charge to the first particle
86  // If m_allowElecMu is true allow also Z -> emu compinations (with charge requirements as above)
87  if ((m_allowSameCharge && (std::abs(pdgId2) == std::abs(pdgId1) || (m_allowElecMu && (std::abs(pdgId2) == 11 || std::abs(pdgId2) == 13) ) ) ) ||
88  (!m_allowSameCharge && (pdgId2 == -1*pdgId1 || (m_allowElecMu && (pdgId2 == (pdgId1 < 0 ? 1 : -1) * 11 || (pdgId1 < 0 ? 1 : -1) * pdgId2 == 13) ) ) ) ) {
89  if ((*pitr2)->momentum().perp() >= m_minPt && std::abs((*pitr2)->momentum().pseudoRapidity()) <= m_maxEta){
90 
91  // Calculate invariant mass and apply cut
92  HepMC::FourVector vec((*pitr1)->momentum().px() + (*pitr2)->momentum().px(),
93  (*pitr1)->momentum().py() + (*pitr2)->momentum().py(),
94  (*pitr1)->momentum().pz() + (*pitr2)->momentum().pz(),
95  (*pitr1)->momentum().e() + (*pitr2)->momentum().e());
96 
97  double invMass = vec.m();
98  double dilepPt = vec.perp();
99 
100  ATH_MSG_DEBUG(" Lepton1 : Pt = " << (*pitr1)->momentum().perp() << ", Eta = " << (*pitr1)->momentum().pseudoRapidity() <<
101  (*pitr1)<<
102  " Lepton2 : Pt = " << (*pitr2)->momentum().perp() << ", Eta = " << (*pitr2)->momentum().pseudoRapidity() <<
103  (*pitr2)<<
104  " Mass = " << invMass <<
105  " DilepPt = " << dilepPt);
106 
107  if (m_minMass < invMass && invMass < m_maxMass && dilepPt > m_minDilepPt) {
108  ATH_MSG_DEBUG("PASSED FILTER");
109  return StatusCode::SUCCESS;
110  }
111  }
112  }
113  }
114  }
115  }
116  }
117  }
118 
119  setFilterPassed(false);
120  return StatusCode::SUCCESS;
121 }
DiLeptonMassFilter::m_minDilepPt
double m_minDilepPt
Definition: DiLeptonMassFilter.h:31
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
DiLeptonMassFilter::m_allowSameCharge
bool m_allowSameCharge
Definition: DiLeptonMassFilter.h:33
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
DiLeptonMassFilter::DiLeptonMassFilter
DiLeptonMassFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: DiLeptonMassFilter.cxx:9
DiLeptonMassFilter::m_AthenaCalls
int m_AthenaCalls
Definition: DiLeptonMassFilter.h:34
HepMC::end
GenEvent::particle_iterator end(HepMC::GenEvent &e)
Definition: GenEvent.h:499
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
DiLeptonMassFilter::m_allowElecMu
bool m_allowElecMu
Definition: DiLeptonMassFilter.h:32
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
DiLeptonMassFilter.h
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::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
DiLeptonMassFilter::m_minMass
double m_minMass
Definition: DiLeptonMassFilter.h:29
DiLeptonMassFilter::m_maxMass
double m_maxMass
Definition: DiLeptonMassFilter.h:30
DiLeptonMassFilter::filterEvent
virtual StatusCode filterEvent()
Definition: DiLeptonMassFilter.cxx:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DiLeptonMassFilter::filterFinalize
virtual StatusCode filterFinalize()
Definition: DiLeptonMassFilter.cxx:35
DiLeptonMassFilter::m_minPt
double m_minPt
Definition: DiLeptonMassFilter.h:27
GenFilter::m_nPass
int m_nPass
Definition: GenFilter.h:65
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
DiLeptonMassFilter::m_maxEta
double m_maxEta
Definition: DiLeptonMassFilter.h:28
HepMC::begin
GenEvent::particle_iterator begin(HepMC::GenEvent &e)
Definition: GenEvent.h:498
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
DiLeptonMassFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: DiLeptonMassFilter.cxx:23
HepMCHelpers.h
isMuon
bool isMuon(const T &p)
Definition: AtlasPID.h:145