diff --git a/algo/qa/Histo1D.cxx b/algo/qa/Histo1D.cxx index 9a02940b615e7f0679d84e2f7108853bf82c7e79..e25b98cd880ac774f5df3eab05e891ba5e29be51 100644 --- a/algo/qa/Histo1D.cxx +++ b/algo/qa/Histo1D.cxx @@ -18,8 +18,10 @@ namespace cbm::algo { // ----- Standard constructor - Histo1D::Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name) + Histo1D::Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name, + const std::string& title) : fName(name) + , fTitle(title) , fNumBins(numBins) , fMinValue(minValue) , fMaxValue(maxValue) @@ -56,7 +58,7 @@ namespace cbm::algo // ----- Content access double Histo1D::Content(uint32_t bin) const { - if (bin >= fNumBins) return 0.; + if (fNumBins < bin) return 0.; else return fContent[bin]; } @@ -115,7 +117,8 @@ namespace cbm::algo { std::stringstream ss; ss << fName << ": bins " << fNumBins << " range " << fMinValue << " to " << fMaxValue << " entries " << fNumEntries - << " mean " << Mean() << " stddev " << Stddev() << " out of range " << fUnderflow << " , " << fOverflow; + << " mean " << Mean() << " stddev " << Stddev() << " out of range " << fUnderflow << " , " << fOverflow + << " title <" << fTitle << ">"; return ss.str(); } diff --git a/algo/qa/Histo1D.h b/algo/qa/Histo1D.h index 7f6b8f35acd18e6cabbe24b3024c3be220652e24..069ffb6ca4559e28f83fde4c9637bb7d5921b1f9 100644 --- a/algo/qa/Histo1D.h +++ b/algo/qa/Histo1D.h @@ -5,6 +5,9 @@ #ifndef ALGO_QA_HISTO1D_H #define ALGO_QA_HISTO1D_H 1 +#include <boost/serialization/access.hpp> +#include <boost/serialization/version.hpp> + #include <cstdint> #include <string> #include <vector> @@ -21,17 +24,19 @@ namespace cbm::algo **/ class Histo1D { public: - /** @brief No default constructor **/ - Histo1D() = delete; - - /** @brief Standard constructor ** @param numBins Number of bins ** @param minValue Lower edge of histogram range ** @param maxValue Upper edge of histogram range ** @param name Histogram name + ** @param title ROOT convention: Histogram title; Axis X title; Axis Y title **/ - Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name = ""); + Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name = "", + const std::string& title = ""); + + + /** @brief Copy constructor: needed for boost serialization of vector of Histo1D **/ + Histo1D(const Histo1D&) = default; /** @brief Destructor **/ @@ -76,6 +81,10 @@ namespace cbm::algo const std::string& Name() const { return fName; } + /** @brief Histogram name **/ + const std::string& Title() const { return fTitle; } + + /** @brief Number of bins **/ uint32_t NumBins() const { return fNumBins; } @@ -89,6 +98,10 @@ namespace cbm::algo double Overflow() const { return fOverflow; } + /** @brief Underflow **/ + double Underflow() const { return fUnderflow; } + + /** @brief Second moment of distribution **/ double Stddev() const; @@ -97,22 +110,37 @@ namespace cbm::algo std::string ToString() const; - /** @brief Underflow **/ - double UnderFlow() const { return fUnderflow; } - - private: - /** Properties **/ - const std::string fName; - const uint32_t fNumBins; - const double fMinValue; - const double fMaxValue; + /** Properties (no need for const if no accessors, avoid really complicated boost serialization) **/ + std::string fName; + std::string fTitle; + uint32_t fNumBins; + double fMinValue; + double fMaxValue; /** Content **/ std::vector<double> fContent = {}; double fUnderflow = 0; double fOverflow = 0; size_t fNumEntries = 0; + + friend class boost::serialization::access; + template<class Archive> + void serialize(Archive& ar, const unsigned int /*version*/) + { + ar& fName; + ar& fTitle; + ar& fNumBins; + ar& fMinValue; + ar& fMaxValue; + ar& fContent; + ar& fUnderflow; + ar& fOverflow; + ar& fNumEntries; + } + + /** @brief Default constructor: needed for boost serialization of vector of Histo1D, need copy ctor call after! **/ + Histo1D() : fName(""), fTitle(""), fNumBins(0), fMinValue(0), fMaxValue(0) {}; }; @@ -128,4 +156,6 @@ namespace cbm::algo } /* namespace cbm::algo */ +BOOST_CLASS_VERSION(cbm::algo::Histo1D, 1) + #endif /* ALGO_QA_HISTO1D_H */