yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
YODA::DbnStorage< DbnN, AxisT > Class Template Reference

All histograms can be instantiated through this alias. More...

#include <BinnedDbn.h>

Inheritance diagram for YODA::DbnStorage< DbnN, AxisT >:
YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... > YODA::AnalysisObject YODA::Fillable YODA::BinnedStorage< BinContentT, AxisT >

Public Types

using BaseT = FillableStorage< DbnN, Dbn< DbnN >, AxisT... >
 
using BinningT = typename BaseT::BinningT
 
using BinT = typename BaseT::BinT
 
using BinType = typename BaseT::BinT
 
using FillType = typename BaseT::FillType
 
- Public Types inherited from YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >
using FillType = FillCoordsT
 Type of the fill coordinates.
 
using FillDimension = std::integral_constant< size_t, FillDim >
 Fill dimension.
 
using FillAdapterT = std::function< void(BinT &, FillCoordsT &&, double, double)>
 Adapter type (type of lambda used to access stored object).
 
- Public Types inherited from YODA::BinnedStorage< BinContentT, AxisT >
using BinningType = BinningT
 
using BinType = BinT
 
using BinDimension = std::integral_constant< size_t, sizeof...(AxisT)>
 
- Public Types inherited from YODA::AnalysisObject
typedef std::map< std::string, std::string > Annotations
 Collection type for annotations, as a string-string map.
 

Public Member Functions

Constructors
 DbnStorage ()
 Nullary constructor for unique pointers etc.
 
 DbnStorage (std::vector< AxisT > &&... binsEdges, const std::string &path="", const std::string &title="")
 Constructor giving explicit bin edges as rvalue reference.
 
 DbnStorage (const std::vector< AxisT > &... binsEdges, const std::string &path="", const std::string &title="")
 Constructor giving explicit bin edges as lvalue const reference.
 
 DbnStorage (std::initializer_list< AxisT > &&... binsEdges, const std::string &path="", const std::string &title="")
 Constructor giving explicit bin edges as initializer list.
 
template<typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT...>>
 DbnStorage (const std::vector< size_t > &nBins, const std::vector< std::pair< EdgeT, EdgeT > > &limitsLowUp, const std::string &path="", const std::string &title="")
 Constructor giving range and number of bins.
 
 DbnStorage (const Axis< AxisT > &... axes, const std::string &path="", const std::string &title="")
 Constructor given a sequence of axes.
 
 DbnStorage (Axis< AxisT > &&... axes, const std::string &path="", const std::string &title="")
 Constructor given a sequence of rvalue axes.
 
 DbnStorage (const BinningT &binning, const std::string &path="", const std::string &title="")
 Constructor given a BinningT (needed for type reductions)
 
 DbnStorage (BinningT &&binning, const std::string &path="", const std::string &title="")
 Constructor given an rvalue BinningT.
 
template<typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT...>>
 DbnStorage (const ScatterND< sizeof...(AxisT)+1 > &s, const std::string &path="", const std::string &title="")
 Constructor given a scatter.
 
 DbnStorage (const DbnStorage &other, const std::string &path="")
 Copy constructor.
 
 DbnStorage (DbnStorage &&other, const std::string &path="")
 Move constructor.
 
DbnStorage clone () const noexcept
 Make a copy on the stack.
 
DbnStoragenewclone () const noexcept
 Make a copy on the heap.
 
Transformations
virtual int fill (FillType &&coords, const double weight=1.0, const double fraction=1.0)
 Triggers fill adapter on the bin corresponding to coords.
 
void scaleW (const double scalefactor) noexcept
 Rescale as if all fill weights had been different by factor scalefactor.
 
void scale (const size_t i, const double scalefactor) noexcept
 Rescale as if all fill weights had been different by factor scalefactor along dimension i.
 
void normalize (const double normto=1.0, const bool includeOverflows=true)
 Normalize the (visible) histo "volume" to the normto value.
 
template<size_t axisN>
void rebinBy (unsigned int n, size_t begin=1, size_t end=UINT_MAX)
 Merge every group of n bins, from start to end inclusive.
 
template<size_t axisN>
void rebin (unsigned int n, size_t begin=1, size_t end=UINT_MAX)
 Overloaded alias for rebinBy.
 
template<size_t axisN>
void rebinTo (const std::vector< typename BinningT::template getAxisT< axisN >::EdgeT > &newedges)
 Rebin to the given list of bin edges.
 
template<size_t axisN>
void rebin (const std::vector< typename BinningT::template getAxisT< axisN >::EdgeT > &newedges)
 Overloaded alias for rebinTo.
 
DbnStorageoperator= (const DbnStorage &dbn) noexcept
 Copy assignment.
 
DbnStorageoperator= (DbnStorage &&dbn) noexcept
 Move assignment.
 
DbnStorageoperator+= (const DbnStorage &dbn)
 Add two DbnStorages.
 
DbnStorageoperator+= (DbnStorage &&dbn)
 
DbnStorageoperator-= (const DbnStorage &dbn)
 Subtract one DbnStorages from another one.
 
DbnStorageoperator-= (DbnStorage &&dbn)
 
Reset methods
void reset () noexcept
 Reset the histogram.
 
Binning info.
size_t fillDim () const noexcept
 Fill-dimension of this data object.
 
size_t dim () const noexcept
 Total dimension of the object (number of axes + filled value)
 
template<size_t I, typename E = typename BinningT::template getEdgeT<I>>
std::vector< E > edges (const bool includeOverflows=false) const noexcept
 Returns the edges of axis N by value.
 
template<size_t I, typename E = typename BinningT::template getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, std::vector< E > > widths (const bool includeOverflows=false) const noexcept
 Templated version to get bin widths of axis N by reference.
 
template<size_t I, typename E = typename BinningT::template getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, E > min () const noexcept
 Get the lowest non-overflow edge of the axis.
 
template<size_t I, typename E = typename BinningT::template getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, E > max () const noexcept
 Get the highest non-overflow edge of the axis.
 
Whole histo data
double integral (const bool includeOverflows=true) const noexcept
 Get the total volume of the histogram.
 
double integralError (const bool includeOverflows=true) const noexcept
 Get the total volume error of the histogram.
 
double integralTo (const size_t binIndex) const noexcept
 Get the total volume of the histogram.
 
double integralRange (const size_t binIndex1, size_t binIndex2) const
 Calculates the integrated volume of the histogram between global bins binindex1 and binIndex2.
 
double integralRangeError (const size_t binIndex1, size_t binIndex2) const
 Calculates the integrated volume error of the histogram between global bins binindex1 and binIndex2.
 
double numEntries (const bool includeOverflows=true) const noexcept
 Get the number of fills (fractional fills are possible).
 
double effNumEntries (const bool includeOverflows=true) const noexcept
 Get the effective number of fills.
 
double sumW (const bool includeOverflows=true) const noexcept
 Calculates sum of weights in histo.
 
double sumW2 (const bool includeOverflows=true) const noexcept
 Calculates sum of squared weights in histo.
 
double sumWA (const size_t dim, const bool includeOverflows=true) const
 Calculates first moment along axis dim in histo.
 
double sumWA2 (const size_t dim, const bool includeOverflows=true) const
 Calculates second moment along axis dim in histo.
 
template<size_t dim = DbnN, typename = std::enable_if_t<(dim >= 2)>>
double crossTerm (const size_t A1, const size_t A2, const bool includeOverflows=true) const
 Calculates cross-term along axes A1 and A2 in histo.
 
double mean (size_t axisN, const bool includeOverflows=true) const noexcept
 Calculates the mean value at axis.
 
double variance (size_t axisN, const bool includeOverflows=true) const noexcept
 Calculates the variance at axis.
 
double stdDev (size_t axisN, const bool includeOverflows=true) const noexcept
 Calculates the standard deviation at axis.
 
double stdErr (size_t axisN, const bool includeOverflows=true) const noexcept
 Calculates the standard error at axis.
 
double rms (size_t axisN, const bool includeOverflows=true) const noexcept
 Calculates the RMS at axis.
 
double dVol (const bool includeOverflows=true) const noexcept
 
double density (const bool includeOverflows=true) const noexcept
 Get the total density of the histogram.
 
double densityError (const bool includeOverflows=true) const noexcept
 Get the total density error of the histogram.
 
double densitySum (const bool includeOverflows=true) const noexcept
 Returns the sum of the bin densities.
 
double maxDensity (const bool includeOverflows=true) const noexcept
 Returns the largest density in any of the bins.
 
MPI (de-)serialisation
size_t lengthContent (bool=false) const noexcept
 Length of serialized content vector for MPI reduce operations.
 
std::vector< double > serializeContent (bool=false) const noexcept
 Content serialisation for MPI reduce operations.
 
void deserializeContent (const std::vector< double > &data)
 Content deserialisation for MPI reduce operations.
 
Type reductions
BinnedEstimate< AxisT... > mkEstimate (const std::string &path="", const std::string &source="", const bool divbyvol=true) const
 Produce a BinnedEstimate from a DbnStorage.
 
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT)) >>
auto mkEstimates (const std::string &path="", const std::string source="", const bool divbyvol=true, const bool includeOverflows=false)
 Produce a BinnedEstimate for each bin along axis axisN and return as a vector.
 
auto mkScatter (const std::string &path="", const bool divbyvol=true, const bool usefocus=false, const bool includeOverflows=false, const bool includeMaskedBins=false) const
 Produce a ScatterND from a DbnStorage.
 
template<size_t N = DbnN, typename = std::enable_if_t< (N == sizeof...(AxisT)+1) >>
BinnedHisto< AxisT... > mkHisto (const std::string &path="") const
 Produce a BinnedHisto from BinnedProfile.
 
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT)) >>
auto mkMarginalProfile (const std::string &path="") const
 Produce a BinnedProfile from a DbnStorage.
 
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT)) >>
auto mkMarginalHisto (const std::string &path="") const
 Produce a BinnedHisto from a DbnStorage.
 
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT) && sizeof...(AxisT)>=2 && DbnN > sizeof...(AxisT)) >>
auto mkProfiles (const std::string &path="", const bool includeOverflows=false) const
 Split into vector of BinnedProfile along axis axisN.
 
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT) && sizeof...(AxisT)>=2) >>
auto mkHistos (const std::string &path="", const bool includeOverflows=false) const
 Split into vector of BinnedHisto along axis axisN.
 
AnalysisObjectmkInert (const std::string &path="", const std::string &source="") const noexcept
 Return an inert version of the analysis object (e.g. scatter, estimate)
 
- Public Member Functions inherited from YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >
 FillableStorage (FillAdapterT adapter=AdapterWrapperT()._adapter)
 Nullary constructor for unique pointers etc.
 
 FillableStorage (const BinningT &binning, FillAdapterT adapter=AdapterWrapperT()._adapter)
 Constructs FillableStorage from Binning.
 
 FillableStorage (BinningT &&binning, FillAdapterT adapter=AdapterWrapperT()._adapter)
 Constructs FillableStorage from Binning. Rvalue.
 
 FillableStorage (const std::vector< AxisT > &... edges, FillAdapterT adapter=AdapterWrapperT()._adapter)
 Constructs binning from an adapter and vectors of axes' edges.
 
 FillableStorage (std::vector< AxisT > &&... edges, FillAdapterT adapter=AdapterWrapperT()._adapter)
 Constructs binning from an adapter and Rvalue vectors of axes' edges.
 
 FillableStorage (const Axis< AxisT > &... axes, FillAdapterT adapter=AdapterWrapperT()._adapter)
 Constructs binning from an adapter and a sequence of axes.
 
 FillableStorage (Axis< AxisT > &&... axes, FillAdapterT adapter=AdapterWrapperT()._adapter)
 Constructs binning from an adapter and a sequence of Rvalue axes.
 
 FillableStorage (const FillableStorage &other)
 Copy constructor.
 
 FillableStorage (FillableStorage &&other)
 Move constructor.
 
int fill (FillCoordsT &&coords, std::index_sequence< Is... >, const double weight=1.0, const double fraction=1.0) noexcept
 Triggers fill adapter on the bin corresponding to coords.
 
int fill (FillCoordsT &&coords, const double weight=1.0, const double fraction=1.0) noexcept
 Triggers fill adapter on the bin corresponding to coords.
 
size_t fillDim () const
 Returns the dimension of the filling tuple.
 
size_t nanCount () const
 
double nanSumW () const
 
double nanSumW2 () const
 
void setNanLog (size_t count, double sumw, double sumw2)
 
void reset () noexcept
 Reset the Fillable.
 
FillableStorageoperator= (const FillableStorage &other) noexcept
 Copy assignment.
 
FillableStorageoperator= (FillableStorage &&other) noexcept
 Move assignment.
 
FillableStorageoperator+= (const FillableStorage &other)
 Add another BinnedStorage to this one.
 
FillableStorageoperator-= (const FillableStorage &other)
 Subtract another BinnedStorage from this one.
 
- Public Member Functions inherited from YODA::BinnedStorage< BinContentT, AxisT >
 BinnedStorage ()
 Nullary constructor for unique pointers etc.
 
 BinnedStorage (const BinningT &binning)
 Constructs BinnedStorage from Binning.
 
 BinnedStorage (BinningT &&binning)
 Constructs BinnedStorage from Binning. Rvalue.
 
 BinnedStorage (const std::vector< AxisT > &... edges)
 Constructs binning from an adapter and vectors of axes' edges.
 
 BinnedStorage (std::vector< AxisT > &&... edges)
 Constructs binning from an adapter and Rvalue vectors of axes' edges.
 
 BinnedStorage (std::initializer_list< AxisT > &&... edges)
 Constructs binning from an adapter and Rvalue initializer lists of axes' edges.
 
 BinnedStorage (const Axis< AxisT > &... axes)
 Constructs binning from an adapter and a sequence of axes.
 
 BinnedStorage (Axis< AxisT > &&... axes)
 Constructs binning from an adapter and a sequence of Rvalue axes.
 
 BinnedStorage (const BinnedStorage &other)
 Copy constructor.
 
 BinnedStorage (BinnedStorage &&other)
 Move constructor.
 
size_t dim () const noexcept
 Total dimension of the object ( = number of axes + content)
 
BinTbin (size_t idx) noexcept
 Returns reference to the bin at idx.
 
const BinTbin (size_t idx) const noexcept
 Returns Bin at idx.
 
BinTbin (const std::array< size_t, sizeof...(AxisT)> &idxLocal) noexcept
 Bin access using local bin indices.
 
const BinTbin (const std::array< size_t, sizeof...(AxisT)> &idxLocal) const noexcept
 Bin access using local bin indices.
 
BinTbinAt (typename BinningT::EdgeTypesTuple &&coords) noexcept
 Returns reference to the bin at coordinates.
 
const BinTbinAt (typename BinningT::EdgeTypesTuple &&coords) const noexcept
 Returns reference to the bin at coordinates (const version).
 
void set (typename BinningT::EdgeTypesTuple &&coords, BinContentT &&content) noexcept
 Sets the bin corresponding to coords with an rvalue content.
 
void set (typename BinningT::EdgeTypesTuple &&coords, const BinContentT &content) noexcept
 Sets the bin corresponding to coords with content.
 
void set (const size_t binIdx, BinContentT &&content) noexcept
 Sets the bin corresponding to binIndex with an rvalue content.
 
void set (const size_t binIdx, const BinContentT &content) noexcept
 Sets the bin corresponding to binIndex with content.
 
std::vector< size_t > calcIndicesToSkip (const bool includeOverflows, const bool includeMaskedBins) const noexcept
 Calculates indices of bins which are marked or located in the overflow.
 
BinsVecWrapper< BinsVecTbins (const bool includeOverflows=false, const bool includeMaskedBins=false) noexcept
 Returns bins vector wrapper, which skips masked elements when iterated over.
 
const BinsVecWrapper< const BinsVecTbins (const bool includeOverflows=false, const bool includeMaskedBins=false) const noexcept
 Const version.
 
const BinningTbinning () const noexcept
 Returns dimension underlying binning object reference.
 
size_t binDim () const noexcept
 Returns dimension of binning.
 
size_t numBins (const bool includeOverflows=false, const bool includeMaskedBins=false) const noexcept
 Number of bins in the BinnedStorage.
 
size_t numBinsAt (const size_t axisN, const bool includeOverflows=false) const noexcept
 Number of bins in the BinnedStorage.
 
void reset () noexcept
 Reset the BinnedStorage.
 
void clearBins () noexcept
 Deletes all bins and creates empty new ones.
 
void maskBins (const std::vector< size_t > &indicesToMask, const bool status=true) noexcept
 Mask a range of bins.
 
void maskBin (const size_t indexToMask, const bool status=true) noexcept
 Mask a bin at a given index.
 
void maskSlice (const size_t dim, const size_t idx, const bool status=true)
 Mask a slice of the binning at local bin index idx along axis dimesnion dim.
 
void maskBinAt (typename BinningT::EdgeTypesTuple &&coords, const bool status=true) noexcept
 Mask a bin at a given set of corrdinates.
 
bool isMasked (const size_t binIndex) const noexcept
 
std::vector< size_t > maskedBins () const noexcept
 
bool isVisible (const size_t binIndex) const noexcept
 
template<size_t... AxisNs, class RetT = void>
auto mergeBins (std::decay_t< decltype(AxisNs, std::declval< std::pair< size_t, size_t > >())>... mergeRanges) noexcept -> std::enable_if_t< MetaUtils::is_detected_v< MetaUtils::operatorTraits::addition_assignment_t, BinContentT >, RetT >
 Merge bins from A to B at G axis.
 
template<size_t axisN, template< typename... > typename BinnedT, typename Func , typename = std::enable_if_t< (axisN < sizeof...(AxisT) && sizeof...(AxisT)>=2) >>
auto mkBinnedSlices (Func &&how2add, const bool includeOverflows=false) const
 Split this BinnedStorage into a vector of BinnedStorages along axisN.
 
BinnedStorageoperator= (const BinnedStorage &other) noexcept
 Copy assignment.
 
BinnedStorageoperator= (BinnedStorage &&other) noexcept
 Move assignment.
 
bool operator== (const BinnedStorage &other) const noexcept
 Compares BinnedStorages for equality, e.g. dimensions of underlying binnings and all axes edges are equal.
 
bool operator!= (const BinnedStorage &other) const noexcept
 Compares BinnedStorages for inequality.
 
- Public Member Functions inherited from YODA::AnalysisObject
 AnalysisObject ()
 Default constructor.
 
 AnalysisObject (const std::string &type, const std::string &path, const std::string &title="")
 Constructor giving a type, a path and an optional title.
 
 AnalysisObject (const std::string &type, const std::string &path, const AnalysisObject &ao, const std::string &title="")
 Constructor giving a type, a path, another AO to copy annotation from, and an optional title.
 
virtual ~AnalysisObject ()
 Default destructor.
 
virtual AnalysisObjectoperator= (const AnalysisObject &ao) noexcept
 Default copy assignment operator.
 
std::vector< std::string > annotations () const
 
bool hasAnnotation (const std::string &name) const
 Check if an annotation is defined.
 
const std::string & annotation (const std::string &name) const
 Get an annotation by name (as a string)
 
const std::string & annotation (const std::string &name, const std::string &defaultreturn) const
 Get an annotation by name (as a string) with a default in case the annotation is not found.
 
template<typename T >
const T annotation (const std::string &name) const
 Get an annotation by name (copied to another type)
 
template<typename T >
const T annotation (const std::string &name, const T &defaultreturn) const
 Get an annotation by name (copied to another type) with a default in case the annotation is not found.
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name (templated for remaining types)
 
void setAnnotations (const Annotations &anns)
 Set all annotations at once.
 
template<typename T >
void addAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name.
 
void rmAnnotation (const std::string &name)
 Delete an annotation by name.
 
void clearAnnotations ()
 Delete an annotation by name.
 
const std::string title () const
 Get the AO title.
 
void setTitle (const std::string &title)
 Set the AO title.
 
const std::string path () const
 Get the AO path.
 
void setPath (const std::string &path)
 
const std::string name () const
 
virtual std::string type () const
 Get name of the analysis object type.
 
size_t lengthMeta (const bool skipPath=true, const bool skipTitle=true) const noexcept
 Length of serialized meta-data vector for MPI reduce operations.
 
std::vector< std::string > serializeMeta (const bool skipPath=true, const bool skipTitle=true) const noexcept
 Mate-data serialisation for MPI reduce operations.
 
virtual void deserializeMeta (const std::vector< std::string > &data, const bool resetPath=false, const bool resetTitle=false)
 Mate-data deserialisation for MPI reduce operations.
 
- Public Member Functions inherited from YODA::Fillable
virtual ~Fillable ()=default
 Virtual destructor for inheritance.
 

Additional Inherited Members

- Protected Types inherited from YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >
using BaseT = BinnedStorage< Dbn< DbnN >, AxisT... >
 Convenience alias to be used in constructor.
 
using BinningT = typename BaseT::BinningT
 
using BinT = Bin< sizeof...(AxisT), Dbn< DbnN >, BinningT >
 
using AdapterWrapperT = defaultAdapter< FillDim, BinT >
 
using FillableT = FillableStorage< FillDim, Dbn< DbnN >, AxisT... >
 
using FillCoordsT = decltype(std::tuple_cat(std::declval< typename BinningT::EdgeTypesTuple >(), dblPadding(std::make_index_sequence< FillDim-sizeof...(AxisT)>{})))
 
- Protected Types inherited from YODA::BinnedStorage< BinContentT, AxisT >
using BinningT = Binning< std::decay_t< decltype(std::declval< Axis< AxisT > >())>... >
 Convenience alias to be used in constructor.
 
using BinT = Bin< sizeof...(AxisT), BinContentT, BinningT >
 
using BinsVecT = std::vector< BinT >
 
using BaseT = BinnedStorage< BinContentT, AxisT... >
 
- Protected Member Functions inherited from YODA::BinnedStorage< BinContentT, AxisT >
void fillBins () noexcept
 Fills bins with wrapped BinContent objects.
 
void fillBins (const BinsVecT &bins) noexcept
 
void fillBins (BinsVecT &&bins) noexcept
 

Detailed Description

template<size_t DbnN, typename... AxisT>
class YODA::DbnStorage< DbnN, AxisT >

All histograms can be instantiated through this alias.

Histogram convenience class based on FillableStorage.

Since objects with continuous axes are by far the most commonly used type in practice, we define convenient short-hand aliases HistoND/ProfileND for with only continuous axes, along with the familar types Histo1D, Profile2D, etc.

Note
We use this abstraction layer to implement the bulk once and only once. The user-facing BinnedDbn type(s) will inherit all their methods from this base class along with a few axis-specifc mixins.
Alias generates index sequence later used to create a parameter pack consisting of axis types to instantiate the Binning template.

Definition at line 115 of file BinnedDbn.h.

Member Typedef Documentation

◆ BaseT

template<size_t DbnN, typename... AxisT>
using YODA::DbnStorage< DbnN, AxisT >::BaseT = FillableStorage<DbnN, Dbn<DbnN>, AxisT...>

Definition at line 119 of file BinnedDbn.h.

◆ BinningT

template<size_t DbnN, typename... AxisT>
using YODA::DbnStorage< DbnN, AxisT >::BinningT = typename BaseT::BinningT

Definition at line 120 of file BinnedDbn.h.

◆ BinT

template<size_t DbnN, typename... AxisT>
using YODA::DbnStorage< DbnN, AxisT >::BinT = typename BaseT::BinT

Definition at line 121 of file BinnedDbn.h.

◆ BinType

template<size_t DbnN, typename... AxisT>
using YODA::DbnStorage< DbnN, AxisT >::BinType = typename BaseT::BinT

Definition at line 122 of file BinnedDbn.h.

◆ FillType

template<size_t DbnN, typename... AxisT>
using YODA::DbnStorage< DbnN, AxisT >::FillType = typename BaseT::FillType

Definition at line 123 of file BinnedDbn.h.

Constructor & Destructor Documentation

◆ DbnStorage() [1/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( )
inline

Nullary constructor for unique pointers etc.

Note
The setting of optional path/title is not possible here in order to avoid overload ambiguity for brace-initialised constructors.

Definition at line 133 of file BinnedDbn.h.

133: BaseT(), AnalysisObject(mkTypeString<DbnN, AxisT...>(), "") { }
AnalysisObject()
Default constructor.
FillableStorage< DbnN, Dbn< DbnN >, AxisT... > BaseT
Definition BinnedDbn.h:119

Referenced by YODA::DbnStorage< DbnN, AxisT >::clone(), and YODA::DbnStorage< DbnN, AxisT >::newclone().

◆ DbnStorage() [2/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( std::vector< AxisT > &&...  binsEdges,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving explicit bin edges as rvalue reference.

Discrete axes have as many edges as bins. Continuous axes have number of edges = number of bins + 1, the last one being the upper bound of the last bin.

Definition at line 140 of file BinnedDbn.h.

142 : BaseT(Axis<AxisT>(std::move(binsEdges))...),
143 AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }
const std::string title() const
Get the AO title.
const std::string path() const
Get the AO path.

◆ DbnStorage() [3/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( const std::vector< AxisT > &...  binsEdges,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving explicit bin edges as lvalue const reference.

Discrete axes have as many edges as bins. Continuous axes have bins.size()+1 edges, the last one being the upper bound of the last bin.

Definition at line 150 of file BinnedDbn.h.

152 : BaseT(Axis<AxisT>(binsEdges)...),
153 AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }

◆ DbnStorage() [4/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( std::initializer_list< AxisT > &&...  binsEdges,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving explicit bin edges as initializer list.

Discrete axes have as many edges as bins. Continuous axes have number of edges = number of bins + 1, the last one being the upper bound of the last bin.

Definition at line 160 of file BinnedDbn.h.

162 : BaseT(Axis<AxisT>(std::move(binsEdges))...),
163 AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }

◆ DbnStorage() [5/12]

template<size_t DbnN, typename... AxisT>
template<typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT...>>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( const std::vector< size_t > &  nBins,
const std::vector< std::pair< EdgeT, EdgeT > > &  limitsLowUp,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving range and number of bins.

Note
This constructor is only supported for objects with purely continous axes. It is also the only place where the index sequence sequence is actually needed.

Definition at line 170 of file BinnedDbn.h.

172 : BaseT( _mkBinning(nBins, limitsLowUp, std::make_index_sequence<sizeof...(AxisT)>{}) ),
173 AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }

◆ DbnStorage() [6/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( const Axis< AxisT > &...  axes,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor given a sequence of axes.

Definition at line 176 of file BinnedDbn.h.

177 : BaseT(axes...), AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }

◆ DbnStorage() [7/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( Axis< AxisT > &&...  axes,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor given a sequence of rvalue axes.

Definition at line 180 of file BinnedDbn.h.

181 : BaseT(std::move(axes)...), AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }

◆ DbnStorage() [8/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( const BinningT binning,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor given a BinningT (needed for type reductions)

Definition at line 184 of file BinnedDbn.h.

185 : BaseT(binning), AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }
const BinningT & binning() const noexcept
Returns dimension underlying binning object reference.

◆ DbnStorage() [9/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( BinningT &&  binning,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor given an rvalue BinningT.

Definition at line 188 of file BinnedDbn.h.

189 : BaseT(std::move(binning)), AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }

◆ DbnStorage() [10/12]

template<size_t DbnN, typename... AxisT>
template<typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT...>>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( const ScatterND< sizeof...(AxisT)+1 > &  s,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor given a scatter.

Definition at line 193 of file BinnedDbn.h.

194 : BaseT(_mkBinning(s, std::make_index_sequence<sizeof...(AxisT)>{})),
195 AnalysisObject(mkTypeString<DbnN, AxisT...>(), path, title) { }

◆ DbnStorage() [11/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( const DbnStorage< DbnN, AxisT > &  other,
const std::string &  path = "" 
)
inline

Copy constructor.

Todo:
Also allow title setting from the constructor?

Definition at line 200 of file BinnedDbn.h.

200 : BaseT(other),
201 AnalysisObject(mkTypeString<DbnN, AxisT...>(), path!=""? path : other.path(), other, other.title()) { }

◆ DbnStorage() [12/12]

template<size_t DbnN, typename... AxisT>
YODA::DbnStorage< DbnN, AxisT >::DbnStorage ( DbnStorage< DbnN, AxisT > &&  other,
const std::string &  path = "" 
)
inline

Move constructor.

Todo:
Also allow title setting from the constructor?

Definition at line 206 of file BinnedDbn.h.

206 : BaseT(std::move(other)),
207 AnalysisObject(mkTypeString<DbnN, AxisT...>(), path!=""? path : other.path(), other, other.title()) { }

Member Function Documentation

◆ clone()

template<size_t DbnN, typename... AxisT>
DbnStorage YODA::DbnStorage< DbnN, AxisT >::clone ( ) const
inlinenoexcept

Make a copy on the stack.

Definition at line 210 of file BinnedDbn.h.

210 {
211 return DbnStorage(*this);
212 }
DbnStorage()
Nullary constructor for unique pointers etc.
Definition BinnedDbn.h:133

References YODA::DbnStorage< DbnN, AxisT >::DbnStorage().

◆ crossTerm()

template<size_t DbnN, typename... AxisT>
template<size_t dim = DbnN, typename = std::enable_if_t<(dim >= 2)>>
double YODA::DbnStorage< DbnN, AxisT >::crossTerm ( const size_t  A1,
const size_t  A2,
const bool  includeOverflows = true 
) const
inline

Calculates cross-term along axes A1 and A2 in histo.

Definition at line 557 of file BinnedDbn.h.

557 {
558 if (A1 >= DbnN || A2 >= DbnN) throw RangeError("Invalid axis int, must be in range 0..dim-1");
559 if (A1 >= A2) throw RangeError("Indices need to be different for cross term");
560 double sumw = 0;
561 for (const auto& b : BaseT::bins(includeOverflows))
562 sumw += b.crossTerm(A1, A2);
563 return sumw;
564 }
BinsVecWrapper< BinsVecT > bins(const bool includeOverflows=false, const bool includeMaskedBins=false) noexcept
Returns bins vector wrapper, which skips masked elements when iterated over.
double crossTerm(const size_t A1, const size_t A2, const bool includeOverflows=true) const
Calculates cross-term along axes A1 and A2 in histo.
Definition BinnedDbn.h:557

References YODA::BinnedStorage< BinContentT, AxisT >::bins().

Referenced by YODA::WriterYODA1::writeHisto2D(), and YODA::WriterYODA1::writeProfile2D().

◆ density()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::density ( const bool  includeOverflows = true) const
inlinenoexcept

Get the total density of the histogram.

Definition at line 611 of file BinnedDbn.h.

611 {
612 const double vol = dVol(includeOverflows);
613 if (vol) return integral(includeOverflows) / vol;
614 return std::numeric_limits<double>::quiet_NaN();
615 }
double dVol(const bool includeOverflows=true) const noexcept
Definition BinnedDbn.h:603
double integral(const bool includeOverflows=true) const noexcept
Get the total volume of the histogram.
Definition BinnedDbn.h:463

References YODA::DbnStorage< DbnN, AxisT >::dVol(), and YODA::DbnStorage< DbnN, AxisT >::integral().

◆ densityError()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::densityError ( const bool  includeOverflows = true) const
inlinenoexcept

Get the total density error of the histogram.

Definition at line 618 of file BinnedDbn.h.

618 {
619 const double vol = dVol(includeOverflows);
620 if (vol) return integralError(includeOverflows) / vol;
621 return std::numeric_limits<double>::quiet_NaN();
622 }
double integralError(const bool includeOverflows=true) const noexcept
Get the total volume error of the histogram.
Definition BinnedDbn.h:468

References YODA::DbnStorage< DbnN, AxisT >::dVol(), and YODA::DbnStorage< DbnN, AxisT >::integralError().

◆ densitySum()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::densitySum ( const bool  includeOverflows = true) const
inlinenoexcept

Returns the sum of the bin densities.

Definition at line 625 of file BinnedDbn.h.

625 {
626 double rho = 0.0;
627 for (const auto& b : BaseT::bins(includeOverflows))
628 rho += b.sumW() / b.dVol();
629 return rho;
630 }
double sumW(const bool includeOverflows=true) const noexcept
Calculates sum of weights in histo.
Definition BinnedDbn.h:522

References YODA::BinnedStorage< BinContentT, AxisT >::bins().

◆ deserializeContent()

template<size_t DbnN, typename... AxisT>
void YODA::DbnStorage< DbnN, AxisT >::deserializeContent ( const std::vector< double > &  data)
inlinevirtual

Content deserialisation for MPI reduce operations.

Implements YODA::AnalysisObject.

Definition at line 729 of file BinnedDbn.h.

729 {
730
731 constexpr size_t dbnSize = Dbn<DbnN>::DataSize::value;
732 const size_t nBins = BaseT::numBins(true, true);
733 if (data.size() != nBins * dbnSize)
734 throw UserError("Length of serialized data should be "
735 + std::to_string(nBins * dbnSize)+"!");
736
737 const auto itr = data.cbegin();
738 for (size_t i = 0; i < nBins; ++i) {
739 auto first = itr + i*dbnSize;
740 auto last = first + dbnSize;
741 BaseT::bin(i)._deserializeContent(std::vector<double>{first, last});
742 }
743
744 }
BinT & bin(size_t idx) noexcept
Returns reference to the bin at idx.
size_t numBins(const bool includeOverflows=false, const bool includeMaskedBins=false) const noexcept
Number of bins in the BinnedStorage.

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), and YODA::BinnedStorage< BinContentT, AxisT >::numBins().

◆ dim()

template<size_t DbnN, typename... AxisT>
size_t YODA::DbnStorage< DbnN, AxisT >::dim ( ) const
inlinevirtualnoexcept

Total dimension of the object (number of axes + filled value)

Implements YODA::AnalysisObject.

Definition at line 417 of file BinnedDbn.h.

417{ return sizeof...(AxisT) + 1; }

Referenced by YODA::DbnStorage< DbnN, AxisT >::sumWA(), and YODA::DbnStorage< DbnN, AxisT >::sumWA2().

◆ dVol()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::dVol ( const bool  includeOverflows = true) const
inlinenoexcept

Definition at line 603 of file BinnedDbn.h.

603 {
604 double vol = 0.0;
605 for (const auto& b : BaseT::bins(includeOverflows))
606 vol += b.dVol();
607 return vol;
608 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins().

Referenced by YODA::DbnStorage< DbnN, AxisT >::density(), and YODA::DbnStorage< DbnN, AxisT >::densityError().

◆ edges()

template<size_t DbnN, typename... AxisT>
template<size_t I, typename E = typename BinningT::template getEdgeT<I>>
std::vector< E > YODA::DbnStorage< DbnN, AxisT >::edges ( const bool  includeOverflows = false) const
inlinenoexcept

Returns the edges of axis N by value.

Definition at line 424 of file BinnedDbn.h.

424 {
425 return BaseT::_binning.template edges<I>(includeOverflows);
426 }

◆ effNumEntries()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::effNumEntries ( const bool  includeOverflows = true) const
inlinevirtualnoexcept

Get the effective number of fills.

Implements YODA::Fillable.

Definition at line 514 of file BinnedDbn.h.

514 {
515 double n = 0;
516 for (const auto& b : BaseT::bins(includeOverflows))
517 n += b.effNumEntries();
518 return n;
519 }
double effNumEntries(const bool includeOverflows=true) const noexcept
Get the effective number of fills.
Definition BinnedDbn.h:514

References YODA::BinnedStorage< BinContentT, AxisT >::bins().

Referenced by YODA::DbnStorage< DbnN, AxisT >::mkEstimate().

◆ fill()

template<size_t DbnN, typename... AxisT>
virtual int YODA::DbnStorage< DbnN, AxisT >::fill ( FillType &&  coords,
const double  weight = 1.0,
const double  fraction = 1.0 
)
inlinevirtual

Triggers fill adapter on the bin corresponding to coords.

Note
Accepts coordinates only as rvalue tuple. The tuple members are then moved (bringing tuple member to unspecified state) later in adapters.

Definition at line 229 of file BinnedDbn.h.

229 {
230 return BaseT::fill(std::move(coords), std::make_index_sequence<sizeof...(AxisT)>{}, weight, fraction);
231 }
int fill(FillCoordsT &&coords, std::index_sequence< Is... >, const double weight=1.0, const double fraction=1.0) noexcept
Triggers fill adapter on the bin corresponding to coords.

References YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::fill().

◆ fillDim()

template<size_t DbnN, typename... AxisT>
size_t YODA::DbnStorage< DbnN, AxisT >::fillDim ( ) const
inlinevirtualnoexcept

Fill-dimension of this data object.

Implements YODA::Fillable.

Definition at line 414 of file BinnedDbn.h.

414{ return BaseT::fillDim(); }
size_t fillDim() const
Returns the dimension of the filling tuple.

References YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::fillDim().

◆ integral()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::integral ( const bool  includeOverflows = true) const
inlinenoexcept

Get the total volume of the histogram.

Definition at line 463 of file BinnedDbn.h.

463 {
464 return sumW(includeOverflows);
465 }

References YODA::DbnStorage< DbnN, AxisT >::sumW().

Referenced by YODA::DbnStorage< DbnN, AxisT >::density(), YODA::mkIntegralEff(), YODA::DbnStorage< DbnN, AxisT >::normalize(), YODA::WriterYODA1::writeHisto1D(), and YODA::WriterYODA1::writeHisto2D().

◆ integralError()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::integralError ( const bool  includeOverflows = true) const
inlinenoexcept

Get the total volume error of the histogram.

Definition at line 468 of file BinnedDbn.h.

468 {
469 return sqrt(sumW2(includeOverflows));
470 }
double sumW2(const bool includeOverflows=true) const noexcept
Calculates sum of squared weights in histo.
Definition BinnedDbn.h:530

References YODA::DbnStorage< DbnN, AxisT >::sumW2().

Referenced by YODA::DbnStorage< DbnN, AxisT >::densityError(), and YODA::mkIntegralEff().

◆ integralRange()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::integralRange ( const size_t  binIndex1,
size_t  binIndex2 
) const
inline

Calculates the integrated volume of the histogram between global bins binindex1 and binIndex2.

Definition at line 479 of file BinnedDbn.h.

479 {
480 assert(binIndex2 >= binIndex1);
481 if (binIndex1 >= BaseT::numBins(true)) throw RangeError("binindex1 is out of range");
482 if (binIndex2 >= BaseT::numBins(true)) throw RangeError("binindex2 is out of range");
483 double sumw = 0;
484 for (size_t idx = binIndex1; idx <= binIndex2; ++idx) {
485 if (BaseT::bin(idx).isMasked()) continue;
486 sumw += BaseT::bin(idx).sumW();
487 }
488 return sumw;
489 }
bool isMasked(const size_t binIndex) const noexcept

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), YODA::BinnedStorage< BinContentT, AxisT >::isMasked(), and YODA::BinnedStorage< BinContentT, AxisT >::numBins().

Referenced by YODA::DbnStorage< DbnN, AxisT >::integralTo().

◆ integralRangeError()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::integralRangeError ( const size_t  binIndex1,
size_t  binIndex2 
) const
inline

Calculates the integrated volume error of the histogram between global bins binindex1 and binIndex2.

Definition at line 493 of file BinnedDbn.h.

493 {
494 assert(binIndex2 >= binIndex1);
495 if (binIndex1 >= BaseT::numBins(true)) throw RangeError("binindex1 is out of range");
496 if (binIndex2 >= BaseT::numBins(true)) throw RangeError("binindex2 is out of range");
497 double sumw2 = 0;
498 for (size_t idx = binIndex1; idx <= binIndex2; ++idx) {
499 if (BaseT::bin(idx).isMasked()) continue;
500 sumw2 += BaseT::bin(idx).sumW2();
501 }
502 return sumw2;
503 }

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), YODA::BinnedStorage< BinContentT, AxisT >::isMasked(), and YODA::BinnedStorage< BinContentT, AxisT >::numBins().

◆ integralTo()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::integralTo ( const size_t  binIndex) const
inlinenoexcept

Get the total volume of the histogram.

Definition at line 473 of file BinnedDbn.h.

473 {
474 return integralRange(0, binIndex);
475 }
double integralRange(const size_t binIndex1, size_t binIndex2) const
Calculates the integrated volume of the histogram between global bins binindex1 and binIndex2.
Definition BinnedDbn.h:479

References YODA::DbnStorage< DbnN, AxisT >::integralRange().

◆ lengthContent()

template<size_t DbnN, typename... AxisT>
size_t YODA::DbnStorage< DbnN, AxisT >::lengthContent ( bool  fixed_length = false) const
inlinevirtualnoexcept

Length of serialized content vector for MPI reduce operations.

Implements YODA::AnalysisObject.

Definition at line 712 of file BinnedDbn.h.

712 {
713 return BaseT::numBins(true, true) * Dbn<DbnN>::DataSize::value;
714 }

References YODA::BinnedStorage< BinContentT, AxisT >::numBins().

◆ max()

template<size_t DbnN, typename... AxisT>
template<size_t I, typename E = typename BinningT::template getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, E > YODA::DbnStorage< DbnN, AxisT >::max ( ) const
inlinenoexcept

Get the highest non-overflow edge of the axis.

Note
This method is only supported for continuous axes

Definition at line 452 of file BinnedDbn.h.

452 {
453 return BaseT::_binning.template max<I>();
454 }

◆ maxDensity()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::maxDensity ( const bool  includeOverflows = true) const
inlinenoexcept

Returns the largest density in any of the bins.

Definition at line 633 of file BinnedDbn.h.

633 {
634 std::vector<double> vals;
635 for (auto& b : BaseT::bins(includeOverflows))
636 vals.emplace_back(b.sumW() / b.dVol());
637 return *max_element(vals.begin(), vals.end());
638 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins().

◆ mean()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::mean ( size_t  axisN,
const bool  includeOverflows = true 
) const
inlinenoexcept

Calculates the mean value at axis.

Definition at line 567 of file BinnedDbn.h.

567 {
568 Dbn<DbnN> dbn;
569 for (const auto& b : BaseT::bins(includeOverflows))
570 dbn += b;
571 return dbn.mean(axisN+1);
572 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), and YODA::DbnBase< N >::mean().

◆ min()

template<size_t DbnN, typename... AxisT>
template<size_t I, typename E = typename BinningT::template getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, E > YODA::DbnStorage< DbnN, AxisT >::min ( ) const
inlinenoexcept

Get the lowest non-overflow edge of the axis.

Note
This method is only supported for continuous axes

Definition at line 444 of file BinnedDbn.h.

444 {
445 return BaseT::_binning.template min<I>();
446 }

◆ mkEstimate()

template<size_t DbnN, typename... AxisT>
BinnedEstimate< AxisT... > YODA::DbnStorage< DbnN, AxisT >::mkEstimate ( const std::string &  path = "",
const std::string &  source = "",
const bool  divbyvol = true 
) const
inline

Produce a BinnedEstimate from a DbnStorage.

The binning remains unchanged.

Definition at line 754 of file BinnedDbn.h.

756 {
757
758 // @todo Should we check BaseT::nanCount() and report?
759 BinnedEstimate<AxisT...> rtn(BaseT::_binning);
760 for (const std::string& a : annotations()) {
761 if (a != "Type") rtn.setAnnotation(a, annotation(a));
762 }
763 rtn.setAnnotation("Path", path);
764
765 if (BaseT::nanCount()) {
766 const double nanc = BaseT::nanCount();
767 const double nanw = BaseT::nanSumW();
768 const double frac = nanc / (nanc + numEntries());
769 const double wtot = nanw + effNumEntries();
770 rtn.setAnnotation("NanFraction", frac);
771 if (wtot) rtn.setAnnotation("WeightedNanFraction", nanw/wtot);
772 }
773
774 for (const auto& b : BaseT::bins(true, true)) {
775 if (!b.isVisible()) continue;
776 if constexpr(DbnN > sizeof...(AxisT)) {
777 rtn.bin(b.index()).setVal(b.mean(DbnN));
778 if (b.numEntries()) { // only set uncertainty for filled Dbns
779 rtn.bin(b.index()).setErr(b.stdErr(DbnN), source);
780 }
781 }
782 else {
783 const double scale = divbyvol? b.dVol() : 1.0;
784 rtn.bin(b.index()).setVal(b.sumW() / scale);
785 if (b.numEntries()) { // only set uncertainty for filled Dbns
786 rtn.bin(b.index()).setErr(b.errW() / scale, source);
787 }
788 }
789 }
790
791 return rtn;
792 }
std::vector< std::string > annotations() const
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
double numEntries(const bool includeOverflows=true) const noexcept
Get the number of fills (fractional fills are possible).
Definition BinnedDbn.h:506
void scale(const size_t i, const double scalefactor) noexcept
Rescale as if all fill weights had been different by factor scalefactor along dimension i.
Definition BinnedDbn.h:242

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::BinnedStorage< BinContentT, AxisT >::bins(), YODA::DbnStorage< DbnN, AxisT >::effNumEntries(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanCount(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanSumW(), YODA::DbnStorage< DbnN, AxisT >::numEntries(), YODA::AnalysisObject::path(), and YODA::DbnStorage< DbnN, AxisT >::scale().

Referenced by YODA::add(), YODA::divide(), YODA::divide(), YODA::DbnStorage< DbnN, AxisT >::mkEstimates(), YODA::DbnStorage< DbnN, AxisT >::mkInert(), YODA::mkIntegral(), YODA::DbnStorage< DbnN, AxisT >::mkScatter(), and YODA::subtract().

◆ mkEstimates()

template<size_t DbnN, typename... AxisT>
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT)) >>
auto YODA::DbnStorage< DbnN, AxisT >::mkEstimates ( const std::string &  path = "",
const std::string  source = "",
const bool  divbyvol = true,
const bool  includeOverflows = false 
)
inline

Produce a BinnedEstimate for each bin along axis axisN and return as a vector.

The binning dimension is reduced by one unit.

Definition at line 799 of file BinnedDbn.h.

800 {
801
802 BinnedEstimate<AxisT...> est = mkEstimate(path, source, divbyvol);
803 return est.template mkEstimates<axisN>(path, includeOverflows);
804 }
BinnedEstimate< AxisT... > mkEstimate(const std::string &path="", const std::string &source="", const bool divbyvol=true) const
Produce a BinnedEstimate from a DbnStorage.
Definition BinnedDbn.h:754

References YODA::DbnStorage< DbnN, AxisT >::mkEstimate(), and YODA::AnalysisObject::path().

◆ mkHisto()

template<size_t DbnN, typename... AxisT>
template<size_t N = DbnN, typename = std::enable_if_t< (N == sizeof...(AxisT)+1) >>
BinnedHisto< AxisT... > YODA::DbnStorage< DbnN, AxisT >::mkHisto ( const std::string &  path = "") const
inline

Produce a BinnedHisto from BinnedProfile.

The binning remains unchanged, but the fill dimension is reduced by one unit.

Definition at line 838 of file BinnedDbn.h.

838 {
839
840 BinnedHisto<AxisT...> rtn(BaseT::_binning);
841 rtn.setNanLog(BaseT::nanCount(), BaseT::nanSumW(), BaseT::nanSumW2());
842 for (const std::string& a : annotations()) {
843 if (a != "Type") rtn.setAnnotation(a, annotation(a));
844 }
845 rtn.setAnnotation("Path", path);
846
847 for (const auto& b : BaseT::bins(true)) {
848 rtn.bin(b.index()) += b.template reduce<N-1>();
849 }
850
851 return rtn;
852 }
BinnedDbn< sizeof...(AxisTypes), AxisTypes... > BinnedHisto
Definition BinnedDbn.h:97

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::BinnedStorage< BinContentT, AxisT >::bins(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanCount(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanSumW(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanSumW2(), and YODA::AnalysisObject::path().

Referenced by YODA::DbnStorage< DbnN, AxisT >::mkHistos(), and YODA::DbnStorage< DbnN, AxisT >::mkMarginalHisto().

◆ mkHistos()

template<size_t DbnN, typename... AxisT>
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT) && sizeof...(AxisT)>=2) >>
auto YODA::DbnStorage< DbnN, AxisT >::mkHistos ( const std::string &  path = "",
const bool  includeOverflows = false 
) const
inline

Split into vector of BinnedHisto along axis axisN.

The binning dimension of the returned ojects are reduced by one unit.

Note
Requires at least two binning dimensions.

Definition at line 999 of file BinnedDbn.h.

999 {
1000
1001 if constexpr (DbnN != sizeof...(AxisT)) {
1002 // Case 1: BP(N+1) -> BH(N+1) -> BHN
1003 return mkHisto().template mkHistos<axisN>(path, includeOverflows);
1004 }
1005 else {
1006 // Case 2: BH(N+1) -> BHN
1007
1008 // Need to provide a prescription for how to add the two bin contents
1009 auto how2add = [](auto& pivot, const BinType& toCopy) { pivot = toCopy.template reduce<axisN>(); };
1010 auto rtn = BaseT::template mkBinnedSlices<axisN,BinnedHisto>(how2add, includeOverflows);
1011 for (const std::string& a : annotations()) {
1012 if (a == "Type") continue;
1013 for (size_t i = 0; i < rtn.size(); ++i) {
1014 rtn[i].setAnnotation(a, annotation(a));
1015 }
1016 }
1017 for (size_t i = 0; i < rtn.size(); ++i) {
1018 rtn[i].setAnnotation("Path", path);
1019 }
1020 return rtn;
1021 }
1022 }
typename BaseT::BinT BinType
Definition BinnedDbn.h:122
BinnedHisto< AxisT... > mkHisto(const std::string &path="") const
Produce a BinnedHisto from BinnedProfile.
Definition BinnedDbn.h:838

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::DbnStorage< DbnN, AxisT >::mkHisto(), and YODA::AnalysisObject::path().

◆ mkInert()

template<size_t DbnN, typename... AxisT>
AnalysisObject * YODA::DbnStorage< DbnN, AxisT >::mkInert ( const std::string &  path = "",
const std::string &  source = "" 
) const
inlinevirtualnoexcept

Return an inert version of the analysis object (e.g. scatter, estimate)

Reimplemented from YODA::AnalysisObject.

Definition at line 1026 of file BinnedDbn.h.

1027 {
1028 return mkEstimate(path, source).newclone();
1029 }

References YODA::DbnStorage< DbnN, AxisT >::mkEstimate(), YODA::AnalysisObject::newclone(), and YODA::AnalysisObject::path().

◆ mkMarginalHisto()

template<size_t DbnN, typename... AxisT>
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT)) >>
auto YODA::DbnStorage< DbnN, AxisT >::mkMarginalHisto ( const std::string &  path = "") const
inline

Produce a BinnedHisto from a DbnStorage.

Case 1: BinnedProfile(N+1)D -> BinnedHistoND The binning dimension is reduced by one unit, and the fill dimension is reduced by two units.

Case 2: BinnedHisto(N+1)D -> BinnedHisto Both fill and binning dimension are reduced by one unit.

Todo:
use a parameter pack and allow marginalising over multiple axes?
Note
Binning iteratively shrinks, so the next bin slice to merge will always be the next.

Definition at line 920 of file BinnedDbn.h.

920 {
921
922 if constexpr (DbnN != sizeof...(AxisT)) {
923 // Case 1: BP(N+1) -> BH(N+1) -> BHN
924 return mkHisto().template mkMarginalHisto<axisN>(path);
925 }
926 else {
927 // Case 2: BH(N+1) -> BHN
928
929 auto rtn = BaseT::template _mkBinnedT<BinnedHisto>(BaseT::_binning.template _getAxesExcept<axisN>());
930 rtn.setNanLog(BaseT::nanCount(), BaseT::nanSumW(), BaseT::nanSumW2());
931 for (const std::string& a : annotations()) {
932 if (a != "Type") rtn.setAnnotation(a, annotation(a));
933 }
934 rtn.setAnnotation("Path", path);
935
936 auto collapseStorageBins =
937 [&oldBinning = BaseT::_binning, &oldBins = BaseT::_bins, &rtn](auto I, auto dbnRed) {
938
939 auto collapse = [&oldBins, &rtn](const auto& binsIndicesToMerge, auto axis) {
940 assert(rtn.numBins(true) == binsIndicesToMerge.size());
941
942 // for any given pivot, add the content
943 // from the old slice to the new slice
944 for (size_t i = 0; i < rtn.numBins(true); ++i) {
945 auto& pivotBin = rtn.bin(i);
946 auto& binToAppend = oldBins[binsIndicesToMerge[i]];
947 pivotBin += binToAppend.template reduce<axis>();
948 }
949 };
950
951 // get bin slice for any given bin along the axis that is to be
952 // collapsed, then copy the values into the new binning
953 ssize_t nBinRowsToBeMerged = oldBinning.numBinsAt(I);
954 while (nBinRowsToBeMerged--) {
957 collapse(oldBinning.sliceIndices(I, nBinRowsToBeMerged), dbnRed);
958 }
959 };
960 // collapse Dbn along axisN
961 auto dbnRed = std::integral_constant<size_t, axisN>();
962 (void)collapseStorageBins(std::integral_constant<std::size_t, axisN>(), dbnRed);
963
964 return rtn;
965 }
966 }

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::DbnStorage< DbnN, AxisT >::mkHisto(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanCount(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanSumW(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanSumW2(), and YODA::AnalysisObject::path().

◆ mkMarginalProfile()

template<size_t DbnN, typename... AxisT>
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT)) >>
auto YODA::DbnStorage< DbnN, AxisT >::mkMarginalProfile ( const std::string &  path = "") const
inline

Produce a BinnedProfile from a DbnStorage.

Case 1: BinnedHisto(N+1)D -> BinnedProfileND The fill dimension remains the same, but the binning is reduced by one dimension.

Case 2: BinnedProfile(N+1)D -> BinnedProfileND Both fill and binning dimmensions are reduced by one unit.

Todo:
use a parameter pack and allow marginalising over multiple axes?
Note
Binning iteratively shrinks, so the next bin slice to merge will always be the next.

If the calling object is a histogram, we can just copy the Dbn<N>, otherwise we need to collapse an axis first in order to produce a Dbn<N-1>.

Note
Dbn axes are 0-indexed, so asking to reduce DbnN doesn't reduce anything.

Definition at line 866 of file BinnedDbn.h.

866 {
867
868 auto rtn = BaseT::template _mkBinnedT<BinnedProfile>(BaseT::_binning.template _getAxesExcept<axisN>());
869 rtn.setNanLog(BaseT::nanCount(), BaseT::nanSumW(), BaseT::nanSumW2());
870 for (const std::string& a : annotations()) {
871 if (a != "Type") rtn.setAnnotation(a, annotation(a));
872 }
873 rtn.setAnnotation("Path", path);
874
875 auto collapseStorageBins =
876 [&oldBinning = BaseT::_binning, &oldBins = BaseT::_bins, &rtn](auto I, auto dbnRed) {
877
878 auto collapse = [&oldBins, &rtn](const auto& binsIndicesToMerge, auto axis) {
879 assert(rtn.numBins(true) == binsIndicesToMerge.size());
880
881 // for any given pivot, add the content
882 // from the old slice to the new slice
883 for (size_t i = 0; i < rtn.numBins(true); ++i) {
884 auto& pivotBin = rtn.bin(i);
885 auto& binToAppend = oldBins[binsIndicesToMerge[i]];
886 pivotBin += binToAppend.template reduce<axis>();
887 }
888 };
889
890 // get bin slice for any given bin along the axis that is to be
891 // collapsed, then copy the values into the new binning
892 ssize_t nBinRowsToBeMerged = oldBinning.numBinsAt(I);
893 while (nBinRowsToBeMerged--) {
896 collapse(oldBinning.sliceIndices(I, nBinRowsToBeMerged), dbnRed);
897 }
898 };
902 auto dbnRed = std::integral_constant<size_t, (sizeof...(AxisT) == DbnN)? DbnN : axisN>();
903 (void)collapseStorageBins(std::integral_constant<std::size_t, axisN>(), dbnRed);
904
905 return rtn;
906 }

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanCount(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanSumW(), YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::nanSumW2(), and YODA::AnalysisObject::path().

◆ mkProfiles()

template<size_t DbnN, typename... AxisT>
template<size_t axisN, typename = std::enable_if_t< (axisN < sizeof...(AxisT) && sizeof...(AxisT)>=2 && DbnN > sizeof...(AxisT)) >>
auto YODA::DbnStorage< DbnN, AxisT >::mkProfiles ( const std::string &  path = "",
const bool  includeOverflows = false 
) const
inline

Split into vector of BinnedProfile along axis axisN.

The binning dimension of the returned objects are reduced by one unit.

Note
Requires at least two binning dimensions.

Definition at line 976 of file BinnedDbn.h.

976 {
977
978 // Need to provide a prescription for how to add the two bin contents
979 auto how2add = [](auto& pivot, const BinType& toCopy) { pivot = toCopy.template reduce<axisN>(); };
980 auto rtn = BaseT::template mkBinnedSlices<axisN, BinnedProfile>(how2add, includeOverflows);
981 for (const std::string& a : annotations()) {
982 if (a == "Type") continue;
983 for (size_t i = 0; i < rtn.size(); ++i) {
984 rtn[i].setAnnotation(a, annotation(a));
985 }
986 }
987 for (size_t i = 0; i < rtn.size(); ++i) {
988 rtn[i].setAnnotation("Path", path);
989 }
990 return rtn;
991 }

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), and YODA::AnalysisObject::path().

◆ mkScatter()

template<size_t DbnN, typename... AxisT>
auto YODA::DbnStorage< DbnN, AxisT >::mkScatter ( const std::string &  path = "",
const bool  divbyvol = true,
const bool  usefocus = false,
const bool  includeOverflows = false,
const bool  includeMaskedBins = false 
) const
inline

Produce a ScatterND from a DbnStorage.

Definition at line 808 of file BinnedDbn.h.

811 {
812 const BinnedEstimate<AxisT...> est = mkEstimate("", "", divbyvol);
813 ScatterND<sizeof...(AxisT)+1> rtn = est.mkScatter(path, "", includeOverflows, includeMaskedBins);
814 if (usefocus) {
815 size_t idx = 0;
816 for (const auto& b : BaseT::bins(includeOverflows, includeMaskedBins)) {
817 auto shiftIfContinuous = [&rtn, &b, &idx](auto I) {
818 using isContinuous = typename BinningT::template is_CAxis<I>;
819 if constexpr (isContinuous::value) {
820 const double oldMax = rtn.point(idx).max(I);
821 const double oldMin = rtn.point(idx).min(I);
822 const double newVal = b.mean(I+1);
823 rtn.point(idx).set(I, newVal, newVal - oldMin, oldMax - newVal);
824 }
825 };
826 MetaUtils::staticFor<BinningT::Dimension::value>(shiftIfContinuous);
827 ++idx;
828 }
829 }
830 return rtn;
831 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), YODA::DbnStorage< DbnN, AxisT >::mkEstimate(), YODA::AnalysisObject::path(), and YODA::ScatterND< N >::point().

◆ newclone()

template<size_t DbnN, typename... AxisT>
DbnStorage * YODA::DbnStorage< DbnN, AxisT >::newclone ( ) const
inlinevirtualnoexcept

Make a copy on the heap.

Implements YODA::AnalysisObject.

Definition at line 215 of file BinnedDbn.h.

215 {
216 return new DbnStorage(*this);
217 }

References YODA::DbnStorage< DbnN, AxisT >::DbnStorage().

◆ normalize()

template<size_t DbnN, typename... AxisT>
void YODA::DbnStorage< DbnN, AxisT >::normalize ( const double  normto = 1.0,
const bool  includeOverflows = true 
)
inline

Normalize the (visible) histo "volume" to the normto value.

If includeoverflows is true, the original normalisation is computed with the overflow bins included, so that the resulting visible normalisation can be less than normto. This is probably what you want.

Definition at line 255 of file BinnedDbn.h.

255 {
256 const double oldintegral = integral(includeOverflows);
257 if (oldintegral == 0) throw WeightError("Attempted to normalize a histogram with null area");
258 scaleW(normto / oldintegral);
259 }
void scaleW(const double scalefactor) noexcept
Rescale as if all fill weights had been different by factor scalefactor.
Definition BinnedDbn.h:234

References YODA::DbnStorage< DbnN, AxisT >::integral(), and YODA::DbnStorage< DbnN, AxisT >::scaleW().

◆ numEntries()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::numEntries ( const bool  includeOverflows = true) const
inlinevirtualnoexcept

Get the number of fills (fractional fills are possible).

Implements YODA::Fillable.

Definition at line 506 of file BinnedDbn.h.

506 {
507 double n = 0;
508 for (const auto& b : BaseT::bins(includeOverflows))
509 n += b.numEntries();
510 return n;
511 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins().

Referenced by YODA::DbnStorage< DbnN, AxisT >::mkEstimate(), YODA::WriterYODA1::writeHisto1D(), YODA::WriterYODA1::writeHisto2D(), YODA::WriterYODA1::writeProfile1D(), and YODA::WriterYODA1::writeProfile2D().

◆ operator+=() [1/2]

template<size_t DbnN, typename... AxisT>
DbnStorage & YODA::DbnStorage< DbnN, AxisT >::operator+= ( const DbnStorage< DbnN, AxisT > &  dbn)
inline

Add two DbnStorages.

Note
Adding DbnStorages will unset any ScaledBy attribute from previous calls to scale or normalize.
Todo:
What happens if two storages disagree on masked bins?

Definition at line 349 of file BinnedDbn.h.

349 {
350 if (*this != dbn)
351 throw BinningError("Arithmetic operation requires compatible binning!");
352 if (AO::hasAnnotation("ScaledBy")) AO::rmAnnotation("ScaledBy");
353 for (size_t i = 0; i < BaseT::numBins(true, true); ++i) {
354 BaseT::bin(i) += dbn.bin(i);
355 }
356 BaseT::maskBins(dbn.maskedBins(), true);
357 return *this;
358 }
void rmAnnotation(const std::string &name)
Delete an annotation by name.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
void maskBins(const std::vector< size_t > &indicesToMask, const bool status=true) noexcept
Mask a range of bins.

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), YODA::AnalysisObject::hasAnnotation(), YODA::BinnedStorage< BinContentT, AxisT >::maskBins(), YODA::BinnedStorage< BinContentT, AxisT >::maskedBins(), YODA::BinnedStorage< BinContentT, AxisT >::numBins(), and YODA::AnalysisObject::rmAnnotation().

◆ operator+=() [2/2]

template<size_t DbnN, typename... AxisT>
DbnStorage & YODA::DbnStorage< DbnN, AxisT >::operator+= ( DbnStorage< DbnN, AxisT > &&  dbn)
inline

Definition at line 360 of file BinnedDbn.h.

360 {
361 if (*this != dbn)
362 throw BinningError("Arithmetic operation requires compatible binning!");
363 if (AO::hasAnnotation("ScaledBy")) AO::rmAnnotation("ScaledBy");
364 for (size_t i = 0; i < BaseT::numBins(true, true); ++i) {
365 BaseT::bin(i) += std::move(dbn.bin(i));
366 }
367 BaseT::maskBins(dbn.maskedBins(), true);
368 return *this;
369 }

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), YODA::AnalysisObject::hasAnnotation(), YODA::BinnedStorage< BinContentT, AxisT >::maskBins(), YODA::BinnedStorage< BinContentT, AxisT >::numBins(), and YODA::AnalysisObject::rmAnnotation().

◆ operator-=() [1/2]

template<size_t DbnN, typename... AxisT>
DbnStorage & YODA::DbnStorage< DbnN, AxisT >::operator-= ( const DbnStorage< DbnN, AxisT > &  dbn)
inline

Subtract one DbnStorages from another one.

Note
Subtracting DbnStorages will unset any ScaledBy attribute from previous calls to scale or normalize.

Definition at line 376 of file BinnedDbn.h.

376 {
377 if (*this != dbn)
378 throw BinningError("Arithmetic operation requires compatible binning!");
379 if (AO::hasAnnotation("ScaledBy")) AO::rmAnnotation("ScaledBy");
380 for (size_t i = 0; i < BaseT::numBins(true, true); ++i) {
381 BaseT::bin(i) -= dbn.bin(i);
382 }
383 BaseT::maskBins(dbn.maskedBins(), true);
384 return *this;
385 }

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), YODA::AnalysisObject::hasAnnotation(), YODA::BinnedStorage< BinContentT, AxisT >::maskBins(), YODA::BinnedStorage< BinContentT, AxisT >::maskedBins(), YODA::BinnedStorage< BinContentT, AxisT >::numBins(), and YODA::AnalysisObject::rmAnnotation().

◆ operator-=() [2/2]

template<size_t DbnN, typename... AxisT>
DbnStorage & YODA::DbnStorage< DbnN, AxisT >::operator-= ( DbnStorage< DbnN, AxisT > &&  dbn)
inline

Definition at line 387 of file BinnedDbn.h.

387 {
388 if (*this != dbn)
389 throw BinningError("Arithmetic operation requires compatible binning!");
390 if (AO::hasAnnotation("ScaledBy")) AO::rmAnnotation("ScaledBy");
391 for (size_t i = 0; i < BaseT::numBins(true, true); ++i) {
392 BaseT::bin(i) -= std::move(dbn.bin(i));
393 }
394 BaseT::maskBins(dbn.maskedBins(), true);
395 return *this;
396 }

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), YODA::AnalysisObject::hasAnnotation(), YODA::BinnedStorage< BinContentT, AxisT >::maskBins(), YODA::BinnedStorage< BinContentT, AxisT >::numBins(), and YODA::AnalysisObject::rmAnnotation().

◆ operator=() [1/2]

template<size_t DbnN, typename... AxisT>
DbnStorage & YODA::DbnStorage< DbnN, AxisT >::operator= ( const DbnStorage< DbnN, AxisT > &  dbn)
inlinenoexcept

Copy assignment.

Definition at line 325 of file BinnedDbn.h.

325 {
326 if (this != &dbn) {
329 }
330 return *this;
331 }
virtual AnalysisObject & operator=(const AnalysisObject &ao) noexcept
Default copy assignment operator.
FillableStorage & operator=(const FillableStorage &other) noexcept
Copy assignment.

References YODA::AnalysisObject::operator=(), and YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::operator=().

◆ operator=() [2/2]

template<size_t DbnN, typename... AxisT>
DbnStorage & YODA::DbnStorage< DbnN, AxisT >::operator= ( DbnStorage< DbnN, AxisT > &&  dbn)
inlinenoexcept

Move assignment.

Definition at line 334 of file BinnedDbn.h.

334 {
335 if (this != &dbn) {
337 BaseT::operator = (std::move(dbn));
338 }
339 return *this;
340 }

References YODA::AnalysisObject::operator=(), and YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::operator=().

◆ rebin() [1/2]

template<size_t DbnN, typename... AxisT>
template<size_t axisN>
void YODA::DbnStorage< DbnN, AxisT >::rebin ( const std::vector< typename BinningT::template getAxisT< axisN >::EdgeT > &  newedges)
inline

Overloaded alias for rebinTo.

Definition at line 320 of file BinnedDbn.h.

320 {
321 rebinTo<axisN>(newedges);
322 }

◆ rebin() [2/2]

template<size_t DbnN, typename... AxisT>
template<size_t axisN>
void YODA::DbnStorage< DbnN, AxisT >::rebin ( unsigned int  n,
size_t  begin = 1,
size_t  end = UINT_MAX 
)
inline

Overloaded alias for rebinBy.

Definition at line 287 of file BinnedDbn.h.

287 {
288 rebinBy<axisN>(n, begin, end);
289 }

◆ rebinBy()

template<size_t DbnN, typename... AxisT>
template<size_t axisN>
void YODA::DbnStorage< DbnN, AxisT >::rebinBy ( unsigned int  n,
size_t  begin = 1,
size_t  end = UINT_MAX 
)
inline

Merge every group of n bins, from start to end inclusive.

If the number of bins is not a multiple of n, the last m < n bins on the RHS will also be merged, as the closest possible approach to factor
rebinning everywhere.

Note
Only visible bins are being rebinned. Underflow (index = 0) and overflow (index = numBins() + 1) are not included.

Definition at line 271 of file BinnedDbn.h.

271 {
272 if (n < 1) throw UserError("Rebinning requested in groups of 0!");
273 if (!begin) throw UserError("Visible bins start with index 1!");
274 if (end > BaseT::numBinsAt(axisN)+1) end = BaseT::numBinsAt(axisN) + 1;
275 for (size_t m = begin; m < end; ++m) {
276 if (m > BaseT::numBinsAt(axisN)+1) break; // nothing to be done
277 const size_t myend = (m+n-1 < BaseT::numBinsAt(axisN)+1) ? m+n-1 : BaseT::numBinsAt(axisN);
278 if (myend > m) {
279 BaseT::template mergeBins<axisN>({m, myend});
280 end -= myend-m; //< reduce upper index by the number of removed bins
281 }
282 }
283 }
size_t numBinsAt(const size_t axisN, const bool includeOverflows=false) const noexcept
Number of bins in the BinnedStorage.

References YODA::BinnedStorage< BinContentT, AxisT >::numBinsAt().

◆ rebinTo()

template<size_t DbnN, typename... AxisT>
template<size_t axisN>
void YODA::DbnStorage< DbnN, AxisT >::rebinTo ( const std::vector< typename BinningT::template getAxisT< axisN >::EdgeT > &  newedges)
inline

Rebin to the given list of bin edges.

Definition at line 293 of file BinnedDbn.h.

293 {
294 if (newedges.size() < 2)
295 throw UserError("Requested rebinning to an edge list which defines no bins");
296 using thisAxisT = typename BinningT::template getAxisT<axisN>;
297 using thisEdgeT = typename thisAxisT::EdgeT;
298 // get list of shared edges
299 thisAxisT& oldAxis = BaseT::_binning.template axis<axisN>();
300 const thisAxisT newAxis(newedges);
301 const std::vector<thisEdgeT> eshared = oldAxis.sharedEdges(newAxis);
302 if (eshared.size() != newAxis.edges().size())
303 throw BinningError("Requested rebinning to incompatible edges");
304 // loop over new lower bin edges (= first bin index of merge range)
305 for (size_t begin = 0; begin < eshared.size() - 1; ++begin) {
306 // find index of upper edge along old axis
307 // (subtracting 1 gives index of last bin to be merged)
308 size_t end = oldAxis.index(eshared[begin+1]) - 1;
309 // if the current edge is the last visible edge before the overflow
310 // merge the remaining bins into the overflow
311 if (begin == newAxis.numBins(true)-1) end = oldAxis.numBins(true)-1;
312 // merge this range
313 if (end > begin) BaseT::template mergeBins<axisN>({begin, end});
314 if (eshared.size() == oldAxis.edges().size()) break; // we're done
315 }
316 }

◆ reset()

template<size_t DbnN, typename... AxisT>
void YODA::DbnStorage< DbnN, AxisT >::reset ( )
inlinevirtualnoexcept

Reset the histogram.

Keep the binning but set all bin contents and related quantities to zero

Implements YODA::AnalysisObject.

Definition at line 406 of file BinnedDbn.h.

406{ BaseT::reset(); }

References YODA::FillableStorage< DbnN, Dbn< DbnN >, AxisT... >::reset().

◆ rms()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::rms ( size_t  axisN,
const bool  includeOverflows = true 
) const
inlinenoexcept

Calculates the RMS at axis.

Definition at line 596 of file BinnedDbn.h.

596 {
597 Dbn<DbnN> dbn;
598 for (const auto& b : BaseT::bins(includeOverflows))
599 dbn += b;
600 return dbn.RMS(axisN+1);
601 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), and YODA::DbnBase< N >::RMS().

◆ scale()

template<size_t DbnN, typename... AxisT>
void YODA::DbnStorage< DbnN, AxisT >::scale ( const size_t  i,
const double  scalefactor 
)
inlinenoexcept

Rescale as if all fill weights had been different by factor scalefactor along dimension i.

Definition at line 242 of file BinnedDbn.h.

242 {
243 setAnnotation("ScaledBy", annotation<double>("ScaledBy", 1.0) * scalefactor);
244 for (auto& bin : BaseT::_bins) {
245 bin.scale(i, scalefactor);
246 }
247 }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name (templated for remaining types)

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), and YODA::AnalysisObject::setAnnotation().

Referenced by YODA::DbnStorage< DbnN, AxisT >::mkEstimate().

◆ scaleW()

template<size_t DbnN, typename... AxisT>
void YODA::DbnStorage< DbnN, AxisT >::scaleW ( const double  scalefactor)
inlinevirtualnoexcept

Rescale as if all fill weights had been different by factor scalefactor.

Implements YODA::Fillable.

Definition at line 234 of file BinnedDbn.h.

234 {
235 setAnnotation("ScaledBy", annotation<double>("ScaledBy", 1.0) * scalefactor);
236 for (auto& bin : BaseT::_bins) {
237 bin.scaleW(scalefactor);
238 }
239 }

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), and YODA::AnalysisObject::setAnnotation().

Referenced by YODA::DbnStorage< DbnN, AxisT >::normalize().

◆ serializeContent()

template<size_t DbnN, typename... AxisT>
std::vector< double > YODA::DbnStorage< DbnN, AxisT >::serializeContent ( bool  fixed_length = false) const
inlinevirtualnoexcept

Content serialisation for MPI reduce operations.

Implements YODA::AnalysisObject.

Definition at line 716 of file BinnedDbn.h.

716 {
717 std::vector<double> rtn;
718 const size_t nBins = BaseT::numBins(true, true);
719 rtn.reserve(nBins * Dbn<DbnN>::DataSize::value);
720 for (size_t i = 0; i < nBins; ++i) {
721 std::vector<double> bdata = BaseT::bin(i)._serializeContent();
722 rtn.insert(std::end(rtn),
723 std::make_move_iterator(std::begin(bdata)),
724 std::make_move_iterator(std::end(bdata)));
725 }
726 return rtn;
727 }

References YODA::BinnedStorage< BinContentT, AxisT >::bin(), and YODA::BinnedStorage< BinContentT, AxisT >::numBins().

◆ stdDev()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::stdDev ( size_t  axisN,
const bool  includeOverflows = true 
) const
inlinenoexcept

Calculates the standard deviation at axis.

Definition at line 583 of file BinnedDbn.h.

583 {
584 return std::sqrt(variance(axisN, includeOverflows));
585 }
double variance(size_t axisN, const bool includeOverflows=true) const noexcept
Calculates the variance at axis.
Definition BinnedDbn.h:575

References YODA::DbnStorage< DbnN, AxisT >::variance().

◆ stdErr()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::stdErr ( size_t  axisN,
const bool  includeOverflows = true 
) const
inlinenoexcept

Calculates the standard error at axis.

Definition at line 588 of file BinnedDbn.h.

588 {
589 Dbn<DbnN> dbn;
590 for (const auto& b : BaseT::bins(includeOverflows))
591 dbn += b;
592 return dbn.stdErr(axisN+1);
593 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), and YODA::DbnBase< N >::stdErr().

◆ sumW()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::sumW ( const bool  includeOverflows = true) const
inlinevirtualnoexcept

Calculates sum of weights in histo.

Implements YODA::Fillable.

Definition at line 522 of file BinnedDbn.h.

522 {
523 double sumw = 0;
524 for (const auto& b : BaseT::bins(includeOverflows))
525 sumw += b.sumW();
526 return sumw;
527 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins().

Referenced by YODA::DbnStorage< DbnN, AxisT >::integral(), YODA::WriterYODA1::writeHisto1D(), YODA::WriterYODA1::writeHisto2D(), YODA::WriterYODA1::writeProfile1D(), and YODA::WriterYODA1::writeProfile2D().

◆ sumW2()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::sumW2 ( const bool  includeOverflows = true) const
inlinevirtualnoexcept

Calculates sum of squared weights in histo.

Implements YODA::Fillable.

Definition at line 530 of file BinnedDbn.h.

530 {
531 double sumw2 = 0;
532 for (const auto& b : BaseT::bins(includeOverflows))
533 sumw2 += b.sumW2();
534 return sumw2;
535 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins().

Referenced by YODA::DbnStorage< DbnN, AxisT >::integralError(), YODA::WriterYODA1::writeHisto1D(), YODA::WriterYODA1::writeHisto2D(), YODA::WriterYODA1::writeProfile1D(), and YODA::WriterYODA1::writeProfile2D().

◆ sumWA()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::sumWA ( const size_t  dim,
const bool  includeOverflows = true 
) const
inline

Calculates first moment along axis dim in histo.

Definition at line 538 of file BinnedDbn.h.

538 {
539 if (dim >= DbnN) throw RangeError("Invalid axis int, must be in range 0..dim-1");
540 double sumwa = 0;
541 for (const auto& b : BaseT::bins(includeOverflows))
542 sumwa += b.sumW(dim+1);
543 return sumwa;
544 }
size_t dim() const noexcept
Total dimension of the object (number of axes + filled value)
Definition BinnedDbn.h:417

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), and YODA::DbnStorage< DbnN, AxisT >::dim().

Referenced by YODA::WriterYODA1::writeHisto1D(), YODA::WriterYODA1::writeHisto2D(), YODA::WriterYODA1::writeProfile1D(), and YODA::WriterYODA1::writeProfile2D().

◆ sumWA2()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::sumWA2 ( const size_t  dim,
const bool  includeOverflows = true 
) const
inline

Calculates second moment along axis dim in histo.

Definition at line 547 of file BinnedDbn.h.

547 {
548 if (dim >= DbnN) throw RangeError("Invalid axis int, must be in range 0..dim-1");
549 double sumwa2 = 0;
550 for (const auto& b : BaseT::bins(includeOverflows))
551 sumwa2 += b.sumW2(dim+1);
552 return sumwa2;
553 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), and YODA::DbnStorage< DbnN, AxisT >::dim().

Referenced by YODA::WriterYODA1::writeHisto1D(), YODA::WriterYODA1::writeHisto2D(), YODA::WriterYODA1::writeProfile1D(), and YODA::WriterYODA1::writeProfile2D().

◆ variance()

template<size_t DbnN, typename... AxisT>
double YODA::DbnStorage< DbnN, AxisT >::variance ( size_t  axisN,
const bool  includeOverflows = true 
) const
inlinenoexcept

Calculates the variance at axis.

Definition at line 575 of file BinnedDbn.h.

575 {
576 Dbn<DbnN> dbn;
577 for (const auto& b : BaseT::bins(includeOverflows))
578 dbn += b;
579 return dbn.variance(axisN+1);
580 }

References YODA::BinnedStorage< BinContentT, AxisT >::bins(), and YODA::DbnBase< N >::variance().

Referenced by YODA::DbnStorage< DbnN, AxisT >::stdDev().

◆ widths()

template<size_t DbnN, typename... AxisT>
template<size_t I, typename E = typename BinningT::template getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, std::vector< E > > YODA::DbnStorage< DbnN, AxisT >::widths ( const bool  includeOverflows = false) const
inlinenoexcept

Templated version to get bin widths of axis N by reference.

Overflows are included depending on includeOverflows Needed by axis-specific version from AxisMixin

Note
This version is only supported for continuous axes.

Definition at line 436 of file BinnedDbn.h.

436 {
437 return BaseT::_binning.template widths<I>(includeOverflows);
438 }

The documentation for this class was generated from the following file: