Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
FastHist.h
1/*
2 * FastHist.h
3 *
4 * Created on: 6 cze 2022
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#ifndef HAL_FEATURES_HIST_FASTHIST_H_
10#define HAL_FEATURES_HIST_FASTHIST_H_
11
12#include <TH1.h>
13#include <TH2.h>
14#include <TH3.h>
15#include <TNamed.h>
16
17namespace Hal {
18
19 class FastHist : public TNamed {
20 protected:
21 TString fAxisNameX;
22 TString fAxisNameY;
23 TString fAxisNameZ;
24 TString fTitle;
25 Int_t fBinsNoX;
26 Int_t fBinsNoY;
27 Int_t fBinsNoZ;
28 Int_t fTotalBinsNo;
29 Double_t* fValues; //[fTotalBinsNo]
30
31 public:
32 FastHist(TString name = "", TString title = "");
33 void SetXaxisName(TString name) { fAxisNameX = name; }
34 void SetYaxisName(TString name) { fAxisNameY = name; }
35 void SetZaxisName(TString name) { fAxisNameZ = name; }
36 Int_t GetNbinsX() const { return fBinsNoX; };
37 Int_t GetNbinsY() const { return fBinsNoY; };
38 Int_t GetNbinsZ() const { return fBinsNoZ; };
39 virtual Int_t FindBin(Double_t /*x*/) const { return 0; };
40 virtual Int_t FindBin(Double_t /*x*/, Double_t /*y*/) const { return 0; };
41 virtual Int_t FindBin(Double_t /*x*/, Double_t /*y*/, Double_t /*z*/) const { return 0; };
42 virtual Double_t GetBinContent(Int_t /*i*/) const { return 0; };
43 virtual Double_t GetBinContent(Int_t /*i*/, Int_t /*j*/) const { return 0; };
44 virtual Double_t GetBinContent(Int_t /*i*/, Int_t /*j*/, Int_t /*k*/) const { return 0; };
45 virtual void Fill(Double_t /*x*/, Double_t /*w*/) {};
46 virtual void Fill(Double_t /*x*/, Double_t /*y*/, Double_t /*w*/) {};
47 virtual void Fill(Double_t /*x*/, Double_t /*y*/, Double_t /*z*/, Double_t /*w*/) {};
48 inline void SetRawBinContent(Int_t bin, Double_t w) { fValues[bin] = w; };
49 inline Double_t GetRawBinContent(Int_t bin) const { return fValues[bin]; }
50 inline void IncrementRawBinContent(Int_t bin, Double_t w) { fValues[bin] += w; };
51 virtual TH1* GetTH1() const { return nullptr; };
52 virtual ~FastHist();
53 ClassDef(FastHist, 1);
54 };
55 class FastHist1D : public FastHist {
56 Double_t fStepX;
57 Double_t fMinX;
58 Double_t fMaxX;
59
60 public:
61 FastHist1D(TString name = "", TString title = "", Int_t nbins = 0, Double_t min = 0, Double_t max = 0);
62 Int_t FindBin(Double_t x) const;
63 Double_t GetBinCenterX(Int_t bin) const { return fMinX + (-0.5 + bin) * fStepX; }
64 Double_t GetBinWidthX() const { return 1.0 / fStepX; }
65 void Fill(Double_t x, Double_t w);
66 Double_t GetBinContent(Int_t i) const { return fValues[i]; }
67 virtual TH1* GetTH1() const;
68 virtual ~FastHist1D() {};
69 ClassDef(FastHist1D, 1);
70 };
71
72 class FastHist2D : public FastHist {
73 Double_t fStepX;
74 Double_t fMinX;
75 Double_t fMaxX;
76 Double_t fStepY;
77 Double_t fMinY;
78 Double_t fMaxY;
79
80 public:
81 FastHist2D(TString name = "",
82 TString title = "",
83 Int_t nbinsX = 0,
84 Double_t xmin = 0,
85 Double_t xmax = 0,
86 Int_t nbinsY = 0,
87 Double_t ymin = 0,
88 Double_t ymax = 0);
89 Double_t GetBinContent(Int_t i, Int_t j) const;
90 Int_t FindBin(Double_t x, Double_t y) const;
91 Double_t GetBinCenterX(Int_t bin) const { return fMinX + (-0.5 + bin) * fStepX; }
92 Double_t GetBinWidthX() const { return 1.0 / fStepX; }
93 Double_t GetBinCenterY(Int_t bin) const { return fMinY + (-0.5 + bin) * fStepY; }
94 Double_t GetBinWidthY() const { return 1.0 / fStepY; }
95 void Fill(Double_t x, Double_t y, Double_t w);
96 virtual TH1* GetTH1() const;
97 virtual ~FastHist2D() {};
98 ClassDef(FastHist2D, 1)
99 };
100
101 class FastHist3D : public FastHist {
102 Double_t fStepX;
103 Double_t fMinX;
104 Double_t fMaxX;
105 Double_t fStepY;
106 Double_t fMinY;
107 Double_t fMaxY;
108 Double_t fStepZ;
109 Double_t fMinZ;
110 Double_t fMaxZ;
111 Int_t fBinsYZ;
112
113 public:
114 FastHist3D(TString name = "",
115 TString title = "",
116 Int_t nbinsX = 0,
117 Double_t xmin = 0,
118 Double_t xmax = 0,
119 Int_t nbinsY = 0,
120 Double_t ymin = 0,
121 Double_t ymax = 0,
122 Int_t nbinsZ = 0,
123 Double_t zmin = 0,
124 Double_t zmax = 0);
125 void Fill(Double_t x, Double_t y, Double_t z, Double_t w);
126 Int_t FindBin(Double_t x, Double_t y, Double_t z) const;
127 Double_t GetBinContent(Int_t i, Int_t j, Int_t k) const;
128 Double_t GetBinCenterX(Int_t bin) const { return fMinX + (-0.5 + bin) * fStepX; }
129 Double_t GetBinWidthX() const { return 1.0 / fStepX; }
130 Double_t GetBinCenterY(Int_t bin) const { return fMinY + (-0.5 + bin) * fStepY; }
131 Double_t GetBinWidthY() const { return 1.0 / fStepY; }
132 Double_t GetBinCenterZ(Int_t bin) const { return fMinZ + (-0.5 + bin) * fStepZ; }
133 Double_t GetBinWidthZ() const { return 1.0 / fStepZ; }
134 virtual TH1* GetTH1() const;
135 virtual ~FastHist3D() {};
136 ClassDef(FastHist3D, 1)
137 };
138
139} /* namespace Hal */
140
141#endif /* HAL_FEATURES_HIST_FASTHIST_H_ */