CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
Majority< T > Class Template Reference

#include <Majority.h>

Public Member Functions

void add (const T &value)
 
void add (const T &value)
 
 Majority ()
 
 Majority ()
 
T result (double *proba) const
 
T 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 12 of file Majority.h.

Constructor & Destructor Documentation

◆ Majority() [1/2]

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

Constructs a Majority

Definition at line 17 of file Majority.h.

17 : n_(0) {}

◆ ~Majority() [1/2]

template<class T>
virtual Majority< T >::~Majority ( )
inlinevirtual

Destructor

Definition at line 21 of file Majority.h.

21 {}

◆ Majority() [2/2]

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

Constructs a Majority

Definition at line 18 of file Majority.h.

18 : n_(0) {}

◆ ~Majority() [2/2]

template<class T>
virtual Majority< T >::~Majority ( )
inlinevirtual

Destructor

Definition at line 22 of file Majority.h.

22 {}

Member Function Documentation

◆ add() [1/2]

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

Definition at line 23 of file Majority.h.

23  {
24  votes_[value] += 1.;
25  n_ += 1.;
26  }

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

Referenced by counter.Counter::register(), SequenceTypes.Task::remove(), and SequenceTypes.Task::replace().

◆ add() [2/2]

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

Collects event

Parameters
valueevent

Definition at line 27 of file Majority.h.

27  {
28  votes_[value] += 1.;
29  n_ += 1.;
30  }

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

Referenced by counter.Counter::register(), SequenceTypes.Task::remove(), and SequenceTypes.Task::replace().

◆ result() [1/2]

template<class T>
T Majority< T >::result ( double *  proba) const
inline

Definition at line 28 of file Majority.h.

28  {
29  std::pair<T, double> m(T(), -1.);
30  for (typename std::map<T, double>::const_iterator it = votes_.begin(); it != votes_.end(); ++it) {
31  if (it->second > m.second) {
32  m = *it;
33  }
34  }
35  if (proba)
36  *proba = n_ > 0 ? m.second / n_ : -1;
37  return m.first;
38  }

References visualization-live-secondInstance_cfg::m, Majority< T >::n_, and Majority< T >::votes_.

◆ result() [2/2]

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 37 of file Majority.h.

37  {
38  std::pair<T, double> m(T(), -1.);
39  for (typename std::map<T, double>::const_iterator it = votes_.begin(); it != votes_.end(); ++it) {
40  if (it->second > m.second) {
41  m = *it;
42  }
43  }
44  if (proba)
45  *proba = n_ > 0 ? m.second / n_ : -1;
46  return m.first;
47  }

References visualization-live-secondInstance_cfg::m, Majority< T >::n_, and Majority< T >::votes_.

Member Data Documentation

◆ n_

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

Definition at line 47 of file Majority.h.

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

◆ votes_

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

Definition at line 46 of file Majority.h.

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

Majority::n_
double n_
Definition: Majority.h:47
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
Majority::votes_
std::map< T, double > votes_
Definition: Majority.h:46
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53