Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Public Attributes | List of all members
ActsUtils::StatHist Class Reference

Extend Stat helper by an equidistant binned histogram. More...

#include <StatUtils.h>

Inheritance diagram for ActsUtils::StatHist:
Collaboration diagram for ActsUtils::StatHist:

Public Member Functions

 StatHist ()=default
 The default constructor will disable histogramming. More...
 
 StatHist (unsigned int n_bins, float xmin, float xmax)
 Set up class to also fill a histogram. More...
 
void setBinning (unsigned int n_bins, float xmin, float xmax)
 Define histogramm bins and enable histogramming. More...
 
StatHist createEmptyClone ()
 
void add (double val)
 Gather statistics and fill the histogram if not disabled. More...
 
void reset ()
 Set histogram contents and statistics to zero. More...
 
StatHistoperator+= (const StatHist &b)
 Add the statistucs and histogrammed data fro the given object. More...
 
double lowerEdge (unsigned int i) const
 Get the lower edge of the given bin. More...
 
std::string histogramToString () const
 Create a string showing the contents of the histogram The string. More...
 
unsigned int n () const
 
double min () const
 
double max () const
 
double mean () const
 
double rms2 () const
 
double rms () const
 
Statoperator+= (const Stat &b)
 @breif Add the statistics gathered in the Stat object b More...
 

Public Attributes

double m_xmin {}
 
double m_scale {1.0}
 
std::vector< unsigned int > m_histogram
 
unsigned int m_n =0
 
double m_sum =0.
 
double m_sum2 =0.
 
double m_min =std::numeric_limits<double>::max()
 
double m_max =-std::numeric_limits<double>::max()
 

Detailed Description

Extend Stat helper by an equidistant binned histogram.

Definition at line 81 of file StatUtils.h.

Constructor & Destructor Documentation

◆ StatHist() [1/2]

ActsUtils::StatHist::StatHist ( )
default

The default constructor will disable histogramming.

◆ StatHist() [2/2]

ActsUtils::StatHist::StatHist ( unsigned int  n_bins,
float  xmin,
float  xmax 
)
inline

Set up class to also fill a histogram.

Parameters
n_binsnumber of bins without over and underflow
thevalue at the lower edge of the first bin
thevalue at the upper edge of the last bin

Definition at line 90 of file StatUtils.h.

91  {
92  setBinning(n_bins,xmin,xmax);
93  }

Member Function Documentation

◆ add()

void ActsUtils::StatHist::add ( double  val)
inline

Gather statistics and fill the histogram if not disabled.

Definition at line 117 of file StatUtils.h.

117  {
118  Stat::add(val);
119  if (!m_histogram.empty()) {
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)) );
122  ++m_histogram.at(bin) ;
123  }
124  }

◆ createEmptyClone()

StatHist ActsUtils::StatHist::createEmptyClone ( )
inline

Definition at line 108 of file StatUtils.h.

108  {
109  StatHist tmp;
110  tmp.m_histogram.resize( m_histogram.size());
111  tmp.m_xmin = m_xmin;
112  tmp.m_scale = m_scale;
113  return tmp;
114  }

◆ histogramToString()

std::string ActsUtils::StatHist::histogramToString ( ) const
inline

Create a string showing the contents of the histogram The string.

Definition at line 153 of file StatUtils.h.

153  {
154  std::stringstream msg;
155  if (m_histogram.size()>2) {
156  const unsigned int max_val = *std::max_element(m_histogram.begin(), m_histogram.end());
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);
160  msg << (m_xmin+bin_width) << " .. " << ((m_histogram.size()-2)/m_scale + m_xmin+bin_width) << " : "
161  << std::setw(wtitle) << "lower edge" << " |";
162  for (unsigned int i=1; i<m_histogram.size()-1; ++i) {
163  msg << " " << std::setw(w) << lowerEdge(i);
164  }
165  msg << " | " << std::endl;
166  msg << (m_xmin+bin_width) << " .. " << ((m_histogram.size()-2)/m_scale + m_xmin+bin_width) << " : "
167 
168  << std::setw(wtitle) << m_histogram[0] << " |";
169  for (unsigned int i=1; i<m_histogram.size()-1; ++i) {
170  msg << " " << std::setw(w) << m_histogram[i];
171  }
172  msg << " | " << std::setw(w) << m_histogram.back();
173  }
174  return msg.str();
175  }

◆ lowerEdge()

double ActsUtils::StatHist::lowerEdge ( unsigned int  i) const
inline

Get the lower edge of the given bin.

Parameters
ithe bin (0: underflow; n+1 overflow)

Definition at line 147 of file StatUtils.h.

147  {
148  return m_xmin + i/m_scale;
149  }

◆ max()

double ActsUtils::Stat::max ( ) const
inlineinherited

Definition at line 30 of file StatUtils.h.

30 { return m_max; }

◆ mean()

double ActsUtils::Stat::mean ( ) const
inlineinherited

Definition at line 31 of file StatUtils.h.

31 { return m_n>0 ? m_sum/m_n : 0.; }

◆ min()

double ActsUtils::Stat::min ( ) const
inlineinherited

Definition at line 29 of file StatUtils.h.

29 { return m_min; }

◆ n()

unsigned int ActsUtils::Stat::n ( ) const
inlineinherited

Definition at line 28 of file StatUtils.h.

28 { return m_n; }

◆ operator+=() [1/2]

Stat& ActsUtils::Stat::operator+= ( const Stat b)
inlineinherited

@breif Add the statistics gathered in the Stat object b

Definition at line 45 of file StatUtils.h.

45  {
46  m_n += b.m_n;
47  m_sum += b.m_sum;
48  m_sum2 += b.m_sum2;
49  m_min = std::min(m_min, b.m_min);
50  m_max = std::max(m_max, b.m_max);
51  return *this;
52  }

◆ operator+=() [2/2]

StatHist& ActsUtils::StatHist::operator+= ( const StatHist b)
inline

Add the statistucs and histogrammed data fro the given object.

Definition at line 135 of file StatUtils.h.

135  {
137  if (m_histogram.size() == b.m_histogram.size()) {
138  for (unsigned int bin_i=0; bin_i< m_histogram.size(); ++bin_i) {
139  m_histogram[bin_i] += b.m_histogram[bin_i];
140  }
141  }
142  return *this;
143  }

◆ reset()

void ActsUtils::StatHist::reset ( )
inline

Set histogram contents and statistics to zero.

Definition at line 127 of file StatUtils.h.

127  {
128  Stat::reset();
129  for (unsigned int &bin : m_histogram) {
130  bin = 0u;
131  }
132  }

◆ rms()

double ActsUtils::Stat::rms ( ) const
inlineinherited

Definition at line 33 of file StatUtils.h.

33 { return std::sqrt( rms2() ); }

◆ rms2()

double ActsUtils::Stat::rms2 ( ) const
inlineinherited

Definition at line 32 of file StatUtils.h.

32 { return m_n>1 ? (m_sum2 - m_sum *m_sum/m_n)/(m_n-1) : 0.; }

◆ setBinning()

void ActsUtils::StatHist::setBinning ( unsigned int  n_bins,
float  xmin,
float  xmax 
)
inline

Define histogramm bins and enable histogramming.

Parameters
n_binsnumber of bins without over and underflow
thevalue at the lower edge of the first bin
thevalue at the upper edge of the last bin

Definition at line 99 of file StatUtils.h.

100  {
101  m_xmin=xmin;
102  m_scale = ( n_bins / (xmax-xmin) );
103  m_xmin -= 1./m_scale;
104  m_histogram.resize(n_bins+2,0u);
105  }

Member Data Documentation

◆ m_histogram

std::vector<unsigned int> ActsUtils::StatHist::m_histogram

Definition at line 179 of file StatUtils.h.

◆ m_max

double ActsUtils::Stat::m_max =-std::numeric_limits<double>::max()
inherited

Definition at line 58 of file StatUtils.h.

◆ m_min

double ActsUtils::Stat::m_min =std::numeric_limits<double>::max()
inherited

Definition at line 57 of file StatUtils.h.

◆ m_n

unsigned int ActsUtils::Stat::m_n =0
inherited

Definition at line 54 of file StatUtils.h.

◆ m_scale

double ActsUtils::StatHist::m_scale {1.0}

Definition at line 178 of file StatUtils.h.

◆ m_sum

double ActsUtils::Stat::m_sum =0.
inherited

Definition at line 55 of file StatUtils.h.

◆ m_sum2

double ActsUtils::Stat::m_sum2 =0.
inherited

Definition at line 56 of file StatUtils.h.

◆ m_xmin

double ActsUtils::StatHist::m_xmin {}

Definition at line 177 of file StatUtils.h.


The documentation for this class was generated from the following file:
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
CheckAppliedSFs.bin_width
bin_width
Definition: CheckAppliedSFs.py:242
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
bin
Definition: BinsDiffFromStripMedian.h:43
ActsUtils::Stat::operator+=
Stat & operator+=(const Stat &b)
@breif Add the statistics gathered in the Stat object b
Definition: StatUtils.h:45
ActsUtils::Stat::m_max
double m_max
Definition: StatUtils.h:58
ActsUtils::StatHist::lowerEdge
double lowerEdge(unsigned int i) const
Get the lower edge of the given bin.
Definition: StatUtils.h:147
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
ActsUtils::Stat::add
void add(double val)
@bruef Gather a new value will update min, max and the sums to compute mean and rms
Definition: StatUtils.h:21
ActsUtils::StatHist::StatHist
StatHist()=default
The default constructor will disable histogramming.
lumiFormat.i
int i
Definition: lumiFormat.py:85
xmin
double xmin
Definition: listroot.cxx:60
ActsUtils::Stat::m_sum
double m_sum
Definition: StatUtils.h:55
ActsUtils::Stat::m_n
unsigned int m_n
Definition: StatUtils.h:54
ActsUtils::StatHist::m_scale
double m_scale
Definition: StatUtils.h:178
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ActsUtils::StatHist::m_xmin
double m_xmin
Definition: StatUtils.h:177
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ActsUtils::Stat::m_sum2
double m_sum2
Definition: StatUtils.h:56
ActsUtils::Stat::m_min
double m_min
Definition: StatUtils.h:57
ActsUtils::StatHist::setBinning
void setBinning(unsigned int n_bins, float xmin, float xmax)
Define histogramm bins and enable histogramming.
Definition: StatUtils.h:99
ActsUtils::Stat::rms2
double rms2() const
Definition: StatUtils.h:32
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
ActsUtils::Stat::reset
void reset()
Set statistics to zero.
Definition: StatUtils.h:36
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
xmax
double xmax
Definition: listroot.cxx:61
ActsUtils::StatHist::m_histogram
std::vector< unsigned int > m_histogram
Definition: StatUtils.h:179
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7