ATLAS Offline Software
JetAttributeSelector.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 JetAttributeSelector::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 JetAttributeSelector::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(NULL)
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 
50 
52  SelValueRetriever* retriever = NULL;
53  if(type=="float") retriever = new ::ValueRetriever<float>(name);
54  else if(type=="int") retriever = new ::ValueRetriever<int>(name);
55  else if(type=="vector<float>") retriever = new ::VecValueRetriever<float>(name, index);
56  else if(type=="vector<int>") retriever = new ::VecValueRetriever<int>(name, index);
57  else {
58  ATH_MSG_ERROR("Unsupported attribute type : "<< type);
59  // will return NULL
60  }
61  return retriever;
62 }
63 
64 
66  if(m_attName=="") {
67  ATH_MSG_ERROR("Please specify an attribute name");
68  return StatusCode::FAILURE;
69  }
70 
72  if(m_vretriever==NULL) {
73  ATH_MSG_ERROR("Can't retrieve attribute type : "<< m_attType<< " name : "<< m_attName);
74  return StatusCode::FAILURE;
75  }
76  ATH_MSG_INFO(" will select on attribute of type : "<< m_attType<< ". "<<m_min << " < "<< m_attName << " < "<< m_max);
77  return StatusCode::SUCCESS;
78 }
79 
81  float v = m_vretriever->value(jet);
82  return (m_min <= v ) && (v<=m_max);
83 }
84 
85 
87 
89  float v = fabs(m_vretriever->value(jet));
90  return (m_min <= v ) && (v<=m_max);
91 }
92 
94  , m_attName2("")
95  , m_attType2("float")
96  , m_vectorAttIndex2(0)
97  , m_vretriever2(NULL) {
98  declareProperty("Attribute2",m_attName2) ;
99  declareProperty("AttributeType2",m_attType2) ;
100  declareProperty("VectorIndex2",m_vectorAttIndex2) ;
101 
102 }
103 
104 
107 
109  if(m_vretriever2==NULL) {
110  ATH_MSG_ERROR("Can't retrieve attribute type : "<< m_attType2<< " name : "<< m_attName2);
111  return StatusCode::FAILURE;
112  }
113  ATH_MSG_INFO(" will select on RATIO of attribute of type : "<< m_attType<< " , "<< m_attName );
114  ATH_MSG_INFO(" over attribute of type : "<< m_attType2<< " , "<< m_attName << " within "<<m_min << " < r < "<< m_max);
115  return StatusCode::SUCCESS;
116 
117 }
118 
120  float v1 = m_vretriever->value(jet);
121  float v2 = m_vretriever2->value(jet);
122  if( v2 == 0.) return false;
123  double r = v1/v2;
124  return (m_min <= r ) && (r<=m_max);
125 }
JetAttributeSelector::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetAttributeSelector.cxx:65
beamspotman.r
def r
Definition: beamspotman.py:676
JetAttributeSelector::m_attName
std::string m_attName
Definition: JetAttributeSelector.h:64
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:66
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
JetAttributeRatioSelector::JetAttributeRatioSelector
JetAttributeRatioSelector(const std::string &t)
Definition: JetAttributeSelector.cxx:93
JetAttributeSelector::m_vretriever
SelValueRetriever * m_vretriever
if the attribute is a vector we'll use the value at this index. else it is ignored.
Definition: JetAttributeSelector.h:68
JetAttributeSelector::m_max
float m_max
Definition: JetAttributeSelector.h:62
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
JetAttributeRatioSelector::m_vectorAttIndex2
int m_vectorAttIndex2
Definition: JetAttributeSelector.h:96
JetAttributeSelector::~JetAttributeSelector
virtual ~JetAttributeSelector()
Definition: JetAttributeSelector.cxx:46
JetAttributeSelector::SelValueRetriever::value
virtual float value(const xAOD::Jet &j) const =0
JetAttributeSelector::m_vectorAttIndex
int m_vectorAttIndex
Definition: JetAttributeSelector.h:67
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
JetAttributeRatioSelector::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetAttributeSelector.cxx:105
JetAbsAttributeSelector::keep
virtual int keep(const xAOD::Jet &jet) const
Method to select.
Definition: JetAttributeSelector.cxx:88
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JetAbsAttributeSelector::JetAbsAttributeSelector
JetAbsAttributeSelector(const std::string &t)
Definition: JetAttributeSelector.cxx:86
JetAttributeSelector::JetAttributeSelector
JetAttributeSelector(const std::string &t)
Definition: JetAttributeSelector.cxx:28
JetAttributeSelector::m_attType
std::string m_attType
Definition: JetAttributeSelector.h:65
JetAttributeRatioSelector::m_attType2
std::string m_attType2
Definition: JetAttributeSelector.h:94
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
JetAttributeSelector
a IJetSelector implementation which select according to an attribute
Definition: JetAttributeSelector.h:40
JetAttributeSelector::SelValueRetriever
Definition: JetAttributeSelector.h:46
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
python.PyAthena.v
v
Definition: PyAthena.py:157
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
DeMoScan.index
string index
Definition: DeMoScan.py:362
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
JetAttributeSelector.h
define simple IJetSelector based on jet attributes
JetAttributeRatioSelector::m_attName2
std::string m_attName2
Definition: JetAttributeSelector.h:93
JetAttributeRatioSelector::m_vretriever2
SelValueRetriever * m_vretriever2
if the attribute is a vector we'll use the value at this index. else it is ignored.
Definition: JetAttributeSelector.h:97
JetAttributeSelector::buildValueRetriever
SelValueRetriever * buildValueRetriever(const std::string &type, const std::string &name, int index)
Definition: JetAttributeSelector.cxx:51
JetAttributeSelector::m_min
float m_min
Definition: JetAttributeSelector.h:61
readCCLHist.float
float
Definition: readCCLHist.py:83
checkFileSG.ind
list ind
Definition: checkFileSG.py:118
JetAttributeSelector::keep
virtual int keep(const xAOD::Jet &jet) const
Method to select.
Definition: JetAttributeSelector.cxx:80
JetAttributeRatioSelector::keep
virtual int keep(const xAOD::Jet &jet) const
Method to select.
Definition: JetAttributeSelector.cxx:119