]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliL3Histogram1D.cxx
Changes as a result of making AliL3Transform static.
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Histogram1D.cxx
CommitLineData
95a00d93 1//$Id$
2
b1886074 3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4//*-- Copyright &copy ASV
f7473b79 5
95a00d93 6#include <string.h>
f7473b79 7#include "AliL3Logging.h"
8#include "AliL3Histogram1D.h"
9
b1886074 10//_____________________________________________________________
11// AliL3Histogram1D
12//
13// 1D histogram class.
f7473b79 14
15ClassImp(AliL3Histogram1D)
16
17AliL3Histogram1D::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
33AliL3Histogram1D::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;
95a00d93 43#ifdef use_root
f7473b79 44 fRootHisto = 0;
95a00d93 45#endif
f7473b79 46 fThreshold = 0;
47
48 fContent = new Double_t[fNcells];
49 Reset();
50}
51
52AliL3Histogram1D::~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
64void AliL3Histogram1D::Reset()
65{
66 bzero(fContent,fNcells*sizeof(Double_t));
67 fEntries=0;
68}
69
70void AliL3Histogram1D::Fill(Double_t x,Int_t weight)
71{
72 Int_t bin = FindBin(x);
73 AddBinContent(bin,weight);
74}
75
76
77Int_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
b1886074 86Int_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
f7473b79 101Double_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
116void 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
131void 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
145Double_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
154void 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