]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // @(#) $Id$ |
6b88e8ee | 2 | |
3 | // Author: Anders Vestbo <mailto:vestbo@fi.uib.no> | |
3e87ef69 | 4 | //*-- Copyright © ALICE HLT Group |
6b88e8ee | 5 | |
e4a2d541 | 6 | #include "AliL3StandardIncludes.h" |
6b88e8ee | 7 | #include "AliL3Logging.h" |
8 | #include "AliL3HistogramAdaptive.h" | |
9 | #include "AliL3Transform.h" | |
10 | #include "AliL3Track.h" | |
11 | ||
0bd0c1ef | 12 | #if __GNUC__ == 3 |
02f030e3 | 13 | using namespace std; |
14 | #endif | |
15 | ||
6b88e8ee | 16 | //_____________________________________________________________ |
17 | // AliL3HistogramAdaptive | |
18 | // | |
0a86fbb7 | 19 | // 2D histogram class adapted for kappa and psi as used in the Circle Hough Transform. |
20 | // The bins in kappa is not linear, but has a width which is specified by argument | |
21 | // ptres in the constructor. This gives the relative pt resolution which should | |
22 | // be kept throughout the kappa range. | |
6b88e8ee | 23 | |
24 | ClassImp(AliL3HistogramAdaptive) | |
25 | ||
26 | AliL3HistogramAdaptive::AliL3HistogramAdaptive() : AliL3Histogram() | |
27 | { | |
bd2f8772 | 28 | //default ctor |
0a86fbb7 | 29 | fKappaBins=0; |
6b88e8ee | 30 | } |
31 | ||
32 | ||
6b9816d6 | 33 | AliL3HistogramAdaptive::AliL3HistogramAdaptive(Char_t *name,Double_t minpt,Double_t maxpt,Double_t ptres, |
6b88e8ee | 34 | Int_t nybins,Double_t ymin,Double_t ymax) |
35 | { | |
bd2f8772 | 36 | //normal ctor |
6b88e8ee | 37 | strcpy(fName,name); |
38 | ||
6b9816d6 | 39 | fPtres = ptres; |
6b88e8ee | 40 | fXmin = -1*AliL3Transform::GetBFact()*AliL3Transform::GetBField()/minpt; |
41 | fXmax = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/minpt; | |
42 | ||
6b88e8ee | 43 | fMinPt = minpt; |
44 | fMaxPt = maxpt; | |
0a86fbb7 | 45 | fNxbins = InitKappaBins(); |
6b88e8ee | 46 | fNybins = nybins; |
0a86fbb7 | 47 | |
6b88e8ee | 48 | fYmin = ymin; |
49 | fYmax = ymax; | |
50 | fFirstXbin=1; | |
51 | fFirstYbin=1; | |
52 | fLastXbin = fNxbins; | |
53 | fLastYbin = fNybins; | |
54 | fNcells = (fNxbins+2)*(fNybins+2); | |
0a86fbb7 | 55 | |
6b88e8ee | 56 | fThreshold=0; |
57 | fContent = new Int_t[fNcells]; | |
58 | Reset(); | |
59 | } | |
60 | ||
61 | AliL3HistogramAdaptive::~AliL3HistogramAdaptive() | |
62 | { | |
bd2f8772 | 63 | //dtor |
0a86fbb7 | 64 | if(fKappaBins) |
65 | delete [] fKappaBins; | |
6b88e8ee | 66 | } |
67 | ||
0a86fbb7 | 68 | Int_t AliL3HistogramAdaptive::InitKappaBins() |
6b88e8ee | 69 | { |
0a86fbb7 | 70 | //Here a LUT for the kappa values created. This has to be done since |
71 | //the binwidth in kappa is not constant, but change according to the | |
72 | //set relative resolution in pt. | |
73 | //Since the kappa values are symmetric about origo, the size of the | |
74 | //LUT is half of the total number of bins in kappa direction. | |
6b88e8ee | 75 | |
bd2f8772 | 76 | Double_t pt = fMinPt,deltapt,localpt; |
6b9816d6 | 77 | Int_t bin=0; |
0a86fbb7 | 78 | |
b0be0269 | 79 | while(pt < fMaxPt) |
6b88e8ee | 80 | { |
bd2f8772 | 81 | localpt = pt; |
82 | deltapt = fPtres*localpt*localpt; | |
83 | pt += 2*deltapt; | |
b0be0269 | 84 | bin++; |
6b88e8ee | 85 | } |
0a86fbb7 | 86 | fKappaBins = new Double_t[bin+1]; |
87 | pt=fMinPt; | |
88 | bin=0; | |
89 | fKappaBins[bin] = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/fMinPt; | |
90 | while(pt < fMaxPt) | |
91 | { | |
bd2f8772 | 92 | localpt = pt; |
93 | deltapt = fPtres*localpt*localpt; | |
94 | pt += 2*deltapt; //*2 because pt +- 1/2*deltapt is one bin | |
0a86fbb7 | 95 | bin++; |
96 | fKappaBins[bin] = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/pt; | |
97 | } | |
6b9816d6 | 98 | return (bin+1)*2; //Both negative and positive kappa. |
6b88e8ee | 99 | } |
100 | ||
101 | ||
102 | void AliL3HistogramAdaptive::Fill(Double_t x,Double_t y,Int_t weight) | |
103 | { | |
bd2f8772 | 104 | //Fill a given bin in the histogram |
6b88e8ee | 105 | Int_t bin = FindBin(x,y); |
106 | if(bin < 0) | |
107 | return; | |
108 | AddBinContent(bin,weight); | |
109 | ||
110 | } | |
111 | ||
1f1942b8 | 112 | Int_t AliL3HistogramAdaptive::FindBin(Double_t x,Double_t y) const |
6b88e8ee | 113 | { |
bd2f8772 | 114 | //Find a bin in the histogram |
6b88e8ee | 115 | Int_t xbin = FindXbin(x); |
116 | Int_t ybin = FindYbin(y); | |
117 | ||
b2a02bce | 118 | if(!xbin || !ybin) |
6b88e8ee | 119 | return -1; |
120 | return GetBin(xbin,ybin); | |
121 | } | |
122 | ||
1f1942b8 | 123 | Int_t AliL3HistogramAdaptive::FindXbin(Double_t x) const |
6b88e8ee | 124 | { |
bd2f8772 | 125 | //Find X bin in the histogram |
0a86fbb7 | 126 | if(x < fXmin || x > fXmax || fabs(x) < fKappaBins[(fNxbins/2-1)]) |
b2a02bce | 127 | return 0; |
3e87ef69 | 128 | |
0a86fbb7 | 129 | //Remember that kappa value is decreasing with bin number! |
130 | //Also, the bin numbering starts at 1 and ends at fNxbins, | |
131 | //so the corresponding elements in the LUT is bin - 1. | |
132 | ||
6b9816d6 | 133 | Int_t bin=0; |
0a86fbb7 | 134 | while(bin < fNxbins/2) |
6b88e8ee | 135 | { |
0a86fbb7 | 136 | if(fabs(x) <= fKappaBins[bin] && fabs(x) > fKappaBins[bin+1]) |
137 | break; | |
b0be0269 | 138 | bin++; |
6b88e8ee | 139 | } |
140 | if(x < 0) | |
0a86fbb7 | 141 | return bin + 1; |
142 | else | |
143 | return fNxbins - bin; | |
144 | ||
6b88e8ee | 145 | } |
146 | ||
1f1942b8 | 147 | Int_t AliL3HistogramAdaptive::FindYbin(Double_t y) const |
6b88e8ee | 148 | { |
bd2f8772 | 149 | //Find Y bin in the histogram |
6b88e8ee | 150 | if(y < fYmin || y > fYmax) |
151 | return 0; | |
152 | ||
153 | return 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin)); | |
6b88e8ee | 154 | } |
155 | ||
1f1942b8 | 156 | Double_t AliL3HistogramAdaptive::GetBinCenterX(Int_t xbin) const |
6b88e8ee | 157 | { |
bd2f8772 | 158 | //Returns bin center in X |
0a86fbb7 | 159 | if(xbin < fFirstXbin || xbin > fLastXbin) |
6b88e8ee | 160 | { |
0a86fbb7 | 161 | LOG(AliL3Log::kWarning,"AliL3HistogramAdaptive::GetBinCenterX","Bin-value") |
162 | <<"XBinvalue out of range "<<xbin<<ENDLOG; | |
6b9816d6 | 163 | return 0; |
6b88e8ee | 164 | } |
b0be0269 | 165 | |
0a86fbb7 | 166 | //The bin numbers go from 1 to fNxbins, so the corresponding |
167 | //element in the LUT is xbin - 1. This is the reason why we | |
168 | //substract a 1 here: | |
169 | ||
170 | Int_t bin = xbin; | |
171 | bin -= 1; | |
172 | if(bin >= fNxbins/2) | |
173 | bin = fNxbins - 1 - bin; | |
174 | ||
175 | //Remember again that the kappa-values are _decreasing_ with bin number. | |
176 | ||
177 | Double_t binwidth = fKappaBins[bin] - fKappaBins[bin+1]; | |
178 | Double_t kappa = fKappaBins[bin] - 0.5*binwidth; | |
179 | if(xbin < fNxbins/2) | |
6b88e8ee | 180 | return -1.*kappa; |
181 | else | |
182 | return kappa; | |
0a86fbb7 | 183 | |
6b88e8ee | 184 | } |
185 | ||
1f1942b8 | 186 | Double_t AliL3HistogramAdaptive::GetBinCenterY(Int_t ybin) const |
6b88e8ee | 187 | { |
bd2f8772 | 188 | //Returns bin center in Y |
0a86fbb7 | 189 | if(ybin < fFirstYbin || ybin > fLastYbin) |
190 | { | |
191 | LOG(AliL3Log::kError,"AliL3HistogramAdaptive::GetBinCenterY","ybin") | |
192 | <<"Bin-value out of range "<<ybin<<ENDLOG; | |
193 | return -1; | |
194 | } | |
6b88e8ee | 195 | Double_t binwidth = (fYmax - fYmin) / fNybins; |
0a86fbb7 | 196 | return fYmin + (ybin-0.5) * binwidth; |
197 | ||
6b88e8ee | 198 | } |
199 | ||
0a86fbb7 | 200 | |
6b88e8ee | 201 | void AliL3HistogramAdaptive::Draw(Char_t *option) |
202 | { | |
bd2f8772 | 203 | //Draw the histogram |
6b88e8ee | 204 | #ifdef use_root |
205 | if(!fRootHisto) | |
206 | CreateRootHisto(); | |
207 | ||
208 | Double_t kappa,psi; | |
209 | Int_t content,bin; | |
0a86fbb7 | 210 | for(Int_t i=fFirstXbin; i<=fLastXbin; i++) |
6b88e8ee | 211 | { |
212 | kappa = GetBinCenterX(i); | |
0a86fbb7 | 213 | for(Int_t j=fFirstYbin; j<=fLastYbin; j++) |
6b88e8ee | 214 | { |
215 | psi = GetBinCenterY(j); | |
216 | bin = GetBin(i,j); | |
217 | content = GetBinContent(bin); | |
218 | fRootHisto->Fill(kappa,psi,content); | |
219 | } | |
220 | } | |
221 | fRootHisto->Draw(option); | |
222 | return; | |
223 | #endif | |
224 | cerr<<"AliL3HistogramAdaptive::Draw : You need to compile with ROOT in order to draw histogram"<<endl; | |
225 | } | |
226 | ||
bd2f8772 | 227 | void AliL3HistogramAdaptive::Print() const |
6b88e8ee | 228 | { |
bd2f8772 | 229 | //Print the contents of the histogram |
6b88e8ee | 230 | cout<<"Printing content of histogram "<<fName<<endl; |
231 | for(Int_t i=0; i<fNcells; i++) | |
232 | { | |
233 | if(GetBinContent(i)==0) continue; | |
234 | cout<<"Bin "<<i<<": "<<GetBinContent(i)<<endl; | |
235 | } | |
236 | ||
237 | } |