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 maxPt: " << m_maxPt);
42  return StatusCode::FAILURE;
43  }
44  if (m_minEta < 0 || !std::isfinite (m_minEta))
45  {
46  ATH_MSG_ERROR ("invalid value of minEta: " << m_minEta);
47  return StatusCode::FAILURE;
48  }
49  if (m_maxEta < 0 || !std::isfinite (m_maxEta))
50  {
51  ATH_MSG_ERROR ("invalid value of maxEta: " << m_maxEta);
52  return StatusCode::FAILURE;
53  }
54  if (m_etaGapLow < 0 || !std::isfinite (m_etaGapLow))
55  {
56  ATH_MSG_ERROR ("invalid value of etaGapLow: " << m_etaGapLow);
57  return StatusCode::FAILURE;
58  }
59  if (m_etaGapHigh < 0 || !std::isfinite (m_etaGapHigh))
60  {
61  ATH_MSG_ERROR ("invalid value of etaGapHigh: " << m_etaGapHigh);
62  return StatusCode::FAILURE;
63  }
65  {
66  ATH_MSG_ERROR ("invalid eta gap: " << m_etaGapLow << " to " << m_etaGapHigh);
67  return StatusCode::FAILURE;
68  }
69  if (m_etaGapLow > 0 && m_minEta > 0 && m_etaGapLow <= m_minEta)
70  {
71  ATH_MSG_ERROR ("etaGapLow=" << m_etaGapLow << " <= minEta=" << m_minEta);
72  return StatusCode::FAILURE;
73  }
74  if (m_etaGapHigh > 0 && m_maxEta > 0 && m_etaGapHigh >= m_maxEta)
75  {
76  ATH_MSG_ERROR ("etaGapHigh=" << m_etaGapHigh << " >= maxEta=" << m_maxEta);
77  return StatusCode::FAILURE;
78  }
79 
81  ATH_MSG_DEBUG( "Performing pt and eta cuts on the dressed properties" );
82  m_dressedPropertiesIndex = m_accept.addCut ("dressedProperties", "has dressed properties");
83  m_dressedPtAccessor = std::make_unique<SG::AuxElement::ConstAccessor<float>> ("pt_dressed");
84  m_dressedEtaAccessor = std::make_unique<SG::AuxElement::ConstAccessor<float>> ("eta_dressed");
85  }
86  if (m_minPt > 0) {
87  ATH_MSG_DEBUG( "Performing pt >= " << m_minPt << " MeV selection" );
88  m_minPtCutIndex = m_accept.addCut ("minPt", "minimum pt cut");
89  }
90  if (m_maxPt > 0) {
91  ATH_MSG_DEBUG( "Performing pt < " << m_maxPt << " MeV selection" );
92  m_maxPtCutIndex = m_accept.addCut ("maxPt", "maximum pt cut");
93  }
94  if (m_useClusterEta) {
95  ATH_MSG_DEBUG( "Performing eta cut on the e/gamma cluster" );
96  m_egammaCastCutIndex = m_accept.addCut ("castEgamma", "cast to egamma");
97  m_egammaClusterCutIndex = m_accept.addCut ("caloCluster", "egamma object has cluster");
98  }
99  if (m_minEta > 0) {
100  ATH_MSG_DEBUG( "Performing |eta| >= " << m_minEta << " selection");
101  m_minEtaCutIndex = m_accept.addCut ("minEta", "minimum eta cut");
102  }
103  if (m_maxEta > 0) {
104  ATH_MSG_DEBUG( "Performing |eta| < " << m_maxEta << " selection" );
105  m_maxEtaCutIndex = m_accept.addCut ("maxEta", "maximum eta cut");
106  }
107  if (m_etaGapHigh > 0) {
108  ATH_MSG_DEBUG( "Performing !( " << m_etaGapLow << " < |eta| < "
109  << m_etaGapHigh << " ) selection" );
110  m_etaGapCutIndex = m_accept.addCut ("etaGap", "eta gap cut");
111  }
114 
115  return StatusCode::SUCCESS;
116  }
117 
118 
119 
121  getAcceptInfo () const
122  {
123  return m_accept;
124  }
125 
126 
127 
129  accept (const xAOD::IParticle *particle) const
130  {
132 
133  // Check if dressed properties exist if needed
135  if (!m_dressedPtAccessor->isAvailable(*particle)) {
136  ANA_MSG_WARNING ("dressed decorations not available");
137  return accept;
138  }
140  }
141 
142  // Perform the tranverse momentum cuts.
143  if (m_minPtCutIndex >= 0 || m_maxPtCutIndex >= 0)
144  {
145  float pt = particle->pt();
147  pt = (*m_dressedPtAccessor) (*particle);
148  }
149 
150  if (m_minPtCutIndex >= 0) {
151  if (!std::isfinite(pt) || pt < 0.)
152  {
153  ANA_MSG_WARNING ("invalid pt value, setting object to fail pt-cut: " << pt);
155  } else
156  {
158  }
159  }
160  if (m_maxPtCutIndex >= 0) {
162  }
163  }
164 
165  // Perform the eta cut(s).
166  if (m_minEtaCutIndex >= 0 || m_maxEtaCutIndex >= 0 || m_etaGapCutIndex >= 0)
167  {
168  float absEta = 0;
169 
170  if (m_useClusterEta == true)
171  {
172  const xAOD::Egamma *egamma
173  = dynamic_cast<const xAOD::Egamma*>(particle);
174  if (egamma == nullptr)
175  {
177  ANA_MSG_ERROR ("failed to cast input particle to electron");
178  m_shouldPrintCastWarning = false;
179  return accept;
180  }
182  const xAOD::CaloCluster *const caloCluster {egamma->caloCluster()};
183  if (!caloCluster)
184  {
186  ANA_MSG_ERROR ("no calo-cluster associated with e-gamma object");
188  return accept;
189  }
191  absEta = std::abs (caloCluster->etaBE(2));
192  } else if (m_useDressedProperties)
193  {
194  absEta = std::abs ((*m_dressedEtaAccessor) (*particle));
195  } else
196  {
197  absEta = std::abs (particle->eta());
198  }
199 
200  if (m_minEtaCutIndex >= 0) {
202  }
203  if (m_maxEtaCutIndex >= 0) {
205  }
206  if (m_etaGapCutIndex >= 0) {
208  absEta > m_etaGapHigh));
209  }
210  }
211 
212  return accept;
213  }
214 }
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
CP::AsgPtEtaSelectionTool::m_minEta
Gaudi::Property< float > m_minEta
Definition: AsgPtEtaSelectionTool.h:76
IParticle.h
CP::AsgPtEtaSelectionTool::m_accept
asg::AcceptInfo m_accept
the asg::AcceptInfo we are using
Definition: AsgPtEtaSelectionTool.h:132
CP::AsgPtEtaSelectionTool::m_useClusterEta
Gaudi::Property< bool > m_useClusterEta
Definition: AsgPtEtaSelectionTool.h:80
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:81
CP::AsgPtEtaSelectionTool::m_egammaClusterCutIndex
int m_egammaClusterCutIndex
Index for the e/gamma calo-cluster.
Definition: AsgPtEtaSelectionTool.h:100
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:41
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:115
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:128
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:98
CP::AsgPtEtaSelectionTool::m_etaGapLow
Gaudi::Property< float > m_etaGapLow
Definition: AsgPtEtaSelectionTool.h:78
CP::AsgPtEtaSelectionTool::m_maxEta
Gaudi::Property< float > m_maxEta
Definition: AsgPtEtaSelectionTool.h:77
CP::AsgPtEtaSelectionTool::m_minPtCutIndex
int m_minPtCutIndex
Index for the minimum pT selection.
Definition: AsgPtEtaSelectionTool.h:88
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:129
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:121
CP::AsgPtEtaSelectionTool::m_etaGapHigh
Gaudi::Property< float > m_etaGapHigh
Definition: AsgPtEtaSelectionTool.h:79
CP::AsgPtEtaSelectionTool::m_maxEtaCutIndex
int m_maxEtaCutIndex
Index for the maximum eta selection.
Definition: AsgPtEtaSelectionTool.h:94
CP::AsgPtEtaSelectionTool::m_etaGapCutIndex
int m_etaGapCutIndex
Index for the eta gap selection.
Definition: AsgPtEtaSelectionTool.h:96
CP::AsgPtEtaSelectionTool::m_printClusterWarning
Gaudi::Property< bool > m_printClusterWarning
Definition: AsgPtEtaSelectionTool.h:83
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:234
CP::AsgPtEtaSelectionTool::m_dressedPtAccessor
std::unique_ptr< SG::AuxElement::ConstAccessor< float > > m_dressedPtAccessor
dressed pt and eta accessors
Definition: AsgPtEtaSelectionTool.h:136
CP::AsgPtEtaSelectionTool::m_dressedEtaAccessor
std::unique_ptr< SG::AuxElement::ConstAccessor< float > > m_dressedEtaAccessor
Definition: AsgPtEtaSelectionTool.h:137
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:90
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:82
CP::AsgPtEtaSelectionTool::m_minEtaCutIndex
int m_minEtaCutIndex
Index for the minimum eta selection.
Definition: AsgPtEtaSelectionTool.h:92
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:102