ATLAS Offline Software
JetSelectorAttributeRunII.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <limits>
7 
8 namespace {
9 
10  template <class T>
11  struct ValueRetriever : public JetSelectorAttributeRunII::SelValueRetriever {
12  ValueRetriever(const std::string &n) : acc(n) {}
13  virtual float value(const xAOD::Jet& j) const override { return acc(j);}
15  };
16 
17  template <class T>
18  struct VecValueRetriever : public JetSelectorAttributeRunII::SelValueRetriever {
19  VecValueRetriever(const std::string &n, int ind) : acc(n), index(ind) {}
20  virtual float value(const xAOD::Jet& j) const override { return acc(j)[index];}
22  int index;
23  };
24 
25 
26 }
27 
29  : asg::AsgTool(t)
30  , m_min(-std::numeric_limits<float>::max())
31  , m_max( std::numeric_limits<float>::max())
32  , m_attName("")
33  , m_attType("float")
34  , m_vectorAttIndex(0)
35  , m_vretriever(nullptr)
36 {
37 
38  declareProperty("CutMin", m_min );
39  declareProperty("CutMax", m_max );
40  declareProperty("Attribute",m_attName) ;
41  declareProperty("AttributeType",m_attType) ;
42  declareProperty("VectorIndex",m_vectorAttIndex) ;
43 
44 }
45 
47  if(m_vretriever) delete m_vretriever;
48 }
49 
51  if(m_attName.empty()) {
52  ATH_MSG_ERROR("Please specify an attribute name");
53  return StatusCode::FAILURE;
54  }
55 
56  if(m_attType=="float") m_vretriever = new ::ValueRetriever<float>(m_attName);
57  else if(m_attType=="int") m_vretriever = new ::ValueRetriever<int>(m_attName);
58  else if(m_attType=="vector<float>") m_vretriever = new ::VecValueRetriever<float>(m_attName, m_vectorAttIndex);
59  else {
60  ATH_MSG_ERROR("Unsupported attribute type : "<< m_attType);
61  return StatusCode::FAILURE;
62  }
63  ATH_MSG_INFO(" will select on attribute of type : "<< m_attType<< ". "<<m_min << " < "<< m_attName << " < "<< m_max);
64  return StatusCode::SUCCESS;
65 }
66 
68  float v = m_vretriever->value(jet);
69  return (m_min < v ) && (v<m_max);
70 }
JetSelectorAttributeRunII::m_attType
std::string m_attType
Definition: JetSelectorAttributeRunII.h:46
JetSelectorAttributeRunII::SelValueRetriever
Definition: JetSelectorAttributeRunII.h:28
max
#define max(a, b)
Definition: cfImp.cxx:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
JetSelectorAttributeRunII.h
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
asg
Definition: DataHandleTestTool.h:28
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
JetSelectorAttributeRunII::JetSelectorAttributeRunII
JetSelectorAttributeRunII(const std::string &t)
Definition: JetSelectorAttributeRunII.cxx:28
JetSelectorAttributeRunII::SelValueRetriever::value
virtual float value(const xAOD::Jet &j) const =0
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
JetSelectorAttributeRunII::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetSelectorAttributeRunII.cxx:50
JetSelectorAttributeRunII::m_min
float m_min
Definition: JetSelectorAttributeRunII.h:42
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JetSelectorAttributeRunII::m_vectorAttIndex
int m_vectorAttIndex
Definition: JetSelectorAttributeRunII.h:48
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
JetSelectorAttributeRunII::keep
int keep(const xAOD::Jet &jet) const
Method to select.
Definition: JetSelectorAttributeRunII.cxx:67
JetSelectorAttributeRunII::m_max
float m_max
Definition: JetSelectorAttributeRunII.h:43
python.PyAthena.v
v
Definition: PyAthena.py:154
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
DeMoScan.index
string index
Definition: DeMoScan.py:364
JetSelectorAttributeRunII::m_vretriever
SelValueRetriever * m_vretriever
if the attribute is a vector we'll use the value at this index. else it is ignored.
Definition: JetSelectorAttributeRunII.h:49
JetSelectorAttributeRunII::m_attName
std::string m_attName
Definition: JetSelectorAttributeRunII.h:45
JetSelectorAttributeRunII::~JetSelectorAttributeRunII
virtual ~JetSelectorAttributeRunII()
Definition: JetSelectorAttributeRunII.cxx:46
readCCLHist.float
float
Definition: readCCLHist.py:83
checkFileSG.ind
list ind
Definition: checkFileSG.py:118