Go to the documentation of this file.
17 #include <fmt/format.h>
18 #include <nlohmann/json.hpp>
20 #include <type_traits>
27 template <std::
size_t,
typename T>
30 template <
typename Type,
unsigned int ND>
32 template <
typename Type,
unsigned int ND>
34 template <
typename Type,
unsigned int ND>
39 template <
typename Type>
47 fmt::format(
"Histogram title \'{}\' has whitespace at front or back -- please remove", sv ),
57 template <
typename Arithmetic>
67 template <
typename Arithmetic>
69 return v.first *
v.second;
77 template <
typename Arithmetic>
79 return v.first *
v.first *
v.second;
89 template <atomicity Atomicity,
typename Arithmetic>
91 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, ExtractWeight> {
94 using Base::operator+=;
97 *
this += { Arithmetic{}, weight };
109 template <atomicity Atomicity,
typename Arithmetic>
111 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedProduct> {
122 template <atomicity Atomicity,
typename Arithmetic =
double>
124 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedSquare> {
135 template <atomicity Atomicity,
typename Arithmetic>
144 template <atomicity Atomicity,
typename Arithmetic>
151 template <
typename Arithmetic>
153 Axis(
unsigned int _nBins, Arithmetic _minValue, Arithmetic _maxValue,
std::string _title = {},
160 ,
ratio( _nBins / ( _maxValue - _minValue ) ) {
179 unsigned int index( Arithmetic value )
const {
181 return idx < 0 ? 0 : ( (
unsigned int)idx >
nBins ?
nBins + 1 : (
unsigned int)idx );
186 template <
typename Arithmetic>
191 {
"title", axis.
title } };
196 template <
typename Arithmetic,
unsigned int ND,
unsigned int NIndex = ND>
199 template <
class... ARGS,
typename =
typename std::enable_if_t<(
sizeof...( ARGS ) == NIndex )>>
205 unsigned int index = 0;
206 for (
unsigned int j = 0; j < NIndex; j++ ) {
207 unsigned int dim = NIndex - j - 1;
209 int localIndex = axis[dim].index( ( *
this )[dim] );
211 index *= ( axis[dim].nBins + 2 );
217 template <
typename AxisType,
long unsigned NAxis>
219 unsigned int nTotBins = 1;
220 for (
unsigned int i = 0; i < NAxis; i++ ) { nTotBins *= ( axis[i].nBins + 2 ); }
227 template <
typename Arithmetic>
235 operator Arithmetic()
const {
return value; }
237 template <
typename AxisType>
239 return axis[0].nBins + 2;
247 template <
typename Arithmetic,
unsigned int ND,
unsigned int NIndex = ND>
254 return this->first.computeIndex( axis );
257 template <
typename AxisType,
long unsigned NAxis>
277 template <
atomicity Atomicity,
typename InputType,
typename Arithmetic,
typename ND,
278 template <atomicity Ato,
typename Arith>
typename BaseAccumulatorT>
280 template <atomicity,
typename,
typename,
typename,
template <atomicity,
typename>
typename>
294 template <atomicity ato>
311 template <atomicity ato>
314 for (
unsigned int index = 0; index <
m_totNBins; index++ ) {
318 [[nodiscard]]
auto operator[](
typename InputType::ValueType
v ) {
349 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
358 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
368 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
378 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
436 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
437 template <atomicity,
typename,
typename>
typename Accumulator,
typename Seq>
439 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
440 template <atomicity,
typename,
typename>
typename Accumulator,
std::size_t... NDs>
442 :
public BufferableCounter<Atomicity, Accumulator, Arithmetic, std::integral_constant<int, ND>> {
445 using AccumulatorType = Accumulator<Atomicity, Arithmetic, std::integral_constant<int, ND>>;
448 template <
typename OWNER>
451 :
Parent( owner,
name, *this, axis,
std::make_index_sequence<ND>{} ), m_title( title ) {
454 template <
typename OWNER>
459 template <
typename stream>
461 o << ND <<
"D Histogram with config ";
462 for (
unsigned int i = 0; i < ND; i++ ) {
463 o << this->nBins( i ) <<
" " << this->minValue( i ) <<
" " << this->maxValue( i ) <<
" ";
468 return printImpl( o, tableFormat );
474 bins.
reserve( this->totNBins() );
475 unsigned long totNEntries{ 0 };
476 for (
unsigned int i = 0; i < this->totNBins(); i++ ) {
482 {
"title", m_title },
484 {
"empty", totNEntries == 0 },
485 {
"nEntries", totNEntries },
486 {
"axis", this->axis() },
493 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
494 template <atomicity,
typename,
typename>
typename Accumulator>
505 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
510 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
515 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
520 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.
void requireValidTitle(std::string_view sv)
HistogramingCounterBaseInternal(OWNER *owner, std::string const &name, std::string const &title, details::GetTuple_t< typename AccumulatorType::AxisType, ND > 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
constexpr char weightedHistogramString[]
nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
HistogramingCounterBaseInternal(OWNER *owner, std::string const &name, std::string const &title, details::alwaysT< NDs, typename AccumulatorType::AxisType >... allAxis)
HistogramingAccumulatorInternal & operator+=(InputType v)
constexpr char weightedProfilehistogramString[]
AveragingAccumulatorBase.
constexpr char profilehistogramString[]
HistogramingAccumulatorInternal(details::GetTuple_t< AxisType, ND::value > axis, std::index_sequence< Is... >)
Definition of an Histogram Axis.
Accumulator< Atomicity, Arithmetic, std::integral_constant< int, ND > > AccumulatorType
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
decltype(std::tuple_cat(std::declval< std::tuple< Type > >(), std::declval< GetTuple_t< Type, ND - 1 > >())) type
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
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
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.
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
friend class HistogramingAccumulatorInternal
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< AxisType, ND::value > m_axis
set of Axis of this Histogram
constexpr static const auto FAILURE
typename GetTuple< Type, ND >::type GetTuple_t
constexpr char histogramString[]
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