| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

Public Member Functions | Static Public Member Functions | Private Attributes

# StatEntity Class Reference

The basic counter used for Monitoring purposes. More...

`#include <GaudiKernel/StatEntity.h>`

List of all members.

## Public Member Functions
| StatEntity ()
| the default constructor
| StatEntity (const unsigned long entries, const double flag, const double flag2, const double minFlag, const double maxFlag)
| ~StatEntity ()
| destructor
const unsigned long & | nEntries () const
| getters
const double & | sum () const
| accumulated value
const double & | sum2 () const
| accumulated value**2
double | mean () const
| mean value of counter
double | rms () const
| r.m.s of value
double | meanErr () const
| error in mean value of counter
const double & | min () const
| minimal value
const double & | max () const
| maximal value
double | efficiency () const
| Interpret the counter as some measure of efficiency The efficiency is calculated as the ratio of the weight over the number of entries One gets the correct interpretation in the case of filling the counters only with 0 and 1.
double | efficiencyErr () const
| Interpret the counter as some measure of efficiency and evaluate the uncertainty of this efficiency using binomial estimate.
double | eff () const
| shortcut,
double | effErr () const
| shortcut,
StatEntity & | operator+= (const double f)
| General increment operator for the flag Could be used for easy manipulation with StatEntity object:
StatEntity & | operator++ ()
| Pre-increment operator for the flag Could be used for easy manipulation with StatEntity object:
StatEntity & | operator++ (int)
| Post-increment operator for the flag.
StatEntity & | operator-= (const double f)
| General decrement operator for the flag Could be used for easy manipulation with StatEntity object:
StatEntity & | operator-- ()
| Pre-decrement operator for the flag Could be used for easy manipulation with StatEntity object:
StatEntity & | operator-- (int)
| Post-decrement operator for the flag Could be used for easy manipulation with StatEntity object:
StatEntity & | operator= (const double f)
| Assignment from the flag The action: reset and the general increment Such case could be useful for statistical monitoring.
StatEntity & | operator+= (const StatEntity &other)
| increment with other counter (useful for Monitoring/Adder )
bool | operator< (const StatEntity &se) const
| comparison
unsigned long | add (const double Flag)
| add a value
void | reset ()
| reset the counters
void | setnEntriesBeforeReset (unsigned long nEntriesBeforeReset)
| DR specify number of entry before reset.
std::string | toString () const
| representation as string
std::ostream & | print (std::ostream &o=std::cout) const
| printout to std::ostream
std::ostream & | fillStream (std::ostream &o) const
| printout to std::ostream
double | Sum () const
| get sum
double | Mean () const
| get mean
double | MeanErr () const
| get error in mean
double | Rms () const
| get rms
double | RMS () const
| get rms
double | Eff () const
| get efficiency
double | Min () const
| get minimal value
double | Max () const
| get maximal value
double | flag () const
| accumulated "flag"
double | flag2 () const
| accumulated "flag squared"
double | flagMean () const
| mean value of flag
double | flagRMS () const
| r.m.s of flag
double | flagMeanErr () const
| error in mean value of flag
double | flagMin () const
| minimal flag
double | flagMax () const
| maximal flag
unsigned long | addFlag (const double Flag)
| add a flag
## Static Public Member Functions
static const std::string & | format ()
| the internal format description
static int | size ()
| the actual size of published data
## Private Attributes
unsigned long | m_se_nEntries
| number of calls
double | m_se_accumulatedFlag
| accumulated flag
double | m_se_accumulatedFlag2
double | m_se_minimalFlag
double | m_se_maximalFlag
long | m_se_nEntriesBeforeReset

## Detailed Description

The basic counter used for Monitoring purposes.

It is used as a small helper class for implementation of class ChronoStatSvc but it also could be used in stand-alone mode to perform trivial statistical evaluations. e.g.

Essentially the generic counter could be considered as the trivial 1-bin

       // get all tracks
       const Tracks* tracks = ... ;
       // create the counter
       StatEntity chi2 ;
       // make a loop over all tracks:
       for ( Tracks::const_iterator itrack = tracks->begin() ;
             tracks->end() != itrack ; ++itrack )
        {
            const Track* track = *itrack ;

            // use the counters to accumulate information:
            chi2 += track -> chi2  () ;
        } ;

       // Extract the information from the counter:

       // get number of entries (== number of tracks)
       int nEntries = chi2.nEntries() ;

       // get the minimal value of chi2
       double chi2Min = chi2.flagMin() ;

       // get the average value of chi2:
       double meanChi2 = chi2.flagMean() ;

       // get R.M.S. for chi2-distribution:
       double rmsChi2   = chi2.flagRMS() ;

       .. etc...

Author:
  Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr

Date:
  26/11/1999
  2005-08-02

Definition at line 68 of file StatEntity.h.

## Constructor & Destructor Documentation

StatEntity::StatEntity | ( | ) | `[inline]`

the default constructor

Definition at line 73 of file StatEntity.h.

    { reset() ; }

StatEntity::StatEntity | ( | const unsigned long | entries,
|  | const double | flag,
|  | const double | flag2,
|  | const double | minFlag,
|  | const double | maxFlag
| ) |  |

Definition at line 48 of file StatEntity.cpp.

      : m_se_nEntries            ( entries )
      , m_se_accumulatedFlag     ( flag    )
      , m_se_accumulatedFlag2    ( flag2   )
      , m_se_minimalFlag         ( minFlag )
      , m_se_maximalFlag         ( maxFlag )
      , m_se_nEntriesBeforeReset ( -1      )
    {}

StatEntity::~StatEntity | ( | ) | `[inline]`

destructor

Definition at line 91 of file StatEntity.h.

    {}

## Member Function Documentation

unsigned long StatEntity::add | ( | const double | Flag ) |

add a value

Parameters:

  Flag | value to be added

Returns:
  number of entries

accumulate the flag

evaluate min/max

Definition at line 189 of file StatEntity.cpp.

    {
      //
      if      ( 0 <  m_se_nEntriesBeforeReset ) { --m_se_nEntriesBeforeReset; }
      else if ( 0 == m_se_nEntriesBeforeReset ) { reset(); }

      m_se_accumulatedFlag   += Flag        ; // accumulate the flag
      m_se_minimalFlag = std::min ( m_se_minimalFlag , Flag ) ; // evaluate min/max
      m_se_maximalFlag = std::max ( m_se_maximalFlag , Flag ) ; // evaluate min/max
      // accumulate statistics, but avoid FPE for small flags...
      static const double s_min1 = 2 * ::sqrt ( std::numeric_limits<double>::min() ) ;
      if ( s_min1 < Flag || -s_min1 > Flag )
      { m_se_accumulatedFlag2  += Flag * Flag ; }// accumulate statistics:
      //
      return ++m_se_nEntries ;
    }

unsigned long StatEntity::addFlag | ( | const double | Flag ) | `[inline]`

add a flag

Parameters:

  Flag | value to be added

Returns:
  number of entries

Definition at line 416 of file StatEntity.h.

    { return add ( Flag ) ; }

double StatEntity::Eff | ( | ) | const`[inline]`

get efficiency

Definition at line 390 of file StatEntity.h.

    { return eff     () ; } // get efficiency

double StatEntity::eff | ( | ) | const`[inline]`

shortcut,

See also:
  StatEntity::efficiency

Definition at line 185 of file StatEntity.h.

    { return efficiency    () ; }

double StatEntity::effErr | ( | ) | const`[inline]`

shortcut,

See also:
  StatEntity::efficiencyErr

Definition at line 187 of file StatEntity.h.

    { return efficiencyErr () ; }

double StatEntity::efficiency | ( | ) | const

Interpret the counter as some measure of efficiency The efficiency is calculated as the ratio of the weight over the number of entries One gets the correct interpretation in the case of filling the counters only with 0 and 1.

Some checks are performed:

- number of counts must be positive
- "flag" must be non-negative
- "flag" does not exceed the overall number of counts

If these conditions are not satisfied the method returns -1, otherwise it returns the value of "flagMean"

      StatEntity& stat = ... ;

      for ( TRACKS::iterator itrack = tracks.begin() ;
            tracks.end() != itrack ; itrack )
       {
         const bool good = PT( *itrack ) > 1 * Gaudi::Units::GeV ;
         stat += good ;
       }

      std::cout << " Efficiency of PT-cut is "
                << stat.efficiency() << std::endl ;

See also:
  StatEntity::flagMean
  StatEntity::eff
  StatEntity::efficiencyErr

Definition at line 123 of file StatEntity.cpp.

    {
      if ( 1 > nEntries () || 0 > sum() || sum() > nEntries() ) { return -1 ; }
      const long double fMin = min () ;
      if ( 0 != fMin && 1 != fMin ) { return -1 ; }
      const long double fMax = max () ;
      if ( 0 != fMax && 1 != fMax ) { return -1 ; }
      return mean() ;
    }

double StatEntity::efficiencyErr | ( | ) | const

Interpret the counter as some measure of efficiency and evaluate the uncertainty of this efficiency using binomial estimate.

The efficiency is calculated as the ratio of the weight over the number of entries One gets the correct interpretation in the case of filling the counters only with 0 and 1. Some checks are performed:

- number of counts must be positive
- "flag" must be non-negative
- "flag" does not exceed the overall number of counts

If these conditions are not satisfied the method returns -1.

Attention:
  The action of this method is DIFFERENT from the action of the method StatEntity::flagMeanErr

      StatEntity& stat = ... ;

      for ( TRACKS::iterator itrack = tracks.begin() ;
            tracks.end() != itrack ; itrack )
       {
         const bool good = PT( *itrack ) > 1 * Gaudi::Units::GeV ;
         stat += good ;
       }

      std::cout << " Efficiency of PT-cut is "
                << stat.efficiency    () << "+-"
                << stat.efficiencyErr () << std::endl ;

See also:
  StatEntity::efficiency
  StatEntity::effErr
  StatEntity::flagMeanErr

Definition at line 135 of file StatEntity.cpp.

    {
      if ( 0 > efficiency() ) { return -1 ; }
      //
      long double n1 = sum () ;
      // treat properly the bins with eff=0
      if ( 0 == n1 ) { n1 = 1 ; }
      const long double n3 = nEntries  () ;
      long double       n2 = n3 - flag () ;
      // treat properly the bins with eff=100%
      if ( 1 > fabsl( n2 ) ) { n2 = 1 ; }
      //
      return ::sqrtl( n1 * n2 / n3 ) / n3 ;
    }

std::ostream& StatEntity::fillStream | ( | std::ostream & | o ) | const`[inline]`

printout to std::ostream

Parameters:

  s | the reference to the output stream

Definition at line 375 of file StatEntity.h.

    { return print ( o ) ; }

double StatEntity::flag | ( | ) | const`[inline]`

accumulated "flag"

Definition at line 399 of file StatEntity.h.

    { return sum     () ; }

double StatEntity::flag2 | ( | ) | const`[inline]`

accumulated "flag squared"

Definition at line 401 of file StatEntity.h.

    { return sum2    () ; }

double StatEntity::flagMax | ( | ) | const`[inline]`

maximal flag

Definition at line 411 of file StatEntity.h.

    { return max     () ; }

double StatEntity::flagMean | ( | ) | const`[inline]`

mean value of flag

Definition at line 403 of file StatEntity.h.

    { return mean    () ; }

double StatEntity::flagMeanErr | ( | ) | const`[inline]`

error in mean value of flag

Definition at line 407 of file StatEntity.h.

    { return meanErr () ; }

double StatEntity::flagMin | ( | ) | const`[inline]`

minimal flag

Definition at line 409 of file StatEntity.h.

    { return min     () ; }

double StatEntity::flagRMS | ( | ) | const`[inline]`

r.m.s of flag

Definition at line 405 of file StatEntity.h.

    { return rms     () ; }

const std::string & StatEntity::format | ( | ) | `[static]`

the internal format description

Attention:
  : it needs to be coherent with the actual class structure! It is useful for DIM publishing

See also:
  StatEntity::size

< check for "D"

Definition at line 63 of file StatEntity.cpp.

    {
      // check for "X" or "L"
      BOOST_STATIC_ASSERT(((sizeof(unsigned long)==4)||(sizeof(unsigned long)==8)));
      // check for "D"
      BOOST_STATIC_ASSERT((sizeof(double)==8))        ;
      //
      static const std::string s_fmt =
        ( ( 8 == sizeof(unsigned long) ) ?"X:1;" : "L:1;" ) + std::string("D:4") ;
      return s_fmt ;
    }

double StatEntity::Max | ( | ) | const`[inline]`

get maximal value

Definition at line 394 of file StatEntity.h.

    { return max     () ; } // get maximal value

const double& StatEntity::max | ( | ) | const`[inline]`

maximal value

Definition at line 110 of file StatEntity.h.

    { return m_se_maximalFlag ; }

double StatEntity::mean | ( | ) | const

mean value of counter

Definition at line 85 of file StatEntity.cpp.

    {
      if ( 0 >= nEntries() ) { return 0 ;}
      const long double f1 = m_se_accumulatedFlag ;
      const long double f2 = m_se_nEntries ;
      return f1 / f2 ;
    }

double StatEntity::Mean | ( | ) | const`[inline]`

get mean

Definition at line 382 of file StatEntity.h.

    { return mean    () ; } // get mean

double StatEntity::meanErr | ( | ) | const

error in mean value of counter

Definition at line 108 of file StatEntity.cpp.

    {
      if ( 0 >= nEntries () ) { return 0 ; }
      const long double f1  = m_se_accumulatedFlag  ;
      const long double f2  = f1 / nEntries () ;
      const long double f3  = m_se_accumulatedFlag2 ;
      const long double f4  = f3 / nEntries () ;
      const long double result = f4 - f2 * f2  ;
      if ( 0 > result      ) { return 0 ; }
      //
      return ::sqrtl ( result / nEntries () ) ;
    }

double StatEntity::MeanErr | ( | ) | const`[inline]`

get error in mean

Definition at line 384 of file StatEntity.h.

    { return meanErr () ; } // get error in mean

double StatEntity::Min | ( | ) | const`[inline]`

get minimal value

Definition at line 392 of file StatEntity.h.

    { return min     () ; } // get minimal value

const double& StatEntity::min | ( | ) | const`[inline]`

minimal value

Definition at line 108 of file StatEntity.h.

    { return m_se_minimalFlag ; }

const unsigned long& StatEntity::nEntries | ( | ) | const`[inline]`

getters

Definition at line 96 of file StatEntity.h.

    { return m_se_nEntries         ; }

StatEntity& StatEntity::operator++ | ( | ) | `[inline]`

Pre-increment operator for the flag Could be used for easy manipulation with StatEntity object:

       StatEntity stat ;

       for ( int i =    ... )
        {
           double eTotal = .... ;

           // increment the counter
           if ( eTotal > 1 * TeV ) { ++stat ; } ;
        }

Definition at line 232 of file StatEntity.h.

    { return   (*this)+= 1  ; }

StatEntity& StatEntity::operator++ | ( | int | ) | `[inline]`

Post-increment operator for the flag.

Actually it is the same as pre-increment. Could be used for easy manipulation with StatEntity object:

       StatEntity stat ;

       for ( int i =    ... )
        {
           double eTotal = .... ;

           // increment the counter
           if ( eTotal > 1 * TeV ) { stat++ ; } ;
        }

Definition at line 251 of file StatEntity.h.

    { return ++(*this)      ; }

StatEntity & StatEntity::operator+= | ( | const StatEntity & | other ) |

increment with other counter (useful for Monitoring/Adder )

       const StatEntity second = ... ;

       StatEntity first = ... ;

       first += second ;

Parameters:

  other | counter to be added

Returns:
  self-reference

Definition at line 152 of file StatEntity.cpp.

    {
      m_se_nEntries         += other.m_se_nEntries ;
      m_se_accumulatedFlag  += other.m_se_accumulatedFlag  ;
      m_se_accumulatedFlag2 += other.m_se_accumulatedFlag2 ;
      m_se_minimalFlag = std::min ( m_se_minimalFlag , other.m_se_minimalFlag ) ;
      m_se_maximalFlag = std::max ( m_se_maximalFlag , other.m_se_maximalFlag ) ;
      //
      return *this ;
    }

StatEntity& StatEntity::operator+= | ( | const double | f ) | `[inline]`

General increment operator for the flag Could be used for easy manipulation with StatEntity object:

       StatEntity stat ;

       for ( int i =    ... )
        {
           double eTotal = .... ;

           // increment the counter
           stat += eTotal ;
        }

Parameters:

  f | counter increment

Definition at line 210 of file StatEntity.h.

      {
        addFlag ( f ) ;
        return *this ;
      }

StatEntity& StatEntity::operator-- | ( | ) | `[inline]`

Pre-decrement operator for the flag Could be used for easy manipulation with StatEntity object:

       StatEntity stat ;

       for ( int i =    ... )
        {
           double eTotal = .... ;

           // increment the counter
           if ( eTotal > 1 * TeV ) { --stat ; } ;
        }

Definition at line 293 of file StatEntity.h.

    { return (*this)-=1  ; }

StatEntity& StatEntity::operator-- | ( | int | ) | `[inline]`

Post-decrement operator for the flag Could be used for easy manipulation with StatEntity object:

       StatEntity stat ;

       for ( int i =    ... )
        {
           double eTotal = .... ;

           // increment the counter
           if ( eTotal > 1 * TeV ) { stat-- ; } ;
        }

Definition at line 311 of file StatEntity.h.

    { return --(*this) ; }

StatEntity& StatEntity::operator-= | ( | const double | f ) | `[inline]`

General decrement operator for the flag Could be used for easy manipulation with StatEntity object:

       StatEntity stat ;

       for ( int i =    ... )
        {
           double eTotal = .... ;

           // decrement the counter
           stat -= eTotal ;
        }

Parameters:

  f | counter increment

Definition at line 271 of file StatEntity.h.

      {
        addFlag ( -f ) ;
        return *this ;
      }

bool StatEntity::operator< | ( | const StatEntity & | se ) | const

comparison

Definition at line 165 of file StatEntity.cpp.

    {
      if      ( &se == this                     ) { return false ; }
      else if ( nEntries () <   se.nEntries ()  ) { return true  ; }
      else if ( nEntries () ==  se.nEntries () &&
                sum      () <   se.sum      ()  ) { return true  ; }
      else if ( nEntries () ==  se.nEntries () &&
                sum      () ==  se.sum      () &&
                min      () <   se.min      ()  ) { return true  ; }
      else if ( nEntries () ==  se.nEntries () &&
                sum      () ==  se.sum      () &&
                min      () ==  se.min      () &&
                max      () <   se.max      ()  ) { return true  ; }
      else if ( nEntries () ==  se.nEntries () &&
                sum      () ==  se.flag     () &&
                min      () ==  se.min      () &&
                max      () ==  se.max      () &&
                sum2     () <   se.sum2     ()  ) { return true  ; }
      return false;
    }

StatEntity& StatEntity::operator= | ( | const double | f ) | `[inline]`

Assignment from the flag The action: reset and the general increment Such case could be useful for statistical monitoring.

      const long numberOfHits = ... ;

      StatEntity& stat = ... ;

      stat = numberOfHits ;

Parameters:

  f | new value of the counter

Returns:
  self-reference

< reset the statistics

< use the regular increment

Definition at line 329 of file StatEntity.h.

      {
        // reset the statistics
        reset() ;
        // use the regular increment
        return ((*this)+=f);
      }

std::ostream & StatEntity::print | ( | std::ostream & | o = `std::cout` ) | const

printout to std::ostream

Parameters:

  s | the reference to the output stream

Definition at line 236 of file StatEntity.cpp.

    {
      boost::format fmt1 ("#=%|-7lu| Sum=%|-11.5g|" ) ;
      o << fmt1 % nEntries() % sum() ;
      boost::format fmt2 ( " Mean=%|#10.4g| +- %|-#10.5g| Min/Max=%|#10.4g|/%|-#10.4g|" ) ;
      o << fmt2 % mean() % rms() % min() % max() ;
      return o ;
    }

void StatEntity::reset | ( | ) |

reset the counters

Definition at line 209 of file StatEntity.cpp.

    {
      //
      m_se_nEntries            =        0 ;
      m_se_accumulatedFlag     =        0 ;
      m_se_minimalFlag         =       std::numeric_limits<double>::max() ;
      m_se_maximalFlag         =  -1 * std::numeric_limits<double>::max() ;
      m_se_accumulatedFlag2    =        0 ;
      m_se_nEntriesBeforeReset =       -1 ; // ?
    }

double StatEntity::Rms | ( | ) | const`[inline]`

get rms

Definition at line 386 of file StatEntity.h.

    { return rms     () ; } // get rms

double StatEntity::RMS | ( | ) | const`[inline]`

get rms

Definition at line 388 of file StatEntity.h.

    { return rms     () ; } // get rms

double StatEntity::rms | ( | ) | const

r.m.s of value

Definition at line 95 of file StatEntity.cpp.

    {
      if ( 0 >= nEntries() ) { return 0 ; }
      const long double f1  = m_se_accumulatedFlag  ;
      const long double f2  = f1 / nEntries () ;
      const long double f3  = m_se_accumulatedFlag2 ;
      const long double f4  = f3 / nEntries () ;
      const long double result = f4 - f2 * f2  ;
      return ( 0 > result ) ? 0 : ::sqrtl ( result ) ;
    }

void StatEntity::setnEntriesBeforeReset | ( | unsigned long | nEntriesBeforeReset ) |

DR specify number of entry before reset.

Definition at line 222 of file StatEntity.cpp.

    { m_se_nEntriesBeforeReset = nEntriesBeforeReset; }

int StatEntity::size | ( | void | ) | `[static]`

the actual size of published data

Attention:
  : it needs to be coherent with the actual class structure! It is useful for DIM publishing

See also:
  StatEntity::format

Definition at line 77 of file StatEntity.cpp.

    {
      static const int s_size = sizeof(unsigned long) + 4 * sizeof(double) ;
      return s_size ;
    }

const double& StatEntity::sum | ( | ) | const`[inline]`

accumulated value

Definition at line 98 of file StatEntity.h.

    { return m_se_accumulatedFlag  ; }

double StatEntity::Sum | ( | ) | const`[inline]`

get sum

Definition at line 380 of file StatEntity.h.

    { return sum     () ; } // get sum

const double& StatEntity::sum2 | ( | ) | const`[inline]`

accumulated value**2

Definition at line 100 of file StatEntity.h.

    { return m_se_accumulatedFlag2 ; }

std::string StatEntity::toString | ( | ) | const

representation as string

Definition at line 227 of file StatEntity.cpp.

    {
      std::ostringstream ost ;
      print ( ost )  ;
      return ost.str () ;
    }

## Member Data Documentation

double StatEntity::m_se_accumulatedFlag`[private]`

accumulated flag

Definition at line 440 of file StatEntity.h.

double StatEntity::m_se_accumulatedFlag2`[private]`

Definition at line 441 of file StatEntity.h.

double StatEntity::m_se_maximalFlag`[private]`

Definition at line 443 of file StatEntity.h.

double StatEntity::m_se_minimalFlag`[private]`

Definition at line 442 of file StatEntity.h.

unsigned long StatEntity::m_se_nEntries`[private]`

number of calls

Definition at line 438 of file StatEntity.h.

long StatEntity::m_se_nEntriesBeforeReset`[private]`

Definition at line 445 of file StatEntity.h.

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v23r1/GaudiKernel/GaudiKernel/StatEntity.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v23r1/GaudiKernel/src/Lib/StatEntity.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines