CMS 3D CMS Logo

Majority.h
Go to the documentation of this file.
1 /*
2  */
3 
4 #ifndef MAJORITY_H
5 #define MAJORITY_H
6 
7 #include <map>
8 
12 template<class T>
13 class Majority {
14  //constructor(s) and destructor(s)
15 public:
18  Majority(): n_(0){}
19 
22  virtual ~Majority(){}
23 
27  void
28  add(const T& value){
29  votes_[value] += 1.;
30  n_ += 1.;
31  }
32 
38  T result(double* proba) const{
39  std::pair<T, double> m(T(), -1.);
40  for(typename std::map<T, double>::const_iterator it = votes_.begin();
41  it != votes_.end();
42  ++it){
43  if(it->second > m.second){
44  m = *it;
45  }
46  }
47  if(proba) *proba = n_>0?m.second/n_:-1;
48  return m.first;
49  }
50 
51  //method(s)
52 public:
53 private:
54 
55  //attribute(s)
56 protected:
57 private:
58  std::map<T, double> votes_;
59  double n_;
60 };
61 
62 #endif //MAJORITY_H not defined
std::map< T, double > votes_
Definition: Majority.h:46
double n_
Definition: Majority.h:47
virtual ~Majority()
Definition: Majority.h:22
void add(const T &value)
Definition: Majority.h:28
Definition: value.py:1
T result(double *proba) const
Definition: Majority.h:38
long double T
Majority()
Definition: Majority.h:18