The Gaudi Framework  master (37c0b60a)
StaticHistogram.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <Gaudi/Accumulators.h>
14 #include <Gaudi/MonitoringHub.h>
15 #include <GaudiKernel/HistoDef.h>
16 
17 #include <array>
18 #include <cassert>
19 #include <cmath>
20 #include <fmt/format.h>
21 #include <nlohmann/json.hpp>
22 #include <string>
23 #include <type_traits>
24 #include <utility>
25 #include <vector>
26 
27 namespace {
28  // Helper class creating a "subtuple" type from a tuple type by keeping only
29  // the first N items.
30  template <typename Tuple, typename Seq>
31  struct SubTuple;
32  template <typename Tuple, size_t... I>
33  struct SubTuple<Tuple, std::index_sequence<I...>> {
34  using type = decltype( std::make_tuple( std::get<I>( std::declval<Tuple>() )... ) );
35  };
36  template <typename Tuple, unsigned int N>
37  using SubTuple_t = typename SubTuple<Tuple, std::make_index_sequence<N>>::type;
38 
40  template <typename T, unsigned int ND, typename = std::make_integer_sequence<unsigned int, ND>>
41  struct make_tuple;
42  template <typename T, unsigned int ND, unsigned int... S>
43  struct make_tuple<T, ND, std::integer_sequence<unsigned int, S...>> {
44  template <unsigned int>
45  using typeMap = T;
46  using type = std::tuple<typeMap<S>...>;
47  };
48  template <typename T, unsigned int ND>
49  using make_tuple_t = typename make_tuple<T, ND>::type;
50 
52  template <typename AxisTupleType>
53  struct AxisToArithmetic;
54  template <typename... Axis>
55  struct AxisToArithmetic<std::tuple<Axis...>> {
56  using type = std::tuple<typename Axis::ArithmeticType...>;
57  };
58  template <typename AxisTupleType>
59  using AxisToArithmetic_t = typename AxisToArithmetic<AxisTupleType>::type;
60  template <typename ProfArithmetic, typename AxisTupleType>
61  using ProfileAxisToArithmetic_t = decltype( std::tuple_cat( std::declval<AxisToArithmetic_t<AxisTupleType>>(),
63 } // namespace
64 
65 namespace Gaudi::Accumulators {
66 
67  namespace details {
68  inline void requireValidTitle( std::string_view sv ) {
69  if ( !sv.empty() && ( std::isspace( sv.back() ) || std::isspace( sv.front() ) ) ) {
70  throw GaudiException(
71  fmt::format( "Histogram title \'{}\' has whitespace at front or back -- please remove", sv ),
72  "Gaudi::Accumulators", StatusCode::FAILURE );
73  }
74  }
75  } // namespace details
76 
80  struct ExtractWeight {
81  template <typename Arithmetic>
82  constexpr decltype( auto ) operator()( const std::pair<unsigned long, Arithmetic>& v ) const noexcept {
83  return v.second;
84  }
85  };
86 
90  struct WeightedProduct {
91  template <typename Arithmetic>
92  constexpr decltype( auto ) operator()( const std::pair<Arithmetic, Arithmetic>& v ) const noexcept {
93  return v.first * v.second;
94  }
95  };
96 
100  struct WeightedSquare {
101  template <typename Arithmetic>
102  constexpr decltype( auto ) operator()( const std::pair<Arithmetic, Arithmetic>& v ) const noexcept {
103  return v.first * v.first * v.second;
104  }
105  };
106 
111  template <typename Arithmetic>
112  constexpr decltype( auto ) operator()( const std::pair<Arithmetic, Arithmetic>& v ) const noexcept {
113  return std::pair<unsigned int, Arithmetic>{ 1ul, v.second };
114  }
115  };
116 
122  template <typename Arithmetic, atomicity Atomicity>
123  struct WeightedAdder {
127  static constexpr bool isAtomic = Atomicity == atomicity::full;
128  using InternalType = std::conditional_t<isAtomic, AtomicType, OutputType>;
129  static constexpr OutputType getValue( const InternalType& v ) noexcept {
130  if constexpr ( isAtomic ) {
131  return { v.first.load( std::memory_order_relaxed ), v.second.load( std::memory_order_relaxed ) };
132  } else {
133  return v;
134  }
135  }
136  static RegularType exchange( InternalType& v, RegularType newv ) noexcept {
137  if constexpr ( isAtomic ) {
138  return { v.first.exchange( newv.first ), v.second.exchange( newv.second ) };
139  } else {
140  return { std::exchange( v.first, newv.first ), std::exchange( v.second, newv.second ) };
141  }
142  }
143  static constexpr OutputType DefaultValue() { return { 0, Arithmetic{} }; }
144  static void merge( InternalType& a, RegularType b ) noexcept {
145  if constexpr ( isAtomic ) {
146  fetch_add( a.first, b.first );
147  fetch_add( a.second, b.second );
148  } else {
149  a.first += b.first;
150  a.second += b.second;
151  }
152  }
153  };
154 
160  template <atomicity Atomicity, typename Arithmetic>
162  : GenericAccumulator<std::pair<Arithmetic, Arithmetic>, std::pair<unsigned long, Arithmetic>, Atomicity,
163  WeightedProfileTransform, ExtractWeight, WeightedAdder<Arithmetic, Atomicity>> {
166  using Base::Base;
167  using Base::operator+=;
169  WeightedCountAccumulator operator+=( const Arithmetic weight ) {
170  *this += { 1ul, weight };
171  return *this;
172  }
173  unsigned long nEntries() const { return this->rawValue().first; }
174  Arithmetic sumOfWeights() const { return this->rawValue().second; }
175  };
176 
183  template <atomicity Atomicity, typename Arithmetic>
185  : GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedProduct> {
186  using GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity,
188  Arithmetic sum() const { return this->value(); }
189  };
190 
196  template <atomicity Atomicity, typename Arithmetic = double>
198  : GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity, WeightedSquare> {
199  using GenericAccumulator<std::pair<Arithmetic, Arithmetic>, Arithmetic, Atomicity,
201  Arithmetic sum2() const { return this->value(); }
202  };
203 
209  template <atomicity Atomicity, typename Arithmetic>
212 
218  template <atomicity Atomicity, typename Arithmetic>
221 
228  template <typename Arithmetic>
229  class Axis {
230  public:
231  using ArithmeticType = Arithmetic;
232  Axis( unsigned int nBins = 0, Arithmetic minValue = Arithmetic{}, Arithmetic maxValue = Arithmetic{},
234  : m_title( std::move( title ) )
235  , nBins( nBins )
236  , m_minValue( minValue )
237  , m_maxValue( maxValue )
238  , m_labels( std::move( labels ) ) {
240  recomputeRatio();
241  for ( const auto& s : m_labels ) details::requireValidTitle( s );
242  }
243  explicit Axis( Gaudi::Histo1DDef const& def )
244  : Axis( (unsigned int)def.bins(), def.lowEdge(), def.highEdge(), def.title() ) {}
245 
247  unsigned int index( Arithmetic value ) const {
248  // In case we use integer as Arithmetic type, we cannot use ratio for computing indices,
249  // as ratios < 1.0 will simply be 0, so we have to pay the division in such a case
250  int idx;
251  if constexpr ( std::is_integral_v<Arithmetic> ) {
252  idx = ( ( value - m_minValue ) * nBins / ( m_maxValue - m_minValue ) ) + 1;
253  } else {
254  idx = std::floor( ( value - m_minValue ) * m_ratio ) + 1;
255  }
256  return idx < 0 ? 0 : ( (unsigned int)idx > numBins() ? numBins() + 1 : (unsigned int)idx );
257  }
258 
259  friend std::ostream& operator<<( std::ostream& o, Axis const& axis ) {
260  // Note that we print python code here, as the generic toStream implementation uses this
261  // operator to generate python code.
262  o << "(" << axis.numBins() << ", " << axis.minValue() << ", " << axis.maxValue() << ", "
263  << "\"" << axis.m_title << "\", (";
264  for ( auto const& label : axis.m_labels ) { o << "\"" << label << "\", "; }
265  return o << "))";
266  }
267 
269  bool inAcceptance( Arithmetic value ) const { return value >= m_minValue && value <= m_maxValue; }
270 
271  // accessors
272  unsigned int numBins() const { return nBins; }
273  void setNumBins( unsigned int n ) {
274  nBins = n;
275  recomputeRatio();
276  }
277  Arithmetic minValue() const { return m_minValue; }
278  void setMinValue( Arithmetic v ) {
279  m_minValue = v;
280  recomputeRatio();
281  }
282  Arithmetic maxValue() const { return m_maxValue; }
283  void setMaxValue( Arithmetic v ) {
284  m_maxValue = v;
285  recomputeRatio();
286  }
287  std::string const& title() const { return m_title; }
288  void setTitle( std::string const& t ) { m_title = t; }
289  std::vector<std::string> const labels() const { return m_labels; }
290 
291  private:
294 
295  public:
298  unsigned int nBins;
299 
300  private:
302  Arithmetic m_minValue, m_maxValue;
307  Arithmetic m_ratio;
310 
311  void recomputeRatio() {
312  m_ratio = ( m_maxValue == m_minValue ) ? Arithmetic{} : nBins / ( m_maxValue - m_minValue );
313  }
314  };
315 
317  template <typename Arithmetic>
318  void to_json( nlohmann::json& j, const Axis<Arithmetic>& axis ) {
319  j = nlohmann::json{ { "nBins", axis.numBins() },
320  { "minValue", axis.minValue() },
321  { "maxValue", axis.maxValue() },
322  { "title", axis.title() } };
323  if ( !axis.labels().empty() ) { j["labels"] = axis.labels(); }
324  }
325 
341  template <typename Arithmetic, unsigned int NIndex>
342  struct HistoInputType : HistoInputType<make_tuple_t<Arithmetic, NIndex>, NIndex> {
344  };
345  template <unsigned int NIndex, typename... Elements>
346  struct HistoInputType<std::tuple<Elements...>, NIndex> : std::tuple<Elements...> {
347  using InternalType = std::tuple<Elements...>;
349  using std::tuple<Elements...>::tuple;
350  template <class... AxisType, typename = typename std::enable_if_t<( sizeof...( AxisType ) == NIndex )>>
351  unsigned int computeIndex( std::tuple<AxisType...> const& axis ) const {
352  return computeIndexInternal<0, std::tuple<AxisType...>>( axis );
353  }
354  template <class... AxisType, typename = typename std::enable_if_t<( sizeof...( AxisType ) == NIndex )>>
355  static unsigned int computeTotNBins( std::tuple<AxisType...> const& axis ) {
356  return computeTotNBinsInternal<0, std::tuple<AxisType...>>( axis );
357  }
358  auto forInternalCounter() const { return 1ul; }
359  template <class... AxisType, typename = typename std::enable_if_t<( sizeof...( AxisType ) == NIndex )>>
360  bool inAcceptance( std::tuple<AxisType...> const& axis ) const {
361  return inAcceptanceInternal<0, std::tuple<AxisType...>>( axis );
362  }
363 
364  private:
365  template <int N, class Tuple>
366  unsigned int computeIndexInternal( Tuple const& allAxis ) const {
367  // compute global index. Bins are stored in a column first manner
368  auto const& axis = std::get<N>( allAxis );
369  unsigned int localIndex = axis.index( std::get<N>( *this ) );
370  if constexpr ( N + 1 == NIndex )
371  return localIndex;
372  else
373  return localIndex + ( axis.numBins() + 2 ) * computeIndexInternal<N + 1, Tuple>( allAxis );
374  }
375  template <int N, class Tuple>
376  static unsigned int computeTotNBinsInternal( Tuple const& allAxis ) {
377  auto const& axis = std::get<N>( allAxis );
378  unsigned int localNBins = axis.numBins() + 2;
379  if constexpr ( N + 1 == NIndex )
380  return localNBins;
381  else
382  return localNBins * computeTotNBinsInternal<N + 1, Tuple>( allAxis );
383  }
384  template <int N, class Tuple>
385  bool inAcceptanceInternal( Tuple const& allAxis ) const {
386  auto const& axis = std::get<N>( allAxis );
387  bool localAnswer = axis.inAcceptance( std::get<N>( *this ) );
388  if constexpr ( N + 1 == NIndex )
389  return localAnswer;
390  else
391  return localAnswer || inAcceptanceInternal<N + 1, Tuple>( allAxis );
392  }
393  };
394 
400  template <typename ArithmeticTuple, unsigned int NIndex, typename WArithmetic>
401  struct WeightedHistoInputType : std::pair<HistoInputType<ArithmeticTuple, NIndex>, WArithmetic> {
404  template <class... AxisType, typename = typename std::enable_if_t<( sizeof...( AxisType ) == NIndex )>>
405  unsigned int computeIndex( std::tuple<AxisType...> const& axis ) const {
406  return this->first.computeIndex( axis );
407  }
408  template <class... AxisType, typename = typename std::enable_if_t<( sizeof...( AxisType ) == NIndex )>>
409  static unsigned int computeTotNBins( std::tuple<AxisType...> const& axis ) {
411  }
412  auto forInternalCounter() const { return std::pair( this->first.forInternalCounter(), this->second ); }
413  template <class... AxisType, typename = typename std::enable_if_t<( sizeof...( AxisType ) == NIndex )>>
414  bool inAcceptance( std::tuple<AxisType...> const& axis ) const {
415  return this->first.inAcceptance( axis );
416  }
417  };
418 
464  template <atomicity Atomicity, typename InputType, typename Arithmetic,
465  template <atomicity Ato, typename Arith> typename BaseAccumulatorT, typename AxisTupleType>
467  template <atomicity, typename, typename, template <atomicity, typename> typename, typename>
469 
470  public:
472  using BaseAccumulator = BaseAccumulatorT<Atomicity, Arithmetic>;
473  using AxisTupleArithmeticType = typename InputType::ValueType;
475  : m_axis{ axis }
476  , m_totNBins{ InputType::computeTotNBins( m_axis ) }
478  reset();
479  }
480  template <atomicity ato>
484  : m_axis( other.m_axis ), m_totNBins{ other.m_totNBins }, m_value( new BaseAccumulator[m_totNBins] ) {
485  reset();
486  }
487  [[deprecated( "Use `++h1[x]`, `++h2[{x,y}]`, etc. instead." )]] HistogramingAccumulatorInternal&
488  operator+=( InputType v ) {
489  accumulator( v.computeIndex( m_axis ) ) += v.forInternalCounter();
490  return *this;
491  }
492  void reset() {
493  for ( unsigned int index = 0; index < m_totNBins; index++ ) { accumulator( index ).reset(); }
494  }
495  template <atomicity ato>
498  assert( m_totNBins == other.m_totNBins );
499  for ( unsigned int index = 0; index < m_totNBins; index++ ) {
500  accumulator( index ).mergeAndReset( other.accumulator( index ) );
501  }
502  }
503  [[nodiscard]] auto operator[]( typename InputType::ValueType v ) {
505  }
506 
507  template <unsigned int N>
508  auto& axis() const {
509  return std::get<N>( m_axis );
510  }
511  auto& axis() const { return m_axis; }
512  auto binValue( unsigned int i ) const { return accumulator( i ).value(); }
513  auto nEntries( unsigned int i ) const { return accumulator( i ).nEntries(); }
514  auto totNBins() const { return m_totNBins; }
515 
516  // FIXME These methods are there for backwrad compatibility with previous implementation
517  // where all Axis had to be of type Axis<...> and were stored in an array
518  // Newer code should call axis<N>().foo for whatever foo is defined in that axis type
519  auto nBins( unsigned int i ) const { return _getAxis( i, std::integral_constant<size_t, 0>() ).numBins(); }
520  auto minValue( unsigned int i ) const { return _getAxis( i, std::integral_constant<size_t, 0>() ).minValue(); }
521  auto maxValue( unsigned int i ) const { return _getAxis( i, std::integral_constant<size_t, 0>() ).maxValue(); }
522 
523  private:
524  BaseAccumulator& accumulator( unsigned int index ) const {
525  assert( index < m_totNBins );
526  assert( m_value.get() );
527  return m_value[index];
528  }
529 
530  // FIXME Only used for backward compatibility. should be dropped at some stage
531  // Can only work if all axis have same type, which is no more the case
532  std::tuple_element_t<0, AxisTupleType> const& _getAxis( size_t i,
533  typename std::tuple_size<AxisTupleType>::type ) const {
534  throw std::logic_error(
535  fmt::format( "Retrieving axis {} in Histogram of dimension {}", i, std::tuple_size_v<AxisTupleType> ) );
536  }
537  template <size_t N, typename = std::enable_if_t<std::tuple_size_v<AxisTupleType> != N>>
538  auto& _getAxis( size_t i, std::integral_constant<size_t, N> ) const {
539  if ( i == N ) return std::get<N>( m_axis );
541  }
542 
544  AxisTupleType m_axis;
546  unsigned int m_totNBins{};
549  };
550 
556  template <atomicity Atomicity, typename Arithmetic, typename ND, typename AxisTupleType>
559  unsigned long, IntegralAccumulator, AxisTupleType>;
560 
566  template <atomicity Atomicity, typename Arithmetic, typename ND, typename AxisTupleType>
570  Arithmetic, WeightedCountAccumulator, AxisTupleType>;
571 
577  template <atomicity Atomicity, typename Arithmetic, typename ND, typename AxisTupleType>
581  Arithmetic, SigmaAccumulator, AxisTupleType>;
582 
588  template <atomicity Atomicity, typename Arithmetic, typename ND, typename AxisTupleType>
591  Arithmetic, WeightedSigmaAccumulator, AxisTupleType>;
592 
651  template <unsigned int ND, atomicity Atomicity, typename Arithmetic, const char* Type,
652  template <atomicity, typename, typename, typename> typename Accumulator, typename AxisTupleType>
654  template <unsigned int ND, atomicity Atomicity, typename Arithmetic, const char* Type,
655  template <atomicity, typename, typename, typename> typename Accumulator, typename... AxisTypes>
656  class HistogramingCounterBase<ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple<AxisTypes...>>
657  : public BufferableCounter<Atomicity, Accumulator, Arithmetic, std::integral_constant<unsigned int, ND>,
658  std::tuple<AxisTypes...>> {
659  public:
660  using AxisTupleType = std::tuple<AxisTypes...>;
663  using AccumulatorType = Accumulator<Atomicity, Arithmetic, NumberDimensions, AxisTupleType>;
664  using AxisTupleArithmeticType = typename AccumulatorType::AxisTupleArithmeticType;
666  using AxisArithmeticType = typename std::tuple_element<0, AxisTupleType>::type::ArithmeticType;
667  inline static const std::string typeString{ std::string{ Type } + ':' + typeid( Arithmetic ).name() };
669  template <typename OWNER>
670  HistogramingCounterBase( OWNER* owner, std::string const& name, std::string const& title, AxisTupleType axis )
671  : Parent( owner, name, *this, axis ), m_title( title ) {
672  details::requireValidTitle( m_title );
673  }
675  template <typename OWNER>
676  HistogramingCounterBase( OWNER* owner, std::string const& name, std::string const& title, AxisTypes... allAxis )
677  : HistogramingCounterBase( owner, name, title, std::make_tuple( allAxis... ) ) {}
678  using Parent::print;
679  template <typename stream>
680  stream& printImpl( stream& o, bool /*tableFormat*/ ) const {
681  o << ND << "D Histogram with config ";
682  std::apply( [&o]( auto&&... args ) { ( ( o << args << "\n" ), ... ); }, this->axis() );
683  return o;
684  }
685  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
686  return printImpl( o, tableFormat );
687  }
688  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
689  friend void reset( HistogramingCounterBase& c ) { c.reset(); }
690  friend void mergeAndReset( HistogramingCounterBase& h, HistogramingCounterBase& o ) { h.mergeAndReset( o ); }
691  friend void to_json( nlohmann::json& j, HistogramingCounterBase const& h ) { h.to_json( j ); }
692  virtual void to_json( nlohmann::json& j ) const {
693  // get all bin values and compute total nbEntries
695  bins.reserve( this->totNBins() );
696  unsigned long totNEntries{ 0 };
697  for ( unsigned int i = 0; i < this->totNBins(); i++ ) {
698  bins.push_back( this->binValue( i ) );
699  totNEntries += this->nEntries( i );
700  }
701  // build json
702  j = { { "type", std::string( Type ) + ":" + typeid( Arithmetic ).name() },
703  { "title", m_title },
704  { "dimension", ND },
705  { "empty", totNEntries == 0 },
706  { "nEntries", totNEntries },
707  { "axis", this->axis() },
708  { "bins", bins } };
709  }
710  std::string const& title() const { return m_title; }
711 
712  protected:
714  };
715 
716  namespace naming {
717  inline constexpr char histogramString[] = "histogram:Histogram";
718  inline constexpr char weightedHistogramString[] = "histogram:WeightedHistogram";
719  inline constexpr char profilehistogramString[] = "histogram:ProfileHistogram";
720  inline constexpr char weightedProfilehistogramString[] = "histogram:WeightedProfileHistogram";
721  } // namespace naming
722 
724  template <unsigned int ND, atomicity Atomicity = atomicity::full, typename Arithmetic = double,
725  typename AxisTupleType = make_tuple_t<Axis<Arithmetic>, ND>>
727  HistogramingAccumulator, AxisTupleType>;
728 
730  template <unsigned int ND, atomicity Atomicity = atomicity::full, typename Arithmetic = double,
731  typename AxisTupleType = make_tuple_t<Axis<Arithmetic>, ND>>
733  WeightedHistogramingAccumulator, AxisTupleType>;
734 
736  template <unsigned int ND, atomicity Atomicity = atomicity::full, typename Arithmetic = double,
737  typename AxisTupleType = make_tuple_t<Axis<Arithmetic>, ND>>
739  ProfileHistogramingAccumulator, AxisTupleType>;
740 
742  template <unsigned int ND, atomicity Atomicity = atomicity::full, typename Arithmetic = double,
743  typename AxisTupleType = make_tuple_t<Axis<Arithmetic>, ND>>
747 
748 } // namespace Gaudi::Accumulators
Gaudi::Accumulators::HistogramingAccumulatorInternal::operator[]
auto operator[](typename InputType::ValueType v)
Definition: StaticHistogram.h:503
Gaudi::Accumulators::ExtractWeight
A functor to extract weight, take a pair (valueTuple, weight) as input.
Definition: StaticHistogram.h:80
Gaudi::Accumulators::Axis::operator<<
friend std::ostream & operator<<(std::ostream &o, Axis const &axis)
Definition: StaticHistogram.h:259
std::floor
T floor(T... args)
std::make_tuple
T make_tuple(T... args)
std::integral_constant
Gaudi::Accumulators::WeightedSquareAccumulator
WeightedSquareAccumulator.
Definition: StaticHistogram.h:198
Write.stream
stream
Definition: Write.py:32
Gaudi::Accumulators::Axis::m_minValue
Arithmetic m_minValue
min and max values on this axis
Definition: StaticHistogram.h:302
std::string
STL class.
Gaudi::Accumulators::Axis::index
unsigned int index(Arithmetic value) const
returns the bin number for a given value, ranging from 0 (underflow) to nBins+1 (overflow)
Definition: StaticHistogram.h:247
IOTest.N
N
Definition: IOTest.py:112
Gaudi::Accumulators::details::requireValidTitle
void requireValidTitle(std::string_view sv)
Definition: StaticHistogram.h:68
std::move
T move(T... args)
Gaudi::Accumulators::WeightedProfileHistogramingAccumulator
HistogramingAccumulatorInternal< Atomicity, WeightedHistoInputType< ProfileAxisToArithmetic_t< Arithmetic, AxisTupleType >, ND::value, Arithmetic >, Arithmetic, WeightedSigmaAccumulator, AxisTupleType > WeightedProfileHistogramingAccumulator
Class implementing a weighted profile histogram accumulator.
Definition: StaticHistogram.h:591
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::printImpl
stream & printImpl(stream &o, bool) const
Definition: StaticHistogram.h:680
MonitoringHub.h
Gaudi::Accumulators::GenericAccumulator< std::pair< Arithmetic, Arithmetic >, std::pair< unsigned long, Arithmetic >, Atomicity, WeightedProfileTransform, ExtractWeight, WeightedAdder< Arithmetic, Atomicity > >::rawValue
auto rawValue() const
Definition: Accumulators.h:514
Gaudi::Accumulators::HistogramingAccumulatorInternal::maxValue
auto maxValue(unsigned int i) const
Definition: StaticHistogram.h:521
std::pair
Gaudi::Accumulators::HistogramingAccumulatorInternal::minValue
auto minValue(unsigned int i) const
Definition: StaticHistogram.h:520
std::vector::reserve
T reserve(T... args)
Gaudi::Accumulators::atomicity::full
@ full
Gaudi::Accumulators::Axis::Axis
Axis(unsigned int nBins=0, Arithmetic minValue=Arithmetic{}, Arithmetic maxValue=Arithmetic{}, std::string title={}, std::vector< std::string > labels={})
Definition: StaticHistogram.h:232
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< std::string >
Gaudi::Accumulators::HistogramingCounterBase
A base counter dealing with Histograms.
Definition: StaticHistogram.h:653
Gaudi::Accumulators::Axis::ArithmeticType
Arithmetic ArithmeticType
Definition: StaticHistogram.h:231
Gaudi::Accumulators::Axis::title
std::string const & title() const
Definition: StaticHistogram.h:287
Gaudi::Accumulators::IntegralAccumulator
IntegralAccumulator.
Definition: Accumulators.h:640
jsonFromLHCbLog.json
json
Definition: jsonFromLHCbLog.py:86
Gaudi::Accumulators::WeightedAdder::InternalType
std::conditional_t< isAtomic, AtomicType, OutputType > InternalType
Definition: StaticHistogram.h:128
GaudiException
Definition: GaudiException.h:31
Gaudi::Accumulators::naming::weightedHistogramString
constexpr char weightedHistogramString[]
Definition: StaticHistogram.h:718
Gaudi::Accumulators::HistogramingAccumulatorInternal::m_totNBins
unsigned int m_totNBins
total number of bins in this histogram, under and overflow included
Definition: StaticHistogram.h:546
Gaudi::Accumulators::WeightedCountAccumulator::sumOfWeights
Arithmetic sumOfWeights() const
Definition: StaticHistogram.h:174
std::unique_ptr::get
T get(T... args)
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::HistogramingCounterBase
HistogramingCounterBase(OWNER *owner, std::string const &name, std::string const &title, AxisTupleType axis)
This constructor takes the axis as a tuple.
Definition: StaticHistogram.h:670
Gaudi::Accumulators::WeightedSumAccumulator::sum
Arithmetic sum() const
Definition: StaticHistogram.h:188
Gaudi::Accumulators::HistogramingAccumulatorInternal::HistogramingAccumulatorInternal
HistogramingAccumulatorInternal(AxisTupleType axis)
Definition: StaticHistogram.h:474
std::tuple
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::to_json
virtual void to_json(nlohmann::json &j) const
Definition: StaticHistogram.h:692
gaudirun.c
c
Definition: gaudirun.py:525
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::AccumulatorType
Accumulator< Atomicity, Arithmetic, NumberDimensions, AxisTupleType > AccumulatorType
Definition: StaticHistogram.h:663
Gaudi::Accumulators::Axis::setMaxValue
void setMaxValue(Arithmetic v)
Definition: StaticHistogram.h:283
Gaudi::Accumulators::HistogramingAccumulatorInternal::m_axis
AxisTupleType m_axis
set of Axis of this Histogram
Definition: StaticHistogram.h:544
Gaudi::Accumulators::WeightedSigmaAccumulator
SigmaAccumulatorBase< Atomicity, Arithmetic, WeightedAveragingAccumulator, WeightedSquareAccumulator > WeightedSigmaAccumulator
WeightedSigmaAccumulator.
Definition: StaticHistogram.h:220
Gaudi::Accumulators::naming::weightedProfilehistogramString
constexpr char weightedProfilehistogramString[]
Definition: StaticHistogram.h:720
Gaudi::Accumulators::WeightedHistoInputType::inAcceptance
bool inAcceptance(std::tuple< AxisType... > const &axis) const
Definition: StaticHistogram.h:414
Gaudi::Accumulators::Axis::Axis
Axis(Gaudi::Histo1DDef const &def)
Definition: StaticHistogram.h:243
Gaudi::Accumulators::HistogramingAccumulatorInternal::axis
auto & axis() const
Definition: StaticHistogram.h:508
Gaudi::Accumulators::WeightedCountAccumulator::nEntries
unsigned long nEntries() const
Definition: StaticHistogram.h:173
Gaudi::Accumulators::AveragingAccumulatorBase
AveragingAccumulatorBase.
Definition: Accumulators.h:752
Gaudi::Accumulators::HistoInputType< std::tuple< Elements... >, NIndex >::computeTotNBins
static unsigned int computeTotNBins(std::tuple< AxisType... > const &axis)
Definition: StaticHistogram.h:355
Gaudi::Accumulators::Axis::numBins
unsigned int numBins() const
Definition: StaticHistogram.h:272
Gaudi::Accumulators::WeightedSumAccumulator
WeightedSumAccumulator.
Definition: StaticHistogram.h:185
Gaudi::Accumulators::ProfileHistogramingAccumulator
HistogramingAccumulatorInternal< Atomicity, HistoInputType< ProfileAxisToArithmetic_t< Arithmetic, AxisTupleType >, ND::value >, Arithmetic, SigmaAccumulator, AxisTupleType > ProfileHistogramingAccumulator
Class implementing a profile histogram accumulator.
Definition: StaticHistogram.h:581
Gaudi::Accumulators::naming::profilehistogramString
constexpr char profilehistogramString[]
Definition: StaticHistogram.h:719
Gaudi::Accumulators::WeightedAdder::DefaultValue
static constexpr OutputType DefaultValue()
Definition: StaticHistogram.h:143
Gaudi::Accumulators::WeightedHistoInputType::computeTotNBins
static unsigned int computeTotNBins(std::tuple< AxisType... > const &axis)
Definition: StaticHistogram.h:409
HistoDef.h
Gaudi::Accumulators::Axis::m_labels
std::vector< std::string > m_labels
labels for the bins
Definition: StaticHistogram.h:309
Gaudi::Accumulators::SigmaAccumulator
SigmaAccumulatorBase< Atomicity, Arithmetic, AveragingAccumulator, SquareAccumulator > SigmaAccumulator
SigmaAccumulator.
Definition: Accumulators.h:832
Gaudi::Accumulators::WeightedProfileTransform
An inputTransform for WeightedProfile histograms, keeping weight and replacing value by 1.
Definition: StaticHistogram.h:110
std::vector::push_back
T push_back(T... args)
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::m_title
std::string const m_title
Definition: StaticHistogram.h:713
Gaudi::Accumulators::WeightedAdder::getValue
static constexpr OutputType getValue(const InternalType &v) noexcept
Definition: StaticHistogram.h:129
Gaudi::Accumulators::HistoInputType< std::tuple< Elements... >, NIndex >::computeIndex
unsigned int computeIndex(std::tuple< AxisType... > const &axis) const
Definition: StaticHistogram.h:351
Gaudi::Accumulators::Axis::setNumBins
void setNumBins(unsigned int n)
Definition: StaticHistogram.h:273
bug_34121.t
t
Definition: bug_34121.py:31
Gaudi::Histo1DDef
Definition: HistoDef.h:41
Gaudi::Accumulators::HistoInputType
small class used as InputType for regular Histograms basically a tuple of the given values,...
Definition: StaticHistogram.h:342
Gaudi::Accumulators::HistoInputType< std::tuple< Elements... >, NIndex >::computeTotNBinsInternal
static unsigned int computeTotNBinsInternal(Tuple const &allAxis)
Definition: StaticHistogram.h:376
details
Definition: AnyDataWrapper.h:19
Gaudi::Accumulators::Axis::labels
std::vector< std::string > const labels() const
Definition: StaticHistogram.h:289
Gaudi::Accumulators::Axis::nBins
unsigned int nBins
number of bins for this Axis FIXME : should be private and called m_nBins but will break backward com...
Definition: StaticHistogram.h:298
Gaudi::Accumulators::HistogramingAccumulatorInternal::totNBins
auto totNBins() const
Definition: StaticHistogram.h:514
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::title
std::string const & title() const
Definition: StaticHistogram.h:710
ProduceConsume.j
j
Definition: ProduceConsume.py:104
std::ostream
STL class.
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::AxisArithmeticType
typename std::tuple_element< 0, AxisTupleType >::type::ArithmeticType AxisArithmeticType
for backward compatibility with previous implementation, should not be used FIXME
Definition: StaticHistogram.h:666
Gaudi::Accumulators::HistogramingAccumulatorInternal::binValue
auto binValue(unsigned int i) const
Definition: StaticHistogram.h:512
AlgSequencer.h
h
Definition: AlgSequencer.py:31
Gaudi::Accumulators::WeightedHistoInputType
small class used as InputType for weighted Histograms only a pair of the InnerType and the weight.
Definition: StaticHistogram.h:401
Gaudi::Accumulators::HistoInputType< std::tuple< Elements... >, NIndex >::forInternalCounter
auto forInternalCounter() const
Definition: StaticHistogram.h:358
Gaudi::Accumulators::GenericAccumulator< std::pair< Arithmetic, Arithmetic >, Arithmetic, Atomicity, WeightedProduct >::GenericAccumulator
friend class GenericAccumulator
Definition: Accumulators.h:473
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::mergeAndReset
friend void mergeAndReset(HistogramingCounterBase &h, HistogramingCounterBase &o)
Definition: StaticHistogram.h:690
Gaudi::Accumulators::HistogramingAccumulatorInternal::m_value
std::unique_ptr< BaseAccumulator[]> m_value
Histogram content.
Definition: StaticHistogram.h:548
Gaudi::Accumulators::WeightedAdder::exchange
static RegularType exchange(InternalType &v, RegularType newv) noexcept
Definition: StaticHistogram.h:136
Gaudi::Accumulators::WeightedHistoInputType::ValueType
typename HistoInputType< ArithmeticTuple, NIndex >::ValueType ValueType
Definition: StaticHistogram.h:402
Gaudi::Accumulators::WeightedAdder
An Adder ValueHandler, taking weight into account and computing a count plus the sum of the weights I...
Definition: StaticHistogram.h:123
std::logic_error
STL class.
Gaudi::Accumulators::Axis::inAcceptance
bool inAcceptance(Arithmetic value) const
says whether the given value is within the range of the axis
Definition: StaticHistogram.h:269
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
std::atomic< Arithmetic >
Gaudi::Accumulators::Axis::setTitle
void setTitle(std::string const &t)
Definition: StaticHistogram.h:288
Gaudi::Accumulators::GenericAccumulator
Generic Accumulator, templated by.
Definition: Accumulators.h:471
MsgStream
Definition: MsgStream.h:33
Gaudi::Accumulators::HistogramingAccumulatorInternal::_getAxis
std::tuple_element_t< 0, AxisTupleType > const & _getAxis(size_t i, typename std::tuple_size< AxisTupleType >::type) const
Definition: StaticHistogram.h:532
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: StaticHistogram.h:688
Gaudi::Accumulators::to_json
void to_json(nlohmann::json &j, const Axis< Arithmetic > &axis)
automatic conversion of the Axis type to json
Definition: StaticHistogram.h:318
Gaudi::Accumulators::HistogramingAccumulatorInternal::BaseAccumulator
BaseAccumulatorT< Atomicity, Arithmetic > BaseAccumulator
Definition: StaticHistogram.h:472
Gaudi::Accumulators::GenericAccumulator< std::pair< Arithmetic, Arithmetic >, Arithmetic, Atomicity, WeightedProduct >::value
OutputType value() const
Definition: Accumulators.h:501
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Gaudi::Accumulators::WeightedProduct
A Product functor, take a pair (value, weight) as input.
Definition: StaticHistogram.h:90
Gaudi::Accumulators::BufferableCounter
An empty ancester of all counters that provides a buffer method that returns a buffer on itself Also ...
Definition: Accumulators.h:911
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: StaticHistogram.h:685
Gaudi::Accumulators::HistogramingAccumulatorInternal
Internal Accumulator class dealing with Histograming.
Definition: StaticHistogram.h:466
Gaudi::Accumulators::WeightedAdder::isAtomic
static constexpr bool isAtomic
Definition: StaticHistogram.h:127
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::reset
friend void reset(HistogramingCounterBase &c)
Definition: StaticHistogram.h:689
Accumulators.h
Gaudi::Accumulators
Definition: CounterArray.h:18
gaudirun.type
type
Definition: gaudirun.py:160
Gaudi::Accumulators::HistoInputType< std::tuple< Elements... >, NIndex >::computeIndexInternal
unsigned int computeIndexInternal(Tuple const &allAxis) const
Definition: StaticHistogram.h:366
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi::Accumulators::HistogramingAccumulatorInternal::nEntries
auto nEntries(unsigned int i) const
Definition: StaticHistogram.h:513
Gaudi::Accumulators::Axis::maxValue
Arithmetic maxValue() const
Definition: StaticHistogram.h:282
Gaudi::Accumulators::WeightedAdder::RegularType
std::pair< unsigned long, Arithmetic > RegularType
Definition: StaticHistogram.h:124
gaudirun.args
args
Definition: gaudirun.py:336
std
STL namespace.
Gaudi::Accumulators::WeightedSquare
A WeightedSquare functor, take a pair (value, weight) as input.
Definition: StaticHistogram.h:100
Gaudi::Accumulators::HistogramingAccumulatorInternal::HistogramingAccumulatorInternal
HistogramingAccumulatorInternal(construct_empty_t, const HistogramingAccumulatorInternal< ato, InputType, Arithmetic, BaseAccumulatorT, AxisTupleType > &other)
Definition: StaticHistogram.h:481
Gaudi::Accumulators::Axis::m_maxValue
Arithmetic m_maxValue
Definition: StaticHistogram.h:302
Gaudi::Accumulators::WeightedHistoInputType::forInternalCounter
auto forInternalCounter() const
Definition: StaticHistogram.h:412
Gaudi::Accumulators::HistogramingAccumulatorInternal::axis
auto & axis() const
Definition: StaticHistogram.h:511
Gaudi::Accumulators::Axis::m_title
std::string m_title
title of this axis
Definition: StaticHistogram.h:293
Gaudi::Accumulators::HistogramingAccumulatorInternal::HistogramingAccumulatorInternal
friend class HistogramingAccumulatorInternal
Definition: StaticHistogram.h:468
Gaudi::Accumulators::WeightedHistoInputType::computeIndex
unsigned int computeIndex(std::tuple< AxisType... > const &axis) const
Definition: StaticHistogram.h:405
Gaudi::Accumulators::SigmaAccumulatorBase
SigmaAccumulatorBase.
Definition: Accumulators.h:781
Gaudi::Accumulators::Buffer
Buffer is a non atomic Accumulator which, when it goes out-of-scope, updates the underlying thread-sa...
Definition: Accumulators.h:849
Gaudi::Accumulators::WeightedHistogramingAccumulator
HistogramingAccumulatorInternal< Atomicity, WeightedHistoInputType< AxisToArithmetic_t< AxisTupleType >, ND::value, Arithmetic >, Arithmetic, WeightedCountAccumulator, AxisTupleType > WeightedHistogramingAccumulator
Class implementing a weighted histogram accumulator.
Definition: StaticHistogram.h:570
std::isspace
T isspace(T... args)
Gaudi::Accumulators::Axis::recomputeRatio
void recomputeRatio()
Definition: StaticHistogram.h:311
Gaudi::Accumulators::atomicity
atomicity
Defines atomicity of the accumulators.
Definition: Accumulators.h:263
std::vector::empty
T empty(T... args)
Gaudi::Accumulators::fetch_add
void fetch_add(AtomicType &atVar, Arithmetic value)
generic fetch_add, also dealing with atomic types with no fetch_add member method
Definition: Accumulators.h:366
Gaudi::Accumulators::Axis::minValue
Arithmetic minValue() const
Definition: StaticHistogram.h:277
Properties.v
v
Definition: Properties.py:122
Gaudi::Accumulators::construct_empty_t
constant used to disambiguate construction of an empty Accumulator versus the copy constructor.
Definition: Accumulators.h:446
std::tuple_cat
T tuple_cat(T... args)
Gaudi::Accumulators::WeightedCountAccumulator
WeightedCountAccumulator.
Definition: StaticHistogram.h:163
Gaudi::Accumulators::Axis::setMinValue
void setMinValue(Arithmetic v)
Definition: StaticHistogram.h:278
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::to_json
friend void to_json(nlohmann::json &j, HistogramingCounterBase const &h)
Definition: StaticHistogram.h:691
Gaudi::Accumulators::HistogramingAccumulatorInternal::reset
void reset()
Definition: StaticHistogram.h:492
Gaudi::Accumulators::HistogramingAccumulator
HistogramingAccumulatorInternal< Atomicity, HistoInputType< AxisToArithmetic_t< AxisTupleType >, ND::value >, unsigned long, IntegralAccumulator, AxisTupleType > HistogramingAccumulator
Class implementing a regular histogram accumulator.
Definition: StaticHistogram.h:559
Gaudi::Accumulators::HistogramingAccumulatorInternal::accumulator
BaseAccumulator & accumulator(unsigned int index) const
Definition: StaticHistogram.h:524
Gaudi::Accumulators::HistogramingAccumulatorInternal::operator+=
HistogramingAccumulatorInternal & operator+=(InputType v)
Definition: StaticHistogram.h:488
Gaudi::Accumulators::naming::histogramString
constexpr char histogramString[]
Definition: StaticHistogram.h:717
Gaudi::Accumulators::HistoInputType< std::tuple< Elements... >, NIndex >::inAcceptanceInternal
bool inAcceptanceInternal(Tuple const &allAxis) const
Definition: StaticHistogram.h:385
Gaudi::Accumulators::Axis::m_ratio
Arithmetic m_ratio
precomputed ratio to convert a value into bin number equal to nBins/(maxValue-minValue).
Definition: StaticHistogram.h:307
std::unique_ptr< BaseAccumulator[]>
Gaudi::Accumulators::WeightedSquareAccumulator::sum2
Arithmetic sum2() const
Definition: StaticHistogram.h:201
Gaudi::Accumulators::WeightedCountAccumulator::operator+=
WeightedCountAccumulator operator+=(const Arithmetic weight)
overload of operator+= to be able to only give weight and no value
Definition: StaticHistogram.h:169
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::AxisTupleArithmeticType
typename AccumulatorType::AxisTupleArithmeticType AxisTupleArithmeticType
Definition: StaticHistogram.h:664
Gaudi::Accumulators::Axis
Definition of a default type of Histogram Axis It contains number of bins, min and max value plus a t...
Definition: StaticHistogram.h:229
Gaudi::Accumulators::HistogramingAccumulatorInternal::mergeAndReset
void mergeAndReset(HistogramingAccumulatorInternal< ato, InputType, Arithmetic, BaseAccumulatorT, AxisTupleType > &other)
Definition: StaticHistogram.h:496
Gaudi::Accumulators::HistogramingAccumulatorInternal::_getAxis
auto & _getAxis(size_t i, std::integral_constant< size_t, N >) const
Definition: StaticHistogram.h:538
Gaudi::Accumulators::HistogramingCounterBase< ND, Atomicity, Arithmetic, Type, Accumulator, std::tuple< AxisTypes... > >::HistogramingCounterBase
HistogramingCounterBase(OWNER *owner, std::string const &name, std::string const &title, AxisTypes... allAxis)
This constructor takes the axis one by one, when ND >= 2. If ND = 1, the other one can be used.
Definition: StaticHistogram.h:676
std::declval
T declval(T... args)
Gaudi::Accumulators::HistogramingAccumulatorInternal< Atomicity, HistoInputType< AxisToArithmetic_t< AxisTupleType >, ND >, unsigned long, IntegralAccumulator, AxisTupleType >::AxisTupleArithmeticType
typename InputType::ValueType AxisTupleArithmeticType
Definition: StaticHistogram.h:473
Gaudi::ParticleProperties::index
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...
Definition: IParticlePropertySvc.cpp:39
Gaudi::Accumulators::HistoInputType< std::tuple< Elements... >, NIndex >::inAcceptance
bool inAcceptance(std::tuple< AxisType... > const &axis) const
Definition: StaticHistogram.h:360
Gaudi::Accumulators::WeightedAdder::merge
static void merge(InternalType &a, RegularType b) noexcept
Definition: StaticHistogram.h:144
Gaudi::Accumulators::HistogramingAccumulatorInternal::nBins
auto nBins(unsigned int i) const
Definition: StaticHistogram.h:519