Loading [MathJax]/extensions/tex2jax.js
Go to the documentation of this file.
19 #include <fmt/format.h>
20 #include <nlohmann/json.hpp>
22 #include <type_traits>
29 template <std::
size_t,
typename T>
32 template <
typename Type,
unsigned int ND>
34 template <
typename Type,
unsigned int ND>
36 template <
typename Type,
unsigned int ND>
41 template <
typename Type>
49 fmt::format(
"Histogram title \'{}\' has whitespace at front or back -- please remove", sv ),
59 template <
typename Arithmetic>
69 template <
typename Arithmetic>
71 return v.first *
v.second;
79 template <
typename Arithmetic>
81 return v.first *
v.first *
v.second;
91 template <atomicity Atomicity,
typename Arithmetic>
93 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, ExtractWeight> {
96 using Base::operator+=;
99 *
this += { Arithmetic{}, weight };
111 template <atomicity Atomicity,
typename Arithmetic>
113 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedProduct> {
124 template <atomicity Atomicity,
typename Arithmetic =
double>
126 :
GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedSquare> {
137 template <atomicity Atomicity,
typename Arithmetic>
146 template <atomicity Atomicity,
typename Arithmetic>
153 template <
typename Arithmetic>
155 Axis(
unsigned int _nBins, Arithmetic _minValue, Arithmetic _maxValue,
std::string _title = {},
162 ,
ratio( _nBins / ( _maxValue - _minValue ) ) {
167 :
Axis( (unsigned int)def.bins(), def.lowEdge(), def.highEdge(), def.
title() ){};
183 unsigned int index( Arithmetic value )
const {
187 if constexpr ( std::is_integral_v<Arithmetic> ) {
192 return idx < 0 ? 0 : ( (
unsigned int)idx >
nBins ?
nBins + 1 : (
unsigned int)idx );
199 template <
typename Arithmetic>
204 {
"title", axis.
title } };
209 template <
typename Arithmetic,
unsigned int ND,
unsigned int NIndex = ND>
212 template <
class... ARGS,
typename =
typename std::enable_if_t<(
sizeof...( ARGS ) == NIndex )>>
219 unsigned int index = 0;
220 for (
unsigned int j = 0;
j < NIndex;
j++ ) {
221 unsigned int dim = NIndex -
j - 1;
223 int localIndex = axis[dim].index( ( *
this )[dim] );
225 index *= ( axis[dim].nBins + 2 );
231 for (
unsigned int dim = 0; dim < NIndex; dim++ ) {
232 if ( !axis[dim].
inAcceptance( ( *
this )[dim] ) )
return false;
237 template <
typename AxisType,
long unsigned NAxis>
239 unsigned int nTotBins = 1;
240 for (
unsigned int i = 0; i < NAxis; i++ ) { nTotBins *= ( axis[i].nBins + 2 ); }
247 template <
typename Arithmetic>
257 operator Arithmetic()
const {
return value; }
259 template <
typename AxisType>
261 return axis[0].nBins + 2;
269 template <
typename Arithmetic,
unsigned int ND,
unsigned int NIndex = ND>
276 return this->first.computeIndex( axis );
279 return this->first.inAcceptance( axis );
282 template <
typename AxisType,
long unsigned NAxis>
302 template <
atomicity Atomicity,
typename InputType,
typename Arithmetic,
typename ND,
303 template <atomicity Ato,
typename Arith>
typename BaseAccumulatorT>
305 template <atomicity,
typename,
typename,
typename,
template <atomicity,
typename>
typename>
319 template <atomicity ato>
336 template <atomicity ato>
343 [[nodiscard]]
auto operator[](
typename InputType::ValueType
v ) {
373 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
382 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
392 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
402 template <atomicity Atomicity,
typename Arithmetic,
typename ND>
462 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
463 template <atomicity,
typename,
typename>
typename Accumulator,
typename Seq>
465 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
466 template <atomicity,
typename,
typename>
typename Accumulator,
std::size_t... NDs>
468 :
public BufferableCounter<Atomicity, Accumulator, Arithmetic, std::integral_constant<int, ND>> {
471 using AccumulatorType = Accumulator<Atomicity, Arithmetic, std::integral_constant<int, ND>>;
474 template <
typename OWNER>
477 :
Parent( owner,
name, *this, axis,
std::make_index_sequence<ND>{} ), m_title( title ) {
480 template <
typename OWNER>
485 template <
typename stream>
487 o << ND <<
"D Histogram with config ";
488 for (
unsigned int i = 0; i < ND; i++ ) {
489 o << this->nBins( i ) <<
" " << this->minValue( i ) <<
" " << this->maxValue( i ) <<
" ";
494 return printImpl( o, tableFormat );
499 h.mergeAndReset( o );
505 unsigned long totNEntries{ 0 };
506 for (
unsigned int i = 0; i <
h.totNBins(); i++ ) {
508 totNEntries +=
h.nEntries( i );
512 {
"title",
h.m_title },
514 {
"empty", totNEntries == 0 },
515 {
"nEntries", totNEntries },
516 {
"axis",
h.axis() },
523 template <
unsigned int ND,
atomicity Atomicity,
typename Arithmetic,
const char*
Type,
524 template <atomicity,
typename,
typename>
typename Accumulator>
535 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
540 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
545 template <
unsigned int ND, atomicity Atomicity = atomicity::full,
typename Arithmetic =
double>
550 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
friend void reset(HistogramingCounterBaseInternal &c)
Arithmetic nEntries() const
typename InputType::AxisArithmeticType AxisArithmeticType
unsigned int nBins
number of bins for this Axis
auto binValue(unsigned int i) const
constexpr char weightedHistogramString[]
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.
friend void to_json(nlohmann::json &j, HistogramingCounterBaseInternal const &h)
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)
void mergeAndReset(HistogramingAccumulatorInternal< ato, InputType, Arithmetic, ND, BaseAccumulatorT > &other)
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.
Axis(Gaudi::Histo1DDef const &def)
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.
friend void mergeAndReset(HistogramingCounterBaseInternal &h, HistogramingCounterBaseInternal &o)
std::array< AxisType, ND::value > m_axis
set of Axis of this Histogram
constexpr static const auto FAILURE
bool inAcceptance(Arithmetic value) const
says whether the given value is within the range of the axis
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
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...