ATLAS Offline Software
AsgNumDecorationSelectionTool.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 namespace CP
8 {
9 
10  #ifndef XAOD_STANDALONE
11  template <typename T>
13  const std::string& type,
14  const std::string& myname,
15  const IInterface* parent)
16  : asg::AsgTool(std::string(asg::ptrToString(parent))+"#"+type+"/"+myname)
17  {
18  // cppcheck-suppress missingReturn; false positive
19  }
20  template <typename T>
22  {
23  }
24  #else
25  template <typename T>
27  : asg::AsgTool(myname)
28  {
29  }
30  #endif
31 
32  template <typename T>
34  {
35  if (m_doEqual) {
36  if (m_doMin || m_doMax) {
37  ATH_MSG_WARNING("Equal cut overrides min/max on \"" << m_name << "\"; disabling min/max.");
38  m_doMin = false;
39  m_doMax = false;
40  }
41  ATH_MSG_DEBUG("Applying " << m_name << " == " << m_equal << " selection");
42  m_equalCutIndex = m_accept.addCut("equal", "Exact equality cut");
43  }
44 
45  if (m_doMin) {
46  ATH_MSG_DEBUG("Applying " << m_name << " >= " << m_min << " selection");
47  m_minCutIndex = m_accept.addCut("min", "Minimum cut");
48  }
49 
50  if (m_doMax) {
51  ATH_MSG_DEBUG("Applying " << m_name << " < " << m_max << " selection");
52  m_maxCutIndex = m_accept.addCut("max", "Maximum cut");
53  }
54 
55  // Construct the decoration accessor for the desired type
56  m_accessor = std::make_unique<SG::ConstAccessor<T>>(m_name);
57 
58  return StatusCode::SUCCESS;
59  }
60 
61  template <typename T>
63  {
64  return m_accept;
65  }
66 
67  template <typename T>
69  {
70  asg::AcceptData accept(&m_accept);
71 
72  const SG::AuxElement* aux = dynamic_cast<const SG::AuxElement*>(particle);
73  if (!aux) {
74  ATH_MSG_ERROR("Particle is not derived from AuxElement, cannot read decoration. Cut considered as failed.");
75  return accept; // reject all cuts by default
76  }
77 
78  if (!m_accessor->isAvailable(*aux)) {
79  ATH_MSG_WARNING("Decoration \"" << m_name << "\" not available; setting all cuts as passed.");
80  if (m_equalCutIndex >= 0) accept.setCutResult(m_equalCutIndex, true);
81  if (m_minCutIndex >= 0) accept.setCutResult(m_minCutIndex, true);
82  if (m_maxCutIndex >= 0) accept.setCutResult(m_maxCutIndex, true);
83  return accept;
84  }
85 
86  const T value = (*m_accessor)(*aux);
87 
88  if (m_equalCutIndex >= 0) {
89  accept.setCutResult(m_equalCutIndex, static_cast<float>(value) == m_equal);
90  }
91 
92  if (m_minCutIndex >= 0) {
93  accept.setCutResult(m_minCutIndex, static_cast<float>(value) >= m_min);
94  }
95 
96  if (m_maxCutIndex >= 0) {
97  accept.setCutResult(m_maxCutIndex, static_cast<float>(value) < m_max);
98  }
99 
100  return accept;
101  }
102 
103  #ifndef XAOD_STANDALONE
105  const std::string& type,
106  const std::string& myname,
107  const IInterface* parent)
109  {
110  }
112  const std::string& type,
113  const std::string& myname,
114  const IInterface* parent)
116  {
117  }
118  #else
121  {
122  }
124  : AsgNumDecorationSelectionTool<uint8_t>(myname)
125  {
126  }
127  #endif
128 
129  // Explicit template instantiations
130  template class AsgNumDecorationSelectionTool<int>;
131  template class AsgNumDecorationSelectionTool<uint8_t>;
132 
133 }
CP::AsgNumDecorationSelectionToolUInt8::AsgNumDecorationSelectionToolUInt8
AsgNumDecorationSelectionToolUInt8(const std::string &type, const std::string &myname, const IInterface *parent)
Definition: AsgNumDecorationSelectionTool.cxx:111
AsgNumDecorationSelectionTool.h
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:79
CP::AsgNumDecorationSelectionToolInt::AsgNumDecorationSelectionToolInt
AsgNumDecorationSelectionToolInt(const std::string &type, const std::string &myname, const IInterface *parent)
Definition: AsgNumDecorationSelectionTool.cxx:104
CP::AsgNumDecorationSelectionTool
a templated IAsgSelectionTool that performs basic cut on numerical decorations (e....
Definition: AsgNumDecorationSelectionTool.h:26
CP::AsgNumDecorationSelectionTool::~AsgNumDecorationSelectionTool
virtual ~AsgNumDecorationSelectionTool()
Definition: AsgNumDecorationSelectionTool.cxx:21
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:558
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:483
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
asg
Definition: DataHandleTestTool.h:28
athena.value
value
Definition: athena.py:124
m_name
std::string m_name
Definition: ColumnarPhysliteTest.cxx:63
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CP::AsgNumDecorationSelectionTool::AsgNumDecorationSelectionTool
AsgNumDecorationSelectionTool(const std::string &type, const std::string &myname, const IInterface *parent)
Definition: AsgNumDecorationSelectionTool.cxx:12
CP::AsgNumDecorationSelectionTool::getAcceptInfo
virtual const asg::AcceptInfo & getAcceptInfo() const override
Declare the interface ID for this pure-virtual interface class to the Athena framework.
Definition: AsgNumDecorationSelectionTool.cxx:62
CP::AsgNumDecorationSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *particle) const override
The main accept method: the actual cuts are applied here.
Definition: AsgNumDecorationSelectionTool.cxx:68
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
columnar::m_accessor
ColumnAccessor< CI, std::vector< typename ColumnTypeTraits< CT, CM >::ColumnType >, CM > m_accessor
Definition: VectorColumn.h:164
asg::ptrToString
std::string ptrToString(const void *p)
Definition: AsgToolMacros.cxx:14
CP::AsgNumDecorationSelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: AsgNumDecorationSelectionTool.cxx:33
asg::AcceptData
Definition: AcceptData.h:30