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