Gaudi Framework, version v21r9

Home   Generated: 3 May 2010

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
unsigned long nEntries () const
 getters
double sum () const
 accumulated value
double sum2 () const
 accumulated valeu**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
double min () const
 minimal value
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,
StatEntityoperator+= (const double f)
 General increment operator for the flag Could be used for easy manipulation with StatEntity object:.
StatEntityoperator++ ()
 Pre-increment operator for the flag Could be used for easy manipulation with StatEntity object:.
StatEntityoperator++ (int)
 Post-increment operator for the flag.
StatEntityoperator-= (const double f)
 General decrement operator for the flag Could be used for easy manipulation with StatEntity object:.
StatEntityoperator-- ()
 Pre-decrement operator for the flag Could be used for easy manipulation with StatEntity object:.
StatEntityoperator-- (int)
 Post-decrement operator for the flag Could be used for easy manipulation with StatEntity object:.
StatEntityoperator= (const double f)
 Assignment from the flag The action: reset and the general increment Such case could be useful for statistical monitoring.
StatEntityoperator+= (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::ostreamprint (std::ostream &o=std::cout) const
 printout to std::ostream
std::ostreamfillStream (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::stringformat ()
 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.

00073 { 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.

00053   : m_se_nEntries            ( entries )
00054   , m_se_accumulatedFlag     ( flag    ) 
00055   , m_se_accumulatedFlag2    ( flag2   ) 
00056   , m_se_minimalFlag         ( minFlag ) 
00057   , m_se_maximalFlag         ( maxFlag ) 
00058   , m_se_nEntriesBeforeReset ( -1      )
00059 {}

StatEntity::~StatEntity (  )  [inline]

destructor

Definition at line 91 of file StatEntity.h.

00091 {}


Member Function Documentation

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

getters

Definition at line 96 of file StatEntity.h.

00096 { return m_se_nEntries         ; }

double StatEntity::sum (  )  const [inline]

accumulated value

Definition at line 98 of file StatEntity.h.

00098 { return m_se_accumulatedFlag  ; }  

double StatEntity::sum2 (  )  const [inline]

accumulated valeu**2

Definition at line 100 of file StatEntity.h.

00100 { return m_se_accumulatedFlag2 ; }

double StatEntity::mean (  )  const

mean value of counter

Definition at line 85 of file StatEntity.cpp.

00086 { 
00087   if ( 0 >= nEntries() ) { return 0 ;}
00088   const long double f1 = m_se_accumulatedFlag ;
00089   const long double f2 = m_se_nEntries ;
00090   return f1 / f2 ;
00091 }

double StatEntity::rms (  )  const

r.m.s of value

Definition at line 95 of file StatEntity.cpp.

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

double StatEntity::meanErr (  )  const

error in mean value of counter

Definition at line 108 of file StatEntity.cpp.

00109 {
00110   if ( 0 >= nEntries () ) { return 0 ; }
00111   const long double f1  = m_se_accumulatedFlag  ;
00112   const long double f2  = f1 / nEntries () ;
00113   const long double f3  = m_se_accumulatedFlag2 ;
00114   const long double f4  = f3 / nEntries () ;
00115   const long double result = f4 - f2 * f2  ;
00116   if ( 0 > result      ) { return 0 ; }
00117   //
00118   return ::sqrtl ( result / nEntries () ) ;
00119 }

double StatEntity::min (  )  const [inline]

minimal value

Definition at line 108 of file StatEntity.h.

00108 { return m_se_minimalFlag ; }

double StatEntity::max (  )  const [inline]

maximal value

Definition at line 110 of file StatEntity.h.

00110 { 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 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.

00124 {
00125   if ( 1 > nEntries () || 0 > sum() || sum() > nEntries() ) { return -1 ; }
00126   const long double fMin = min () ;
00127   if ( 0 != fMin && 1 != fMin ) { return -1 ; }
00128   const long double fMax = max () ;
00129   if ( 0 != fMax && 1 != fMax ) { return -1 ; }
00130   return mean() ;
00131 }

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.

00136 {
00137   if ( 0 > efficiency() ) { return -1 ; }
00138   //
00139   long double n1 = sum () ;
00140   // treat properly the bins with eff=0 
00141   if ( 0 == n1 ) { n1 = 1 ; } 
00142   const long double n3 = nEntries  () ;
00143   long double       n2 = n3 - flag () ;
00144   // treat properly the bins with eff=100% 
00145   if ( 1 > fabsl( n2 ) ) { n2 = 1 ; } 
00146   //
00147   return ::sqrtl( n1 * n2 / n3 ) / n3 ;
00148 }

double StatEntity::eff (  )  const [inline]

shortcut,

See also:
StatEntity::efficiency

Definition at line 185 of file StatEntity.h.

00185 { return efficiency    () ; }

double StatEntity::effErr (  )  const [inline]

shortcut,

See also:
StatEntity::efficiencyErr

Definition at line 187 of file StatEntity.h.

00187 { 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 210 of file StatEntity.h.

00211   {
00212     addFlag ( f ) ;
00213     return *this ;
00214   }

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.

00232 { 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.

00251 { 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.

00272   {
00273     addFlag ( -f ) ;
00274     return *this ;
00275   }

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.

00293 { 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.

00311 { return --(*this) ; }

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 inrement

Definition at line 329 of file StatEntity.h.

00330   {
00331     // reset the statistics
00332     reset() ;            
00333     // use the regular inrement
00334     return ((*this)+=f); 
00335   }

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.

00153 {
00154   m_se_nEntries         += other.m_se_nEntries ;
00155   m_se_accumulatedFlag  += other.m_se_accumulatedFlag  ;
00156   m_se_accumulatedFlag2 += other.m_se_accumulatedFlag2 ;
00157   m_se_minimalFlag = std::min ( m_se_minimalFlag , other.m_se_minimalFlag ) ;
00158   m_se_maximalFlag = std::max ( m_se_maximalFlag , other.m_se_maximalFlag ) ;
00159   //
00160   return *this ;
00161 }

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

comparison

Definition at line 165 of file StatEntity.cpp.

00166 {  
00167   if      ( &se == this                     ) { return false ; }
00168   else if ( nEntries () <   se.nEntries ()  ) { return true  ; }
00169   else if ( nEntries () ==  se.nEntries () && 
00170             sum      () <   se.sum      ()  ) { return true  ; } 
00171   else if ( nEntries () ==  se.nEntries () && 
00172             sum      () ==  se.sum      () &&  
00173             min      () <   se.min      ()  ) { return true  ; } 
00174   else if ( nEntries () ==  se.nEntries () && 
00175             sum      () ==  se.sum      () &&  
00176             min      () ==  se.min      () &&
00177             max      () <   se.max      ()  ) { return true  ; } 
00178   else if ( nEntries () ==  se.nEntries () && 
00179             sum      () ==  se.flag     () &&  
00180             min      () ==  se.min      () &&
00181             max      () ==  se.max      () && 
00182             sum2     () <   se.sum2     ()  ) { return true  ; }
00184   return false; 
00185 }

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.

00190 {  
00191   //
00192   if      ( 0 <  m_se_nEntriesBeforeReset ) { --m_se_nEntriesBeforeReset; }
00193   else if ( 0 == m_se_nEntriesBeforeReset ) { reset(); } 
00194 
00195   m_se_accumulatedFlag   += Flag        ; // accumulate the flag
00197   m_se_minimalFlag = std::min ( m_se_minimalFlag , Flag ) ; // evaluate min/max 
00198   m_se_maximalFlag = std::max ( m_se_maximalFlag , Flag ) ; // evaluate min/max 
00199   // accumulate statistics, but avoid FPE for small flags... 
00200   static const double s_min1 = 2 * ::sqrt ( std::numeric_limits<double>::min() ) ;
00201   if ( s_min1 < Flag || -s_min1 > Flag )  
00202   { m_se_accumulatedFlag2  += Flag * Flag ; }// accumulate statistics:
00203   //
00204   return ++m_se_nEntries ;  
00205 }

void StatEntity::reset (  ) 

reset the counters

Definition at line 209 of file StatEntity.cpp.

00210 {
00211   //
00212   m_se_nEntries            =        0 ;
00213   m_se_accumulatedFlag     =        0 ; 
00214   m_se_minimalFlag         =       std::numeric_limits<double>::max() ;
00215   m_se_maximalFlag         =  -1 * std::numeric_limits<double>::max() ;
00216   m_se_accumulatedFlag2    =        0 ;
00217   m_se_nEntriesBeforeReset =       -1 ; // ? 
00218 }

void StatEntity::setnEntriesBeforeReset ( unsigned long  nEntriesBeforeReset  ) 

DR specify number of entry before reset.

Definition at line 222 of file StatEntity.cpp.

00223 { m_se_nEntriesBeforeReset = nEntriesBeforeReset; }

std::string StatEntity::toString (  )  const

representation as string

Definition at line 227 of file StatEntity.cpp.

00228 {
00229   std::ostringstream ost ;
00230   print ( ost )  ;
00231   return ost.str () ;
00232 } 

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.

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

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.

00375 { return print ( o ) ; }

double StatEntity::Sum (  )  const [inline]

get sum

Definition at line 380 of file StatEntity.h.

00380 { return sum     () ; } // get sum

double StatEntity::Mean (  )  const [inline]

get mean

Definition at line 382 of file StatEntity.h.

00382 { return mean    () ; } // get mean

double StatEntity::MeanErr (  )  const [inline]

get error in mean

Definition at line 384 of file StatEntity.h.

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

double StatEntity::Rms (  )  const [inline]

get rms

Definition at line 386 of file StatEntity.h.

00386 { return rms     () ; } // get rms 

double StatEntity::RMS (  )  const [inline]

get rms

Definition at line 388 of file StatEntity.h.

00388 { return rms     () ; } // get rms 

double StatEntity::Eff (  )  const [inline]

get efficiency

Definition at line 390 of file StatEntity.h.

00390 { return eff     () ; } // get efficiency

double StatEntity::Min (  )  const [inline]

get minimal value

Definition at line 392 of file StatEntity.h.

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

double StatEntity::Max (  )  const [inline]

get maximal value

Definition at line 394 of file StatEntity.h.

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

double StatEntity::flag (  )  const [inline]

accumulated "flag"

Definition at line 399 of file StatEntity.h.

00399 { return sum     () ; }

double StatEntity::flag2 (  )  const [inline]

accumulated "flag squared"

Definition at line 401 of file StatEntity.h.

00401 { return sum2    () ; }

double StatEntity::flagMean (  )  const [inline]

mean value of flag

Definition at line 403 of file StatEntity.h.

00403 { return mean    () ; }

double StatEntity::flagRMS (  )  const [inline]

r.m.s of flag

Definition at line 405 of file StatEntity.h.

00405 { return rms     () ; }

double StatEntity::flagMeanErr (  )  const [inline]

error in mean value of flag

Definition at line 407 of file StatEntity.h.

00407 { return meanErr () ; }

double StatEntity::flagMin (  )  const [inline]

minimal flag

Definition at line 409 of file StatEntity.h.

00409 { return min     () ; }

double StatEntity::flagMax (  )  const [inline]

maximal flag

Definition at line 411 of file StatEntity.h.

00411 { return max     () ; }

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.

00416 { return add ( Flag ) ; }

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.

00064 {
00065   // check for "X" or "L"
00066   BOOST_STATIC_ASSERT(((sizeof(unsigned long)==4)||(sizeof(unsigned long)==8)));
00067   // check for "D"
00068   BOOST_STATIC_ASSERT((sizeof(double)==8))        ; 
00069   //
00070   static const std::string s_fmt = 
00071     ( ( 8 == sizeof(unsigned long) ) ?"X:1;" : "L:1;" ) + std::string("D:4") ;
00072   return s_fmt ;
00073 } 

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.

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


Member Data Documentation

unsigned long StatEntity::m_se_nEntries [private]

number of calls

Definition at line 438 of file StatEntity.h.

accumulated flag

Definition at line 440 of file StatEntity.h.

Definition at line 441 of file StatEntity.h.

double StatEntity::m_se_minimalFlag [private]

Definition at line 442 of file StatEntity.h.

double StatEntity::m_se_maximalFlag [private]

Definition at line 443 of file StatEntity.h.

Definition at line 445 of file StatEntity.h.


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

Generated at Mon May 3 12:26:31 2010 for Gaudi Framework, version v21r9 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004