CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
TaggingVariableIterator operator++(int dummy)
TaggingVariableIterator< Iter_t > iterator(Iter_t iter) const
double eval(Iter_t first, Iter_t last) const
TaggingVariableIterator(TaggingVariableMapping const *mapping, const Iter_t &iter)
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
bool operator==(const TaggingVariableIterator &other) const
Main interface class to the generic discriminator computer framework.
Definition: MVAComputer.h:39
bool operator!=(const TaggingVariableIterator &other) const
reco::JetExtendedAssociation::JetExtendedData Value
bool operator<(const TaggingVariableIterator &other) const
AtomicId getAtomicId(TaggingName taggingName) const
static const TaggingVariableMapping mapping
std::iterator_traits< Iter_t >::difference_type difference_type
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:236
MVAComputer(const Calibration::MVAComputer *calib)
construct a discriminator computer from a const calibation object
Definition: MVAComputer.cc:37
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
GenericMVAComputer(const PhysicsTools::Calibration::MVAComputer *calib)
double eval(const Container_t &values) const
tuple last
Definition: dqmdumpme.py:56
Value(TaggingVariableMapping const *mapping, const Iter_t &iter)
def template
Definition: svgfig.py:521