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