29-jun-2001 NvE TrackCopy mode introduced in AliJet.
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Histogram.cxx
CommitLineData
18758be6 1//Author: Anders Strand Vestbo
2//Last Modified: 28.6.01
4de874d1 3
18758be6 4#include "AliL3Logging.h"
4de874d1 5#include "AliL3Histogram.h"
6
18758be6 7//2D histogram class.
8
4de874d1 9ClassImp(AliL3Histogram)
10
4de874d1 11AliL3Histogram::AliL3Histogram()
12{
18758be6 13 fNxbins = 0;
14 fNybins = 0;
15 fNcells = 0;
16 fXmin = 0;
17 fYmin = 0;
18 fXmax = 0;
19 fYmax = 0;
20 fEntries = 0;
21 fContent = 0;
4de874d1 22}
23
18758be6 24
25AliL3Histogram::AliL3Histogram(Char_t *name,Char_t *id,Int_t nxbin,Double_t xmin,Double_t xmax,Int_t nybin,Double_t ymin,Double_t ymax) : TH2F(name,id,nxbin,xmin,xmax,nybin,ymin,ymax)
26{
27
28 strcpy(fName,name);
29 fNxbins = nxbin;
30 fNybins = nybin;
31 fNcells = (nxbin+2)*(nybin+2);
32
33 fXmin = xmin;
34 fYmin = ymin;
35 fXmax = xmax;
36 fYmax = ymax;
37 fEntries = 0;
38
39 fContent = new Double_t[fNcells];
40 Reset();
41}
4de874d1 42
43AliL3Histogram::~AliL3Histogram()
44{
45 //Destructor
18758be6 46 if(fContent)
47 delete [] fContent;
48}
49
4de874d1 50
18758be6 51void AliL3Histogram::Reset()
52{
53
54 for(Int_t i=0; i<fNcells; i++)
55 fContent[i] = 0;
56 fEntries=0;
57}
58
59void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight)
60{
61 Int_t bin = FindBin(x,y);
62 AddBinContent(bin,weight);
63
64}
65
66Int_t AliL3Histogram::FindBin(Double_t x,Double_t y)
67{
68 if(x < fXmin || x > fXmax)
69 {
70 LOG(AliL3Log::kError,"AliL3Histogram::FindBin","array")<<AliL3Log::kDec<<
71 "x-value out of range "<<x<<ENDLOG;
72 return 0;
73 }
74 if(y < fYmin || y > fYmax)
75 {
76 LOG(AliL3Log::kError,"AliL3Histogram::FindBin","array")<<AliL3Log::kDec<<
77 "y-value out of range "<<y<<ENDLOG;
78 return 0;
79 }
80
81 Int_t xbin = 1 + (Int_t)(fNxbins*(x-fXmin)/(fXmax-fXmin));
82 Int_t ybin = 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin));
83
84 return xbin + ybin*(fNxbins+2);
85
86}
87
88void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight)
89{
90 Int_t bin = xbin + ybin*(fNxbins+2);
91 AddBinContent(bin,weight);
92
93}
94
95void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight)
96{
97 if(bin < 0 || bin > fNcells)
98 {
99 LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
100 "bin-value out of range "<<bin<<ENDLOG;
101 return;
102 }
103 fEntries++;
104 fContent[bin] += weight;
105}
106
107Double_t AliL3Histogram::GetXBinCenter(Int_t xbin)
108{
109
110 Double_t binwidth = (fXmax - fXmin) / fNxbins;
111 return fXmin + (xbin-1) * binwidth + 0.5*binwidth;
112
113}
114
115Double_t AliL3Histogram::GetYBinCenter(Int_t ybin)
116{
117
118 Double_t binwidth = (fYmax - fYmin) / fNybins;
119 return fYmin + (ybin-1) * binwidth + 0.5*binwidth;
120
121}
122
123
124void AliL3Histogram::Draw()
125{
126 TH2F *hist = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax);
127 for(Int_t bin=0; bin<fNcells; bin++)
128 {
129 hist->AddBinContent(bin,fContent[bin]);
130 if(fContent[bin]!=0) printf("bin %d\n",bin);
131 }
132 //printf("ncells %d %d\n",(hist->GetNbinsX()+2)*(hist->GetNbinsY()+2),fNcells);
133 printf("maxbin %d\n",hist->GetMaximumBin());
134
135 hist->Draw();
4de874d1 136}