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