]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // @(#) $Id$ |
95a00d93 | 2 | |
b1886074 | 3 | // Author: Anders Vestbo <mailto:vestbo@fi.uib.no> |
3e87ef69 | 4 | //*-- Copyright © 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 | ||
bd2f8772 | 12 | #ifdef use_root |
13 | #include <TH1.h> | |
14 | #endif | |
15 | ||
5929c18d | 16 | #if __GNUC__ >= 3 |
e06900d5 | 17 | using namespace std; |
18 | #endif | |
19 | ||
b1886074 | 20 | //_____________________________________________________________ |
21 | // AliL3Histogram1D | |
22 | // | |
23 | // 1D histogram class. | |
f7473b79 | 24 | |
25 | ClassImp(AliL3Histogram1D) | |
26 | ||
27 | AliL3Histogram1D::AliL3Histogram1D() | |
28 | { | |
bd2f8772 | 29 | //default ctor |
f7473b79 | 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 | } | |
f7473b79 | 42 | |
dd7d3870 | 43 | AliL3Histogram1D::AliL3Histogram1D(Char_t *name,Char_t */*id*/,Int_t nxbin,Double_t xmin,Double_t xmax) |
f7473b79 | 44 | |
45 | { | |
bd2f8772 | 46 | //normal ctor |
f7473b79 | 47 | strcpy(fName,name); |
48 | fNbins = nxbin; | |
49 | fNcells = fNbins + 2; | |
50 | fEntries = 0; | |
51 | fXmin = xmin; | |
52 | fXmax = xmax; | |
95a00d93 | 53 | #ifdef use_root |
f7473b79 | 54 | fRootHisto = 0; |
95a00d93 | 55 | #endif |
f7473b79 | 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 | { | |
bd2f8772 | 76 | //Reset histogram contents |
eb86303b | 77 | #if defined(__DECCXX) |
78 | bzero((char *)fContent,fNcells*sizeof(Double_t)); | |
79 | #else | |
f7473b79 | 80 | bzero(fContent,fNcells*sizeof(Double_t)); |
eb86303b | 81 | #endif |
f7473b79 | 82 | fEntries=0; |
83 | } | |
84 | ||
85 | void AliL3Histogram1D::Fill(Double_t x,Int_t weight) | |
86 | { | |
bd2f8772 | 87 | //Fill a given bin with weight |
f7473b79 | 88 | Int_t bin = FindBin(x); |
89 | AddBinContent(bin,weight); | |
90 | } | |
91 | ||
92 | ||
bd2f8772 | 93 | Int_t AliL3Histogram1D::FindBin(Double_t x) const |
f7473b79 | 94 | { |
bd2f8772 | 95 | //Find a given bin |
f7473b79 | 96 | if(x < fXmin || x > fXmax) |
97 | return 0; | |
98 | ||
99 | return 1 + (Int_t)(fNbins*(x-fXmin)/(fXmax-fXmin)); | |
100 | ||
101 | } | |
102 | ||
bd2f8772 | 103 | Int_t AliL3Histogram1D::GetMaximumBin() const |
b1886074 | 104 | { |
bd2f8772 | 105 | //Find the bin with the largest content |
106 | Double_t maxvalue=0; | |
107 | Int_t maxbin=0; | |
b1886074 | 108 | for(Int_t i=0; i<fNcells; i++) |
109 | { | |
bd2f8772 | 110 | if(fContent[i] > maxvalue) |
b1886074 | 111 | { |
bd2f8772 | 112 | maxvalue=fContent[i]; |
113 | maxbin = i; | |
b1886074 | 114 | } |
115 | } | |
bd2f8772 | 116 | return maxbin; |
b1886074 | 117 | } |
118 | ||
bd2f8772 | 119 | Double_t AliL3Histogram1D::GetBinContent(Int_t bin) const |
f7473b79 | 120 | { |
bd2f8772 | 121 | //Get bin content |
f7473b79 | 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 | { | |
bd2f8772 | 137 | //Set bin content |
f7473b79 | 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 | { | |
bd2f8772 | 152 | //Add weight to bin content |
f7473b79 | 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 | ||
bd2f8772 | 165 | Double_t AliL3Histogram1D::GetBinCenter(Int_t bin) const |
f7473b79 | 166 | { |
bd2f8772 | 167 | //Get bin center |
f7473b79 | 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 | { | |
bd2f8772 | 176 | //Draw the histogram |
f7473b79 | 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 |