Go to the documentation of this file.
15 #include <ROOT/RHist.hxx>
17 #include <boost/format.hpp>
18 #include <boost/histogram/algorithm/sum.hpp>
19 #include <boost/histogram/fwd.hpp>
22 #include <nlohmann/json.hpp>
26 #include <type_traits>
35 template <
typename Arithmetic>
45 template <
typename Arithmetic>
47 return v.first *
v.second;
55 template <
typename Arithmetic>
57 return v.first *
v.first *
v.second;
67 template <atomicity Atomicity,
typename Arithmetic>
69 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, ExtractWeight> {
72 using Base::operator+=;
75 *
this += {Arithmetic{}, weight};
87 template <atomicity Atomicity,
typename Arithmetic>
89 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedProduct> {
92 Arithmetic
sum()
const {
return this->
value(); }
100 template <atomicity Atomicity,
typename Arithmetic =
double>
102 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedSquare> {
113 template <atomicity Atomicity,
typename Arithmetic>
122 template <atomicity Atomicity,
typename Arithmetic>
129 template <
typename Arithmetic>
131 Axis(
unsigned int _nBins, Arithmetic _minValue, Arithmetic _maxValue,
const std::string& _title =
"" )
136 ,
ratio( _nBins / ( _maxValue - _minValue ) ){};
151 template <
typename Arithmetic>
158 template <
typename Arithmetic,
unsigned int ND,
unsigned int NIndex = ND>
161 template <
class... ARGS>
167 unsigned int index = 0;
168 for (
unsigned int dim = 0; dim < NIndex; dim++ ) {
170 int localIndex =
std::floor( ( ( *
this )[dim] - axis[dim].minValue ) * axis[dim].ratio ) + 1;
171 localIndex = ( localIndex < 0 )
173 : ( ( (
unsigned int)localIndex > axis[dim].nBins ) ? axis[dim].nBins + 1
174 : (
unsigned int)( localIndex ) );
176 index = ( dim > 0 ? ( axis[dim - 1].nBins + 2 ) : 0 ) * index + localIndex;
185 template <
typename Arithmetic>
192 int index =
std::floor( ( value - axis[0].minValue ) * axis[0].ratio ) + 1;
193 return index < 0 ? 0 : ( (
unsigned int)index > axis[0].nBins ? axis[0].nBins + 1 : (
unsigned int)index );
196 operator Arithmetic()
const {
return value; }
204 template <
typename Arithmetic,
unsigned int ND,
unsigned int NIndex = ND>
211 return this->first.computeIndex( axis );
230 template <
atomicity Atomicity,
typename InputType,
typename Arithmetic,
typename ND,
231 template <atomicity Ato,
typename Arith>
typename BaseAccumulatorT>
233 template <atomicity,
typename,
typename,
typename,
template <atomicity,
typename>
typename>
246 template <atomicity ato>
260 template <atomicity ato>
263 for (
unsigned int index = 0; index <
m_totNBins; index++ ) {
287 unsigned int nTotBins = 1;
288 for (
unsigned int i = 0; i < ND::value; i++ ) { nTotBins *= (
m_axis[i].nBins + 2 ); }
304 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
313 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
323 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
333 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
391 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
392 template <atomicity,
typename,
typename>
typename Accumulator>
394 :
public BufferableCounter<Atomicity, Accumulator, Arithmetic, std::integral_constant<int, ND>> {
397 template <
typename OWNER>
401 std::make_index_sequence<ND>{} )
403 template <
typename OWNER>
407 template <
typename stream>
409 o << ND <<
"D Histogram with config ";
410 for (
unsigned int i = 0; i < ND; i++ ) {
411 o << this->nBins( i ) <<
" " << this->minValue( i ) <<
" " << this->maxValue( i ) <<
" ";
421 using Acc = Accumulator<Atomicity, Arithmetic, std::integral_constant<int, ND>>;
423 bins.
reserve( this->totNBins() );
424 unsigned int totNEntries{0};
425 for (
unsigned int i = 0; i < this->totNBins(); i++ ) {
433 {
"empty", totNEntries == Arithmetic{}},
434 {
"nEntries", totNEntries},
435 {
"axis", this->axis()},
444 static const char histogramString[] =
"histogram:Histogram";
445 static const char weightedHistogramString[] =
"histogram:WeightedHistogram";
446 static const char profilehistogramString[] =
"histogram:ProfileHistogram";
447 static const char weightedProfilehistogramString[] =
"histogram:WeightedProfileHistogram";
450 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
454 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
459 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
464 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
Arithmetic minValue
min and max values on this axis
auto nBins(unsigned int i) const
WeightedSquareAccumulator.
HistogramingCounterBase(OWNER *owner, std::string const &name, std::string const &title, std::initializer_list< Axis< Arithmetic >> axis)
BaseAccumulator & accumulator(unsigned int index) const
Arithmetic nEntries() const
void mergeAndReset(HistogramingAccumulatorInternal< ato, InputType, Arithmetic, ND, BaseAccumulatorT > &&other)
typename InputType::AxisArithmeticType AxisArithmeticType
unsigned int nBins
number of bins for this Axis
long
(c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # # This software i...
auto binValue(unsigned int i) const
A base counter dealing with Histograms.
auto ratio(unsigned int i) const
HistogramingAccumulatorInternal & operator+=(InputType v)
AveragingAccumulatorBase.
std::string const m_title
Definition of an Histogram Axis.
BaseAccumulatorT< Atomicity, Arithmetic > BaseAccumulator
nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
auto operator[](typename InputType::ValueType v)
stream & printImpl(stream &o, bool) const
friend class GenericAccumulator
auto maxValue(unsigned int i) const
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
auto nEntries(unsigned int i) const
HistogramingAccumulatorInternal(std::initializer_list< Axis< AxisArithmeticType >> axis, std::index_sequence< Is... >)
Generic Accumulator, templated by.
auto minValue(unsigned int i) const
HistogramingAccumulatorInternal(construct_empty_t, const HistogramingAccumulatorInternal< ato, InputType, Arithmetic, ND, BaseAccumulatorT > &other)
void to_json(nlohmann::json &j, const Axis< Arithmetic > &axis)
automatic conversion of the Axis type to json
A Product functor, take a pair (value, weight) as input.
An empty ancester of all counters that provides a buffer method that returns a buffer on itself Also ...
Axis(unsigned int _nBins, Arithmetic _minValue, Arithmetic _maxValue, const std::string &_title="")
Internal Accumulator class dealing with Histograming.
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
std::unique_ptr< BaseAccumulator[]> m_value
Histogram content.
A WeightedSquare functor, take a pair (value, weight) as input.
unsigned int m_totNBins
total number of bins in this histogram, under and overflow included
Buffer is a non atomic Accumulator which, when it goes out-of-scope, updates the underlying thread-sa...
atomicity
Defines atomicity of the accumulators.
HistogramingCounterBase(OWNER *owner, std::string const &name, std::string const &title, Axis< Arithmetic > axis)
Arithmetic ratio
precomputed ratio to convert a value into bin number equal to nBins/(maxValue-minValue)
constant used to disambiguate construction of an empty Accumulator versus the copy constructor.
WeightedCountAccumulator.
virtual std::ostream & print(std::ostream &, bool tableFormat=false) const =0
prints the counter to a stream
std::array< Axis< AxisArithmeticType >, ND::value > m_axis
set of Axis of this Histogram
WeightedCountAccumulator operator+=(const Arithmetic weight)
std::string title
title of this axis
Arithmetic operator[](Arithmetic ... args)
unsigned int computeTotNBins() const
MsgStream & print(MsgStream &o, bool tableFormat=false) const override