ALERT
Loading...
Searching...
No Matches
fhist.h
1/*************************************************
2 * Class for 1D histograms
3 *
4 * @author Felix Touchte Codjo
5 * @date November 13,2024
6 * **********************************************/
7
8#ifndef FELIX_HIST_H
9#define FELIX_HIST_H
10
11#include <vector>
12
13class fhist1D {
14 const char * title;
15 int nbins;
16 double xmin;
17 double xmax;
18 double binWidth;
19 unsigned long int entriesAll = 0;
20 std::vector<double> xarray;
21 std::vector<int> warray;
22 unsigned long int underflow = 0;
23 unsigned long int overflow = 0;
24
25 // Statistic quantities
26 bool flagStatOverFlows = false;
27 unsigned long int entries = 0;
28
36 std::vector<double> stats;
37 unsigned long int wmin = 0;
38 unsigned long int wmax = 0;
39
40 public :
41 fhist1D(const char * _title, int _nbins, double _xmin, double _xmax);
42 void Fill(double val);
43 int GetBinNumber(double val);
44 int GetWeight(int bin);
45 double GetCentralValue(int bin);
46 std::vector<double> GetXarray();
47 std::vector<int> GetWarray();
48
49 // Statistics
50 double GetMean();
51 double GetStdev();
52
53 void SetFlagStatOverFlows(bool _flagStatOverFlows);
54
55 void Print();
56 void DrawContour(const char * filename);
57};
58
59class fhist2D {
60 const char * title;
61 int nbinsx;
62 double xmin;
63 double xmax;
64 int nbinsy;
65 double ymin;
66 double ymax;
67 double binwx;
68 double binwy;
69 unsigned long int entriesAll = 0;
70
71 double * xarray = nullptr;
72 double * yarray = nullptr;
73 double ** warray = nullptr;
74
75 unsigned long int xunderflow = 0;
76 unsigned long int xoverflow = 0;
77 unsigned long int yunderflow = 0;
78 unsigned long int yoverflow = 0;
79
80 bool flagStatOverFlows = false;
81
82 unsigned long int entries = 0;
83
94 double * stats = nullptr;
95
96 public :
97 fhist2D(const char * _title, int _nbinsx, double _xmin, double _xmax, int _nbinsy, double _ymin, double _ymax);
98 fhist2D(const fhist2D & hist);
99 ~fhist2D();
100 void Fill(double xval, double yval);
101 int GetBinNumberX(double xval) const;
102 int GetBinNumberY(double yval) const;
103 int GetWeightXY(int xbin, int ybin) const;
104 void GetCentralValueXY(int xbin, int ybin, double & xval, double & yval) const;
105
106 double CetXmean() const;
107 double GetYmean() const;
108 double GetXstdev() const;
109 double GetYstdev() const;
110 double GetCov() const;
111
112 void SetFlagStatOverFlows(bool _flagStatOverFlows);
113
114 void Print() const;
115
116 fhist1D ProjectionX(int ystart, int yend) const;
117 fhist1D ProjectionY(int xstart, int xend) const;
118};
119
120#endif
Definition fhist.h:13
double GetCentralValue(int bin)
Return the center value of this bin.
Definition fhist.cpp:94
double GetMean()
Return the mean of the distribution.
Definition fhist.cpp:107
int GetWeight(int bin)
Return the number of entries in this bin.
Definition fhist.cpp:87
void DrawContour(const char *filename)
Definition fhist.cpp:139
void Print()
Print detailled informations on screen.
Definition fhist.cpp:126
void Fill(double val)
Add a new entry in the histogram.
Definition fhist.cpp:28
std::vector< int > GetWarray()
Return the array of weights.
Definition fhist.cpp:104
double GetStdev()
Return the standard deviation of the distribution.
Definition fhist.cpp:115
std::vector< double > GetXarray()
Return the array of values They are the center of each bins.
Definition fhist.cpp:101
fhist1D(const char *_title, int _nbins, double _xmin, double _xmax)
Constructor.
Definition fhist.cpp:18
void SetFlagStatOverFlows(bool _flagStatOverFlows)
If true, over/underflow values taken into account in the statistics.
Definition fhist.cpp:123
int GetBinNumber(double val)
Return the bin number in which val falls.
Definition fhist.cpp:63
Definition fhist.h:59
int GetBinNumberY(double yval) const
Return the x bin number in which xval falls.
Definition fhist.cpp:331
int GetBinNumberX(double xval) const
Return the x bin number in which xval falls.
Definition fhist.cpp:309
void Fill(double xval, double yval)
Definition fhist.cpp:274