6#ifndef ACTSUTILS_STAT_H
7#define ACTSUTILS_STAT_H 1
21 void add(
double val) {
28 unsigned int n()
const {
return m_n; }
33 double rms()
const {
return std::sqrt(
rms2() ); }
40 m_min=std::numeric_limits<double>::max();
41 m_max=-std::numeric_limits<double>::max();
57 double m_min=std::numeric_limits<double>::max();
58 double m_max=-std::numeric_limits<double>::max();
62template <
class T_Stream>
65 out << std::setw(14) << stat.min() <<
" < "
66 << std::setw(14) << stat.mean() <<
" +- " << std::setw(14) << stat.rms() <<
" < "
67 << std::setw(14) << stat.max()
68 <<
" / " << std::setw(9) << stat.n();
71 out << std::setw(14*4+9+3*3+4) << stat.mean();
120 unsigned int bin = std::min(
static_cast<unsigned int>(
m_histogram.size()-1),
121 static_cast<unsigned int>( std::max(0.,(val -
m_xmin)*
m_scale)) );
138 for (
unsigned int bin_i=0; bin_i<
m_histogram.size(); ++bin_i) {
154 std::stringstream
msg;
157 const double bin_width = 1. /
m_scale;
158 const unsigned int w = max_val > 0 ?
static_cast<unsigned int>(log(1.*max_val) / log(10.))+1 : 1;
159 const unsigned int wtitle = std::max(10u, w);
161 << std::setw(wtitle) <<
"lower edge" <<
" |";
162 for (
unsigned int i=1; i<
m_histogram.size()-1; ++i) {
165 msg <<
" | " << std::endl;
169 for (
unsigned int i=1; i<
m_histogram.size()-1; ++i) {
std::vector< unsigned int > m_histogram
void reset()
Set histogram contents and statistics to zero.
void add(double val)
Gather statistics and fill the histogram if not disabled.
void setBinning(unsigned int n_bins, float xmin, float xmax)
Define histogramm bins and enable histogramming.
double lowerEdge(unsigned int i) const
Get the lower edge of the given bin.
StatHist(unsigned int n_bins, float xmin, float xmax)
Set up class to also fill a histogram.
StatHist & operator+=(const StatHist &b)
Add the statistucs and histogrammed data fro the given object.
StatHist createEmptyClone()
std::string histogramToString() const
Create a string showing the contents of the histogram The string.
StatHist()=default
The default constructor will disable histogramming.
Simple class to gather statistics : min, max, mean, rms.
void add(double val)
@bruef Gather a new value will update min, max and the sums to compute mean and rms
void reset()
Set statistics to zero.
Stat & operator+=(const Stat &b)
@breif Add the statistics gathered in the Stat object b
std::ostream & operator<<(std::ostream &out, const Stat &stat)
void dumpStat(T_Stream &out, const Stat &stat)
Dump the given statistics object to the given output stream.