ATLAS Offline Software
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 
24 namespace CP
25 {
26 
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 
155  getAcceptInfo () const
156  {
157  return m_accept;
158  }
159 
160 
161 
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  }
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);
189  } else
190  {
192  }
193  }
194  if (m_maxPtCutIndex >= 0) {
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");
212  m_shouldPrintCastWarning = false;
213  return accept;
214  }
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  }
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");
237  m_shouldPrintCastWarning = false;
238  return accept;
239  }
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) {
249  }
250  if (m_maxEtaCutIndex >= 0) {
252  }
253  if (m_etaGapCutIndex >= 0) {
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");
272  m_shouldPrintCastWarning = false;
273  return accept;
274  }
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) {
284  }
285  if (m_maxRapidityCutIndex >= 0) {
287  }
288  }
289 
290  return accept;
291  }
292 }
Jet.h
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:79
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:141
CP::AsgPtEtaSelectionTool::m_useClusterEta
Gaudi::Property< bool > m_useClusterEta
Definition: AsgPtEtaSelectionTool.h:82
CP::AsgPtEtaSelectionTool::m_minRapidity
Gaudi::Property< float > m_minRapidity
Definition: AsgPtEtaSelectionTool.h:80
CP::AsgPtEtaSelectionTool::m_minRapidityCutIndex
int m_minRapidityCutIndex
Index for the minimum rapidity selection.
Definition: AsgPtEtaSelectionTool.h:101
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:83
CP::AsgPtEtaSelectionTool::m_egammaClusterCutIndex
int m_egammaClusterCutIndex
Index for the e/gamma calo-cluster.
Definition: AsgPtEtaSelectionTool.h:107
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
CP::AsgPtEtaSelectionTool::m_dressedEtaAccessor
std::unique_ptr< SG::ConstAccessor< float > > m_dressedEtaAccessor
Definition: AsgPtEtaSelectionTool.h:146
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:49
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:124
egamma
Definition: egamma.h:58
CP::AsgPtEtaSelectionTool::m_jetCastCutIndex
int m_jetCastCutIndex
Index for the jet casting.
Definition: AsgPtEtaSelectionTool.h:111
Egamma.h
CP::AsgPtEtaSelectionTool::m_dressedPtAccessor
std::unique_ptr< SG::ConstAccessor< float > > m_dressedPtAccessor
dressed pt and eta accessors
Definition: AsgPtEtaSelectionTool.h:145
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
CP::AsgPtEtaSelectionTool::m_useConstituentMomentum
Gaudi::Property< bool > m_useConstituentMomentum
Definition: AsgPtEtaSelectionTool.h:84
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
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:137
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:105
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_maxRapidityCutIndex
int m_maxRapidityCutIndex
Index for the maximum rapidity selection.
Definition: AsgPtEtaSelectionTool.h:103
CP::AsgPtEtaSelectionTool::m_minPtCutIndex
int m_minPtCutIndex
Index for the minimum pT selection.
Definition: AsgPtEtaSelectionTool.h:91
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
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:163
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:155
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:97
CP::AsgPtEtaSelectionTool::m_etaGapCutIndex
int m_etaGapCutIndex
Index for the eta gap selection.
Definition: AsgPtEtaSelectionTool.h:99
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
CP::AsgPtEtaSelectionTool::m_printClusterWarning
Gaudi::Property< bool > m_printClusterWarning
Definition: AsgPtEtaSelectionTool.h:86
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:245
CP::AsgPtEtaSelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: AsgPtEtaSelectionTool.cxx:28
CP::AsgPtEtaSelectionTool::m_maxPtCutIndex
int m_maxPtCutIndex
Index for the maximum pT selection.
Definition: AsgPtEtaSelectionTool.h:93
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:85
CP::AsgPtEtaSelectionTool::m_maxRapidity
Gaudi::Property< float > m_maxRapidity
Definition: AsgPtEtaSelectionTool.h:81
CP::AsgPtEtaSelectionTool::m_minEtaCutIndex
int m_minEtaCutIndex
Index for the minimum eta selection.
Definition: AsgPtEtaSelectionTool.h:95
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:109