]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/hough/AliL3Histogram1D.cxx
Changes done for new aliroot version. Faster calculation through saving LUT for kappa.
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Histogram1D.cxx
1 //$Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright &copy ASV
5
6 #include "AliL3StandardIncludes.h"
7
8 #include "AliL3Logging.h"
9 #include "AliL3Histogram1D.h"
10
11 #if GCCVERSION == 3
12 using namespace std;
13 #endif
14
15 //_____________________________________________________________
16 // AliL3Histogram1D
17 //
18 // 1D histogram class.
19
20 ClassImp(AliL3Histogram1D)
21
22 AliL3Histogram1D::AliL3Histogram1D()
23 {
24   fNbins = 0;
25   fNcells = 0;
26   fEntries = 0;
27   fXmin = 0;
28   fXmax = 0;
29 #ifdef use_root
30   fRootHisto = 0;
31 #endif
32   fThreshold = 0;
33   fContent = 0;
34   
35 }
36   
37 AliL3Histogram1D::AliL3Histogram1D(Char_t *name,Char_t *id,Int_t nxbin,Double_t xmin,Double_t xmax)
38
39 {
40   
41   strcpy(fName,name);
42   fNbins = nxbin;
43   fNcells = fNbins + 2;
44   fEntries = 0;
45   fXmin = xmin;
46   fXmax = xmax;
47 #ifdef use_root
48   fRootHisto = 0;
49 #endif
50   fThreshold = 0;
51   
52   fContent = new Double_t[fNcells];
53   Reset();
54 }
55
56 AliL3Histogram1D::~AliL3Histogram1D()
57 {
58   //Destructor
59   if(fContent)
60     delete [] fContent;
61 #ifdef use_root
62   if(fRootHisto)
63     delete fRootHisto;
64 #endif
65 }
66
67
68 void AliL3Histogram1D::Reset()
69 {
70   bzero(fContent,fNcells*sizeof(Double_t));
71   fEntries=0;
72 }
73
74 void AliL3Histogram1D::Fill(Double_t x,Int_t weight)
75 {
76   Int_t bin = FindBin(x);
77   AddBinContent(bin,weight);
78 }
79
80
81 Int_t AliL3Histogram1D::FindBin(Double_t x)
82 {
83   if(x < fXmin || x > fXmax)
84     return 0;
85   
86   return 1 + (Int_t)(fNbins*(x-fXmin)/(fXmax-fXmin));
87
88 }
89
90 Int_t AliL3Histogram1D::GetMaximumBin()
91 {
92   Double_t max_value=0;
93   Int_t max_bin=0;
94   for(Int_t i=0; i<fNcells; i++)
95     {
96       if(fContent[i] > max_value)
97         {
98           max_value=fContent[i];
99           max_bin = i;
100         }
101     }
102   return max_bin;
103 }
104
105 Double_t AliL3Histogram1D::GetBinContent(Int_t bin)
106 {
107   if(bin >= fNcells)
108     {
109       LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<<
110         "bin out of range "<<bin<<ENDLOG;
111       return 0;
112     }
113   
114   if(fContent[bin] < fThreshold)
115     return 0;
116   return fContent[bin];
117 }
118
119
120 void AliL3Histogram1D::SetBinContent(Int_t bin,Int_t value)
121 {
122
123   if(bin >= fNcells)
124     {
125       LOG(AliL3Log::kError,"AliL3Histogram::SetBinContent","array")<<AliL3Log::kDec<<
126         "bin out of range "<<bin<<ENDLOG;
127       return;
128     }
129   if(bin == 0)
130     return;
131   fContent[bin]=value;
132   
133 }
134
135 void AliL3Histogram1D::AddBinContent(Int_t bin,Int_t weight)
136 {
137   if(bin < 0 || bin > fNcells)
138     {
139       LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
140         "bin-value out of range "<<bin<<ENDLOG;
141       return;
142     }
143   if(bin == 0)
144     return;
145   fEntries++;
146   fContent[bin] += weight;
147 }
148
149 Double_t AliL3Histogram1D::GetBinCenter(Int_t bin)
150 {
151   
152   Double_t binwidth = (fXmax - fXmin) / fNbins;
153   return fXmin + (bin-1) * binwidth + 0.5*binwidth;
154   
155 }
156
157 #ifdef use_root
158 void AliL3Histogram1D::Draw(Char_t *option)
159 {
160   fRootHisto = new TH1F(fName,"",fNbins,fXmin,fXmax);
161   for(Int_t bin=0; bin<fNcells; bin++)
162     fRootHisto->AddBinContent(bin,GetBinContent(bin));
163   
164   fRootHisto->Draw(option);
165   
166 }
167 #endif