ATLAS Offline Software
AsgPtEtaSelectionTool.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 
7 
8 
9 //
10 // includes
11 //
12 
14 
15 #include <xAODEgamma/Egamma.h>
16 #include <xAODBase/IParticle.h>
17 #include <cmath>
18 
19 //
20 // method implementations
21 //
22 
23 namespace CP
24 {
25 
27  initialize ()
28  {
30  {
31  ATH_MSG_ERROR ("both 'useClusterEta' and 'useDressedProperties' can not be used at the same time");
32  return StatusCode::FAILURE;
33  }
34  if (m_minPt < 0 || !std::isfinite (m_minPt))
35  {
36  ATH_MSG_ERROR ("invalid value of minPt: " << m_minPt);
37  return StatusCode::FAILURE;
38  }
39  if (m_maxPt < 0 || !std::isfinite (m_maxPt))
40  {
41  ATH_MSG_ERROR ("invalid value of m_maxPt: " << m_maxPt);
42  return StatusCode::FAILURE;
43  }
44  if (m_maxEta < 0 || !std::isfinite (m_maxEta))
45  {
46  ATH_MSG_ERROR ("invalid value of maxEta: " << m_maxEta);
47  return StatusCode::FAILURE;
48  }
49  if (m_etaGapLow < 0 || !std::isfinite (m_etaGapLow))
50  {
51  ATH_MSG_ERROR ("invalid value of etaGapLow: " << m_etaGapLow);
52  return StatusCode::FAILURE;
53  }
54  if (m_etaGapHigh < 0 || !std::isfinite (m_etaGapHigh))
55  {
56  ATH_MSG_ERROR ("invalid value of etaGapHigh: " << m_etaGapHigh);
57  return StatusCode::FAILURE;
58  }
60  {
61  ATH_MSG_ERROR ("invalid eta gap: " << m_etaGapLow << " to " << m_etaGapHigh);
62  return StatusCode::FAILURE;
63  }
64  if (m_etaGapHigh > 0 && m_maxEta > 0 && m_etaGapHigh >= m_maxEta)
65  {
66  ATH_MSG_ERROR ("etaGapHigh=" << m_etaGapHigh << " >= maxEta=" << m_maxEta);
67  return StatusCode::FAILURE;
68  }
69 
71  ATH_MSG_DEBUG( "Performing pt and eta cuts on the dressed properties" );
72  m_dressedPropertiesIndex = m_accept.addCut ("dressedProperties", "has dressed properties");
73  m_dressedPtAccessor = std::make_unique<SG::AuxElement::ConstAccessor<float>> ("pt_dressed");
74  m_dressedEtaAccessor = std::make_unique<SG::AuxElement::ConstAccessor<float>> ("eta_dressed");
75  }
76  if (m_minPt > 0) {
77  ATH_MSG_DEBUG( "Performing pt >= " << m_minPt << " MeV selection" );
78  m_minPtCutIndex = m_accept.addCut ("minPt", "minimum pt cut");
79  }
80  if (m_maxPt > 0) {
81  ATH_MSG_DEBUG( "Performing pt < " << m_maxPt << " MeV selection" );
82  m_maxPtCutIndex = m_accept.addCut ("maxPt", "maximum pt cut");
83  }
84  if (m_useClusterEta) {
85  ATH_MSG_DEBUG( "Performing eta cut on the e/gamma cluster" );
86  m_egammaCastCutIndex = m_accept.addCut ("castEgamma", "cast to egamma");
87  m_egammaClusterCutIndex = m_accept.addCut ("caloCluster", "egamma object has cluster");
88  }
89  if (m_maxEta > 0) {
90  ATH_MSG_DEBUG( "Performing |eta| < " << m_maxEta << " selection" );
91  m_maxEtaCutIndex = m_accept.addCut ("maxEta", "maximum eta cut");
92  }
93  if (m_etaGapHigh > 0) {
94  ATH_MSG_DEBUG( "Performing !( " << m_etaGapLow << " < |eta| < "
95  << m_etaGapHigh << " ) selection" );
96  m_etaGapCutIndex = m_accept.addCut ("etaGap", "eta gap cut");
97  }
100 
101  return StatusCode::SUCCESS;
102  }
103 
104 
105 
107  getAcceptInfo () const
108  {
109  return m_accept;
110  }
111 
112 
113 
115  accept (const xAOD::IParticle *particle) const
116  {
118 
119  // Check if dressed properties exist if needed
121  if (!m_dressedPtAccessor->isAvailable(*particle)) {
122  ANA_MSG_WARNING ("dressed decorations not available");
123  return accept;
124  }
126  }
127 
128  // Perform the tranverse momentum cuts.
129  if (m_minPtCutIndex >= 0 || m_maxPtCutIndex >= 0)
130  {
131  float pt = particle->pt();
133  pt = (*m_dressedPtAccessor) (*particle);
134  }
135 
136  if (m_minPtCutIndex >= 0) {
137  if (!std::isfinite(pt) || pt < 0.)
138  {
139  ANA_MSG_WARNING ("invalid pt value, setting object to fail pt-cut: " << pt);
141  } else
142  {
144  }
145  }
146  if (m_maxPtCutIndex >= 0) {
148  }
149  }
150 
151  // Perform the eta cut(s).
152  if (m_maxEtaCutIndex >= 0 || m_etaGapCutIndex >= 0)
153  {
154  float absEta = 0;
155 
156  if (m_useClusterEta == true)
157  {
158  const xAOD::Egamma *egamma
159  = dynamic_cast<const xAOD::Egamma*>(particle);
160  if (egamma == nullptr)
161  {
163  ANA_MSG_ERROR ("failed to cast input particle to electron");
164  m_shouldPrintCastWarning = false;
165  return accept;
166  }
168  const xAOD::CaloCluster *const caloCluster {egamma->caloCluster()};
169  if (!caloCluster)
170  {
172  ANA_MSG_ERROR ("no calo-cluster associated with e-gamma object");
174  return accept;
175  }
177  absEta = std::abs (caloCluster->etaBE(2));
178  } else if (m_useDressedProperties)
179  {
180  absEta = std::abs ((*m_dressedEtaAccessor) (*particle));
181  } else
182  {
183  absEta = std::abs (particle->eta());
184  }
185 
186  if (m_maxEtaCutIndex >= 0) {
188  }
189  if (m_etaGapCutIndex >= 0) {
191  absEta > m_etaGapHigh));
192  }
193  }
194 
195  return accept;
196  }
197 }
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
IParticle.h
CP::AsgPtEtaSelectionTool::m_accept
asg::AcceptInfo m_accept
the asg::AcceptInfo we are using
Definition: AsgPtEtaSelectionTool.h:129
CP::AsgPtEtaSelectionTool::m_useClusterEta
Gaudi::Property< bool > m_useClusterEta
Definition: AsgPtEtaSelectionTool.h:79
test_pyathena.pt
pt
Definition: test_pyathena.py:11
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
CP::AsgPtEtaSelectionTool::m_useDressedProperties
Gaudi::Property< bool > m_useDressedProperties
Definition: AsgPtEtaSelectionTool.h:80
CP::AsgPtEtaSelectionTool::m_egammaClusterCutIndex
int m_egammaClusterCutIndex
Index for the e/gamma calo-cluster.
Definition: AsgPtEtaSelectionTool.h:97
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
AsgPtEtaSelectionTool.h
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::AsgPtEtaSelectionTool::m_shouldPrintCastWarning
std::atomic< bool > m_shouldPrintCastWarning
a version of m_printCastWarning that we modify once we printed the warning
Definition: AsgPtEtaSelectionTool.h:112
egamma
Definition: egamma.h:58
Egamma.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::AsgPtEtaSelectionTool::m_shouldPrintClusterWarning
std::atomic< bool > m_shouldPrintClusterWarning
a version of m_printClusterWarning that we modify once we printed the warning
Definition: AsgPtEtaSelectionTool.h:125
asg::AcceptInfo
Definition: AcceptInfo.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
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
CP::AsgPtEtaSelectionTool::m_egammaCastCutIndex
int m_egammaCastCutIndex
Index for the e/gamma casting.
Definition: AsgPtEtaSelectionTool.h:95
CP::AsgPtEtaSelectionTool::m_etaGapLow
Gaudi::Property< float > m_etaGapLow
Definition: AsgPtEtaSelectionTool.h:77
CP::AsgPtEtaSelectionTool::m_maxEta
Gaudi::Property< float > m_maxEta
Definition: AsgPtEtaSelectionTool.h:76
CP::AsgPtEtaSelectionTool::m_minPtCutIndex
int m_minPtCutIndex
Index for the minimum pT selection.
Definition: AsgPtEtaSelectionTool.h:87
CP::AsgPtEtaSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *particle) const override
The main accept method: the actual cuts are applied here.
Definition: AsgPtEtaSelectionTool.cxx:115
CP::AsgPtEtaSelectionTool::getAcceptInfo
virtual const asg::AcceptInfo & getAcceptInfo() const override
Declare the interface ID for this pure-virtual interface class to the Athena framework.
Definition: AsgPtEtaSelectionTool.cxx:107
CP::AsgPtEtaSelectionTool::m_etaGapHigh
Gaudi::Property< float > m_etaGapHigh
Definition: AsgPtEtaSelectionTool.h:78
CP::AsgPtEtaSelectionTool::m_maxEtaCutIndex
int m_maxEtaCutIndex
Index for the maximum eta selection.
Definition: AsgPtEtaSelectionTool.h:91
CP::AsgPtEtaSelectionTool::m_etaGapCutIndex
int m_etaGapCutIndex
Index for the eta gap selection.
Definition: AsgPtEtaSelectionTool.h:93
CP::AsgPtEtaSelectionTool::m_printClusterWarning
Gaudi::Property< bool > m_printClusterWarning
Definition: AsgPtEtaSelectionTool.h:82
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:134
TauGNNUtils::Variables::absEta
bool absEta(const xAOD::TauJet &tau, double &out)
Definition: TauGNNUtils.cxx:232
CP::AsgPtEtaSelectionTool::m_dressedPtAccessor
std::unique_ptr< SG::AuxElement::ConstAccessor< float > > m_dressedPtAccessor
dressed pt and eta accessors
Definition: AsgPtEtaSelectionTool.h:133
CP::AsgPtEtaSelectionTool::m_dressedEtaAccessor
std::unique_ptr< SG::AuxElement::ConstAccessor< float > > m_dressedEtaAccessor
Definition: AsgPtEtaSelectionTool.h:134
CP::AsgPtEtaSelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: AsgPtEtaSelectionTool.cxx:27
CP::AsgPtEtaSelectionTool::m_maxPtCutIndex
int m_maxPtCutIndex
Index for the maximum pT selection.
Definition: AsgPtEtaSelectionTool.h:89
asg::AcceptData
Definition: AcceptData.h:30
CP::AsgPtEtaSelectionTool::m_minPt
Gaudi::Property< float > m_minPt
tool properties
Definition: AsgPtEtaSelectionTool.h:74
CP::AsgPtEtaSelectionTool::m_printCastWarning
Gaudi::Property< bool > m_printCastWarning
Definition: AsgPtEtaSelectionTool.h:81
CP::AsgPtEtaSelectionTool::m_maxPt
Gaudi::Property< float > m_maxPt
Definition: AsgPtEtaSelectionTool.h:75
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53
CP::AsgPtEtaSelectionTool::m_dressedPropertiesIndex
int m_dressedPropertiesIndex
Index for the existence of dressed properties.
Definition: AsgPtEtaSelectionTool.h:99