14#include <boost/histogram.hpp>
16#include <boost/histogram/serialization.hpp>
17#include <boost/serialization/access.hpp>
18#include <boost/serialization/base_object.hpp>
19#include <boost/serialization/string.hpp>
20#include <boost/serialization/vector.hpp>
30#include <fmt/format.h>
39 using Axes2D_t = std::tuple<RegularAxis_t, RegularAxis_t>;
67 using Flags_t = std::underlying_type_t<EHistFlag>;
79 fFlags = std::stoi(msg,
nullptr, 16);
116 size_t pos = msg.find_last_of(
'!');
117 if (
pos != msg.npos) {
118 return std::make_pair(msg.substr(0,
pos), msg.substr(
pos + 1));
121 return std::make_pair(msg,
"");
127 template<
class Archive>
182 template<
class Archive>
234 template<
class Archive>
237 ar& boost::serialization::base_object<TotalSums1D>(*
this);
250 template<
class Axes,
class Storage,
class TotalSums>
253 using Hist_t = bh::histogram<Axes, Storage>;
254 static constexpr unsigned Rank = std::tuple_size_v<Axes>;
262 template<EAxis A, unsigned IA = static_cast<unsigned>(A), std::enable_if_t<(IA < Rank), bool> =
true>
265 return fHistogram.template axis<IA>().value(0.);
270 template<EAxis A, unsigned IA = static_cast<unsigned>(A), std::enable_if_t<(IA < Rank), bool> =
true>
279 template<EAxis A, unsigned IA = static_cast<unsigned>(A), std::enable_if_t<(IA < Rank), bool> =
true>
316 template<
unsigned RankCheck = Rank, std::enable_if_t<(RankCheck > 1),
bool> =
true>
323 template<
unsigned RankCheck = Rank, std::enable_if_t<(RankCheck > 1),
bool> =
true>
330 template<
unsigned RankCheck = Rank, std::enable_if_t<(RankCheck > 1),
bool> =
true>
411 inline static int GetBinBH(uint32_t iBin) {
return (iBin > 0) ? iBin - 1 : -1; }
422 template<
class Archive>
426 ar& boost::serialization::base_object<TotalSums>(*
this);
450 H1D(
const std::string& name,
const std::string& title, uint32_t nBins,
double xMin,
double xMax)
479 if (iBin == 0 || iBin >
static_cast<int>(
GetNbinsX())) {
483 BaseH1D::UpdateTotalSums(
x, w);
502 template<
class Archive>
505 ar& boost::serialization::base_object<BaseH1D>(*
this);
522 H2D(
const std::string& name,
const std::string& title, uint32_t nBinsX,
double xMin,
double xMax, uint32_t nBinsY,
523 double yMin,
double yMax)
549 int Fill(
double x,
double y,
double w = 1.)
555 uint32_t iBinX = iBin % (
GetNbinsX() + 2);
559 uint32_t iBinY = iBin / (
GetNbinsX() + 2);
564 BaseH2D::UpdateTotalSums(
x,
y, w);
595 template<
class Archive>
598 ar& boost::serialization::base_object<BaseH2D>(*
this);
617 Prof1D(
const std::string& name,
const std::string& title, uint32_t nBinsX,
double xMin,
double xMax,
618 double yMin = 0.,
double yMax = 0.)
645 int Fill(
double x,
double y,
double w = 1.)
652 auto cellIt =
fHistogram(
x, bh::sample(
y), bh::weight(w));
655 if (iBin == 0 || iBin >
static_cast<int>(
GetNbinsX())) {
659 BaseProf1D::UpdateTotalSums(
x, w);
688 template<
class Archive>
691 ar& boost::serialization::base_object<BaseProf1D>(*
this);
716 Prof2D(
const std::string& name,
const std::string& title, uint32_t nBinsX,
double xMin,
double xMax,
717 uint32_t nBinsY,
double yMin,
double yMax,
double zMin = 0.,
double zMax = 0.)
746 int Fill(
double x,
double y,
double z,
double w = 1.)
753 auto cellIt =
fHistogram(
x,
y, bh::sample(z), bh::weight(w));
757 uint32_t iBinX = iBin % (
GetNbinsX() + 2);
761 uint32_t iBinY = iBin / (
GetNbinsX() + 2);
766 BaseProf2D::UpdateTotalSums(
x,
y, w);
811 template<
class Archive>
814 ar& boost::serialization::base_object<BaseProf2D>(*
this);
Custom accumulators for boost::histogram (header)
Data class with information on a STS local track.
H1D & operator=(H1D &&)=default
Move assignment operator.
H1D(const H1D &)=default
Copy constructor.
double GetBinError(uint32_t iBin) const
Gets bin error.
H1D()=default
Default constructor.
auto GetBinAccumulator(uint32_t iBin) const
Gets underlying bin accumulator.
void serialize(Archive &ar, const unsigned int)
int Fill(double x, double w=1.)
Fills histogram.
H1D & operator=(const H1D &)=default
Copy assignment operator.
H1D(const std::string &name, const std::string &title, uint32_t nBins, double xMin, double xMax)
Constructor for 1D-histogram.
friend class boost::serialization::access
Serialization function.
double GetBinContent(uint32_t iBin) const
Gets bin content.
H1D(H1D &&)=default
Move constructor.
H2D(const std::string &name, const std::string &title, uint32_t nBinsX, double xMin, double xMax, uint32_t nBinsY, double yMin, double yMax)
Constructor for 2D-histogram.
double GetBinError(uint32_t iBinX, uint32_t iBinY) const
Gets bin error.
H2D & operator=(H2D &&)=default
Move assignment operator.
H2D()=default
Default constructor.
auto GetBinAccumulator(uint32_t iBinX, uint32_t iBinY) const
Gets underlying bin accumulator.
H2D(const H2D &)=default
Copy constructor.
void serialize(Archive &ar, const unsigned int)
double GetBinContent(uint32_t iBinX, uint32_t iBinY) const
Gets bin content.
friend class boost::serialization::access
Serialization rule.
H2D(H2D &&)=default
Move constructor.
int Fill(double x, double y, double w=1.)
Fills histogram.
H2D & operator=(const H2D &)=default
Copy assignment operator.
Interface to a histogram/profile.
const std::string & GetTitle() const
Gets title.
static int GetBinBH(uint32_t iBin)
Gets bin index in underlying boost histogram.
static constexpr unsigned Rank
std::string fTitle
Title of the histogram.
uint32_t GetAxisNbins() const
Gets number of bins in axis.
std::string fName
Name of the histogram.
void SetName(const std::string &name)
Sets name.
void serialize(Archive &ar, const unsigned int)
Serialization rule.
uint32_t GetNbinsY() const
Gets number of bins for y axis.
double GetMaximum() const
Gets maximum value.
double GetMaxY() const
Gets y-axis lower bound.
double GetAxisMin() const
Gets range lower bound of the selected axis.
void SetFlag(EHistFlag key, bool flag=true)
Get flag.
Histogram(const Hist_t &bhist, const std::string &name, const std::string title)
Constructor.
void Reset()
Resets the histogram.
bh::histogram< Axes, Storage > Hist_t
bool GetFlag(EHistFlag key) const
Get flag.
HistogramMetadata fMetadata
Meta-data for histogram.
double GetAxisMax() const
Gets range upper bound of the selected axis.
Histogram()=default
String representation of the histogram/profile.
Hist_t fHistogram
Underlying boost histogram.
void SetTitle(const std::string &title)
Sets title.
~Histogram()=default
Destructor.
Histogram(const Histogram< Axes, Storage, TotalSums > &h)=default
Copy constructor.
const std::string & GetName() const
Gets name.
double GetMinY() const
Gets y-axis lower bound.
double GetMaxX() const
Gets x-axis lower bound.
double GetEntries() const
Gets number of entries.
friend class boost::serialization::access
double GetMinimum() const
Gets minimum value.
double GetMinX() const
Gets x-axis lower bound.
std::string GetMetadataString() const
Gets metadata string.
int fEntries
Number of histogram entries.
uint32_t GetNbinsX() const
Gets number of bins for x axis.
const HistogramMetadata & GetMetadata() const
Gets metadata instance.
double fYmin
Lower bound of the profile y-axis.
double GetMaxY() const
Gets y-axis lower bound.
Prof1D(const Prof1D &)=default
Copy constructor.
Prof1D & operator=(const Prof1D &)=default
Copy assignment operator.
auto GetBinAccumulator(uint32_t iBin) const
Gets underlying bin accumulator.
double fYmax
Upper bound of the profile y-axis.
double GetMinY() const
Gets y-axis lower bound.
Prof1D(Prof1D &&)=default
Move constructor.
Prof1D(const std::string &name, const std::string &title, uint32_t nBinsX, double xMin, double xMax, double yMin=0., double yMax=0.)
Constructor for 2D-histogram.
void serialize(Archive &ar, const unsigned int)
Prof1D & operator=(Prof1D &&)=default
Move assignment operator.
int Fill(double x, double y, double w=1.)
Fills histogram.
double GetBinError(uint32_t iBin) const
Gets bin error.
Prof1D()=default
Default constructor.
friend class boost::serialization::access
Serialization rule.
double GetBinContent(uint32_t iBin) const
Gets bin content.
double GetBinCount(uint32_t iBin) const
Gets bin entries.
Prof2D(const Prof2D &)=default
Copy constructor.
int Fill(double x, double y, double z, double w=1.)
Fills histogram.
double GetBinCount(uint32_t iBinX, uint32_t iBinY) const
Gets bin entries.
Prof2D & operator=(const Prof2D &)=default
Copy assignment operator.
double GetBinError(uint32_t iBinX, uint32_t iBinY) const
Gets bin error.
Prof2D(Prof2D &&)=default
Move constructor.
auto GetBinAccumulator(uint32_t iBinX, uint32_t iBinY) const
Gets underlying bin accumulator.
Prof2D(const std::string &name, const std::string &title, uint32_t nBinsX, double xMin, double xMax, uint32_t nBinsY, double yMin, double yMax, double zMin=0., double zMax=0.)
Constructor for 2D-histogram.
Prof2D()=default
Default constructor.
double GetMaxZ() const
Gets z-axis lower bound.
double GetMinZ() const
Gets z-axis lower bound.
void serialize(Archive &ar, const unsigned int)
double fZmin
Lower bound of the profile z-axis.
double fZmax
Upper bound of the profile z-axis.
double GetBinContent(uint32_t iBinX, uint32_t iBinY) const
Gets bin content.
friend class boost::serialization::access
Serialization rule.
Prof2D & operator=(Prof2D &&)=default
Move assignment operator.
Storage for total sums of weights, squared weights, weights over x, weights over squared x.
void Reset()
Resets the sums.
double GetTotSumW() const
Gets total sum of weights.
double fTotSumWX
Total sum (over all bins) of weight over x products.
void UpdateTotalSums(double x, double w)
Updates the sums.
double GetTotSumW2() const
Gets total sum of squared weights.
double GetTotSumWX2() const
Gets total sum of weight over squared x products.
double fTotSumW
Total sum (over all bins) of weights.
double GetTotSumWX() const
Gets total sum of weight over x products.
double fTotSumW2
Total sum (over all bins) of squared weights.
friend class boost::serialization::access
Serialization rule.
double fTotSumWX2
Total sum (over all bins) of weight over square x products.
void serialize(Archive &ar, const unsigned int)
TotalSums1D including storage for total sums of w*x*y, w*y, w*y*y products.
double fTotSumWXY
Total sum (over all bins) of weight over square x products.
double GetTotSumWY() const
Gets total sum of weight over y products.
void serialize(Archive &ar, const unsigned int)
double GetTotSumWY2() const
Gets total sum of weight over squared y products.
double GetTotSumWXY() const
Gets total sum of weight over squared y products.
double fTotSumWY2
Total sum (over all bins) of weight over x over y products.
double fTotSumWY
Total sum (over all bins) of weight over y products.
friend class boost::serialization::access
Serialization rule.
void Reset()
Resets the sums.
void UpdateTotalSums(double x, double y, double w)
Updates the sums.
dense_storage< RootStyleProfileAccumulator< T > > RootStyleProfileStorage
Histogram< Axes2D_t, HistStorage_t, TotalSums2D > BaseH2D
std::tuple< RegularAxis_t > Axes1D_t
EHistFlag
Histogram control flags (bit masks)
@ SetMinimum
Sets minimum to the histogram.
@ StoreVsTsId
Store the histogram vs timeslice index.
@ OmitIntegrated
Omits storing integrated histogram.
bh::axis::regular<> RegularAxis_t
bh::RootStyleProfileStorage< double > ProfStorage_t
std::tuple< RegularAxis_t, RegularAxis_t > Axes2D_t
bh::weight_storage HistStorage_t