ATLAS Offline Software
xAODDirectPhotonFilter.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 <algorithm>
8 
9 xAODDirectPhotonFilter::xAODDirectPhotonFilter(const std::string& name, ISvcLocator* pSvcLocator)
10  : GenFilter(name, pSvcLocator)
11 {
12  declareProperty("NPhotons", m_NPhotons = 1);
13  declareProperty("OrderPhotons",m_OrderPhotons = true);
14  declareProperty("Ptmin",m_Ptmin = std::vector<double>(m_NPhotons, 10000.));
15  declareProperty("Ptmax",m_Ptmax = std::vector<double>(m_NPhotons, std::numeric_limits<double>::max()));
16  declareProperty("Etacut", m_EtaRange = 2.50);
17  declareProperty("AllowSUSYDecay",m_AllowSUSYDecay = false);
18 
19 }
20 
22 
23 
24  ATH_MSG_INFO("Initialising DirectPhoton filter with OrderPhotons="<<m_OrderPhotons);
25 
26  if (m_Ptmin.size()>m_NPhotons || m_Ptmax.size()>m_NPhotons) {
27  ATH_MSG_ERROR("Too many Ptmin/max for given NPhotons");
28  return StatusCode::FAILURE;
29  }
30 
31  if (!m_OrderPhotons && (m_Ptmin.size()>1 || m_Ptmax.size()>1)) {
32  ATH_MSG_ERROR("Too many Ptmin/max requirements for OrderPhotons=false case.");
33  return StatusCode::FAILURE;
34  }
35 
36  // allow specifying only one pTmin/max to be applied to all (further) photons
37  // for backward compatibility
38  if (m_Ptmin.size()<m_NPhotons) {
39  size_t origsize = m_Ptmin.size();
40  double lastPt = m_Ptmin.back();
41  m_Ptmin.resize(m_NPhotons);
42  for (size_t i=origsize; i<m_NPhotons; ++i) m_Ptmin[i]=lastPt;
43  }
44  if (m_Ptmax.size()<m_NPhotons) {
45  size_t origsize = m_Ptmax.size();
46  double lastPt = m_Ptmax.back();
47  m_Ptmax.resize(m_NPhotons);
48  for (size_t i=origsize; i<m_NPhotons; ++i) m_Ptmax[i]=lastPt;
49  }
50  return StatusCode::SUCCESS;
51 }
52 
54  return (p1->pt()>p2->pt());
55 }
56 
58 
59  std::vector<const xAOD::TruthParticle*> promptPhotonsInEta;
60 
61  int phot = 0;
62 // Retrieve TruthGen container from xAOD Gen slimmer, contains all particles witout barcode_zero and
63 // duplicated barcode ones
64  const xAOD::TruthParticleContainer* xTruthParticleContainer;
65  if (evtStore()->retrieve(xTruthParticleContainer, "TruthGen").isFailure()) {
66  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthGen" << " found in StoreGate!");
67  return StatusCode::FAILURE;
68  }
69 
70  // Loop over all particles in the event and find photons in given eta range
71  unsigned int nPart = xTruthParticleContainer->size();
72  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
73  const xAOD::TruthParticle* pitr = (*xTruthParticleContainer)[iPart];
74 
75  if (MC::isPhoton(pitr) &&
76  MC::isStable(pitr) &&
77  std::abs(pitr->eta()) <= m_EtaRange) {
78 
79  // iterate over parent particles to exclude photons from hadron decays
80  bool fromHadron(false);
81  for(size_t thisParent_id=0; thisParent_id < pitr->prodVtx()->nIncomingParticles(); thisParent_id++)
82  {
83  auto parent = pitr->prodVtx()->incomingParticle(thisParent_id);
84  int pdgindex = std::abs(parent->pdgId());
85  ATH_MSG_DEBUG("Looping on Production (parents) vertex : " << parent->pdgId());
86  if (pdgindex > 100) {
87  fromHadron = true;
88  if (m_AllowSUSYDecay && ( (pdgindex > 1000000 && pdgindex < 1000040) || (pdgindex > 2000000 && pdgindex < 2000016) ) ) fromHadron = false;
89  }
90  }
91  phot++;
92  if (!fromHadron) promptPhotonsInEta.push_back(pitr);
93  else ATH_MSG_DEBUG("non-prompt photon ignored");
94  }
95  } //loop over TruthParticles
96 
97 
98  ATH_MSG_DEBUG("number of photons" << phot);
99 
100  if (promptPhotonsInEta.size()<m_NPhotons) {
101  setFilterPassed(false);
102  }
103  else {
104  for (const auto& photon: promptPhotonsInEta) {
105 
106  ATH_MSG_DEBUG("Found prompt photon with pt="<<photon->pt());
107  }
108  if (m_OrderPhotons) { // apply cuts to leading/subleading/... photon as specified
109  std::sort(promptPhotonsInEta.begin(), promptPhotonsInEta.end(), xAODDirectPhotonFilterCmpByPt);
110 
111  bool pass = true;
112  for (size_t i = 0; i < m_NPhotons; ++i) {
113  double pt = promptPhotonsInEta[i]->pt();
114  if (pt < m_Ptmin[i] || pt > m_Ptmax[i]) {
115 
116  ATH_MSG_DEBUG(" rejected pt="<<pt);
117  pass = false;
118  }
119  }
120 
121  if (pass) {
122  ATH_MSG_DEBUG("Passed!");
123  }
124  setFilterPassed(pass);
125  }
126  else { // just require NPhotons to pass m_Ptmin/max[0]
127  size_t NPhotons=0;
128  for (size_t i = 0; i < promptPhotonsInEta.size(); ++i) {
129  double pt = promptPhotonsInEta[i]->pt();
130  if (pt > m_Ptmin[0] && pt < m_Ptmax[0]) ++NPhotons;
131  }
132 
133  if (NPhotons>=m_NPhotons) ATH_MSG_DEBUG("Passed!");
134  setFilterPassed(NPhotons>=m_NPhotons);
135  }
136  }
137  return StatusCode::SUCCESS;
138 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAODDirectPhotonFilter.h
xAODDirectPhotonFilter::m_OrderPhotons
bool m_OrderPhotons
Definition: xAODDirectPhotonFilter.h:32
max
#define max(a, b)
Definition: cfImp.cxx:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAODDirectPhotonFilter::xAODDirectPhotonFilter
xAODDirectPhotonFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODDirectPhotonFilter.cxx:9
MC::fromHadron
bool fromHadron(T p, T hadptr, bool &fromTau, bool &fromBSM)
Function to classify the particle.
Definition: HepMCHelpers.h:184
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
test_pyathena.pt
pt
Definition: test_pyathena.py:11
xAODDirectPhotonFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: xAODDirectPhotonFilter.cxx:21
xAODDirectPhotonFilterCmpByPt
bool xAODDirectPhotonFilterCmpByPt(const xAOD::TruthParticle *p1, const xAOD::TruthParticle *p2)
Definition: xAODDirectPhotonFilter.cxx:53
xAODDirectPhotonFilter::m_EtaRange
double m_EtaRange
Definition: xAODDirectPhotonFilter.h:29
xAODDirectPhotonFilter::filterEvent
virtual StatusCode filterEvent()
Definition: xAODDirectPhotonFilter.cxx:57
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
xAODDirectPhotonFilter::m_Ptmin
std::vector< double > m_Ptmin
Definition: xAODDirectPhotonFilter.h:27
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
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::TruthVertex_v1::incomingParticle
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
Definition: TruthVertex_v1.cxx:71
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TruthParticle_v1::prodVtx
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Definition: TruthParticle_v1.cxx:80
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::TruthParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:174
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
xAODDirectPhotonFilter::m_Ptmax
std::vector< double > m_Ptmax
Definition: xAODDirectPhotonFilter.h:28
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:199
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
xAODDirectPhotonFilter::m_AllowSUSYDecay
bool m_AllowSUSYDecay
Definition: xAODDirectPhotonFilter.h:31
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAODDirectPhotonFilter::m_NPhotons
size_t m_NPhotons
Definition: xAODDirectPhotonFilter.h:30
HepMCHelpers.h