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>;
66 using Flags_t = std::underlying_type_t<EHistFlag>;
78 fFlags = std::stoi(msg,
nullptr, 16);
115 size_t pos = msg.find_last_of(
'!');
116 if (
pos != msg.npos) {
117 return std::make_pair(msg.substr(0,
pos), msg.substr(
pos + 1));
120 return std::make_pair(msg,
"");
126 template<
class Archive>
181 template<
class Archive>
233 template<
class Archive>
236 ar& boost::serialization::base_object<TotalSums1D>(*
this);
249 template<
class Axes,
class Storage,
class TotalSums>
252 using Hist_t = bh::histogram<Axes, Storage>;
253 static constexpr unsigned Rank = std::tuple_size_v<Axes>;
261 template<EAxis A, unsigned IA = static_cast<unsigned>(A), std::enable_if_t<(IA < Rank), bool> =
true>
264 return fHistogram.template axis<IA>().value(0.);
269 template<EAxis A, unsigned IA = static_cast<unsigned>(A), std::enable_if_t<(IA < Rank), bool> =
true>
278 template<EAxis A, unsigned IA = static_cast<unsigned>(A), std::enable_if_t<(IA < Rank), bool> =
true>
315 template<
unsigned RankCheck = Rank, std::enable_if_t<(RankCheck > 1),
bool> =
true>
322 template<
unsigned RankCheck = Rank, std::enable_if_t<(RankCheck > 1),
bool> =
true>
329 template<
unsigned RankCheck = Rank, std::enable_if_t<(RankCheck > 1),
bool> =
true>
410 inline static int GetBinBH(uint32_t iBin) {
return (iBin > 0) ? iBin - 1 : -1; }
421 template<
class Archive>
425 ar& boost::serialization::base_object<TotalSums>(*
this);
449 H1D(
const std::string& name,
const std::string& title, uint32_t nBins,
double xMin,
double xMax)
478 if (iBin == 0 || iBin >
static_cast<int>(
GetNbinsX())) {
482 BaseH1D::UpdateTotalSums(
x, w);
501 template<
class Archive>
504 ar& boost::serialization::base_object<BaseH1D>(*
this);
521 H2D(
const std::string& name,
const std::string& title, uint32_t nBinsX,
double xMin,
double xMax, uint32_t nBinsY,
522 double yMin,
double yMax)
548 int Fill(
double x,
double y,
double w = 1.)
554 uint32_t iBinX = iBin % (
GetNbinsX() + 2);
558 uint32_t iBinY = iBin / (
GetNbinsX() + 2);
563 BaseH2D::UpdateTotalSums(
x,
y, w);
594 template<
class Archive>
597 ar& boost::serialization::base_object<BaseH2D>(*
this);
616 Prof1D(
const std::string& name,
const std::string& title, uint32_t nBinsX,
double xMin,
double xMax,
617 double yMin = 0.,
double yMax = 0.)
644 int Fill(
double x,
double y,
double w = 1.)
651 auto cellIt =
fHistogram(
x, bh::sample(
y), bh::weight(w));
654 if (iBin == 0 || iBin >
static_cast<int>(
GetNbinsX())) {
658 BaseProf1D::UpdateTotalSums(
x, w);
687 template<
class Archive>
690 ar& boost::serialization::base_object<BaseProf1D>(*
this);
715 Prof2D(
const std::string& name,
const std::string& title, uint32_t nBinsX,
double xMin,
double xMax,
716 uint32_t nBinsY,
double yMin,
double yMax,
double zMin = 0.,
double zMax = 0.)
745 int Fill(
double x,
double y,
double z,
double w = 1.)
752 auto cellIt =
fHistogram(
x,
y, bh::sample(z), bh::weight(w));
756 uint32_t iBinX = iBin % (
GetNbinsX() + 2);
760 uint32_t iBinY = iBin / (
GetNbinsX() + 2);
765 BaseProf2D::UpdateTotalSums(
x,
y, w);
810 template<
class Archive>
813 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)
@ 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