| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# StatEntity Class Reference

`#include <GaudiKernel/StatEntity.h>`

List of all members.

## 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 standalone 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 65 of file StatEntity.h.

## 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
unsigned long | nEntries () const
| getters
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
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 fro 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)
| Assignement from the flag The action: reset and the general inrement 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 | addFlag (const double Flag)
| add a flag
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
## 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

## Constructor & Destructor Documentation

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

the default constructor

Definition at line 69 of file StatEntity.h.

    00069 { reset() ; }

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

Definition at line 36 of file StatEntity.cpp.

    00041   : m_se_nEntries            ( entries )
    00042   , m_se_accumulatedFlag     ( flag    )
    00043   , m_se_accumulatedFlag2    ( flag2   )
    00044   , m_se_minimalFlag         ( minFlag )
    00045   , m_se_maximalFlag         ( maxFlag )
    00046   , m_se_nEntriesBeforeReset ( -1      )
    00047 {}

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

destructor

Definition at line 87 of file StatEntity.h.

    00087 {}

## Member Function Documentation

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 51 of file StatEntity.cpp.

    00052 {
    00053   // check for "X" or "L"
    00054   BOOST_STATIC_ASSERT(((sizeof(unsigned long)==4)||(sizeof(unsigned long)==8)));
    00055   // check for "D"
    00056   BOOST_STATIC_ASSERT((sizeof(double)==8))        ;
    00057   //
    00058   static const std::string s_fmt =
    00059     ( ( 8 == sizeof(unsigned long) ) ?"X:1;" : "L:1;" ) + std::string("D:4") ;
    00060   return s_fmt ;
    00061 }

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 65 of file StatEntity.cpp.

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

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

getters

Definition at line 106 of file StatEntity.h.

    00106 { return m_se_nEntries         ; }

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

accumulated "flag"

Definition at line 109 of file StatEntity.h.

    00109 { return m_se_accumulatedFlag  ; }

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

accumulated "flag squared"

Definition at line 111 of file StatEntity.h.

    00111 { return m_se_accumulatedFlag2 ; }

double StatEntity::flagMean | ( |  | ) | const

mean value of flag

Definition at line 73 of file StatEntity.cpp.

    00074 {
    00075   if ( 0 >= nEntries() ) { return 0 ;}
    00076   const long double f1 = m_se_accumulatedFlag ;
    00077   const long double f2 = m_se_nEntries ;
    00078   return f1 / f2 ;
    00079 }

double StatEntity::flagRMS | ( |  | ) | const

r.m.s of flag

Definition at line 83 of file StatEntity.cpp.

    00084 {
    00085   if ( 0 >= nEntries() ) { return 0 ; }
    00086   const long double f1  = m_se_accumulatedFlag  ;
    00087   const long double f2  = f1 / nEntries () ;
    00088   const long double f3  = m_se_accumulatedFlag2 ;
    00089   const long double f4  = f3 / nEntries () ;
    00090   const long double result = f4 - f2 * f2  ;
    00091   return ( 0 > result ) ? 0 : ::sqrtl ( result ) ;
    00092 }

double StatEntity::flagMeanErr | ( |  | ) | const

error in mean value of flag

Definition at line 96 of file StatEntity.cpp.

    00097 {
    00098   if ( 0 >= nEntries () ) { return 0 ; }
    00099   const long double f1  = m_se_accumulatedFlag  ;
    00100   const long double f2  = f1 / nEntries () ;
    00101   const long double f3  = m_se_accumulatedFlag2 ;
    00102   const long double f4  = f3 / nEntries () ;
    00103   const long double result = f4 - f2 * f2  ;
    00104   if ( 0 > result      ) { return 0 ; }
    00105   //
    00106   return ::sqrtl ( result / nEntries () ) ;
    00107 }

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

minimal flag

Definition at line 119 of file StatEntity.h.

    00119 { return m_se_minimalFlag      ; }

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

maximal flag

Definition at line 121 of file StatEntity.h.

    00121 { return m_se_maximalFlag      ; }

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 overal number of counts

If these conditions are not satisfied the method returns -1, overwise 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 111 of file StatEntity.cpp.

    00112 {
    00113   if ( 1 > nEntries () || 0 > flag() || flag() > nEntries() ) { return -1 ; }
    00114   const long double fMin = flagMin () ;
    00115   if ( 0 != fMin && 1 != fMin ) { return -1 ; }
    00116   const long double fMax = flagMax () ;
    00117   if ( 0 != fMax && 1 != fMax ) { return -1 ; }
    00118   return flagMean() ;
    00119 }

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 satistied 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 123 of file StatEntity.cpp.

    00124 {
    00125   if ( 0 > efficiency() ) { return -1 ; }
    00126
    00127   long double n1 = flag() ;
    00128   // treat properly the bins with eff=0
    00129   if ( 0 == n1 ) { n1 = 1 ; }
    00130   const long double n3 = nEntries  () ;
    00131   long double       n2 = n3 - flag () ;
    00132   // treat properly the bins with eff=100%
    00133   if ( 1 > fabsl( n2 ) ) { n2 = 1 ; }
    00134   //
    00135   return ::sqrtl( n1 * n2 / n3 ) / n3 ;
    00136 }

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

shortcut,

See also:
  StatEntity::efficiency

Definition at line 193 of file StatEntity.h.

    00193 { return efficiency    () ; }

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

shortcut,

See also:
  StatEntity::efficiencyErr

Definition at line 195 of file StatEntity.h.

    00195 { return efficiencyErr () ; }

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 215 of file StatEntity.h.

    00216   {
    00217     addFlag ( f ) ;
    00218     return *this ;
    00219   }

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 237 of file StatEntity.h.

    00237 { 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 256 of file StatEntity.h.

    00256 { return ++(*this)      ; }

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

General decrement operator fro 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 276 of file StatEntity.h.

    00277   {
    00278     addFlag ( -f ) ;
    00279     return *this ;
    00280   }

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 298 of file StatEntity.h.

    00298 { 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 316 of file StatEntity.h.

    00316 { return --(*this) ; }

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

Assignement from the flag The action: reset and the general inrement 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 inrement

Definition at line 334 of file StatEntity.h.

    00335   {
    00336     // reset the statistics
    00337     reset() ;
    00338     // use the regular inrement
    00339     return ((*this)+=f);
    00340   }

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 140 of file StatEntity.cpp.

    00141 {
    00142   m_se_nEntries         += other.m_se_nEntries ;
    00143   m_se_accumulatedFlag  += other.m_se_accumulatedFlag  ;
    00144   m_se_accumulatedFlag2 += other.m_se_accumulatedFlag2 ;
    00145   m_se_minimalFlag = std::min ( m_se_minimalFlag , other.m_se_minimalFlag ) ;
    00146   m_se_maximalFlag = std::max ( m_se_maximalFlag , other.m_se_maximalFlag ) ;
    00147   //
    00148   return *this ;
    00149 }

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

comparison

Definition at line 153 of file StatEntity.cpp.

    00154 {
    00155   if      ( &se == this                     ) { return false ; }
    00156   else if ( nEntries () <   se.nEntries ()  ) { return true  ; }
    00157   else if ( nEntries () ==  se.nEntries () &&
    00158             flag     () <   se.flag     ()  ) { return true  ; }
    00159   else if ( nEntries () ==  se.nEntries () &&
    00160             flag     () ==  se.flag     () &&
    00161             flagMin  () <   se.flagMin  ()  ) { return true  ; }
    00162   else if ( nEntries () ==  se.nEntries () &&
    00163             flag     () ==  se.flag     () &&
    00164             flagMin  () ==  se.flagMin  () &&
    00165             flagMax  () <   se.flagMax  ()  ) { return true  ; }
    00166   else if ( nEntries () ==  se.nEntries () &&
    00167             flag     () ==  se.flag     () &&
    00168             flagMin  () ==  se.flagMin  () &&
    00169             flagMax  () ==  se.flagMax  () &&
    00170             flag2    () <   se.flag2    ()  ) { return true  ; }
    00172   return false;
    00173 }

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

add a flag

Parameters:

  | Flag | value to be added

Returns:
  number of entries

accumulate the flag

evaluate min/max

Definition at line 177 of file StatEntity.cpp.

    00178 {
    00179   //
    00180   if      ( 0 <  m_se_nEntriesBeforeReset ) { --m_se_nEntriesBeforeReset; }
    00181   else if ( 0 == m_se_nEntriesBeforeReset ) { reset(); }
    00182
    00183   m_se_accumulatedFlag   += Flag        ; // accumulate the flag
    00185   m_se_minimalFlag = std::min ( m_se_minimalFlag , Flag ) ; // evaluate min/max
    00186   m_se_maximalFlag = std::max ( m_se_maximalFlag , Flag ) ; // evaluate min/max
    00187   // accumulate statistics, but avoid FPE for small flags...
    00188   static const double s_min1 = 2 * ::sqrt ( std::numeric_limits<double>::min() ) ;
    00189   if ( s_min1 < Flag || -s_min1 > Flag )
    00190   { m_se_accumulatedFlag2  += Flag * Flag ; }// accumulate statistics:
    00191   //
    00192   return ++m_se_nEntries ;
    00193 }

void StatEntity::reset | ( | void |  | ) |

reset the counters

Definition at line 197 of file StatEntity.cpp.

    00198 {
    00199   //
    00200   m_se_nEntries            =        0 ;
    00201   m_se_accumulatedFlag     =        0 ;
    00202   m_se_minimalFlag         =       std::numeric_limits<double>::max() ;
    00203   m_se_maximalFlag         =  -1 * std::numeric_limits<double>::max() ;
    00204   m_se_accumulatedFlag2    =        0 ;
    00205   m_se_nEntriesBeforeReset =       -1 ; // ?
    00206 }

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

DR specify number of entry before reset.

Definition at line 210 of file StatEntity.cpp.

    00211 { m_se_nEntriesBeforeReset = nEntriesBeforeReset; }

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

representation as string

Definition at line 215 of file StatEntity.cpp.

    00216 {
    00217   std::ostringstream ost ;
    00218   print ( ost )  ;
    00219   return ost.str () ;
    00220 }

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 224 of file StatEntity.cpp.

    00225 {
    00226   boost::format fmt1 ("#=%|-7lu| Sum=%|-11.5g|" ) ;
    00227   o << fmt1 % nEntries() % flag() ;
    00228   boost::format fmt2 ( " Mean=%|#10.4g| +- %|-#10.5g| Min/Max=%|#10.4g|/%|-#10.4g|" ) ;
    00229   o << fmt2 % flagMean() % flagRMS() % flagMin() % flagMax() ;
    00230   return o ;
    00231 }

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

printout to std::ostream

Parameters:

  | s | the reference to the output stream

Definition at line 378 of file StatEntity.h.

    00378 { return print ( o ) ; }

## Member Data Documentation

unsigned long StatEntity::m_se_nEntries`[private]`

number of calls

Definition at line 381 of file StatEntity.h.

double StatEntity::m_se_accumulatedFlag`[private]`

accumulated flag

Definition at line 383 of file StatEntity.h.

double StatEntity::m_se_accumulatedFlag2`[private]`

Definition at line 384 of file StatEntity.h.

double StatEntity::m_se_minimalFlag`[private]`

Definition at line 385 of file StatEntity.h.

double StatEntity::m_se_maximalFlag`[private]`

Definition at line 386 of file StatEntity.h.

long StatEntity::m_se_nEntriesBeforeReset`[private]`

Definition at line 388 of file StatEntity.h.

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

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