CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/TrackingTools/DetLayers/interface/simple_stat.h

Go to the documentation of this file.
00001 #include <numeric>
00002 #include <cmath>
00003 
00008 template< class CONT> 
00009 double stat_mean( const CONT & cont) {
00010   double sum = accumulate (cont.begin(), cont.end(), 0.);
00011   return sum / cont.size();
00012 }
00013 
00019 template< class CONT> 
00020 double stat_RMS( const CONT & cont) {
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 }