CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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> class TaggingVariableIterator;
18 
20  PhysicsTools::MVAComputer(calib) {}
21 
22  // create wrapping iterator
23  template<typename Iter_t>
24  inline TaggingVariableIterator<Iter_t> iterator(Iter_t iter) const
25  { return TaggingVariableIterator<Iter_t>(&mapping, iter); }
26 
27  // overload eval method to work on containers of TaggingVariable
28  template<typename Iter_t>
29  inline double eval(Iter_t first, Iter_t last) const
30  {
31  typedef TaggingVariableIterator<Iter_t> Wrapped_t;
32  return PhysicsTools::MVAComputer::template eval<Wrapped_t>(
33  iterator<Iter_t>(first), iterator<Iter_t>(last));
34  }
35 
36  template<typename Container_t>
37  inline double eval(const Container_t &values) const
38  {
39  typedef typename Container_t::const_iterator Iter_t;
40  return this->template eval<Iter_t>(values.begin(), values.end());
41  }
42 
43  // iterator wrapper with on-the-fly TaggingVariableName -> AtomicId mapping
44  //
45  // Notice that this tells the computer to completely inline it
46  // this is reasonable since inlining it means that the optimizer
47  // will not produce any additional code for the wrapper
48  // (it is entirely optimized away), except for the actual mapping
49  // which is no more than a simple array lookup.
50  //
51  // The result will be inlined into the eval() template of MVAComputer
52  // which will be instantiated as one single tightly-integrated
53  // function.
54  template<typename Iter_t>
55  class TaggingVariableIterator {
56  public:
57  // class implementing MVAComputer::Variable::Value interface
58  struct Value {
59  public:
60  // the actual operator doing the mapping
62  { return mapping->getAtomicId(iter->first); }
63 
64  inline double getValue() const
65  { return iter->second; }
66 
68  {
70  getName(), getValue());
71  }
72 
73  protected:
75 
77  const Iter_t &iter) :
78  mapping(mapping), iter(iter) {}
79 
80  private:
81  // pointer to the current mapping
83  // iterator to reco::TaggingVariable in orig. container
84  Iter_t iter;
85  };
86 
87  typedef std::forward_iterator_tag iterator_category;
88  typedef Value value_type;
89  typedef typename std::iterator_traits<Iter_t>::difference_type difference_type;
90  typedef const Value *pointer;
91  typedef const Value &reference;
92 
94 
95  // methods to make class a standard forward iterator
96 
97  inline const Value &operator * () const { return value; }
98  inline Value &operator * () { return value; }
99 
100  inline const Value *operator -> () const { return &value; }
101  inline Value *operator -> () { return &value; }
102 
103  inline bool operator == (const TaggingVariableIterator &other) const
104  { return value.iter == other.value.iter; }
105  inline bool operator != (const TaggingVariableIterator &other) const
106  { return value.iter != other.value.iter; }
107  inline bool operator < (const TaggingVariableIterator &other) const
108  { return value.iter < other.value.iter; }
109 
110  inline TaggingVariableIterator &operator ++ ()
111  { ++value.iter; return *this; }
112 
113  inline TaggingVariableIterator operator ++ (int dummy)
114  { TaggingVariableIterator orig = *this; ++value.iter; return orig; }
115 
116  protected:
117  friend class GenericMVAComputer;
119  const Iter_t &iter) :
120  value(mapping, iter) {}
121 
122  private:
123  // holds the current "value"
124  // it's really only an iterator that points the original
125  // current TaggingVariable plus required methods
127  };
128 
129  // TaggingVariableName -> PhysicsTools::AtomicId mapping
131  public:
134 
137 
138  inline AtomicId getAtomicId(TaggingName taggingName) const
139  { return taggingVarToAtomicId[taggingName]; }
140 
141  private:
142  std::vector<AtomicId> taggingVarToAtomicId;
143  };
144 
145  private:
147 };
148 
149 #endif // RecoBTau_BTauComputer_GenericMVAComputer_h
TaggingVariableIterator< Iter_t > iterator(Iter_t iter) const
double eval(Iter_t first, Iter_t last) const
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
TaggingVariableIterator(TaggingVariableMapping const *mapping, const Iter_t &iter)
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
Main interface class to the generic discriminator computer framework.
Definition: MVAComputer.h:39
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
reco::JetExtendedAssociation::JetExtendedData Value
AtomicId getAtomicId(TaggingName taggingName) const
static const TaggingVariableMapping mapping
std::iterator_traits< Iter_t >::difference_type difference_type
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
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
GenericMVAComputer(const PhysicsTools::Calibration::MVAComputer *calib)
double eval(const Container_t &values) const
Value(TaggingVariableMapping const *mapping, const Iter_t &iter)
def template
Definition: svgfig.py:520