ROOT  6.06/09
Reference Guide
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
ROOT::THist< DIMENSIONS, PRECISION > Class Template Reference

template<int DIMENSIONS, class PRECISION>
class ROOT::THist< DIMENSIONS, PRECISION >

Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value of type PRECISION.

A histogram counts occurrences of values or n-dimensional combinations thereof. Contrary to for instance a TTree, a histogram combines adjacent values. The resolution of this combination is defined by the binning, see e.g. http://www.wikiwand.com/en/Histogram

Definition at line 31 of file THist.h.

Public Types

using ImplBase_t = Detail::THistImplBase< DIMENSIONS, PRECISION >
 The type of the Detail::THistImplBase of this histogram. More...
 
using Coord_t = typename ImplBase_t::Coord_t
 The coordinates type: a DIMENSIONS-dimensional std::array of double. More...
 
using Weight_t = typename ImplBase_t::Weight_t
 The type of weights (PRECISION) More...
 
using FillFunc_t = typename ImplBase_t::FillFunc_t
 Pointer type to HistImpl_t::Fill, for faster access. More...
 
using const_iterator = Internal::THistBinIter< Internal::HistIterFullRange_t >
 

Public Member Functions

 THist ()=default
 
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>>
 THist (std::array< TAxisConfig, DIMENSIONS > axes, STATISTICS statConfig=STATISTICS())
 Create a histogram from an array of axes (TAxisConfigs) and possibly an initial STATISTICS object. More...
 
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>>
 THist (std::array< TAxisConfig, DIMENSIONS > axes, std::string_view histTitle, std::array< std::string_view, DIMENSIONS > axisTitles, STATISTICS statConfig=STATISTICS())
 Constructor overload taking histogram and axis titles. More...
 
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 1>>
 THist (const TAxisConfig &xaxis, STATISTICS statConfig=STATISTICS())
 Constructor overload that's only available for DIMENSIONS == 1. More...
 
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 1>>
 THist (const TAxisConfig &xaxis, std::string_view histTitle, std::string_view xAxisTitle, STATISTICS statConfig=STATISTICS())
 Constructor overload that's only available for DIMENSIONS == 1, also passing histogram and axis title. More...
 
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 2>>
 THist (const TAxisConfig &xaxis, const TAxisConfig &yaxis, STATISTICS statConfig=STATISTICS())
 Constructor overload that's only available for DIMENSIONS == 2. More...
 
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 2>>
 THist (const TAxisConfig &xaxis, const TAxisConfig &yaxis, std::string_view histTitle, std::string_view xAxisTitle, std::string_view yAxisTitle, STATISTICS statConfig=STATISTICS())
 Constructor overload that's only available for DIMENSIONS == 2, also passing histogram and axis titles. More...
 
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 3>>
 THist (const TAxisConfig &xaxis, const TAxisConfig &yaxis, const TAxisConfig &zaxis, STATISTICS statConfig=STATISTICS())
 Constructor overload that's only available for DIMENSIONS == 3. More...
 
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 3>>
 THist (const TAxisConfig &xaxis, const TAxisConfig &yaxis, const TAxisConfig &zaxis, std::string_view histTitle, std::string_view xAxisTitle, std::string_view yAxisTitle, std::string_view zAxisTitle, STATISTICS statConfig=STATISTICS())
 
ImplBase_tGetImpl () const noexcept
 Access the ImplBase_t this THist points to. More...
 
void Fill (const Coord_t &x, Weight_t weight=1.) noexcept
 Add weight to the bin containing coordinate x. More...
 
void FillN (const std::array_view< Coord_t > xN, const std::array_view< Weight_t > weightN) noexcept
 For each coordinate in xN, add weightN[i] to the bin at coordinate xN[i]. More...
 
void FillN (const std::array_view< Coord_t > xN) noexcept
 Convenience overload: FillN() with weight 1. More...
 
int64_t GetEntries () const noexcept
 Get the number of entries this histogram was filled with. More...
 
const_iterator begin () const
 
const_iterator end () const
 

Static Public Member Functions

static constexpr int GetNDim () noexcept
 Number of dimensions of the coordinates. More...
 

Private Attributes

FillFunc_t fFillFunc = nullptr
 Pinter to THistImpl::Fill() member function. More...
 
std::unique_ptr< ImplBase_tfImpl
 The actual histogram implementation. More...
 
std::string fTitle
 Title of this histogram. More...
 
std::array< std::string, DIMENSIONS > fAxisTitles
 Title of each axis. More...
 

Friends

THist HistFromImpl (std::unique_ptr< ImplBase_t >)
 
void swap (THist< DIMENSIONS, PRECISION > &a, THist< DIMENSIONS, PRECISION > &b) noexcept
 Swap two histograms. More...
 

#include <ROOT/THist.h>

+ Collaboration diagram for ROOT::THist< DIMENSIONS, PRECISION >:

Member Typedef Documentation

template<int DIMENSIONS, class PRECISION>
using ROOT::THist< DIMENSIONS, PRECISION >::const_iterator = Internal::THistBinIter<Internal::HistIterFullRange_t>

Definition at line 66 of file THist.h.

template<int DIMENSIONS, class PRECISION>
using ROOT::THist< DIMENSIONS, PRECISION >::Coord_t = typename ImplBase_t::Coord_t

The coordinates type: a DIMENSIONS-dimensional std::array of double.

Definition at line 60 of file THist.h.

template<int DIMENSIONS, class PRECISION>
using ROOT::THist< DIMENSIONS, PRECISION >::FillFunc_t = typename ImplBase_t::FillFunc_t

Pointer type to HistImpl_t::Fill, for faster access.

Definition at line 64 of file THist.h.

template<int DIMENSIONS, class PRECISION>
using ROOT::THist< DIMENSIONS, PRECISION >::ImplBase_t = Detail::THistImplBase<DIMENSIONS, PRECISION>

The type of the Detail::THistImplBase of this histogram.

Definition at line 58 of file THist.h.

template<int DIMENSIONS, class PRECISION>
using ROOT::THist< DIMENSIONS, PRECISION >::Weight_t = typename ImplBase_t::Weight_t

The type of weights (PRECISION)

Definition at line 62 of file THist.h.

Constructor & Destructor Documentation

template<int DIMENSIONS, class PRECISION>
ROOT::THist< DIMENSIONS, PRECISION >::THist ( )
default
template<int DIMENSIONS, class PRECISION >
template<class STATISTICS >
ROOT::THist< DIMENSIONS, PRECISION >::THist ( std::array< TAxisConfig, DIMENSIONS >  axes,
STATISTICS  statConfig = STATISTICS() 
)

Create a histogram from an array of axes (TAxisConfigs) and possibly an initial STATISTICS object.

The latter is usually just fine when not passed (i.e. default-constructed). Example code:

Construct a 1-dimensional histogram that can be filled with floatss. The axis has 10 bins between 0. and 1. The two outermost sets of curly braces are to reach the initialization of the std::array elements; the inner one is for the initialization of a TAxisCoordinate.

THist<1,float> h1f({{ {10, 0., 1.} }});

Construct a 2-dimensional histogram, with the first axis as before, and the second axis having non-uniform ("irregular") binning, where all bin- edges are specified. As this is itself an array it must be enclosed by double curlies.

THist<2,int> h2i({{ {10, 0., 1.}, {{-1., 0., 1., 10., 100.}} }});  

Definition at line 300 of file THist.h.

template<int DIMENSIONS, class PRECISION>
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>>
ROOT::THist< DIMENSIONS, PRECISION >::THist ( std::array< TAxisConfig, DIMENSIONS >  axes,
std::string_view  histTitle,
std::array< std::string_view, DIMENSIONS >  axisTitles,
STATISTICS  statConfig = STATISTICS() 
)

Constructor overload taking histogram and axis titles.

template<int DIMENSIONS, class PRECISION>
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 1>>
ROOT::THist< DIMENSIONS, PRECISION >::THist ( const TAxisConfig xaxis,
STATISTICS  statConfig = STATISTICS() 
)
inline

Constructor overload that's only available for DIMENSIONS == 1.

Definition at line 101 of file THist.h.

template<int DIMENSIONS, class PRECISION>
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 1>>
ROOT::THist< DIMENSIONS, PRECISION >::THist ( const TAxisConfig xaxis,
std::string_view  histTitle,
std::string_view  xAxisTitle,
STATISTICS  statConfig = STATISTICS() 
)
inline

Constructor overload that's only available for DIMENSIONS == 1, also passing histogram and axis title.

Definition at line 108 of file THist.h.

template<int DIMENSIONS, class PRECISION>
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 2>>
ROOT::THist< DIMENSIONS, PRECISION >::THist ( const TAxisConfig xaxis,
const TAxisConfig yaxis,
STATISTICS  statConfig = STATISTICS() 
)
inline

Constructor overload that's only available for DIMENSIONS == 2.

Definition at line 116 of file THist.h.

template<int DIMENSIONS, class PRECISION>
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 2>>
ROOT::THist< DIMENSIONS, PRECISION >::THist ( const TAxisConfig xaxis,
const TAxisConfig yaxis,
std::string_view  histTitle,
std::string_view  xAxisTitle,
std::string_view  yAxisTitle,
STATISTICS  statConfig = STATISTICS() 
)
inline

Constructor overload that's only available for DIMENSIONS == 2, also passing histogram and axis titles.

Definition at line 124 of file THist.h.

template<int DIMENSIONS, class PRECISION>
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 3>>
ROOT::THist< DIMENSIONS, PRECISION >::THist ( const TAxisConfig xaxis,
const TAxisConfig yaxis,
const TAxisConfig zaxis,
STATISTICS  statConfig = STATISTICS() 
)
inline

Constructor overload that's only available for DIMENSIONS == 3.

Definition at line 133 of file THist.h.

template<int DIMENSIONS, class PRECISION>
template<class STATISTICS = THistStatUncertainty<DIMENSIONS, PRECISION>, class = typename std::enable_if<DIMENSIONS == 3>>
ROOT::THist< DIMENSIONS, PRECISION >::THist ( const TAxisConfig xaxis,
const TAxisConfig yaxis,
const TAxisConfig zaxis,
std::string_view  histTitle,
std::string_view  xAxisTitle,
std::string_view  yAxisTitle,
std::string_view  zAxisTitle,
STATISTICS  statConfig = STATISTICS() 
)
inline

Definition at line 140 of file THist.h.

Member Function Documentation

template<int DIMENSIONS, class PRECISION>
const_iterator ROOT::THist< DIMENSIONS, PRECISION >::begin ( ) const
inline

Definition at line 177 of file THist.h.

template<int DIMENSIONS, class PRECISION>
const_iterator ROOT::THist< DIMENSIONS, PRECISION >::end ( ) const
inline

Definition at line 178 of file THist.h.

template<int DIMENSIONS, class PRECISION>
void ROOT::THist< DIMENSIONS, PRECISION >::Fill ( const Coord_t x,
Weight_t  weight = 1. 
)
inlinenoexcept

Add weight to the bin containing coordinate x.

Definition at line 157 of file THist.h.

Referenced by ROOT::Add().

template<int DIMENSIONS, class PRECISION>
void ROOT::THist< DIMENSIONS, PRECISION >::FillN ( const std::array_view< Coord_t xN,
const std::array_view< Weight_t weightN 
)
inlinenoexcept

For each coordinate in xN, add weightN[i] to the bin at coordinate xN[i].

The sizes of xN and weightN must be the same. This is more efficient than many separate calls to Fill().

Definition at line 164 of file THist.h.

template<int DIMENSIONS, class PRECISION>
void ROOT::THist< DIMENSIONS, PRECISION >::FillN ( const std::array_view< Coord_t xN)
inlinenoexcept

Convenience overload: FillN() with weight 1.

Definition at line 170 of file THist.h.

template<int DIMENSIONS, class PRECISION>
int64_t ROOT::THist< DIMENSIONS, PRECISION >::GetEntries ( ) const
inlinenoexcept

Get the number of entries this histogram was filled with.

Definition at line 175 of file THist.h.

template<int DIMENSIONS, class PRECISION>
ImplBase_t* ROOT::THist< DIMENSIONS, PRECISION >::GetImpl ( ) const
inlinenoexcept

Access the ImplBase_t this THist points to.

Definition at line 154 of file THist.h.

Referenced by ROOT::Add(), ROOT::THistView< DIMENSIONS, PRECISION >::end(), and ROOT::THistView< DIMENSIONS, PRECISION >::SetRange().

template<int DIMENSIONS, class PRECISION>
static constexpr int ROOT::THist< DIMENSIONS, PRECISION >::GetNDim ( )
inlinestaticnoexcept

Number of dimensions of the coordinates.

Definition at line 151 of file THist.h.

Friends And Related Function Documentation

template<int DIMENSIONS, class PRECISION>
THist HistFromImpl ( std::unique_ptr< ImplBase_t )
friend
template<int DIMENSIONS, class PRECISION>
void swap ( THist< DIMENSIONS, PRECISION > &  a,
THist< DIMENSIONS, PRECISION > &  b 
)
friend

Swap two histograms.

Very efficient; swaps the fImpl pointers.

Definition at line 196 of file THist.h.

Member Data Documentation

template<int DIMENSIONS, class PRECISION>
std::array<std::string, DIMENSIONS> ROOT::THist< DIMENSIONS, PRECISION >::fAxisTitles
private

Title of each axis.

Definition at line 184 of file THist.h.

template<int DIMENSIONS, class PRECISION>
FillFunc_t ROOT::THist< DIMENSIONS, PRECISION >::fFillFunc = nullptr
private

Pinter to THistImpl::Fill() member function.

Definition at line 181 of file THist.h.

Referenced by ROOT::THist< DIMENSIONS, PRECISION >::Fill(), and ROOT::HistFromImpl().

template<int DIMENSIONS, class PRECISION>
std::unique_ptr<ImplBase_t> ROOT::THist< DIMENSIONS, PRECISION >::fImpl
private
template<int DIMENSIONS, class PRECISION>
std::string ROOT::THist< DIMENSIONS, PRECISION >::fTitle
private

Title of this histogram.

Definition at line 183 of file THist.h.


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