]>
Commit | Line | Data |
---|---|---|
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 | 9 | ClassImp(AliL3Histogram) |
10 | ||
4de874d1 | 11 | AliL3Histogram::AliL3Histogram() |
12 | { | |
18758be6 | 13 | fNxbins = 0; |
14 | fNybins = 0; | |
15 | fNcells = 0; | |
16 | fXmin = 0; | |
17 | fYmin = 0; | |
18 | fXmax = 0; | |
19 | fYmax = 0; | |
4cafa5fc | 20 | fFirstXbin = 0; |
21 | fLastXbin = 0; | |
22 | fFirstYbin = 0; | |
23 | fLastYbin = 0; | |
18758be6 | 24 | fEntries = 0; |
25 | fContent = 0; | |
4de874d1 | 26 | } |
27 | ||
18758be6 | 28 | |
4cafa5fc | 29 | AliL3Histogram::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) |
18758be6 | 30 | { |
31 | ||
32 | strcpy(fName,name); | |
33 | fNxbins = nxbin; | |
34 | fNybins = nybin; | |
35 | fNcells = (nxbin+2)*(nybin+2); | |
36 | ||
37 | fXmin = xmin; | |
38 | fYmin = ymin; | |
39 | fXmax = xmax; | |
40 | fYmax = ymax; | |
41 | fEntries = 0; | |
4cafa5fc | 42 | fFirstXbin = 1; |
43 | fFirstYbin = 1; | |
44 | fLastXbin = nxbin; | |
45 | fLastYbin = nybin; | |
46 | fRootHisto = 0; | |
47 | ||
18758be6 | 48 | fContent = new Double_t[fNcells]; |
49 | Reset(); | |
50 | } | |
4de874d1 | 51 | |
52 | AliL3Histogram::~AliL3Histogram() | |
53 | { | |
54 | //Destructor | |
18758be6 | 55 | if(fContent) |
56 | delete [] fContent; | |
4cafa5fc | 57 | if(fRootHisto) |
58 | delete fRootHisto; | |
18758be6 | 59 | } |
60 | ||
4de874d1 | 61 | |
18758be6 | 62 | void AliL3Histogram::Reset() |
63 | { | |
64 | ||
65 | for(Int_t i=0; i<fNcells; i++) | |
66 | fContent[i] = 0; | |
67 | fEntries=0; | |
68 | } | |
69 | ||
70 | void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight) | |
71 | { | |
72 | Int_t bin = FindBin(x,y); | |
73 | AddBinContent(bin,weight); | |
74 | ||
75 | } | |
76 | ||
77 | Int_t AliL3Histogram::FindBin(Double_t x,Double_t y) | |
4cafa5fc | 78 | { |
79 | ||
80 | Int_t xbin = FindXbin(x); | |
81 | Int_t ybin = FindYbin(y); | |
7a21af2f | 82 | |
4cafa5fc | 83 | return GetBin(xbin,ybin); |
84 | } | |
85 | ||
86 | Int_t AliL3Histogram::FindXbin(Double_t x) | |
18758be6 | 87 | { |
88 | if(x < fXmin || x > fXmax) | |
7a21af2f | 89 | return 0; |
4cafa5fc | 90 | |
91 | return 1 + (Int_t)(fNxbins*(x-fXmin)/(fXmax-fXmin)); | |
92 | ||
93 | } | |
94 | ||
95 | Int_t AliL3Histogram::FindYbin(Double_t y) | |
96 | { | |
18758be6 | 97 | if(y < fYmin || y > fYmax) |
7a21af2f | 98 | return 0; |
18758be6 | 99 | |
4cafa5fc | 100 | return 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin)); |
18758be6 | 101 | |
4cafa5fc | 102 | } |
103 | ||
104 | Int_t AliL3Histogram::GetBin(Int_t xbin,Int_t ybin) | |
105 | { | |
106 | if(xbin < 0 || xbin > GetLastXbin()) | |
107 | { | |
108 | LOG(AliL3Log::kError,"AliL3Histogram::GetBin","array")<<AliL3Log::kDec<< | |
109 | "xbin out of range "<<xbin<<ENDLOG; | |
110 | return 0; | |
111 | } | |
112 | if(ybin < 0 || ybin > GetLastYbin()) | |
113 | { | |
114 | LOG(AliL3Log::kError,"AliL3Histogram::FindYbin","array")<<AliL3Log::kDec<< | |
115 | "ybin out of range "<<xbin<<ENDLOG; | |
116 | return 0; | |
117 | } | |
118 | ||
18758be6 | 119 | return xbin + ybin*(fNxbins+2); |
4cafa5fc | 120 | } |
121 | ||
122 | Double_t AliL3Histogram::GetBinContent(Int_t bin) | |
123 | { | |
124 | if(bin >= fNcells) | |
125 | { | |
126 | LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<< | |
127 | "bin out of range "<<bin<<ENDLOG; | |
128 | return 0; | |
129 | } | |
130 | ||
131 | return fContent[bin]; | |
132 | } | |
133 | ||
7a21af2f | 134 | void AliL3Histogram::SetBinContent(Int_t xbin,Int_t ybin,Int_t value) |
4cafa5fc | 135 | { |
136 | Int_t bin = GetBin(xbin,ybin); | |
7a21af2f | 137 | if(bin == 0) |
138 | return; | |
139 | SetBinContent(bin,value); | |
4cafa5fc | 140 | } |
141 | ||
7a21af2f | 142 | void AliL3Histogram::SetBinContent(Int_t bin,Int_t value) |
4cafa5fc | 143 | { |
144 | ||
145 | if(bin >= fNcells) | |
146 | { | |
147 | LOG(AliL3Log::kError,"AliL3Histogram::SetBinContent","array")<<AliL3Log::kDec<< | |
148 | "bin out of range "<<bin<<ENDLOG; | |
149 | return; | |
150 | } | |
7a21af2f | 151 | if(bin == 0) |
152 | return; | |
153 | fContent[bin]=value; | |
18758be6 | 154 | |
155 | } | |
156 | ||
157 | void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight) | |
158 | { | |
4cafa5fc | 159 | Int_t bin = GetBin(xbin,ybin); |
7a21af2f | 160 | if(bin == 0) |
161 | return; | |
18758be6 | 162 | AddBinContent(bin,weight); |
163 | ||
164 | } | |
165 | ||
166 | void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight) | |
167 | { | |
168 | if(bin < 0 || bin > fNcells) | |
169 | { | |
170 | LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<< | |
171 | "bin-value out of range "<<bin<<ENDLOG; | |
172 | return; | |
173 | } | |
7a21af2f | 174 | if(bin == 0) |
175 | return; | |
18758be6 | 176 | fEntries++; |
177 | fContent[bin] += weight; | |
178 | } | |
179 | ||
4cafa5fc | 180 | Double_t AliL3Histogram::GetBinCenterX(Int_t xbin) |
18758be6 | 181 | { |
182 | ||
183 | Double_t binwidth = (fXmax - fXmin) / fNxbins; | |
184 | return fXmin + (xbin-1) * binwidth + 0.5*binwidth; | |
185 | ||
186 | } | |
187 | ||
4cafa5fc | 188 | Double_t AliL3Histogram::GetBinCenterY(Int_t ybin) |
18758be6 | 189 | { |
190 | ||
191 | Double_t binwidth = (fYmax - fYmin) / fNybins; | |
192 | return fYmin + (ybin-1) * binwidth + 0.5*binwidth; | |
193 | ||
194 | } | |
195 | ||
196 | ||
4cafa5fc | 197 | void AliL3Histogram::Draw(Char_t *option) |
18758be6 | 198 | { |
4cafa5fc | 199 | fRootHisto = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax); |
18758be6 | 200 | for(Int_t bin=0; bin<fNcells; bin++) |
201 | { | |
4cafa5fc | 202 | fRootHisto->AddBinContent(bin,fContent[bin]); |
18758be6 | 203 | } |
204 | //printf("ncells %d %d\n",(hist->GetNbinsX()+2)*(hist->GetNbinsY()+2),fNcells); | |
18758be6 | 205 | |
4cafa5fc | 206 | fRootHisto->Draw(option); |
207 | ||
4de874d1 | 208 | } |