The Gaudi Framework  master (37c0b60a)
Gaudi::Accumulators::Axis< Arithmetic > Class Template Reference

Definition of a default type of Histogram Axis It contains number of bins, min and max value plus a title and defines the basic type of Axis (non log) It may also contain labels for the bins. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/Accumulators/StaticHistogram.h>

Collaboration diagram for Gaudi::Accumulators::Axis< Arithmetic >:

Public Types

using ArithmeticType = Arithmetic
 

Public Member Functions

 Axis (unsigned int nBins=0, Arithmetic minValue=Arithmetic{}, Arithmetic maxValue=Arithmetic{}, std::string title={}, std::vector< std::string > labels={})
 
 Axis (Gaudi::Histo1DDef const &def)
 
unsigned int index (Arithmetic value) const
 returns the bin number for a given value, ranging from 0 (underflow) to nBins+1 (overflow) More...
 
bool inAcceptance (Arithmetic value) const
 says whether the given value is within the range of the axis More...
 
unsigned int numBins () const
 
void setNumBins (unsigned int n)
 
Arithmetic minValue () const
 
void setMinValue (Arithmetic v)
 
Arithmetic maxValue () const
 
void setMaxValue (Arithmetic v)
 
std::string const & title () const
 
void setTitle (std::string const &t)
 
std::vector< std::string > const labels () const
 

Public Attributes

unsigned int nBins
 number of bins for this Axis FIXME : should be private and called m_nBins but will break backward compatibility with previous implementation. More...
 

Private Member Functions

void recomputeRatio ()
 

Private Attributes

std::string m_title
 title of this axis More...
 
Arithmetic m_minValue
 min and max values on this axis More...
 
Arithmetic m_maxValue
 
Arithmetic m_ratio
 precomputed ratio to convert a value into bin number equal to nBins/(maxValue-minValue). More...
 
std::vector< std::stringm_labels
 labels for the bins More...
 

Friends

std::ostreamoperator<< (std::ostream &o, Axis const &axis)
 

Detailed Description

template<typename Arithmetic>
class Gaudi::Accumulators::Axis< Arithmetic >

Definition of a default type of Histogram Axis It contains number of bins, min and max value plus a title and defines the basic type of Axis (non log) It may also contain labels for the bins.

Definition at line 229 of file StaticHistogram.h.

Member Typedef Documentation

◆ ArithmeticType

template<typename Arithmetic >
using Gaudi::Accumulators::Axis< Arithmetic >::ArithmeticType = Arithmetic

Definition at line 231 of file StaticHistogram.h.

Constructor & Destructor Documentation

◆ Axis() [1/2]

template<typename Arithmetic >
Gaudi::Accumulators::Axis< Arithmetic >::Axis ( unsigned int  nBins = 0,
Arithmetic  minValue = Arithmetic{},
Arithmetic  maxValue = Arithmetic{},
std::string  title = {},
std::vector< std::string labels = {} 
)
inline

Definition at line 232 of file StaticHistogram.h.

232  {}, Arithmetic maxValue = Arithmetic{},
234  : m_title( std::move( title ) )
235  , nBins( nBins )
236  , m_minValue( minValue )
237  , m_maxValue( maxValue )
238  , m_labels( std::move( labels ) ) {
240  recomputeRatio();
241  for ( const auto& s : m_labels ) details::requireValidTitle( s );
242  }

◆ Axis() [2/2]

template<typename Arithmetic >
Gaudi::Accumulators::Axis< Arithmetic >::Axis ( Gaudi::Histo1DDef const &  def)
inlineexplicit

Definition at line 243 of file StaticHistogram.h.

244  : Axis( (unsigned int)def.bins(), def.lowEdge(), def.highEdge(), def.title() ) {}

Member Function Documentation

◆ inAcceptance()

template<typename Arithmetic >
bool Gaudi::Accumulators::Axis< Arithmetic >::inAcceptance ( Arithmetic  value) const
inline

says whether the given value is within the range of the axis

Definition at line 269 of file StaticHistogram.h.

269 { return value >= m_minValue && value <= m_maxValue; }

◆ index()

template<typename Arithmetic >
unsigned int Gaudi::Accumulators::Axis< Arithmetic >::index ( Arithmetic  value) const
inline

returns the bin number for a given value, ranging from 0 (underflow) to nBins+1 (overflow)

Definition at line 247 of file StaticHistogram.h.

247  {
248  // In case we use integer as Arithmetic type, we cannot use ratio for computing indices,
249  // as ratios < 1.0 will simply be 0, so we have to pay the division in such a case
250  int idx;
251  if constexpr ( std::is_integral_v<Arithmetic> ) {
252  idx = ( ( value - m_minValue ) * nBins / ( m_maxValue - m_minValue ) ) + 1;
253  } else {
254  idx = std::floor( ( value - m_minValue ) * m_ratio ) + 1;
255  }
256  return idx < 0 ? 0 : ( (unsigned int)idx > numBins() ? numBins() + 1 : (unsigned int)idx );
257  }

◆ labels()

template<typename Arithmetic >
std::vector<std::string> const Gaudi::Accumulators::Axis< Arithmetic >::labels ( ) const
inline

Definition at line 289 of file StaticHistogram.h.

289 { return m_labels; }

◆ maxValue()

template<typename Arithmetic >
Arithmetic Gaudi::Accumulators::Axis< Arithmetic >::maxValue ( ) const
inline

Definition at line 282 of file StaticHistogram.h.

282 { return m_maxValue; }

◆ minValue()

template<typename Arithmetic >
Arithmetic Gaudi::Accumulators::Axis< Arithmetic >::minValue ( ) const
inline

Definition at line 277 of file StaticHistogram.h.

277 { return m_minValue; }

◆ numBins()

template<typename Arithmetic >
unsigned int Gaudi::Accumulators::Axis< Arithmetic >::numBins ( ) const
inline

Definition at line 272 of file StaticHistogram.h.

272 { return nBins; }

◆ recomputeRatio()

template<typename Arithmetic >
void Gaudi::Accumulators::Axis< Arithmetic >::recomputeRatio ( )
inlineprivate

Definition at line 311 of file StaticHistogram.h.

311  {
312  m_ratio = ( m_maxValue == m_minValue ) ? Arithmetic{} : nBins / ( m_maxValue - m_minValue );
313  }

◆ setMaxValue()

template<typename Arithmetic >
void Gaudi::Accumulators::Axis< Arithmetic >::setMaxValue ( Arithmetic  v)
inline

Definition at line 283 of file StaticHistogram.h.

283  {
284  m_maxValue = v;
285  recomputeRatio();
286  }

◆ setMinValue()

template<typename Arithmetic >
void Gaudi::Accumulators::Axis< Arithmetic >::setMinValue ( Arithmetic  v)
inline

Definition at line 278 of file StaticHistogram.h.

278  {
279  m_minValue = v;
280  recomputeRatio();
281  }

◆ setNumBins()

template<typename Arithmetic >
void Gaudi::Accumulators::Axis< Arithmetic >::setNumBins ( unsigned int  n)
inline

Definition at line 273 of file StaticHistogram.h.

273  {
274  nBins = n;
275  recomputeRatio();
276  }

◆ setTitle()

template<typename Arithmetic >
void Gaudi::Accumulators::Axis< Arithmetic >::setTitle ( std::string const &  t)
inline

Definition at line 288 of file StaticHistogram.h.

288 { m_title = t; }

◆ title()

template<typename Arithmetic >
std::string const& Gaudi::Accumulators::Axis< Arithmetic >::title ( ) const
inline

Definition at line 287 of file StaticHistogram.h.

287 { return m_title; }

Friends And Related Function Documentation

◆ operator<<

template<typename Arithmetic >
std::ostream& operator<< ( std::ostream o,
Axis< Arithmetic > const &  axis 
)
friend

Definition at line 259 of file StaticHistogram.h.

259  {
260  // Note that we print python code here, as the generic toStream implementation uses this
261  // operator to generate python code.
262  o << "(" << axis.numBins() << ", " << axis.minValue() << ", " << axis.maxValue() << ", "
263  << "\"" << axis.m_title << "\", (";
264  for ( auto const& label : axis.m_labels ) { o << "\"" << label << "\", "; }
265  return o << "))";
266  }

Member Data Documentation

◆ m_labels

template<typename Arithmetic >
std::vector<std::string> Gaudi::Accumulators::Axis< Arithmetic >::m_labels
private

labels for the bins

Definition at line 309 of file StaticHistogram.h.

◆ m_maxValue

template<typename Arithmetic >
Arithmetic Gaudi::Accumulators::Axis< Arithmetic >::m_maxValue
private

Definition at line 302 of file StaticHistogram.h.

◆ m_minValue

template<typename Arithmetic >
Arithmetic Gaudi::Accumulators::Axis< Arithmetic >::m_minValue
private

min and max values on this axis

Definition at line 302 of file StaticHistogram.h.

◆ m_ratio

template<typename Arithmetic >
Arithmetic Gaudi::Accumulators::Axis< Arithmetic >::m_ratio
private

precomputed ratio to convert a value into bin number equal to nBins/(maxValue-minValue).

Only used for floating Arithmetic

Definition at line 307 of file StaticHistogram.h.

◆ m_title

template<typename Arithmetic >
std::string Gaudi::Accumulators::Axis< Arithmetic >::m_title
private

title of this axis

Definition at line 293 of file StaticHistogram.h.

◆ nBins

template<typename Arithmetic >
unsigned int Gaudi::Accumulators::Axis< Arithmetic >::nBins

number of bins for this Axis FIXME : should be private and called m_nBins but will break backward compatibility with previous implementation.

Definition at line 298 of file StaticHistogram.h.


The documentation for this class was generated from the following file:
std::floor
T floor(T... args)
Gaudi::Accumulators::Axis::m_minValue
Arithmetic m_minValue
min and max values on this axis
Definition: StaticHistogram.h:302
std::string
STL class.
Gaudi::Accumulators::details::requireValidTitle
void requireValidTitle(std::string_view sv)
Definition: StaticHistogram.h:68
std::move
T move(T... args)
Gaudi::Accumulators::Axis::Axis
Axis(unsigned int nBins=0, Arithmetic minValue=Arithmetic{}, Arithmetic maxValue=Arithmetic{}, std::string title={}, std::vector< std::string > labels={})
Definition: StaticHistogram.h:232
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< std::string >
Gaudi::Accumulators::Axis::title
std::string const & title() const
Definition: StaticHistogram.h:287
Gaudi::Accumulators::Axis::numBins
unsigned int numBins() const
Definition: StaticHistogram.h:272
Gaudi::Accumulators::Axis::m_labels
std::vector< std::string > m_labels
labels for the bins
Definition: StaticHistogram.h:309
bug_34121.t
t
Definition: bug_34121.py:31
Gaudi::Accumulators::Axis::labels
std::vector< std::string > const labels() const
Definition: StaticHistogram.h:289
Gaudi::Accumulators::Axis::nBins
unsigned int nBins
number of bins for this Axis FIXME : should be private and called m_nBins but will break backward com...
Definition: StaticHistogram.h:298
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Gaudi::Accumulators::Axis::maxValue
Arithmetic maxValue() const
Definition: StaticHistogram.h:282
Gaudi::Accumulators::Axis::m_maxValue
Arithmetic m_maxValue
Definition: StaticHistogram.h:302
Gaudi::Accumulators::Axis::m_title
std::string m_title
title of this axis
Definition: StaticHistogram.h:293
Gaudi::Accumulators::Axis::recomputeRatio
void recomputeRatio()
Definition: StaticHistogram.h:311
Gaudi::Accumulators::Axis::minValue
Arithmetic minValue() const
Definition: StaticHistogram.h:277
Properties.v
v
Definition: Properties.py:122
Gaudi::Accumulators::Axis::m_ratio
Arithmetic m_ratio
precomputed ratio to convert a value into bin number equal to nBins/(maxValue-minValue).
Definition: StaticHistogram.h:307