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  }
19  template <typename T>
21  {
22  }
23  #else
24  template <typename T>
26  : asg::AsgTool(myname)
27  {
28  }
29  #endif
30 
31  template <typename T>
33  {
34  if (m_doEqual) {
35  if (m_doMin || m_doMax) {
36  ATH_MSG_WARNING("Equal cut overrides min/max on \"" << m_name << "\"; disabling min/max.");
37  m_doMin = false;
38  m_doMax = false;
39  }
40  ATH_MSG_DEBUG("Applying " << m_name << " == " << m_equal << " selection");
41  m_equalCutIndex = m_accept.addCut("equal", "Exact equality cut");
42  }
43 
44  if (m_doMin) {
45  ATH_MSG_DEBUG("Applying " << m_name << " >= " << m_min << " selection");
46  m_minCutIndex = m_accept.addCut("min", "Minimum cut");
47  }
48 
49  if (m_doMax) {
50  ATH_MSG_DEBUG("Applying " << m_name << " < " << m_max << " selection");
51  m_maxCutIndex = m_accept.addCut("max", "Maximum cut");
52  }
53 
54  // Construct the decoration accessor for the desired type
55  m_accessor = std::make_unique<SG::ConstAccessor<T>>(m_name);
56 
57  return StatusCode::SUCCESS;
58  }
59 
60  template <typename T>
62  {
63  return m_accept;
64  }
65 
66  template <typename T>
68  {
69  asg::AcceptData accept(&m_accept);
70 
71  const SG::AuxElement* aux = dynamic_cast<const SG::AuxElement*>(particle);
72  if (!aux) {
73  ATH_MSG_ERROR("Particle is not derived from AuxElement, cannot read decoration. Cut considered as failed.");
74  return accept; // reject all cuts by default
75  }
76 
77  if (!m_accessor->isAvailable(*aux)) {
78  ATH_MSG_WARNING("Decoration \"" << m_name << "\" not available; setting all cuts as passed.");
79  if (m_equalCutIndex >= 0) accept.setCutResult(m_equalCutIndex, true);
80  if (m_minCutIndex >= 0) accept.setCutResult(m_minCutIndex, true);
81  if (m_maxCutIndex >= 0) accept.setCutResult(m_maxCutIndex, true);
82  return accept;
83  }
84 
85  const T value = (*m_accessor)(*aux);
86 
87  if (m_equalCutIndex >= 0) {
88  accept.setCutResult(m_equalCutIndex, static_cast<float>(value) == m_equal);
89  }
90 
91  if (m_minCutIndex >= 0) {
92  accept.setCutResult(m_minCutIndex, static_cast<float>(value) >= m_min);
93  }
94 
95  if (m_maxCutIndex >= 0) {
96  accept.setCutResult(m_maxCutIndex, static_cast<float>(value) < m_max);
97  }
98 
99  return accept;
100  }
101 
102  #ifndef XAOD_STANDALONE
104  const std::string& type,
105  const std::string& myname,
106  const IInterface* parent)
108  {
109  }
111  const std::string& type,
112  const std::string& myname,
113  const IInterface* parent)
115  {
116  }
117  #else
120  {
121  }
123  : AsgNumDecorationSelectionTool<uint8_t>(myname)
124  {
125  }
126  #endif
127 
128  // Explicit template instantiations
129  template class AsgNumDecorationSelectionTool<int>;
130  template class AsgNumDecorationSelectionTool<uint8_t>;
131 
132 }
CP::AsgNumDecorationSelectionToolUInt8::AsgNumDecorationSelectionToolUInt8
AsgNumDecorationSelectionToolUInt8(const std::string &type, const std::string &myname, const IInterface *parent)
Definition: AsgNumDecorationSelectionTool.cxx:110
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:103
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:20
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:62
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:61
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:67
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:32
asg::AcceptData
Definition: AcceptData.h:30