ATLAS Offline Software
TauFeature.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cmath>
8 #include <stdexcept>
9 
10 static const std::vector<double> s_defaultVec(0);
11 
13  m_featureMap(),
14  m_vecFeatureMap()
15 {
16 }
17 
18 
20 = default;
21 
22 
23 double PanTau::TauFeature::value(const std::string& name, bool& isValid) const
24 {
25  FeatureMapConstIter iter = m_featureMap.find(name);
26  if (m_featureMap.end() == iter) {
27  isValid=false;
28  return -999999.;
29  }
30  isValid=true;
31  return (*iter).second;
32 }
33 
34 
35 const std::vector<double>& PanTau::TauFeature::vecValue(const std::string& name) const {
36  VectorFeatureMapConstIter iter = m_vecFeatureMap.find(name);
37  if (m_vecFeatureMap.end() == iter) {
38  return s_defaultVec;
39  }
40  return (*iter).second;
41 }
42 
43 
44 bool PanTau::TauFeature::addFeature(const std::string& name, const double value) {
45 
46  if (std::isnan(value)) {
47  throw std::runtime_error("TauFeature::addFeature: Given " + name + " value is NaN!");
48  }
49  if (std::isinf(value)){
50  throw std::runtime_error("TauFeature::addFeature: Given " + name + " value is inf!");
51  }
52  std::pair<FeatureMapConstIter, bool> result = m_featureMap.insert(make_pair(name, value));
53  return result.second;
54 }
55 
56 
57 bool PanTau::TauFeature::addVecFeature(const std::string& name,
58  const std::vector<double>& value) {
59  std::pair<VectorFeatureMapConstIter, bool> result = m_vecFeatureMap.insert(make_pair(name, value));
60  return result.second;
61 }
62 
63 
65  return m_featureMap.size();
66 }
67 
68 
70  return m_vecFeatureMap.size();
71 }
72 
73 // FIXME: use StatusCode instead of throwing exceptions
75 
76  //add the scalar features
77  for (const auto& p : otherFeatures->m_featureMap) {
78  if (!(this->addFeature(p.first, p.second))) {
79  throw std::runtime_error("PanTau::TauFeature::add( PanTau::TauFeature* ): Error when adding scalar feature " + p.first);
80  }
81  }
82 
83  //add the vector features
84  for (const auto& p : otherFeatures->m_vecFeatureMap) {
85  if (!(this->addVecFeature(p.first, p.second))) {
86  throw std::runtime_error("PanTau::TauFeature::add( PanTau::TauFeature* ): Error when adding vector feature " + p.first);
87  }
88  }
89 }
get_generator_info.result
result
Definition: get_generator_info.py:21
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
PanTau::TauFeature::VectorFeatureMapConstIter
VectorFeatureMap::const_iterator VectorFeatureMapConstIter
Definition: TauFeature.h:26
PanTau::TauFeature::addFeature
bool addFeature(const std::string &name, const double value)
adds a new feature
Definition: TauFeature.cxx:44
PanTau::TauFeature::nVecValues
int nVecValues() const
returns the size of the m_vecFeatureMap
Definition: TauFeature.cxx:69
athena.value
value
Definition: athena.py:122
PanTau::TauFeature
Definition: TauFeature.h:19
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
PanTau::TauFeature::m_featureMap
FeatureMap m_featureMap
The map containg all features.
Definition: TauFeature.h:61
PanTau::TauFeature::nValues
int nValues() const
returns the size of the m_featureMap
Definition: TauFeature.cxx:64
PanTau::TauFeature::FeatureMapConstIter
FeatureMap::const_iterator FeatureMapConstIter
Definition: TauFeature.h:23
PanTau::TauFeature::value
double value(const std::string &name, bool &isValid) const
returns the value of the feature given by its name
Definition: TauFeature.cxx:23
PanTau::TauFeature::m_vecFeatureMap
VectorFeatureMap m_vecFeatureMap
The map containg all features.
Definition: TauFeature.h:63
PanTau::TauFeature::TauFeature
TauFeature()
Default constructor.
Definition: TauFeature.cxx:12
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
PanTau::TauFeature::add
void add(PanTau::TauFeature *otherFeatures)
Definition: TauFeature.cxx:74
PanTau::TauFeature::addVecFeature
bool addVecFeature(const std::string &name, const std::vector< double > &value)
adds a new vector feature
Definition: TauFeature.cxx:57
TauFeature.h
PanTau::TauFeature::~TauFeature
virtual ~TauFeature()
Destructor.
PanTau::TauFeature::vecValue
const std::vector< double > & vecValue(const std::string &name) const
returns the value of a vector feature given by its name
Definition: TauFeature.cxx:35