ATLAS Offline Software
Loading...
Searching...
No Matches
AsgPtEtaSelectionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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 <xAODJet/Jet.h>
17#include <xAODBase/IParticle.h>
18#include <cmath>
19
20//
21// method implementations
22//
23
24namespace CP
25{
26
27 StatusCode AsgPtEtaSelectionTool ::
28 initialize ()
29 {
31 {
32 ATH_MSG_ERROR ("only one of 'useDressedProperties', 'useClusterEta' and 'useConstituentMomentum' can be used at the same time");
33 return StatusCode::FAILURE;
34 }
35 if (m_minPt < 0 || !std::isfinite (m_minPt))
36 {
37 ATH_MSG_ERROR ("invalid value of minPt: " << m_minPt);
38 return StatusCode::FAILURE;
39 }
40 if (m_maxPt < 0 || !std::isfinite (m_maxPt))
41 {
42 ATH_MSG_ERROR ("invalid value of maxPt: " << m_maxPt);
43 return StatusCode::FAILURE;
44 }
45 if (m_minEta < 0 || !std::isfinite (m_minEta))
46 {
47 ATH_MSG_ERROR ("invalid value of minEta: " << m_minEta);
48 return StatusCode::FAILURE;
49 }
50 if (m_maxEta < 0 || !std::isfinite (m_maxEta))
51 {
52 ATH_MSG_ERROR ("invalid value of maxEta: " << m_maxEta);
53 return StatusCode::FAILURE;
54 }
55 if (m_etaGapLow < 0 || !std::isfinite (m_etaGapLow))
56 {
57 ATH_MSG_ERROR ("invalid value of etaGapLow: " << m_etaGapLow);
58 return StatusCode::FAILURE;
59 }
60 if (m_etaGapHigh < 0 || !std::isfinite (m_etaGapHigh))
61 {
62 ATH_MSG_ERROR ("invalid value of etaGapHigh: " << m_etaGapHigh);
63 return StatusCode::FAILURE;
64 }
66 {
67 ATH_MSG_ERROR ("invalid eta gap: " << m_etaGapLow << " to " << m_etaGapHigh);
68 return StatusCode::FAILURE;
69 }
70 if (m_etaGapLow > 0 && m_minEta > 0 && m_etaGapLow <= m_minEta)
71 {
72 ATH_MSG_ERROR ("etaGapLow=" << m_etaGapLow << " <= minEta=" << m_minEta);
73 return StatusCode::FAILURE;
74 }
75 if (m_etaGapHigh > 0 && m_maxEta > 0 && m_etaGapHigh >= m_maxEta)
76 {
77 ATH_MSG_ERROR ("etaGapHigh=" << m_etaGapHigh << " >= maxEta=" << m_maxEta);
78 return StatusCode::FAILURE;
79 }
80 if (m_minRapidity < 0 || !std::isfinite (m_minRapidity))
81 {
82 ATH_MSG_ERROR ("invalid value of minRapidity: " << m_minRapidity);
83 return StatusCode::FAILURE;
84 }
85 if (m_maxRapidity < 0 || !std::isfinite (m_maxRapidity))
86 {
87 ATH_MSG_ERROR ("invalid value of maxRapidity: " << m_maxRapidity);
88 return StatusCode::FAILURE;
89 }
90 if ((m_minRapidity > 0 && m_maxRapidity > 0) &&
92 {
93 ATH_MSG_ERROR ("invalid rapidity range: " << m_minRapidity << " to " << m_maxRapidity);
94 return StatusCode::FAILURE;
95 }
96 if ((m_minEta > 0 || m_maxEta > 0) && (m_minRapidity > 0 || m_maxRapidity > 0))
97 {
98 ATH_MSG_ERROR ("cannot use both eta and rapidity cuts at the same time");
99 return StatusCode::FAILURE;
100 }
101
103 ATH_MSG_DEBUG( "Performing pt and eta cuts on the dressed properties" );
104 m_dressedPropertiesIndex = m_accept.addCut ("dressedProperties", "has dressed properties");
105 m_dressedPtAccessor = std::make_unique<SG::ConstAccessor<float>> ("pt_dressed");
106 m_dressedEtaAccessor = std::make_unique<SG::ConstAccessor<float>> ("eta_dressed");
107 }
108 if (m_minPt > 0) {
109 ATH_MSG_DEBUG( "Performing pt >= " << m_minPt << " MeV selection" );
110 m_minPtCutIndex = m_accept.addCut ("minPt", "minimum pt cut");
111 }
112 if (m_maxPt > 0) {
113 ATH_MSG_DEBUG( "Performing pt < " << m_maxPt << " MeV selection" );
114 m_maxPtCutIndex = m_accept.addCut ("maxPt", "maximum pt cut");
115 }
116 if (m_useClusterEta) {
117 ATH_MSG_DEBUG( "Performing eta cut on the e/gamma cluster" );
118 m_egammaCastCutIndex = m_accept.addCut ("castEgamma", "cast to egamma");
119 m_egammaClusterCutIndex = m_accept.addCut ("caloCluster", "egamma object has cluster");
120 }
122 ATH_MSG_DEBUG( "Performing eta/rapidity cut on the jet constituent momentum" );
123 m_jetCastCutIndex = m_accept.addCut ("castJet", "cast to jet");
124 }
125 if (m_minEta > 0) {
126 ATH_MSG_DEBUG( "Performing |eta| >= " << m_minEta << " selection");
127 m_minEtaCutIndex = m_accept.addCut ("minEta", "minimum eta cut");
128 }
129 if (m_maxEta > 0) {
130 ATH_MSG_DEBUG( "Performing |eta| < " << m_maxEta << " selection" );
131 m_maxEtaCutIndex = m_accept.addCut ("maxEta", "maximum eta cut");
132 }
133 if (m_etaGapHigh > 0) {
134 ATH_MSG_DEBUG( "Performing !( " << m_etaGapLow << " < |eta| < "
135 << m_etaGapHigh << " ) selection" );
136 m_etaGapCutIndex = m_accept.addCut ("etaGap", "eta gap cut");
137 }
138 if (m_minRapidity > 0) {
139 ATH_MSG_DEBUG( "Performing |rapidity| >= " << m_minRapidity << " selection");
140 m_minRapidityCutIndex = m_accept.addCut ("minRapidity", "minimum eta cut");
141 }
142 if (m_maxRapidity > 0) {
143 ATH_MSG_DEBUG( "Performing |rapidity| < " << m_maxRapidity << " selection" );
144 m_maxRapidityCutIndex = m_accept.addCut ("maxRapidity", "maximum eta cut");
145 }
148
149 return StatusCode::SUCCESS;
150 }
151
152
153
154 const asg::AcceptInfo& AsgPtEtaSelectionTool ::
155 getAcceptInfo () const
156 {
157 return m_accept;
158 }
159
160
161
162 asg::AcceptData AsgPtEtaSelectionTool ::
163 accept (const xAOD::IParticle *particle) const
164 {
166
167 // Check if dressed properties exist if needed
169 if (!m_dressedPtAccessor->isAvailable(*particle)) {
170 ANA_MSG_WARNING ("dressed decorations not available");
171 return accept;
172 }
173 accept.setCutResult (m_dressedPropertiesIndex, true);
174 }
175
176 // Perform the tranverse momentum cuts.
177 if (m_minPtCutIndex >= 0 || m_maxPtCutIndex >= 0)
178 {
179 float pt = particle->pt();
181 pt = (*m_dressedPtAccessor) (*particle);
182 }
183
184 if (m_minPtCutIndex >= 0) {
185 if (!std::isfinite(pt) || pt < 0.)
186 {
187 ANA_MSG_WARNING ("invalid pt value, setting object to fail pt-cut: " << pt);
188 accept.setCutResult (m_minPtCutIndex, false);
189 } else
190 {
191 accept.setCutResult (m_minPtCutIndex, pt >= m_minPt);
192 }
193 }
194 if (m_maxPtCutIndex >= 0) {
195 accept.setCutResult (m_maxPtCutIndex, pt < m_maxPt);
196 }
197 }
198
199 // Perform the eta cut(s).
200 if (m_minEtaCutIndex >= 0 || m_maxEtaCutIndex >= 0 || m_etaGapCutIndex >= 0)
201 {
202 float absEta = 0;
203
204 if (m_useClusterEta == true)
205 {
206 const xAOD::Egamma *egamma
207 = dynamic_cast<const xAOD::Egamma*>(particle);
208 if (egamma == nullptr)
209 {
211 ANA_MSG_ERROR ("failed to cast input particle to electron");
213 return accept;
214 }
215 accept.setCutResult (m_egammaCastCutIndex, true);
216 const xAOD::CaloCluster *const caloCluster {egamma->caloCluster()};
217 if (!caloCluster)
218 {
220 ANA_MSG_ERROR ("no calo-cluster associated with e-gamma object");
222 return accept;
223 }
224 accept.setCutResult (m_egammaClusterCutIndex, true);
225 absEta = std::abs (caloCluster->etaBE(2));
226 } else if (m_useDressedProperties)
227 {
228 absEta = std::abs ((*m_dressedEtaAccessor) (*particle));
229 } else if (m_useConstituentMomentum == true)
230 {
231 const xAOD::Jet *jet
232 = dynamic_cast<const xAOD::Jet*>(particle);
233 if (jet == nullptr)
234 {
236 ANA_MSG_ERROR ("failed to cast input particle to jet");
238 return accept;
239 }
240 accept.setCutResult (m_jetCastCutIndex, true);
241 absEta = std::abs (jet->getAttribute<xAOD::JetFourMom_t>("JetConstitScaleMomentum").eta());
242 } else
243 {
244 absEta = std::abs (particle->eta());
245 }
246
247 if (m_minEtaCutIndex >= 0) {
248 accept.setCutResult (m_minEtaCutIndex, absEta > m_minEta);
249 }
250 if (m_maxEtaCutIndex >= 0) {
251 accept.setCutResult (m_maxEtaCutIndex, absEta <= m_maxEta);
252 }
253 if (m_etaGapCutIndex >= 0) {
254 accept.setCutResult (m_etaGapCutIndex, (absEta < m_etaGapLow ||
255 absEta > m_etaGapHigh));
256 }
257 }
258
259 // Perform the rapdity cut(s).
261 {
262 float absRapidity = 0;
263
264 if (m_useConstituentMomentum == true)
265 {
266 const xAOD::Jet *jet
267 = dynamic_cast<const xAOD::Jet*>(particle);
268 if (jet == nullptr)
269 {
271 ANA_MSG_ERROR ("failed to cast input particle to jet");
273 return accept;
274 }
275 accept.setCutResult (m_jetCastCutIndex, true);
276 absRapidity = std::abs (jet->getAttribute<xAOD::JetFourMom_t>("JetConstitScaleMomentum").Rapidity());
277 } else
278 {
279 absRapidity = std::abs (particle->rapidity());
280 }
281
282 if (m_minRapidityCutIndex >= 0) {
283 accept.setCutResult (m_minRapidityCutIndex, absRapidity > m_minRapidity);
284 }
285 if (m_maxRapidityCutIndex >= 0) {
286 accept.setCutResult (m_maxRapidityCutIndex, absRapidity <= m_maxRapidity);
287 }
288 }
289
290 return accept;
291 }
292}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
int m_jetCastCutIndex
Index for the jet casting.
Gaudi::Property< float > m_maxPt
int m_etaGapCutIndex
Index for the eta gap selection.
std::unique_ptr< SG::ConstAccessor< float > > m_dressedPtAccessor
dressed pt and eta accessors
int m_egammaCastCutIndex
Index for the e/gamma casting.
Gaudi::Property< float > m_etaGapLow
int m_maxEtaCutIndex
Index for the maximum eta selection.
int m_maxPtCutIndex
Index for the maximum pT selection.
virtual asg::AcceptData accept(const xAOD::IParticle *particle) const override
The main accept method: the actual cuts are applied here.
Gaudi::Property< float > m_minEta
Gaudi::Property< bool > m_printClusterWarning
Gaudi::Property< bool > m_useDressedProperties
Gaudi::Property< float > m_minRapidity
Gaudi::Property< bool > m_printCastWarning
std::unique_ptr< SG::ConstAccessor< float > > m_dressedEtaAccessor
int m_egammaClusterCutIndex
Index for the e/gamma calo-cluster.
int m_minPtCutIndex
Index for the minimum pT selection.
Gaudi::Property< bool > m_useClusterEta
int m_maxRapidityCutIndex
Index for the maximum rapidity selection.
std::atomic< bool > m_shouldPrintClusterWarning
a version of m_printClusterWarning that we modify once we printed the warning
Gaudi::Property< float > m_minPt
tool properties
int m_dressedPropertiesIndex
Index for the existence of dressed properties.
int m_minRapidityCutIndex
Index for the minimum rapidity selection.
asg::AcceptInfo m_accept
the asg::AcceptInfo we are using
std::atomic< bool > m_shouldPrintCastWarning
a version of m_printCastWarning that we modify once we printed the warning
Gaudi::Property< bool > m_useConstituentMomentum
Gaudi::Property< float > m_maxEta
Gaudi::Property< float > m_etaGapHigh
int m_minEtaCutIndex
Index for the minimum eta selection.
Gaudi::Property< float > m_maxRapidity
elec/gamma data class.
Definition egamma.h:58
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
Class providing the definition of the 4-vector interface.
Select isolated Photons, Electrons and Muons.
Jet_v1 Jet
Definition of the current "jet version".
setRcore setEtHad setFside pt
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17