13 FastHist::FastHist(TString name, TString title) :
26 FastHist::~FastHist() {
27 if (fValues)
delete[] fValues;
30 FastHist1D::FastHist1D(TString name, TString title, Int_t nbins, Double_t min, Double_t max) : FastHist(name, title) {
33 fValues =
new Double_t[fBinsNoX];
36 fStepX = (fMaxX - fMinX) / nbins;
37 fStepX = 1.0 / fStepX;
39 for (
int i = 0; i < fTotalBinsNo; i++)
41 fTotalBinsNo = fBinsNoX;
44 Int_t FastHist1D::FindBin(Double_t x)
const {
45 Int_t bin = (x - fMinX) * fStepX + 1;
48 }
else if (bin > fBinsNoX - 1) {
54 void FastHist1D::Fill(Double_t x, Double_t w) {
55 Int_t bin = (x - fMinX) * fStepX + 1;
58 }
else if (bin > fBinsNoX - 1) {
64 TH1* FastHist1D::GetTH1()
const {
65 TH1D* h =
new TH1D(GetName(), GetTitle(), fBinsNoX - 2, fMinX, fMaxX);
66 if (fAxisNameX.Length() > 0) h->GetXaxis()->SetTitle(fAxisNameX);
67 if (fAxisNameY.Length() > 0) h->GetYaxis()->SetTitle(fAxisNameY);
68 for (
int i = 0; i < fBinsNoX; i++) {
69 h->SetBinContent(i, fValues[i]);
74 FastHist2D::FastHist2D(TString name,
82 FastHist(name, title) {
83 fBinsNoX = nbinsX + 2;
84 fBinsNoY = nbinsY + 2;
89 fTotalBinsNo = fBinsNoX * fBinsNoY;
90 fValues =
new Double_t[fTotalBinsNo];
91 fStepX = (fMaxX - fMinX) / (Double_t) nbinsX;
92 fStepY = (fMaxY - fMinY) / (Double_t) nbinsY;
93 fStepX = 1.0 / fStepX;
94 fStepY = 1.0 / fStepY;
95 for (
int i = 0; i < fTotalBinsNo; i++)
99 Int_t FastHist2D::FindBin(Double_t x, Double_t y)
const {
100 Int_t binX = (x - fMinX) * fStepX + 1;
101 Int_t binY = (y - fMinY) * fStepY + 1;
105 }
else if (binX + 1 > fBinsNoX) {
110 }
else if (binY + 1 > fBinsNoY) {
113 return binX * fBinsNoY + binY;
116 void FastHist2D::Fill(Double_t x, Double_t y, Double_t w) {
117 Int_t binX = (x - fMinX) * fStepX + 1;
118 Int_t binY = (y - fMinY) * fStepY + 1;
122 }
else if (binX + 1 > fBinsNoX) {
127 }
else if (binY + 1 > fBinsNoY) {
130 fValues[binX * fBinsNoY + binY] += w;
133 Double_t FastHist2D::GetBinContent(Int_t i, Int_t j)
const {
return fValues[i * fBinsNoY + j]; }
135 TH1* FastHist2D::GetTH1()
const {
136 TH2D* h =
new TH2D(GetName(), GetTitle(), fBinsNoX - 2, fMinX, fMaxX, fBinsNoY - 2, fMinY, fMaxY);
137 if (fAxisNameX.Length() > 0) h->GetXaxis()->SetTitle(fAxisNameX);
138 if (fAxisNameY.Length() > 0) h->GetYaxis()->SetTitle(fAxisNameY);
139 if (fAxisNameZ.Length() > 0) h->GetZaxis()->SetTitle(fAxisNameZ);
140 for (
int i = 0; i < fBinsNoX; i++) {
141 for (
int j = 0; j < fBinsNoY; j++) {
142 h->SetBinContent(i, j, fValues[i * fBinsNoY + j]);
148 FastHist3D::FastHist3D(TString name,
159 FastHist(name, title) {
160 fBinsNoX = nbinsX + 2;
161 fBinsNoY = nbinsY + 2;
162 fBinsNoZ = nbinsZ + 2;
169 fTotalBinsNo = fBinsNoX * fBinsNoY * fBinsNoZ;
170 fValues =
new Double_t[fTotalBinsNo];
171 fStepX = (fMaxX - fMinX) / nbinsX;
172 fStepY = (fMaxY - fMinY) / nbinsY;
173 fStepZ = (fMaxZ - fMinZ) / nbinsZ;
174 fStepX = 1.0 / fStepX;
175 fStepY = 1.0 / fStepY;
176 fStepZ = 1.0 / fStepZ;
177 fBinsYZ = fBinsNoY * fBinsNoZ;
178 for (
int i = 0; i < fTotalBinsNo; i++)
182 Int_t FastHist3D::FindBin(Double_t x, Double_t y, Double_t z)
const {
183 Int_t binX = (x - fMinX) * fStepX + 1;
184 Int_t binY = (y - fMinY) * fStepY + 1;
185 Int_t binZ = (z - fMinZ) * fStepZ + 1;
188 }
else if (binX + 1 > fBinsNoX) {
193 }
else if (binY + 1 > fBinsNoY) {
198 }
else if (binZ + 1 > fBinsNoZ) {
201 return binX * fBinsYZ + binY * fBinsNoZ + binZ;
205 void FastHist3D::Fill(Double_t x, Double_t y, Double_t z, Double_t w) {
206 Int_t binX = (x - fMinX) * fStepX + 1;
207 Int_t binY = (y - fMinY) * fStepY + 1;
208 Int_t binZ = (z - fMinZ) * fStepZ + 1;
211 }
else if (binX + 1 > fBinsNoX) {
216 }
else if (binY + 1 > fBinsNoY) {
221 }
else if (binZ + 1 > fBinsNoZ) {
225 fValues[binX * fBinsYZ + binY * fBinsNoZ + binZ] += w;
227 Double_t FastHist3D::GetBinContent(Int_t i, Int_t j, Int_t k)
const {
return fValues[i * fBinsYZ + j * fBinsNoZ + k]; }
229 TH1* FastHist3D::GetTH1()
const {
230 TH3D* h =
new TH3D(GetName(), GetTitle(), fBinsNoX - 2, fMinX, fMaxX, fBinsNoY - 2, fMinY, fMaxY, fBinsNoZ - 2, fMinZ, fMaxZ);
231 if (fAxisNameX.Length() > 0) h->GetXaxis()->SetTitle(fAxisNameX);
232 if (fAxisNameY.Length() > 0) h->GetYaxis()->SetTitle(fAxisNameY);
233 if (fAxisNameZ.Length() > 0) h->GetZaxis()->SetTitle(fAxisNameZ);
234 for (
int i = 0; i < fBinsNoX; i++) {
235 for (
int j = 0; j < fBinsNoY; j++) {
236 for (
int k = 0; k < fBinsNoZ; k++) {
237 h->SetBinContent(i, j, k, fValues[i * fBinsYZ + j * fBinsNoZ + k]);