CMS 3D CMS Logo

Public Member Functions | Private Attributes

Majority< T > Class Template Reference

#include <Majority.h>

List of all members.

Public Member Functions

void add (const T &value)
void add (const T &value)
 Majority ()
 Majority ()
result (double *proba) const
result (double *proba) const
virtual ~Majority ()
virtual ~Majority ()

Private Attributes

double n_
std::map< T, double > votes_

Detailed Description

template<class T>
class Majority< T >

Utility class to take a decision on majority based. Used by MatacqProducer.

Definition at line 13 of file Majority.h.


Constructor & Destructor Documentation

template<class T>
Majority< T >::Majority ( ) [inline]

Constructs a Majority

Definition at line 18 of file Majority.h.

: n_(0){}
template<class T>
virtual Majority< T >::~Majority ( ) [inline, virtual]

Destructor

Definition at line 22 of file Majority.h.

{}
template<class T>
Majority< T >::Majority ( ) [inline]

Constructs a Majority

Definition at line 19 of file Majority.h.

: n_(0){}
template<class T>
virtual Majority< T >::~Majority ( ) [inline, virtual]

Destructor

Definition at line 23 of file Majority.h.

{}

Member Function Documentation

template<class T>
void Majority< T >::add ( const T &  value) [inline]
template<class T>
void Majority< T >::add ( const T &  value) [inline]

Collects event

Parameters:
valueevent

Definition at line 29 of file Majority.h.

References Majority< T >::n_, relativeConstraints::value, and Majority< T >::votes_.

                     {
    votes_[value] += 1.;
    n_ += 1.;
  }
template<class T>
T Majority< T >::result ( double *  proba) const [inline]

Result of majority decision

Parameters:
proba.If not null, filled with the frequency of the selected value.
Returns:
selected value, that is the most frequent one.

Definition at line 39 of file Majority.h.

References m, Majority< T >::n_, and Majority< T >::votes_.

                               {
    std::pair<T, double> m(T(), -1.);
    for(typename std::map<T, double>::const_iterator it = votes_.begin();
        it != votes_.end();
        ++it){
      if(it->second > m.second){
        m = *it;
      }
    }
    if(proba) *proba = n_>0?m.second/n_:-1;
    return m.first;
  }
template<class T>
T Majority< T >::result ( double *  proba) const [inline]

Definition at line 30 of file Majority.h.

References m, Majority< T >::n_, and Majority< T >::votes_.

Referenced by MatacqProducer::getCalibTriggerType(), and LaserSorter::getDetailedTriggerType().

                               {
    std::pair<T, double> m(T(), -1.);
    for(typename std::map<T, double>::const_iterator it = votes_.begin();
        it != votes_.end();
        ++it){
      if(it->second > m.second){
        m = *it;
      }
    }
    if(proba) *proba = n_>0?m.second/n_:-1;
    return m.first;
  }

Member Data Documentation

template<class T>
double Majority< T >::n_ [private]

Definition at line 51 of file Majority.h.

Referenced by Majority< T >::add(), and Majority< T >::result().

template<class T>
std::map< T, double > Majority< T >::votes_ [private]

Definition at line 50 of file Majority.h.

Referenced by Majority< T >::add(), and Majority< T >::result().