CbmRoot
Loading...
Searching...
No Matches
Histo1D.h
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
5#ifndef ALGO_QA_HISTO1D_H
6#define ALGO_QA_HISTO1D_H 1
7
8#include <boost/serialization/access.hpp>
9#include <boost/serialization/version.hpp>
10
11#include <cstdint>
12#include <string>
13#include <vector>
14
15
16namespace cbm::algo
17{
18
25 class Histo1D {
26 public:
34 Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name = "",
35 const std::string& title = "");
36
37
39 Histo1D(const Histo1D&) = default;
40
41
43 virtual ~Histo1D() = default;
44
45
50 void Add(double value, double weight = 1.);
51
52
54 void Clear();
55
56
61 double Content(uint32_t bin) const;
62
63
65 double NumEntries() const { return fNumEntries; }
66
67
69 double MaxValue() const { return fMaxValue; }
70
71
73 double Mean() const;
74
75
77 double MinValue() const { return fMinValue; }
78
79
81 const std::string& Name() const { return fName; }
82
83
85 const std::string& Title() const { return fTitle; }
86
87
89 uint32_t NumBins() const { return fNumBins; }
90
94 Histo1D& operator+=(const Histo1D& other);
95
96
98 double Overflow() const { return fOverflow; }
99
100
102 double Underflow() const { return fUnderflow; }
103
104
106 double Stddev() const;
107
108
110 std::string ToString() const;
111
112
113 private:
115 std::string fName;
116 std::string fTitle;
117 uint32_t fNumBins;
118 double fMinValue;
119 double fMaxValue;
120
122 std::vector<double> fContent = {};
123 double fUnderflow = 0;
124 double fOverflow = 0;
125 size_t fNumEntries = 0;
126
128 template<class Archive>
129 void serialize(Archive& ar, const unsigned int /*version*/)
130 {
131 ar& fName;
132 ar& fTitle;
133 ar& fNumBins;
134 ar& fMinValue;
135 ar& fMaxValue;
136 ar& fContent;
137 ar& fUnderflow;
138 ar& fOverflow;
139 ar& fNumEntries;
140 }
141
143 Histo1D() : fName(""), fTitle(""), fNumBins(0), fMinValue(0), fMaxValue(0){};
144 };
145
146
151 inline Histo1D operator+(Histo1D h1, const Histo1D& h2)
152 {
153 h1 += h2;
154 return h1;
155 }
156
157} /* namespace cbm::algo */
158
159BOOST_CLASS_VERSION(cbm::algo::Histo1D, 1)
160
161#endif /* ALGO_QA_HISTO1D_H */
double Content(uint32_t bin) const
Histogram content in a bin.
Definition Histo1D.cxx:59
std::string fTitle
Definition Histo1D.h:116
void Clear()
Clear histogram contents.
Definition Histo1D.cxx:50
const std::string & Title() const
Histogram name.
Definition Histo1D.h:85
uint32_t NumBins() const
Number of bins.
Definition Histo1D.h:89
double Stddev() const
Second moment of distribution.
Definition Histo1D.cxx:101
const std::string & Name() const
Histogram name.
Definition Histo1D.h:81
uint32_t fNumBins
Definition Histo1D.h:117
void serialize(Archive &ar, const unsigned int)
Definition Histo1D.h:129
virtual ~Histo1D()=default
Destructor.
Histo1D(const Histo1D &)=default
Copy constructor: needed for boost serialization of vector of Histo1D.
double Mean() const
First moment of distribution.
Definition Histo1D.cxx:69
double Overflow() const
Overflow.
Definition Histo1D.h:98
Histo1D & operator+=(const Histo1D &other)
Add another histogram to an existing one.
Definition Histo1D.cxx:85
std::string ToString() const
Properties to string.
Definition Histo1D.cxx:117
void Add(double value, double weight=1.)
Add an entry to the histogram.
Definition Histo1D.cxx:35
double MaxValue() const
Upper edge.
Definition Histo1D.h:69
double Underflow() const
Underflow.
Definition Histo1D.h:102
std::vector< double > fContent
Definition Histo1D.h:122
std::string fName
Definition Histo1D.h:115
Histo1D()
Default constructor: needed for boost serialization of vector of Histo1D, need copy ctor call after!
Definition Histo1D.h:143
friend class boost::serialization::access
Definition Histo1D.h:127
double NumEntries() const
Number of entries.
Definition Histo1D.h:65
double MinValue() const
Lower edge.
Definition Histo1D.h:77
Histo1D operator+(Histo1D h1, const Histo1D &h2)
Adding two histograms.
Definition Histo1D.h:151