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