CMS 3D CMS Logo

simple_stat.h
Go to the documentation of this file.
1 #ifndef TrackingTools_DetLayers_simple_stat_h
2 #define TrackingTools_DetLayers_simple_stat_h
3 
4 #include <algorithm>
5 #include <numeric>
6 #include <cmath>
7 
12 template< class CONT>
13 double stat_mean( const CONT & cont) {
14  double sum = accumulate (cont.begin(), cont.end(), 0.);
15  return sum / cont.size();
16 }
17 
23 template< class CONT>
24 double stat_RMS( const CONT & cont) {
25 
26  typename CONT::const_iterator i;
27 
28  int N = cont.size();
29  if (N > 1) {
30  double sum=0., sum2=0.;
31  for (i=cont.begin(); i!=cont.end(); i++) {
32  sum += *i;
33  sum2 += (*i) * (*i);
34  }
35  return sqrt( std::max( 0., (sum2 - sum*sum/N) / (N-1))) ;
36  }
37  else return 0.;
38 }
39 
40 #endif // TrackingTools_DetLayers_simple_stat_h
double stat_mean(const CONT &cont)
Definition: simple_stat.h:13
T sqrt(T t)
Definition: SSEVec.h:18
double stat_RMS(const CONT &cont)
Definition: simple_stat.h:24
#define N
Definition: blowfish.cc:9