simple_stats.h
Go to the documentation of this file.
1 #ifndef cetlib_simple_stats_h
2 #define cetlib_simple_stats_h
3 
4 // ======================================================================
5 //
6 // simple_stats: yield simple statistics from individually-presented data
7 //
8 // ======================================================================
9 
10 #include <cstddef> // size_t
11 #include <iosfwd> // basic_ostream
12 
13 namespace cet {
14 
15  class simple_stats;
16 
17  template <class charT, class traits>
18  std::basic_ostream<charT, traits>& operator<<(
19  std::basic_ostream<charT, traits>&,
20  simple_stats const&);
21 }
22 
23 // ======================================================================
24 
26 public:
27  // c'tors:
28  simple_stats() noexcept;
29  simple_stats(double x) noexcept;
30 
31  // use compiler-generated copy/move/d'tor
32 
33  // statistics observers:
34  std::size_t
35  size() const noexcept
36  {
37  return n_;
38  }
39  double
40  max() const noexcept
41  {
42  return max_;
43  }
44  double
45  min() const noexcept
46  {
47  return min_;
48  }
49  double
50  small() const noexcept
51  {
52  return small_;
53  }
54  double
55  sum() const noexcept
56  {
57  return sum_;
58  }
59  double
60  sumsq() const noexcept
61  {
62  return sumsq_;
63  }
64 
65  // statistics calculators:
66  double mean() const noexcept;
67  double range() const noexcept;
68  double err_mean(std::size_t nparams = 1u) const noexcept;
69  double rms(std::size_t nparams = 1u) const noexcept;
70  double rms0(std::size_t nparams = 0u) const noexcept;
71  double err_rms(std::size_t nparams = 1u) const noexcept;
72 
73  // mutators:
74  void reset() noexcept;
75  void sample(double) noexcept;
76  template <class Iter>
77  void
78  sample(Iter begin, Iter end) noexcept
79  {
80  for (; begin != end; ++begin)
81  sample(*begin);
82  }
83 
84 private:
85  std::size_t n_; // counter
86  double min_, max_, small_; // extrema
87  double sum_, sumsq_; // accumulations
88 
89 }; // simple_stats
90 
91 // ======================================================================
92 
93 template <class charT, class traits>
94 std::basic_ostream<charT, traits>&
95 cet::operator<<(std::basic_ostream<charT, traits>& os,
96  simple_stats const& stats)
97 {
98  return os << "( " << stats.size() << ", " << stats.mean() << " +/- "
99  << stats.err_mean() << ", " << stats.rms() << " +/- "
100  << stats.err_rms() << ", " << stats.min() << " " << stats.max()
101  << " )";
102 }
103 
104 // ======================================================================
105 
106 #endif /* cetlib_simple_stats_h */
107 
108 // Local Variables:
109 // mode: c++
110 // End:
std::size_t size() const noexcept
Definition: simple_stats.h:35
double small() const noexcept
Definition: simple_stats.h:50
simple_stats() noexcept
std::ostream & operator<<(std::ostream &, map_vector_key const &)
Definition: map_vector.h:330
double mean() const noexcept
double rms0(std::size_t nparams=0u) const noexcept
double range() const noexcept
int stats(TString inputFilePath, Int_t firstRun, Int_t lastRun, Float_t thresh, TString myDet)
Definition: stats.C:13
double err_mean(std::size_t nparams=1u) const noexcept
double min() const noexcept
Definition: simple_stats.h:45
void sample(Iter begin, Iter end) noexcept
Definition: simple_stats.h:78
double rms(std::size_t nparams=1u) const noexcept
double max() const noexcept
Definition: simple_stats.h:40
double sum() const noexcept
Definition: simple_stats.h:55
double sumsq() const noexcept
Definition: simple_stats.h:60
std::size_t n_
Definition: simple_stats.h:85
void sample(double) noexcept
void reset() noexcept
double err_rms(std::size_t nparams=1u) const noexcept