ATLAS Offline Software
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
 
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 80 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 89 of file StatUtils.h.

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

Member Function Documentation

◆ add()

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

Gather statistics and fill the histogram if not disabled.

Definition at line 116 of file StatUtils.h.

116  {
117  Stat::add(val);
118  if (!m_histogram.empty()) {
119  unsigned int bin = std::min( static_cast<unsigned int>(m_histogram.size()-1),
120  static_cast<unsigned int>( std::max(0.,(val - m_xmin)*m_scale)) );
121  ++m_histogram.at(bin) ;
122  }
123  }

◆ createEmptyClone()

StatHist ActsUtils::StatHist::createEmptyClone ( )
inline

Definition at line 107 of file StatUtils.h.

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

◆ histogramToString()

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

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

Definition at line 152 of file StatUtils.h.

152  {
153  std::stringstream msg;
154  if (m_histogram.size()>2) {
155  unsigned int max_val = 0;
156  for (const auto &count : m_histogram) {
157  max_val = std::max(max_val, count);
158  }
159  double bin_width=1./m_scale;
160  unsigned int w = static_cast<unsigned int>(log(1.*max_val) / log(10.))+1;
161  unsigned int wtitle = std::max(10u,w);;
162  msg << (m_xmin+bin_width) << " .. " << ((m_histogram.size()-2)/m_scale + m_xmin+bin_width) << " : "
163  << std::setw(wtitle) << "lower edge" << " |";
164  for (unsigned int i=1; i<m_histogram.size()-1; ++i) {
165  msg << " " << std::setw(w) << lowerEdge(i);
166  }
167  msg << " | " << std::endl;
168  msg << (m_xmin+bin_width) << " .. " << ((m_histogram.size()-2)/m_scale + m_xmin+bin_width) << " : "
169 
170  << std::setw(wtitle) << m_histogram[0] << " |";
171  for (unsigned int i=1; i<m_histogram.size()-1; ++i) {
172  msg << " " << std::setw(w) << m_histogram[i];
173  }
174  msg << " | " << std::setw(w) << m_histogram.back();
175  }
176  return msg.str();
177  }

◆ 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 146 of file StatUtils.h.

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

◆ max()

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

Definition at line 29 of file StatUtils.h.

29 { return m_max; }

◆ mean()

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

Definition at line 30 of file StatUtils.h.

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

◆ min()

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

Definition at line 28 of file StatUtils.h.

28 { return m_min; }

◆ n()

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

Definition at line 27 of file StatUtils.h.

27 { 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 44 of file StatUtils.h.

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

◆ operator+=() [2/2]

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

Add the statistucs and histogrammed data fro the given object.

Definition at line 134 of file StatUtils.h.

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

◆ reset()

void ActsUtils::StatHist::reset ( )
inline

Set histogram contents and statistics to zero.

Definition at line 126 of file StatUtils.h.

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

◆ rms()

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

Definition at line 32 of file StatUtils.h.

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

◆ rms2()

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

Definition at line 31 of file StatUtils.h.

31 { 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 98 of file StatUtils.h.

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

Member Data Documentation

◆ m_histogram

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

Definition at line 181 of file StatUtils.h.

◆ m_max

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

Definition at line 57 of file StatUtils.h.

◆ m_min

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

Definition at line 56 of file StatUtils.h.

◆ m_n

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

Definition at line 53 of file StatUtils.h.

◆ m_scale

double ActsUtils::StatHist::m_scale

Definition at line 180 of file StatUtils.h.

◆ m_sum

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

Definition at line 54 of file StatUtils.h.

◆ m_sum2

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

Definition at line 55 of file StatUtils.h.

◆ m_xmin

double ActsUtils::StatHist::m_xmin

Definition at line 179 of file StatUtils.h.


The documentation for this class was generated from the following file:
max
#define max(a, b)
Definition: cfImp.cxx:41
CheckAppliedSFs.bin_width
bin_width
Definition: CheckAppliedSFs.py:242
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:44
ActsUtils::Stat::m_max
double m_max
Definition: StatUtils.h:57
ActsUtils::StatHist::lowerEdge
double lowerEdge(unsigned int i) const
Get the lower edge of the given bin.
Definition: StatUtils.h:146
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
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:20
ActsUtils::StatHist::StatHist
StatHist()=default
The default constructor will disable histogramming.
lumiFormat.i
int i
Definition: lumiFormat.py:92
xmin
double xmin
Definition: listroot.cxx:60
ActsUtils::Stat::m_sum
double m_sum
Definition: StatUtils.h:54
ActsUtils::Stat::m_n
unsigned int m_n
Definition: StatUtils.h:53
ActsUtils::StatHist::m_scale
double m_scale
Definition: StatUtils.h:180
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
min
#define min(a, b)
Definition: cfImp.cxx:40
ActsUtils::StatHist::m_xmin
double m_xmin
Definition: StatUtils.h:179
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ActsUtils::Stat::m_sum2
double m_sum2
Definition: StatUtils.h:55
ActsUtils::Stat::m_min
double m_min
Definition: StatUtils.h:56
ActsUtils::StatHist::setBinning
void setBinning(unsigned int n_bins, float xmin, float xmax)
Define histogramm bins and enable histogramming.
Definition: StatUtils.h:98
ActsUtils::Stat::rms2
double rms2() const
Definition: StatUtils.h:31
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
ActsUtils::Stat::reset
void reset()
Set statistics to zero.
Definition: StatUtils.h:35
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:181
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7