18 template <
typename tuple_t>
19 constexpr auto get_array_from_tuple( tuple_t&& tuple ) {
20 constexpr auto get_array = [](
auto&&... x ) {
return std::array{ std::forward<decltype( x )>( x )... }; };
21 return std::apply( get_array, std::forward<tuple_t>( tuple ) );
29 constexpr unsigned int NSUMS(
unsigned int ND ) {
return 1 + ND + ND * ( ND + 1 ) / 2; }
31 template <
typename Arithmetic, atomicity Atomicity,
unsigned int ND>
33 using InputType = std::conditional_t<ND == 1, Arithmetic, std::array<Arithmetic, ND>>;
35 struct OutputTypeTS : std::array<std::atomic<Arithmetic>, NSUMS( ND )> {
37 using std::array<std::atomic<Arithmetic>,
NSUMS( ND )>::array;
39 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) { ( *this )[i] = other[i]; }
43 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) { ( *this )[i] = other[i]; }
49 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) { out[i] = ( *this )[i].load( std::memory_order_relaxed ); }
53 using InternalType = std::conditional_t<Atomicity == atomicity::full, OutputTypeTS, OutputType>;
61 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) { old[i] = v[i].exchange( newv[i] ); }
64 return std::exchange( v, newv );
70 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) {
fetch_add( a[i], b[i] ); }
72 for (
unsigned int i = 0; i < ND * ( ND + 3 ); i++ ) a[i] += b[i];
79 if constexpr ( ND == 1 ) {
84 for (
unsigned int i = 0; i < ND; i++ ) diff[i + 1] += b[i];
85 unsigned int n = 1 + ND;
86 for (
unsigned int i = 0; i < ND; i++ ) {
87 for (
unsigned int j = i; j < ND; j++ ) {
88 diff[n] = b[i] * b[j];
95 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) {
fetch_add( a[i], diff[i] ); }
97 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) a[i] += diff[i];
102 template <
typename Arithmetic, atomicity Atomicity,
unsigned int ND>
104 :
GenericAccumulator<std::array<Arithmetic, ND>, std::array<Arithmetic, NSUMS( ND )>, Atomicity, Identity,
105 Identity, SigmasValueHandler<Arithmetic, Atomicity, ND>> {
110 template <
typename Arithmetic, atomicity Atomicity>
112 :
GenericAccumulator<Arithmetic, std::array<Arithmetic, 3>, Atomicity, Identity, Identity,
113 SigmasValueHandler<Arithmetic, Atomicity, 1>> {
114 std::array<Arithmetic, 3>
const sums()
const {
return this->
value(); }
122 template <atomicity Atomicity,
typename Arithmetic,
unsigned int ND,
typename AxisTupleType>
125 unsigned long, IntegralAccumulator, AxisTupleType> {
131 template <atomicity,
typename,
unsigned int,
typename>
134 static_assert(
ND <= 3,
"Root on supports histogrmas with dimension <= 3" );
145 typename InputType::ValueType
m_v;
149 using Parent::Parent;
161 template <atomicity ato>
166 [[nodiscard]]
auto operator[](
typename InputType::ValueType v ) {
return Proxy( *
this, v ); }
175 void update(
typename InputType::ValueType v ) {
178 if ( v.inAcceptance( this->axis() ) ) {
179 if constexpr (
ND == 1 ) {
182 m_accumulator += get_array_from_tuple(
static_cast<typename InputType::InternalType
>( v ) );
194 template <
typename Arithmetic>
195 Arithmetic stddev( Arithmetic n, Arithmetic s, Arithmetic s2 ) {
198 auto v = ( n > 0 ) ? ( ( s2 - s * ( s / n ) ) / n ) : Arithmetic{};
199 return ( Arithmetic{ 0 } > v ) ? Arithmetic{} :
sqrt( v );
206 template <atomicity Atomicity,
typename Arithmetic,
typename ND,
typename AxisTupleType>
209 template <atomicity Atomicity,
typename Arithmetic,
typename AxisTupleType>
216 Arithmetic
sum()
const {
return this->
sums2()[1]; }
222 template <atomicity Atomicity,
typename Arithmetic,
typename AxisTupleType>
240 template <atomicity Atomicity,
typename Arithmetic,
typename AxisTupleType>
282 template <
unsigned int ND, atomicity Atomicity,
typename Arithmetic, const
char* Type,
typename AxisTupleType>
285 template <atomicity Atomicity,
typename Arithmetic, const
char* Type,
typename AxisTupleType>
290 using Parent::Parent;
295 j[
"nTotEntries"] = h.nEntries();
297 j[
"mean"] = h.mean();
298 j[
"sum2"] = h.sum2();
299 j[
"standard_deviation"] = h.standard_deviation();
303 template <atomicity Atomicity,
typename Arithmetic, const
char* Type,
typename AxisTupleType>
308 using Parent::Parent;
313 j[
"nTotEntries"] = h.nEntries();
314 j[
"sumx"] = h.sumx();
315 j[
"sumy"] = h.sumy();
316 j[
"meanx"] = h.meanx();
317 j[
"meany"] = h.meany();
318 j[
"sumx2"] = h.sumx2();
319 j[
"sumy2"] = h.sumy2();
320 j[
"sumxy"] = h.sumxy();
321 j[
"standard_deviationx"] = h.standard_deviationx();
322 j[
"standard_deviationy"] = h.standard_deviationy();
326 template <atomicity Atomicity,
typename Arithmetic, const
char* Type,
typename AxisTupleType>
331 using Parent::Parent;
336 j[
"nTotEntries"] = h.nEntries();
337 j[
"sumx"] = h.sumx();
338 j[
"sumy"] = h.sumy();
339 j[
"sumz"] = h.sumz();
340 j[
"meanx"] = h.meanx();
341 j[
"meany"] = h.meany();
342 j[
"meanz"] = h.meanz();
343 j[
"sumx2"] = h.sumx2();
344 j[
"sumy2"] = h.sumy2();
345 j[
"sumz2"] = h.sumz2();
346 j[
"sumxy"] = h.sumxy();
347 j[
"sumxz"] = h.sumxz();
348 j[
"sumyz"] = h.sumyz();
349 j[
"standard_deviationx"] = h.standard_deviationx();
350 j[
"standard_deviationy"] = h.standard_deviationy();
351 j[
"standard_deviationz"] = h.standard_deviationz();
357 typename AxisTupleType = make_tuple_t<Axis<Arithmetic>, ND>>
friend class GenericAccumulator
auto operator[](typename InputType::ValueType v)
std::integral_constant< unsigned int, std::tuple_size_v< AxisTupleType > > ND
friend class HistogramingAccumulatorInternal
void mergeAndReset(HistogramingAccumulatorInternal< ato, InputType, unsigned long, IntegralAccumulator, AxisTupleType > &other)
A base counter dealing with Histograms.
HistogramingAccumulatorInternal< Atomicity, InputType, unsigned long, IntegralAccumulator, AxisTupleType > Parent
auto operator[](typename InputType::ValueType v)
SigmaNAccumulator< Arithmetic, Atomicity, ND > m_accumulator
friend class RootHistogramingAccumulatorInternal
HistoInputType< AxisToArithmetic_t< AxisTupleType >, ND > InputType
void update(typename InputType::ValueType v)
auto sums2() const
returns the nbentries, sums and "squared sums" of the inputs Practically we have first the number of ...
void mergeAndReset(RootHistogramingAccumulatorInternal< ato, Arithmetic, ND, AxisTupleType > &other)
RootHistogramingAccumulatorInternal & operator+=(typename InputType::ValueType v)
Extension of the standard Gaudi histogram to provide similar functionnality as ROOT.
friend void to_json(nlohmann::json &j, RootHistogramingCounterBase< 3, Atomicity, Arithmetic, Type, AxisTupleType > const &h)
friend void to_json(nlohmann::json &j, RootHistogramingCounterBase< 1, Atomicity, Arithmetic, Type, AxisTupleType > const &h)
HistogramingCounterBase< 3, Atomicity, Arithmetic, Type, RootHistogramingAccumulator, AxisTupleType > Parent
HistogramingCounterBase< 1, Atomicity, Arithmetic, Type, RootHistogramingAccumulator, AxisTupleType > Parent
HistogramingCounterBase< 2, Atomicity, Arithmetic, Type, RootHistogramingAccumulator, AxisTupleType > Parent
friend void to_json(nlohmann::json &j, RootHistogramingCounterBase< 2, Atomicity, Arithmetic, Type, AxisTupleType > const &h)
Efficient counter implementations for Gaudi.
void to_json(nlohmann::json &j, const Axis< Arithmetic > &axis)
automatic conversion of the Axis type to json
constexpr unsigned int NSUMS(unsigned int ND)
number of items in sums for a given dimension = 1 (nb items) + ND (sums of each dimension) + ND*(ND+1...
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
atomicity
Defines atomicity of the accumulators.
RootHistogramingCounterBase< ND, Atomicity, Arithmetic, naming::histogramString, AxisTupleType > StaticRootHistogram
Root histograming counter. See RootHistogramingCounterBase for details.
void fetch_add(AtomicType &atVar, Arithmetic value)
generic fetch_add, also dealing with atomic types with no fetch_add member method
Class implementing a root histogram accumulator.
Arithmetic standard_deviationy() const
Arithmetic nEntries() const
Arithmetic standard_deviationx() const
Arithmetic standard_deviationx() const
Arithmetic nEntries() const
Arithmetic standard_deviation() const
Arithmetic nEntries() const
Arithmetic standard_deviationy() const
Arithmetic standard_deviationz() const
Small procyclass allowing operator[] to work as expected on the RootHistogram that is to return somet...
Proxy(RootHistogramingAccumulatorInternal &histo, typename InputType::ValueType &v)
RootHistogramingAccumulatorInternal & m_histo
std::array< Arithmetic, 3 > const sums() const
std::array< Arithmetic, NSUMS(ND)> const sums() const
OutputTypeTS(OutputType const &other)
OutputTypeTS & operator=(OutputType const &other)
std::conditional_t< Atomicity==atomicity::full, OutputTypeTS, OutputType > InternalType
static constexpr OutputType DefaultValue()
std::conditional_t< ND==1, Arithmetic, std::array< Arithmetic, ND > > InputType
static void merge(InternalType &a, const OutputType &b) noexcept
static constexpr OutputType getValue(const InternalType &v) noexcept
static void merge(InternalType &a, InputType b) noexcept
std::array< Arithmetic, NSUMS(ND)> OutputType
static OutputType exchange(InternalType &v, OutputType newv) noexcept