Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:32

0001 #ifndef TrackingTools_DetLayers_simple_stat_h
0002 #define TrackingTools_DetLayers_simple_stat_h
0003 
0004 #include <algorithm>
0005 #include <numeric>
0006 #include <cmath>
0007 
0008 /** A trivial class computing the mean value of objects in any
0009  *  STL container.
0010  */
0011 
0012 template <class CONT>
0013 double stat_mean(const CONT& cont) {
0014   double sum = accumulate(cont.begin(), cont.end(), 0.);
0015   return sum / cont.size();
0016 }
0017 
0018 /** A simple class computing the R.M.S. of objects in any
0019  *  STL container.
0020  */
0021 
0022 template <class CONT>
0023 double stat_RMS(const CONT& cont) {
0024   typename CONT::const_iterator i;
0025 
0026   int N = cont.size();
0027   if (N > 1) {
0028     double sum = 0., sum2 = 0.;
0029     for (i = cont.begin(); i != cont.end(); i++) {
0030       sum += *i;
0031       sum2 += (*i) * (*i);
0032     }
0033     return sqrt(std::max(0., (sum2 - sum * sum / N) / (N - 1)));
0034   } else
0035     return 0.;
0036 }
0037 
0038 #endif  // TrackingTools_DetLayers_simple_stat_h