CMS 3D CMS Logo

Functions

/data/refman/pasoursint/CMSSW_6_1_1/src/TrackingTools/DetLayers/interface/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)
template<class CONT >
double stat_RMS (const CONT &cont)

Function Documentation

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

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

Definition at line 9 of file simple_stat.h.

                                     {
  double sum = accumulate (cont.begin(), cont.end(), 0.);
  return sum / cont.size();
}
template<class CONT >
double stat_RMS ( const CONT &  cont)

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, and mathSSE::sqrt().

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

                                    {

  typename CONT::const_iterator i;

  int N = cont.size();
  if (N > 1) {
    double sum=0., sum2=0.;
    for (i=cont.begin(); i!=cont.end(); i++) {
      sum  += *i;
      sum2 += (*i) * (*i); 
    }
    return sqrt( std::max( 0., (sum2 - sum*sum/N) / (N-1))) ;
  }
  else return 0.;
}