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>
27 #include <type_traits>
32 template <std::
size_t,
typename T>
35 template <
typename Type,
unsigned int ND>
37 template <
typename Type,
unsigned int ND>
38 using GetTuple_t =
typename GetTuple<Type, ND>::type;
39 template <
typename Type,
unsigned int ND>
44 template <
typename Type>
45 struct GetTuple<
Type, 1> {
56 template <
typename Arithmetic>
66 template <
typename Arithmetic>
68 return v.first *
v.second;
76 template <
typename Arithmetic>
78 return v.first *
v.first *
v.second;
88 template <atomicity Atomicity,
typename Arithmetic>
90 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, ExtractWeight> {
93 using Base::operator+=;
96 *
this += { Arithmetic{}, weight };
108 template <atomicity Atomicity,
typename Arithmetic>
110 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedProduct> {
121 template <atomicity Atomicity,
typename Arithmetic =
double>
123 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedSquare> {
134 template <atomicity Atomicity,
typename Arithmetic>
143 template <atomicity Atomicity,
typename Arithmetic>
150 template <
typename Arithmetic>
152 Axis(
unsigned int _nBins, Arithmetic _minValue, Arithmetic _maxValue,
std::string _title = {},
159 ,
ratio( _nBins / ( _maxValue - _minValue ) ){};
175 unsigned int index( Arithmetic value )
const {
177 return idx < 0 ? 0 : ( (
unsigned int)idx >
nBins ?
nBins + 1 : (
unsigned int)idx );
182 template <
typename Arithmetic>
187 {
"title", axis.
title } };
192 template <
typename Arithmetic,
unsigned int ND,
unsigned int NIndex = ND>
195 template <
class... ARGS>
201 unsigned int index = 0;
202 for (
unsigned int dim = 0; dim < NIndex; dim++ ) {
204 int localIndex = axis[dim].index( ( *
this )[dim] );
206 index = ( dim > 0 ? ( axis[dim].nBins + 2 ) : 0 ) * index + localIndex;
215 template <
typename Arithmetic>
223 operator Arithmetic()
const {
return value; }
231 template <
typename Arithmetic,
unsigned int ND,
unsigned int NIndex = ND>
238 return this->first.computeIndex( axis );
257 template <
atomicity Atomicity,
typename InputType,
typename Arithmetic,
typename ND,
258 template <atomicity Ato,
typename Arith>
typename BaseAccumulatorT>
260 template <atomicity,
typename,
typename,
typename,
template <atomicity,
typename>
typename>
273 template <atomicity ato>
287 template <atomicity ato>
290 for (
unsigned int index = 0; index <
m_totNBins; index++ ) {
313 unsigned int nTotBins = 1;
314 for (
unsigned int i = 0; i < ND::value; i++ ) { nTotBins *= (
m_axis[i].nBins + 2 ); }
330 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
339 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
349 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
359 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
417 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
418 template <atomicity,
typename,
typename>
typename Accumulator,
typename Seq>
420 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
421 template <atomicity,
typename,
typename>
typename Accumulator,
std::size_t... NDs>
423 :
public BufferableCounter<Atomicity, Accumulator, Arithmetic, std::integral_constant<int, ND>> {
426 template <
typename OWNER>
430 std::make_index_sequence<ND>{} )
431 , m_title( title ) {}
432 template <
typename OWNER>
437 template <
typename stream>
439 o << ND <<
"D Histogram with config ";
440 for (
unsigned int i = 0; i < ND; i++ ) {
441 o << this->nBins( i ) <<
" " << this->minValue( i ) <<
" " << this->maxValue( i ) <<
" ";
446 return printImpl( o, tableFormat );
451 using Acc = Accumulator<Atomicity, Arithmetic, std::integral_constant<int, ND>>;
453 bins.
reserve( this->totNBins() );
454 unsigned long totNEntries{ 0 };
455 for (
unsigned int i = 0; i < this->totNBins(); i++ ) {
461 {
"title", m_title },
463 {
"empty", totNEntries == 0 },
464 {
"nEntries", totNEntries },
465 {
"axis", this->axis() },
472 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
473 template <atomicity,
typename,
typename>
typename Accumulator>
478 static const char histogramString[] =
"histogram:Histogram";
479 static const char weightedHistogramString[] =
"histogram:WeightedHistogram";
480 static const char profilehistogramString[] =
"histogram:ProfileHistogram";
481 static const char weightedProfilehistogramString[] =
"histogram:WeightedProfileHistogram";
484 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
488 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
493 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
498 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
Arithmetic minValue
min and max values on this axis
HistogramingAccumulatorInternal(GetTuple_t< Axis< AxisArithmeticType >, ND::value > axis, std::index_sequence< Is... >)
auto nBins(unsigned int i) const
WeightedSquareAccumulator.
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
nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
HistogramingAccumulatorInternal & operator+=(InputType v)
HistogramingCounterBaseInternal(OWNER *owner, std::string const &name, std::string const &title, alwaysT< NDs, Axis< Arithmetic >>... allAxis)
AveragingAccumulatorBase.
Definition of an Histogram Axis.
stream & printImpl(stream &o, bool) const
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
BaseAccumulatorT< Atomicity, Arithmetic > BaseAccumulator
auto operator[](typename InputType::ValueType v)
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
friend class GenericAccumulator
auto maxValue(unsigned int i) const
unsigned int index(Arithmetic value) const
returns the bin number for a given value, ranging from 0 (underflow) to nBins+1 (overflow)
std::string const m_title
auto nEntries(unsigned int i) const
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
Axis(unsigned int _nBins, Arithmetic _minValue, Arithmetic _maxValue, std::string _title={}, std::vector< std::string > _labels={})
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 ...
Internal Accumulator class dealing with Histograming.
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
HistogramingCounterBaseInternal(OWNER *owner, std::string const &name, std::string const &title, GetTuple_t< Axis< Arithmetic >, ND > axis)
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.
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.
std::array< Axis< AxisArithmeticType >, ND::value > m_axis
set of Axis of this Histogram
A base counter dealing with Histograms.
WeightedCountAccumulator operator+=(const Arithmetic weight)
std::string title
title of this axis
std::vector< std::string > labels
labels for the bins
Arithmetic operator[](Arithmetic ... args)
unsigned int computeTotNBins() const