]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliL3Histogram1D.cxx
AliRunDigitizer: a few bugs fixed to run under
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Histogram1D.cxx
CommitLineData
f7473b79 1//Author: Anders Strand Vestbo
2//Last Modified: 28.6.01
3
4#include "AliL3Logging.h"
5#include "AliL3Histogram1D.h"
6
7//2D histogram class.
8
9ClassImp(AliL3Histogram1D)
10
11AliL3Histogram1D::AliL3Histogram1D()
12{
13 fNbins = 0;
14 fNcells = 0;
15 fEntries = 0;
16 fXmin = 0;
17 fXmax = 0;
18#ifdef use_root
19 fRootHisto = 0;
20#endif
21 fThreshold = 0;
22 fContent = 0;
23
24}
25
26
27AliL3Histogram1D::AliL3Histogram1D(Char_t *name,Char_t *id,Int_t nxbin,Double_t xmin,Double_t xmax)
28
29{
30
31 strcpy(fName,name);
32 fNbins = nxbin;
33 fNcells = fNbins + 2;
34 fEntries = 0;
35 fXmin = xmin;
36 fXmax = xmax;
37
38 fRootHisto = 0;
39 fThreshold = 0;
40
41 fContent = new Double_t[fNcells];
42 Reset();
43}
44
45AliL3Histogram1D::~AliL3Histogram1D()
46{
47 //Destructor
48 if(fContent)
49 delete [] fContent;
50#ifdef use_root
51 if(fRootHisto)
52 delete fRootHisto;
53#endif
54}
55
56
57void AliL3Histogram1D::Reset()
58{
59 bzero(fContent,fNcells*sizeof(Double_t));
60 fEntries=0;
61}
62
63void AliL3Histogram1D::Fill(Double_t x,Int_t weight)
64{
65 Int_t bin = FindBin(x);
66 AddBinContent(bin,weight);
67}
68
69
70Int_t AliL3Histogram1D::FindBin(Double_t x)
71{
72 if(x < fXmin || x > fXmax)
73 return 0;
74
75 return 1 + (Int_t)(fNbins*(x-fXmin)/(fXmax-fXmin));
76
77}
78
79Double_t AliL3Histogram1D::GetBinContent(Int_t bin)
80{
81 if(bin >= fNcells)
82 {
83 LOG(AliL3Log::kError,"AliL3Histogram::GetBinContent","array")<<AliL3Log::kDec<<
84 "bin out of range "<<bin<<ENDLOG;
85 return 0;
86 }
87
88 if(fContent[bin] < fThreshold)
89 return 0;
90 return fContent[bin];
91}
92
93
94void AliL3Histogram1D::SetBinContent(Int_t bin,Int_t value)
95{
96
97 if(bin >= fNcells)
98 {
99 LOG(AliL3Log::kError,"AliL3Histogram::SetBinContent","array")<<AliL3Log::kDec<<
100 "bin out of range "<<bin<<ENDLOG;
101 return;
102 }
103 if(bin == 0)
104 return;
105 fContent[bin]=value;
106
107}
108
109void AliL3Histogram1D::AddBinContent(Int_t bin,Int_t weight)
110{
111 if(bin < 0 || bin > fNcells)
112 {
113 LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
114 "bin-value out of range "<<bin<<ENDLOG;
115 return;
116 }
117 if(bin == 0)
118 return;
119 fEntries++;
120 fContent[bin] += weight;
121}
122
123Double_t AliL3Histogram1D::GetBinCenter(Int_t bin)
124{
125
126 Double_t binwidth = (fXmax - fXmin) / fNbins;
127 return fXmin + (bin-1) * binwidth + 0.5*binwidth;
128
129}
130
131#ifdef use_root
132void AliL3Histogram1D::Draw(Char_t *option)
133{
134 fRootHisto = new TH1F(fName,"",fNbins,fXmin,fXmax);
135 for(Int_t bin=0; bin<fNcells; bin++)
136 fRootHisto->AddBinContent(bin,GetBinContent(bin));
137
138 fRootHisto->Draw(option);
139
140}
141#endif