Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Hammer::Histogram Class Reference

Multidimensional histogram class with Tensor as cell bins. More...

#include <Histogram.hh>

+ Collaboration diagram for Hammer::Histogram:

Classes

class  Bin
 Bin class with Tensor contents. More...
 

Public Types

using DataType = std::vector< Bin >
 
using ElementType = Bin
 
using reference = ElementType &
 
using const_reference = const ElementType &
 
using iterator = DataType::iterator
 
using const_iterator = DataType::const_iterator
 

Public Member Functions

iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
reference operator[] (PositionType pos)
 
const_reference operator[] (PositionType pos) const
 
size_t rank () const
 dimensionality of the histograms More...
 
IndexType dim (IndexType index) const
 dimension of a specific coordinate More...
 
const IndexListdims () const
 get the dimensions of all the coordinates at once More...
 
const std::string & name () const
 get the histogram name More...
 
template<typename... Args>
void fillBin (const Tensor &value, Args...rest)
 set the value of a histogram bin based on the bin indices More...
 
void fillBin (const Tensor &value, const IndexList &position)
 set the value of a histogram bin based on the bin indices More...
 
void clear ()
 reset the histogram More...
 
void clearData ()
 reset the histogram contents but not the shape of the histogram More...
 
template<typename... Args>
const TensorgetWeight (Args...rest) const
 get the value of a histogram bin based on an index of the bin More...
 
template<typename... Args>
const TensorgetSquaredWeight (Args...rest) const
 get the value of a histogram bin based on an index of the bin More...
 
template<typename... Args>
size_t getNumEvents (Args...rest) const
 get the value of a histogram bin based on an index of the bin More...
 
Histogramoperator+= (const Histogram &other)
 
std::unique_ptr
< Serial::FBHistogramBuilder > 
write (flatbuffers::FlatBufferBuilder *msgwriter) const
 write the contents of the histogram for serialization More...
 
void read (const Serial::FBHistogram *msgreader, const HistogramDefinition &def)
 read the contents of the histogram for serialization More...
 
const LabelsListgetLabelVector () const
 
IOHistogram evalToList (const Tensor &externalData) const
 
std::unique_ptr< HistogramcollapseIntoNew (const std::string &newName, const HistogramDefinition &newDef, const std::set< uint16_t > &collapsedIndexPositions) const
 
Constructors
 Histogram ()
 constructor More...
 
 Histogram (const Histogram &other)=default
 
Histogramoperator= (const Histogram &other)=default
 
 Histogram (Histogram &&other)=default
 
Histogramoperator= (Histogram &&other)=default
 
virtual ~Histogram ()
 destructor More...
 

Protected Member Functions

Binelement (const IndexList &indices)
 convert the indices into the position in the flattened contents into vector organized as row-major More...
 
const Binelement (const IndexList &indices) const
 access an element given its coordinates (const version) More...
 
size_t numValues () const
 the number of elements (product of all the dimensions) More...
 
LoggetLog () const
 logging facility More...
 

Private Member Functions

void setDefinition (const HistogramDefinition &def)
 set the dimensions of the various coordinates More...
 
void setName (const std::string &name)
 give the histogram a name More...
 
void setDefaultValue (const Tensor &value)
 set the value to be used for out-of-bounds coordinates if extrapolation is off More...
 
void setDefaultValue (const IndexList &defaultDims, const LabelsList &defaultLabels)
 
void initHistogram ()
 allocate and initialize the histogram More...
 

Private Attributes

const HistogramDefinition_definition
 
DataType _data
 
std::string _name
 
MultiDimensional::LabeledIndexing
< MultiDimensional::AlignedIndexing
_defaultTensorIndexing
 
std::string _defaultTensorName
 
bool _initialized
 whether the grid is initialized More...
 

Friends

std::unique_ptr< HistogrammakeHistogram (const std::string &, const HistogramDefinition &, const Tensor &)
 
std::unique_ptr< HistogrammakeHistogram (const std::string &, const HistogramDefinition &, const IndexList &, const LabelsList &)
 

Related Functions

(Note that these are not member functions.)

 makeHistogram
 
 makeHistogram
 

Detailed Description

Multidimensional histogram class with Tensor as cell bins.

Contains the tensor version of an histogram defined by the user

Definition at line 39 of file Histogram.hh.

Member Typedef Documentation

using Hammer::Histogram::const_iterator = DataType::const_iterator

Definition at line 126 of file Histogram.hh.

Definition at line 123 of file Histogram.hh.

using Hammer::Histogram::DataType = std::vector<Bin>

Definition at line 120 of file Histogram.hh.

Definition at line 121 of file Histogram.hh.

using Hammer::Histogram::iterator = DataType::iterator

Definition at line 125 of file Histogram.hh.

Definition at line 122 of file Histogram.hh.

Constructor & Destructor Documentation

Hammer::Histogram::Histogram ( )

constructor

Parameters
[in]withErrorswhether to track squared weights

Definition at line 95 of file Histogram.cc.

Hammer::Histogram::Histogram ( const Histogram other)
default
Hammer::Histogram::Histogram ( Histogram &&  other)
default
Hammer::Histogram::~Histogram ( )
virtual

destructor

Definition at line 99 of file Histogram.cc.

Member Function Documentation

Histogram::iterator Hammer::Histogram::begin ( )

Definition at line 111 of file Histogram.cc.

Histogram::const_iterator Hammer::Histogram::begin ( ) const

Definition at line 115 of file Histogram.cc.

void Hammer::Histogram::clear ( )

reset the histogram

Definition at line 171 of file Histogram.cc.

void Hammer::Histogram::clearData ( )

reset the histogram contents but not the shape of the histogram

Definition at line 216 of file Histogram.cc.

unique_ptr< Histogram > Hammer::Histogram::collapseIntoNew ( const std::string &  newName,
const HistogramDefinition newDef,
const std::set< uint16_t > &  collapsedIndexPositions 
) const

Definition at line 375 of file Histogram.cc.

IndexType Hammer::Histogram::dim ( IndexType  index) const

dimension of a specific coordinate

Parameters
[in]indexthe coordinate index
Returns
the dimension

Definition at line 143 of file Histogram.cc.

const IndexList & Hammer::Histogram::dims ( ) const

get the dimensions of all the coordinates at once

Returns
the list of dimensions

Definition at line 147 of file Histogram.cc.

Histogram::Bin & Hammer::Histogram::element ( const IndexList indices)
protected

convert the indices into the position in the flattened contents into vector organized as row-major

Parameters
[in]indicesindex of coordinate in multidimensional histogram
Returns
the absolute bin position access an element given its coordinates
Parameters
[in]indicesthe list of coordinates, 0-based
Returns
a reference to the bin

Definition at line 189 of file Histogram.cc.

const Histogram::Bin & Hammer::Histogram::element ( const IndexList indices) const
protected

access an element given its coordinates (const version)

Parameters
[in]indicesthe list of coordinates, 0-based
Returns
a reference to the bin

Definition at line 199 of file Histogram.cc.

Histogram::iterator Hammer::Histogram::end ( )

Definition at line 119 of file Histogram.cc.

Histogram::const_iterator Hammer::Histogram::end ( ) const

Definition at line 123 of file Histogram.cc.

IOHistogram Hammer::Histogram::evalToList ( const Tensor externalData) const
Parameters
[in]externalData
Returns

Definition at line 333 of file Histogram.cc.

template<typename... Args>
void Hammer::Histogram::fillBin ( const Tensor value,
Args...  rest 
)

set the value of a histogram bin based on the bin indices

Parameters
[in]valuevalue of the bin
[in]restvariadic argument with remaining indices

Definition at line 22 of file HistogramDefs.hh.

void Hammer::Histogram::fillBin ( const Tensor value,
const IndexList position 
)

set the value of a histogram bin based on the bin indices

Parameters
[in]valuevalue of the bin
[in]positionlist of coordinates

Definition at line 181 of file Histogram.cc.

const LabelsList & Hammer::Histogram::getLabelVector ( ) const
Returns

Definition at line 329 of file Histogram.cc.

Log & Hammer::Histogram::getLog ( ) const
protected

logging facility

Returns
stream to be used for logging

Definition at line 177 of file Histogram.cc.

template<typename... Args>
size_t Hammer::Histogram::getNumEvents ( Args...  rest) const

get the value of a histogram bin based on an index of the bin

Parameters
[in]restvariadic argument with remaining indices
Returns
value of the bin

Definition at line 41 of file HistogramDefs.hh.

template<typename... Args>
const Tensor & Hammer::Histogram::getSquaredWeight ( Args...  rest) const

get the value of a histogram bin based on an index of the bin

Parameters
[in]restvariadic argument with remaining indices
Returns
value of the bin

Definition at line 36 of file HistogramDefs.hh.

template<typename... Args>
const Tensor & Hammer::Histogram::getWeight ( Args...  rest) const

get the value of a histogram bin based on an index of the bin

Parameters
[in]restvariadic argument with remaining indices
Returns
value of the bin

Definition at line 31 of file HistogramDefs.hh.

void Hammer::Histogram::initHistogram ( )
private

allocate and initialize the histogram

Definition at line 209 of file Histogram.cc.

const string & Hammer::Histogram::name ( ) const

get the histogram name

Returns
the name

Definition at line 151 of file Histogram.cc.

size_t Hammer::Histogram::numValues ( ) const
protected

the number of elements (product of all the dimensions)

Definition at line 135 of file Histogram.cc.

Histogram & Hammer::Histogram::operator+= ( const Histogram other)
Parameters
[in]other
Returns

Definition at line 319 of file Histogram.cc.

Histogram& Hammer::Histogram::operator= ( const Histogram other)
default
Histogram& Hammer::Histogram::operator= ( Histogram &&  other)
default
Histogram::reference Hammer::Histogram::operator[] ( PositionType  pos)

Definition at line 127 of file Histogram.cc.

Histogram::const_reference Hammer::Histogram::operator[] ( PositionType  pos) const

Definition at line 131 of file Histogram.cc.

size_t Hammer::Histogram::rank ( ) const

dimensionality of the histograms

Returns
the number of components

Definition at line 139 of file Histogram.cc.

void Hammer::Histogram::read ( const Serial::FBHistogram *  msgreader,
const HistogramDefinition def 
)

read the contents of the histogram for serialization

Parameters
[in]msgreaderthe reader object
[in]defthe location where to write

Definition at line 269 of file Histogram.cc.

void Hammer::Histogram::setDefaultValue ( const Tensor value)
private

set the value to be used for out-of-bounds coordinates if extrapolation is off

Parameters
[in]valuethe default value

Definition at line 155 of file Histogram.cc.

void Hammer::Histogram::setDefaultValue ( const IndexList defaultDims,
const LabelsList defaultLabels 
)
private

Definition at line 163 of file Histogram.cc.

void Hammer::Histogram::setDefinition ( const HistogramDefinition def)
private

set the dimensions of the various coordinates

Parameters
[in]defthe dimensions list (its size specifies the histogram dimensionality)

Definition at line 107 of file Histogram.cc.

void Hammer::Histogram::setName ( const std::string &  name)
private

give the histogram a name

Parameters
[in]namethe name

Definition at line 103 of file Histogram.cc.

unique_ptr< Serial::FBHistogramBuilder > Hammer::Histogram::write ( flatbuffers::FlatBufferBuilder *  msgwriter) const

write the contents of the histogram for serialization

Parameters
[in]msgwriterthe writer object

Definition at line 225 of file Histogram.cc.

Friends And Related Function Documentation

std::unique_ptr<Histogram> makeHistogram ( const std::string &  ,
const HistogramDefinition ,
const Tensor  
)
friend

Definition at line 393 of file Histogram.cc.

std::unique_ptr<Histogram> makeHistogram ( const std::string &  ,
const HistogramDefinition ,
const IndexList ,
const LabelsList  
)
friend

Definition at line 402 of file Histogram.cc.

Hammer::makeHistogram ( )
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]name
[in]def
[in]defaultValue
Returns
Hammer::makeHistogram ( )
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]name
[in]def
[in]defaultTensorDims
[in]defaultTensorLabels
Returns

Member Data Documentation

DataType Hammer::Histogram::_data
private

Definition at line 268 of file Histogram.hh.

MultiDimensional::LabeledIndexing<MultiDimensional::AlignedIndexing> Hammer::Histogram::_defaultTensorIndexing
private

Definition at line 272 of file Histogram.hh.

std::string Hammer::Histogram::_defaultTensorName
private

Definition at line 273 of file Histogram.hh.

const HistogramDefinition* Hammer::Histogram::_definition
private

Definition at line 267 of file Histogram.hh.

bool Hammer::Histogram::_initialized
private

whether the grid is initialized

Definition at line 276 of file Histogram.hh.

std::string Hammer::Histogram::_name
private

Definition at line 270 of file Histogram.hh.


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