The Gaudi Framework  master (34daa81a)
Loading...
Searching...
No Matches
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)
 
bool inAcceptance (Arithmetic value) const
 says whether the given value is within the range of the axis
 
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.
 

Private Member Functions

void recomputeRatio ()
 

Private Attributes

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

Friends

std::ostream & operator<< (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.

234 : m_title( std::move( title ) )
235 , nBins( nBins )
238 , m_labels( std::move( labels ) ) {
241 for ( const auto& s : m_labels ) details::requireValidTitle( s );
242 }
Definition of a default type of Histogram Axis It contains number of bins, min and max value plus a t...
std::string const & title() const
Arithmetic minValue() const
Arithmetic m_minValue
min and max values on this axis
std::vector< std::string > m_labels
labels for the bins
std::vector< std::string > const & labels() const
Arithmetic maxValue() const
std::string m_title
title of this axis
unsigned int nBins
number of bins for this Axis FIXME : should be private and called m_nBins but will break backward com...
void requireValidTitle(std::string_view sv)

◆ 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() ) {}
Axis(unsigned int nBins=0, Arithmetic minValue=Arithmetic{}, Arithmetic maxValue=Arithmetic{}, std::string title={}, std::vector< std::string > labels={})

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 272 of file StaticHistogram.h.

272{ 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 auto floatIdx = std::floor( ( value - m_minValue ) * m_ratio ) + 1;
255 // Converting NaN or infinity to int is undefined behaviour
256 if ( !std::isfinite( floatIdx ) ) { return floatIdx > 0 ? numBins() + 1 : 0; }
257 idx = static_cast<int>( floatIdx );
258 }
259 return idx < 0 ? 0 : ( (unsigned int)idx > numBins() ? numBins() + 1 : (unsigned int)idx );
260 }
unsigned int numBins() const
Arithmetic m_ratio
precomputed ratio to convert a value into bin number equal to nBins/(maxValue-minValue).

◆ labels()

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

Definition at line 292 of file StaticHistogram.h.

292{ return m_labels; }

◆ maxValue()

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

Definition at line 285 of file StaticHistogram.h.

285{ return m_maxValue; }

◆ minValue()

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

Definition at line 280 of file StaticHistogram.h.

280{ return m_minValue; }

◆ numBins()

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

Definition at line 275 of file StaticHistogram.h.

275{ return nBins; }

◆ recomputeRatio()

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

Definition at line 314 of file StaticHistogram.h.

314 {
316 }

◆ setMaxValue()

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

Definition at line 286 of file StaticHistogram.h.

286 {
287 m_maxValue = v;
289 }

◆ setMinValue()

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

Definition at line 281 of file StaticHistogram.h.

281 {
282 m_minValue = v;
284 }

◆ setNumBins()

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

Definition at line 276 of file StaticHistogram.h.

276 {
277 nBins = n;
279 }

◆ setTitle()

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

Definition at line 291 of file StaticHistogram.h.

291{ m_title = t; }

◆ title()

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

Definition at line 290 of file StaticHistogram.h.

290{ return m_title; }

Friends And Related Symbol Documentation

◆ operator<<

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

Definition at line 262 of file StaticHistogram.h.

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

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 312 of file StaticHistogram.h.

◆ m_maxValue

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

Definition at line 305 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 305 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 310 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 296 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 301 of file StaticHistogram.h.


The documentation for this class was generated from the following file: