CMS 3D CMS Logo

GenericMVAComputer.h
Go to the documentation of this file.
1 #ifndef RecoBTau_BTauComputer_GenericMVAComputer_h
2 #define RecoBTau_BTauComputer_GenericMVAComputer_h
3 
4 #include <iterator>
5 #include <vector>
6 
11 
12 // overload MVAComputer and replace eval() methods to work on TaggingVariable
14 public:
15  // forward declarations;
16  template <typename Iter_t>
19 
21 
22  // create wrapping iterator
23  template <typename Iter_t>
24  inline TaggingVariableIterator<Iter_t> iterator(Iter_t iter) const {
26  }
27 
28  // overload eval method to work on containers of TaggingVariable
29  template <typename Iter_t>
30  inline double eval(Iter_t first, Iter_t last) const {
31  typedef TaggingVariableIterator<Iter_t> Wrapped_t;
32  return PhysicsTools::MVAComputer::template eval<Wrapped_t>(iterator<Iter_t>(first), iterator<Iter_t>(last));
33  }
34 
35  template <typename Container_t>
36  inline double eval(const Container_t &values) const {
37  typedef typename Container_t::const_iterator Iter_t;
38  return this->template eval<Iter_t>(values.begin(), values.end());
39  }
40 
41  // iterator wrapper with on-the-fly TaggingVariableName -> AtomicId mapping
42  //
43  // Notice that this tells the computer to completely inline it
44  // this is reasonable since inlining it means that the optimizer
45  // will not produce any additional code for the wrapper
46  // (it is entirely optimized away), except for the actual mapping
47  // which is no more than a simple array lookup.
48  //
49  // The result will be inlined into the eval() template of MVAComputer
50  // which will be instantiated as one single tightly-integrated
51  // function.
52  template <typename Iter_t>
53  class TaggingVariableIterator {
54  public:
55  // class implementing MVAComputer::Variable::Value interface
56  struct Value {
57  public:
58  // the actual operator doing the mapping
59  inline PhysicsTools::AtomicId getName() const { return mapping->getAtomicId(iter->first); }
60 
61  inline double getValue() const { return iter->second; }
62 
64 
65  protected:
67 
68  inline Value(TaggingVariableMapping const *mapping, const Iter_t &iter) : mapping(mapping), iter(iter) {}
69 
70  private:
71  // pointer to the current mapping
73  // iterator to reco::TaggingVariable in orig. container
74  Iter_t iter;
75  };
76 
77  typedef std::forward_iterator_tag iterator_category;
78  typedef Value value_type;
79  typedef typename std::iterator_traits<Iter_t>::difference_type difference_type;
80  typedef const Value *pointer;
81  typedef const Value &reference;
82 
84 
85  // methods to make class a standard forward iterator
86 
87  inline const Value &operator*() const { return value; }
88  inline Value &operator*() { return value; }
89 
90  inline const Value *operator->() const { return &value; }
91  inline Value *operator->() { return &value; }
92 
93  inline bool operator==(const TaggingVariableIterator &other) const { return value.iter == other.value.iter; }
94  inline bool operator!=(const TaggingVariableIterator &other) const { return value.iter != other.value.iter; }
95  inline bool operator<(const TaggingVariableIterator &other) const { return value.iter < other.value.iter; }
96 
98  ++value.iter;
99  return *this;
100  }
101 
103  TaggingVariableIterator orig = *this;
104  ++value.iter;
105  return orig;
106  }
107 
108  protected:
109  friend class GenericMVAComputer;
110  inline TaggingVariableIterator(TaggingVariableMapping const *mapping, const Iter_t &iter) : value(mapping, iter) {}
111 
112  private:
113  // holds the current "value"
114  // it's really only an iterator that points the original
115  // current TaggingVariable plus required methods
117  };
118 
119  // TaggingVariableName -> PhysicsTools::AtomicId mapping
121  public:
124 
127 
128  inline AtomicId getAtomicId(TaggingName taggingName) const { return taggingVarToAtomicId[taggingName]; }
129 
130  private:
131  std::vector<AtomicId> taggingVarToAtomicId;
132  };
133 
134 private:
136 };
137 
138 #endif // RecoBTau_BTauComputer_GenericMVAComputer_h
PhysicsTools::AtomicId
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
GenericMVAComputer::TaggingVariableIterator::Value::Value
Value(TaggingVariableMapping const *mapping, const Iter_t &iter)
Definition: GenericMVAComputer.h:68
GenericMVAComputer::GenericMVAComputer
GenericMVAComputer(const PhysicsTools::Calibration::MVAComputer *calib)
Definition: GenericMVAComputer.h:20
GenericMVAComputer::TaggingVariableIterator::operator==
bool operator==(const TaggingVariableIterator &other) const
Definition: GenericMVAComputer.h:93
GenericMVAComputer::TaggingVariableIterator::pointer
const typedef Value * pointer
Definition: GenericMVAComputer.h:80
GenericMVAComputer::TaggingVariableIterator::operator->
const Value * operator->() const
Definition: GenericMVAComputer.h:90
GenericMVAComputer
Definition: GenericMVAComputer.h:13
GenericMVAComputer::TaggingVariableIterator::operator++
TaggingVariableIterator & operator++()
Definition: GenericMVAComputer.h:97
dqmdumpme.first
first
Definition: dqmdumpme.py:55
PhysicsTools::MVAComputer
Main interface class to the generic discriminator computer framework.
Definition: MVAComputer.h:39
GenericMVAComputer::TaggingVariableMapping::taggingVarToAtomicId
std::vector< AtomicId > taggingVarToAtomicId
Definition: GenericMVAComputer.h:131
GenericMVAComputer::TaggingVariableIterator::~TaggingVariableIterator
~TaggingVariableIterator()
Definition: GenericMVAComputer.h:83
PhysicsTools::MVAComputer::MVAComputer
MVAComputer(const Calibration::MVAComputer *calib)
construct a discriminator computer from a const calibation object
Definition: MVAComputer.cc:37
dqmdumpme.last
last
Definition: dqmdumpme.py:56
GenericMVAComputer::TaggingVariableIterator::GenericMVAComputer
friend class GenericMVAComputer
Definition: GenericMVAComputer.h:109
GenericMVAComputer::eval
double eval(const Container_t &values) const
Definition: GenericMVAComputer.h:36
GenericMVAComputer::TaggingVariableIterator::value
Value value
Definition: GenericMVAComputer.h:116
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
getName
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:235
GenericMVAComputer::TaggingVariableIterator::Value::getName
PhysicsTools::AtomicId getName() const
Definition: GenericMVAComputer.h:59
AtomicId.h
GenericMVAComputer::mapping
static const TaggingVariableMapping mapping
Definition: GenericMVAComputer.h:135
GenericMVAComputer::TaggingVariableIterator::operator*
const Value & operator*() const
Definition: GenericMVAComputer.h:87
trackingPlots.other
other
Definition: trackingPlots.py:1467
GenericMVAComputer::TaggingVariableIterator::Value::iter
Iter_t iter
Definition: GenericMVAComputer.h:74
MVAComputer.h
GenericMVAComputer::TaggingVariableMapping::TaggingName
reco::TaggingVariableName TaggingName
Definition: GenericMVAComputer.h:123
GenericMVAComputer::TaggingVariableMapping::getAtomicId
AtomicId getAtomicId(TaggingName taggingName) const
Definition: GenericMVAComputer.h:128
calib
Definition: CalibElectron.h:12
GenericMVAComputer::TaggingVariableIterator::Value::getValue
double getValue() const
Definition: GenericMVAComputer.h:61
GenericMVAComputer::TaggingVariableIterator::operator++
TaggingVariableIterator operator++(int dummy)
Definition: GenericMVAComputer.h:102
GenericMVAComputer::TaggingVariableIterator::operator*
Value & operator*()
Definition: GenericMVAComputer.h:88
GenericMVAComputer::TaggingVariableIterator::operator->
Value * operator->()
Definition: GenericMVAComputer.h:91
GenericMVAComputer::TaggingVariableIterator::Value::TaggingVariableIterator
friend class TaggingVariableIterator
Definition: GenericMVAComputer.h:66
PhysicsTools::Calibration::MVAComputer
Definition: MVAComputer.h:221
PhysicsTools
Definition: Histogram.h:13
reco::JetExtendedAssociation::getValue
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
Definition: JetExtendedAssociation.cc:50
GenericMVAComputer::TaggingVariableIterator::operator!=
bool operator!=(const TaggingVariableIterator &other) const
Definition: GenericMVAComputer.h:94
value
Definition: value.py:1
GenericMVAComputer::TaggingVariableIterator::value_type
Value value_type
Definition: GenericMVAComputer.h:78
GenericMVAComputer::TaggingVariableMapping::~TaggingVariableMapping
~TaggingVariableMapping()
Definition: GenericMVAComputer.h:126
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
GenericMVAComputer::TaggingVariableIterator::difference_type
std::iterator_traits< Iter_t >::difference_type difference_type
Definition: GenericMVAComputer.h:79
GenericMVAComputer::TaggingVariableIterator::operator<
bool operator<(const TaggingVariableIterator &other) const
Definition: GenericMVAComputer.h:95
GenericMVAComputer::TaggingVariableMapping
Definition: GenericMVAComputer.h:120
GenericMVAComputer::iterator
TaggingVariableIterator< Iter_t > iterator(Iter_t iter) const
Definition: GenericMVAComputer.h:24
relativeConstraints.value
value
Definition: relativeConstraints.py:53
GenericMVAComputer::TaggingVariableIterator::Value
Definition: GenericMVAComputer.h:56
Calibration.h
GenericMVAComputer::eval
double eval(Iter_t first, Iter_t last) const
Definition: GenericMVAComputer.h:30
reco::JetExtendedAssociation::Value
reco::JetExtendedAssociation::JetExtendedData Value
Definition: JetExtendedAssociation.h:27
GenericMVAComputer::TaggingVariableMapping::AtomicId
PhysicsTools::AtomicId AtomicId
Definition: GenericMVAComputer.h:122
dummy
Definition: DummySelector.h:38
TaggingVariable.h
GenericMVAComputer::TaggingVariableIterator::Value::mapping
const TaggingVariableMapping * mapping
Definition: GenericMVAComputer.h:72
GenericMVAComputer::TaggingVariableIterator::reference
const typedef Value & reference
Definition: GenericMVAComputer.h:81
reco::btau::TaggingVariableName
TaggingVariableName
Definition: TaggingVariable.h:30
GenericMVAComputer::TaggingVariableIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: GenericMVAComputer.h:77
GenericMVAComputer::TaggingVariableIterator
Definition: GenericMVAComputer.h:17
GenericMVAComputer::TaggingVariableIterator::TaggingVariableIterator
TaggingVariableIterator(TaggingVariableMapping const *mapping, const Iter_t &iter)
Definition: GenericMVAComputer.h:110