ATLAS Offline Software
Loading...
Searching...
No Matches
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
7namespace 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>
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>
66
67 template <typename T>
69 {
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)
108 : AsgNumDecorationSelectionTool<int>(type, myname, parent)
109 {
110 }
112 const std::string& type,
113 const std::string& myname,
114 const IInterface* parent)
115 : AsgNumDecorationSelectionTool<uint8_t>(type, myname, parent)
116 {
117 }
118 #else
121 {
122 }
124 : AsgNumDecorationSelectionTool<uint8_t>(myname)
125 {
126 }
127 #endif
128
129 // Explicit template instantiations
132
133}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AsgNumDecorationSelectionToolInt(const std::string &type, const std::string &myname, const IInterface *parent)
AsgNumDecorationSelectionToolUInt8(const std::string &type, const std::string &myname, const IInterface *parent)
a templated IAsgSelectionTool that performs basic cut on numerical decorations (e....
virtual const asg::AcceptInfo & getAcceptInfo() const override
Declare the interface ID for this pure-virtual interface class to the Athena framework.
virtual asg::AcceptData accept(const xAOD::IParticle *particle) const override
The main accept method: the actual cuts are applied here.
AsgNumDecorationSelectionTool(const std::string &type, const std::string &myname, const IInterface *parent)
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
std::unique_ptr< SG::ConstAccessor< T > > m_accessor
Base class for elements of a container that can have aux data.
Definition AuxElement.h:483
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
Class providing the definition of the 4-vector interface.
Select isolated Photons, Electrons and Muons.
STL namespace.
setRawEt setRawPhi int