]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliL3HistogramAdaptive.cxx
cluster information
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HistogramAdaptive.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
6b88e8ee 2
3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
3e87ef69 4//*-- Copyright &copy 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
02f030e3 12#if GCCVERSION == 3
13using namespace std;
14#endif
15
6b88e8ee 16//_____________________________________________________________
17// AliL3HistogramAdaptive
18//
19// 2D histogram class
20
21ClassImp(AliL3HistogramAdaptive)
22
23AliL3HistogramAdaptive::AliL3HistogramAdaptive() : AliL3Histogram()
24{
6b9816d6 25
6b88e8ee 26}
27
28
6b9816d6 29AliL3HistogramAdaptive::AliL3HistogramAdaptive(Char_t *name,Double_t minpt,Double_t maxpt,Double_t ptres,
6b88e8ee 30 Int_t nybins,Double_t ymin,Double_t ymax)
31{
32 strcpy(fName,name);
33
6b9816d6 34 fPtres = ptres;
6b88e8ee 35 fXmin = -1*AliL3Transform::GetBFact()*AliL3Transform::GetBField()/minpt;
36 fXmax = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/minpt;
37
6b88e8ee 38 fMinPt = minpt;
39 fMaxPt = maxpt;
6b9816d6 40 fNxbins = InitPtBins();
41 //cout<<"Setting "<<fNxbins<<" bins on x"<<endl;
6b88e8ee 42
43 fNybins = nybins;
44 fYmin = ymin;
45 fYmax = ymax;
46 fFirstXbin=1;
47 fFirstYbin=1;
48 fLastXbin = fNxbins;
49 fLastYbin = fNybins;
50 fNcells = (fNxbins+2)*(fNybins+2);
51
52 fThreshold=0;
53 fContent = new Int_t[fNcells];
54 Reset();
55}
56
57AliL3HistogramAdaptive::~AliL3HistogramAdaptive()
58{
6b9816d6 59
6b88e8ee 60}
61
6b9816d6 62Int_t AliL3HistogramAdaptive::InitPtBins()
6b88e8ee 63{
64
6b9816d6 65 Double_t pt = fMinPt,delta_pt,local_pt;
66 Int_t bin=0;
67
b0be0269 68 while(pt < fMaxPt)
6b88e8ee 69 {
6b88e8ee 70 local_pt = pt;
b0be0269 71
72 delta_pt = fPtres*local_pt;
73 pt += delta_pt;
74 bin++;
02f030e3 75 //cout<<"Setting "<<bin<<" at step "<<local_pt<<" "<<pt<<" interval "<<delta_pt<<endl;
6b88e8ee 76 }
6b9816d6 77
78 return (bin+1)*2; //Both negative and positive kappa.
6b88e8ee 79}
80
81
82void AliL3HistogramAdaptive::Fill(Double_t x,Double_t y,Int_t weight)
83{
84 Int_t bin = FindBin(x,y);
85 if(bin < 0)
86 return;
87 AddBinContent(bin,weight);
88
89}
90
91Int_t AliL3HistogramAdaptive::FindBin(Double_t x,Double_t y)
92{
93
94 Int_t xbin = FindXbin(x);
95 Int_t ybin = FindYbin(y);
96
97 if(xbin < 0)
98 return -1;
99 return GetBin(xbin,ybin);
100}
101
102Int_t AliL3HistogramAdaptive::FindXbin(Double_t x)
103{
3e87ef69 104
6b9816d6 105 Double_t ptfind = fabs(AliL3Transform::GetBFact()*AliL3Transform::GetBField()/x);
106 if(ptfind < fMinPt || ptfind > fMaxPt) return -1;
02f030e3 107 //cout<<"Looking for pt "<<ptfind<<endl;
b0be0269 108 Double_t pt = fMinPt;
109 Double_t delta_pt,local_pt;
6b9816d6 110 Int_t bin=0;
b0be0269 111 while(pt < fMaxPt)
6b88e8ee 112 {
6b9816d6 113 local_pt = pt;
b0be0269 114 delta_pt = fPtres*local_pt;
115 pt += delta_pt;
6b9816d6 116
b0be0269 117 if(ptfind >= local_pt && ptfind < pt)
6b9816d6 118 {
b0be0269 119 // cout<<"Found in range "<<local_pt<<" "<<pt<<endl;
120 break;
6b9816d6 121 }
b0be0269 122 bin++;
6b88e8ee 123 }
6b9816d6 124 if(bin >= fNxbins/2)
125 cerr<<"AliL3HistogramAdaptive::FindXbin : Bin out of range : "<<bin<<endl;
126
02f030e3 127 //cout<<"Found xbin "<<bin<<" and x is "<<x<<endl;
6b88e8ee 128 if(x < 0)
b0be0269 129 {
130 // cout<<"returning xbin "<<bin<<endl;
131 return bin;
132 }
6b88e8ee 133 else
6b9816d6 134 return fNxbins - 1 - bin;
6b88e8ee 135}
136
137Int_t AliL3HistogramAdaptive::FindYbin(Double_t y)
138{
139 if(y < fYmin || y > fYmax)
140 return 0;
141
142 return 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin));
143
144}
145
146Double_t AliL3HistogramAdaptive::GetBinCenterX(Int_t xbin)
147{
02f030e3 148 //cout<<"Looking for bin "<<xbin<<endl;
6b9816d6 149 if(xbin < 0 || xbin > fNxbins)
6b88e8ee 150 {
6b9816d6 151 cerr<<"AliL3HistogramAdaptive::GetBinCenterX : Xbin out of range "<<xbin<<endl;
152 return 0;
6b88e8ee 153 }
b0be0269 154 Double_t pt = fMinPt;
3e87ef69 155 Double_t delta_pt=0,local_pt=0;
6b9816d6 156 Int_t bin=0;
b0be0269 157 while(pt < fMaxPt)
6b9816d6 158 {
159 local_pt = pt;
b0be0269 160 delta_pt = fPtres*local_pt;
161 pt += delta_pt;
162 if(xbin == bin || xbin == fNxbins - 1 - bin)
163 break;
164 bin++;
6b9816d6 165 }
02f030e3 166 //cout<<"get center at ptinterval "<<local_pt<<" "<<pt;
b0be0269 167
168 Double_t kappa = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/(local_pt + 0.5*delta_pt);
02f030e3 169 //cout<<" found pt "<<local_pt+delta_pt*0.5<<" kappa "<<kappa<<" xbin "<<xbin<<" fNxbins/2-1 "<<fNxbins/2-1<<endl;
b0be0269 170 if(xbin == bin)
6b88e8ee 171 return -1.*kappa;
172 else
173 return kappa;
6b88e8ee 174}
175
176Double_t AliL3HistogramAdaptive::GetBinCenterY(Int_t ybin)
177{
178
179 Double_t binwidth = (fYmax - fYmin) / fNybins;
180 return fYmin + (ybin-1) * binwidth + 0.5*binwidth;
181
182}
183
184void AliL3HistogramAdaptive::Draw(Char_t *option)
185{
186#ifdef use_root
187 if(!fRootHisto)
188 CreateRootHisto();
189
190 Double_t kappa,psi;
191 Int_t content,bin;
192 for(Int_t i=0; i<fNxbins; i++)
193 {
194 kappa = GetBinCenterX(i);
195 for(Int_t j=0; j<fNybins; j++)
196 {
197 psi = GetBinCenterY(j);
198 bin = GetBin(i,j);
199 content = GetBinContent(bin);
200 fRootHisto->Fill(kappa,psi,content);
201 }
202 }
203 fRootHisto->Draw(option);
204 return;
205#endif
206 cerr<<"AliL3HistogramAdaptive::Draw : You need to compile with ROOT in order to draw histogram"<<endl;
207}
208
209void AliL3HistogramAdaptive::Print()
210{
211 cout<<"Printing content of histogram "<<fName<<endl;
212 for(Int_t i=0; i<fNcells; i++)
213 {
214 if(GetBinContent(i)==0) continue;
215 cout<<"Bin "<<i<<": "<<GetBinContent(i)<<endl;
216 }
217
218}