CMS 3D CMS Logo

simple_stat.h File Reference

#include <numeric>
#include <cmath>

Go to the source code of this file.

Functions

template<class CONT>
double stat_mean (const CONT &cont)
 A trivial class computing the mean value of objects in any STL container.
template<class CONT>
double stat_RMS (const CONT &cont)
 A simple class computing the R.M.S.


Function Documentation

template<class CONT>
double stat_mean ( const CONT &  cont  )  [inline]

A trivial class computing the mean value of objects in any STL container.

Definition at line 9 of file simple_stat.h.

References sum().

00009                                      {
00010   double sum = accumulate (cont.begin(), cont.end(), 0.);
00011   return sum / cont.size();
00012 }

template<class CONT>
double stat_RMS ( const CONT &  cont  )  [inline]

A simple class computing the R.M.S.

of objects in any STL container.

Definition at line 20 of file simple_stat.h.

References i, max, N, funct::sqrt(), and sum().

Referenced by PhiBorderFinder::PhiBorderFinder(), and RBorderFinder::RBorderFinder().

00020                                     {
00021 
00022   typename CONT::const_iterator i;
00023 
00024   int N = cont.size();
00025   if (N > 1) {
00026     double sum=0., sum2=0.;
00027     for (i=cont.begin(); i!=cont.end(); i++) {
00028       sum  += *i;
00029       sum2 += (*i) * (*i); 
00030     }
00031     return sqrt( std::max( 0., (sum2 - sum*sum/N) / (N-1))) ;
00032   }
00033   else return 0.;
00034 }


Generated on Tue Jun 9 17:56:00 2009 for CMSSW by  doxygen 1.5.4