]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/hough/AliL3HistogramAdaptive.cxx
Removed ASV version in AliL3FileHandler by another effective i/o method using index...
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HistogramAdaptive.cxx
1 // @(#) $Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright &copy ALICE HLT Group
5
6 #include "AliL3StandardIncludes.h"
7 #include "AliL3Logging.h"
8 #include "AliL3HistogramAdaptive.h"
9 #include "AliL3Transform.h"
10 #include "AliL3Track.h"
11
12 #if GCCVERSION == 3
13 using namespace std;
14 #endif
15
16 //_____________________________________________________________
17 // AliL3HistogramAdaptive
18 //
19 // 2D histogram class
20
21 ClassImp(AliL3HistogramAdaptive)
22
23 AliL3HistogramAdaptive::AliL3HistogramAdaptive() : AliL3Histogram()
24 {
25   
26 }
27
28   
29 AliL3HistogramAdaptive::AliL3HistogramAdaptive(Char_t *name,Double_t minpt,Double_t maxpt,Double_t ptres,
30                                                Int_t nybins,Double_t ymin,Double_t ymax)
31 {
32   strcpy(fName,name);
33   
34   fPtres = ptres;
35   fXmin = -1*AliL3Transform::GetBFact()*AliL3Transform::GetBField()/minpt;
36   fXmax = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/minpt;
37
38   fMinPt = minpt;
39   fMaxPt = maxpt;
40   fNxbins = InitPtBins();
41   //cout<<"Setting "<<fNxbins<<" bins on x"<<endl;
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
57 AliL3HistogramAdaptive::~AliL3HistogramAdaptive()
58 {
59   
60 }
61
62 Int_t AliL3HistogramAdaptive::InitPtBins()
63 {
64   
65   Double_t pt = fMinPt,delta_pt,local_pt;
66   Int_t bin=0;
67
68   while(pt < fMaxPt)
69     {
70       local_pt = pt;
71             
72       delta_pt = fPtres*local_pt;
73       pt += delta_pt;
74       bin++;
75       //cout<<"Setting "<<bin<<" at step "<<local_pt<<" "<<pt<<" interval "<<delta_pt<<endl;
76     }
77
78   return (bin+1)*2; //Both negative and positive kappa.
79 }
80
81
82 void 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
91 Int_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
102 Int_t AliL3HistogramAdaptive::FindXbin(Double_t x)
103 {
104   
105   Double_t ptfind = fabs(AliL3Transform::GetBFact()*AliL3Transform::GetBField()/x);
106   if(ptfind < fMinPt || ptfind > fMaxPt) return -1;
107   //cout<<"Looking for pt "<<ptfind<<endl;
108   Double_t pt = fMinPt;
109   Double_t delta_pt,local_pt;
110   Int_t bin=0;
111   while(pt < fMaxPt)
112     {
113       local_pt = pt;
114       delta_pt = fPtres*local_pt;
115       pt += delta_pt;
116       
117       if(ptfind >= local_pt && ptfind < pt)
118         {
119           //      cout<<"Found in range "<<local_pt<<" "<<pt<<endl;
120           break;
121         }
122       bin++;
123     }
124   if(bin >= fNxbins/2)
125     cerr<<"AliL3HistogramAdaptive::FindXbin : Bin out of range : "<<bin<<endl;
126   
127   //cout<<"Found xbin "<<bin<<" and x is "<<x<<endl;
128   if(x < 0)
129     {
130       //        cout<<"returning xbin "<<bin<<endl;
131       return bin;
132     }
133   else
134     return fNxbins - 1 - bin;
135 }
136
137 Int_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
146 Double_t AliL3HistogramAdaptive::GetBinCenterX(Int_t xbin)
147 {
148   //cout<<"Looking for bin "<<xbin<<endl;
149   if(xbin < 0 || xbin > fNxbins)
150     {
151       cerr<<"AliL3HistogramAdaptive::GetBinCenterX : Xbin out of range "<<xbin<<endl;
152       return 0;
153     }
154   Double_t pt = fMinPt;
155   Double_t delta_pt=0,local_pt=0;
156   Int_t bin=0;
157   while(pt < fMaxPt)
158     {
159       local_pt = pt;
160       delta_pt = fPtres*local_pt;
161       pt += delta_pt;
162       if(xbin == bin || xbin == fNxbins - 1 - bin)
163         break;
164       bin++;
165     }
166   //cout<<"get center at ptinterval "<<local_pt<<" "<<pt;
167   
168   Double_t kappa = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/(local_pt + 0.5*delta_pt);
169   //cout<<" found pt "<<local_pt+delta_pt*0.5<<" kappa "<<kappa<<" xbin "<<xbin<<" fNxbins/2-1 "<<fNxbins/2-1<<endl;
170   if(xbin == bin)
171     return -1.*kappa;
172   else
173     return kappa;
174 }
175
176 Double_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
184 void 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
209 void 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 }