]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliSample.cxx
New version from M.Kowalski
[u/mrichter/AliRoot.git] / RALICE / AliSample.cxx
CommitLineData
d88f97cc 1#include "AliSample.h"
2
3AliSample::AliSample()
4{
5// Creation of an Aliample object and resetting the statistics values
6// The dimension is initialised to maximum
7 fDim=fMaxdim;
8 fNames[0]='X';
9 fNames[1]='Y';
10 fNames[2]='Z';
11 fN=0;
12 Reset();
13}
14///////////////////////////////////////////////////////////////////////////
15AliSample::~AliSample()
16{
17// Default destructor
18}
19///////////////////////////////////////////////////////////////////////////
20void AliSample::Reset()
21{
22// Resetting the statistics values for a certain Sample object
23// Dimension is NOT changed
24 fN=0;
25 for (Int_t i=0; i<fDim; i++)
26 {
27 fSum[i]=0.;
28 fMean[i]=0.;
29 fVar[i]=0.;
30 fSigma[i]=0.;
31 for (Int_t j=0; j<fDim; j++)
32 {
33 fSum2[i][j]=0.;
34 fCov[i][j]=0.;
35 fCor[i][j]=0.;
36 }
37 }
38}
39///////////////////////////////////////////////////////////////////////////
40void AliSample::Enter(Float_t x)
41{
42// Entering a value into a 1-dim. sample
43// In case of first entry the dimension is set to 1
44 if (fN == 0)
45 {
46 fDim=1;
47 fNames[0]='X';
48 fNames[1]='-';
49 fNames[2]='-';
50 }
51 if (fDim != 1)
52 {
53 cout << " *AliSample::enter* Error : Not a 1-dim sample." << endl;
54 }
55 else
56 {
57 fN+=1;
58 fSum[0]+=x;
59 fSum2[0][0]+=x*x;
60 Compute();
61 }
62}
63///////////////////////////////////////////////////////////////////////////
64void AliSample::Remove(Float_t x)
65{
66// Removing a value from a 1-dim. sample
67 if (fDim != 1)
68 {
69 cout << " *AliSample::remove* Error : Not a 1-dim sample." << endl;
70 }
71 else
72 {
73 fN-=1;
74 fSum[0]-=x;
75 fSum2[0][0]-=x*x;
76 Compute();
77 }
78}
79///////////////////////////////////////////////////////////////////////////
80void AliSample::Enter(Float_t x,Float_t y)
81{
82// Entering a pair (x,y) into a 2-dim. sample
83// In case of first entry the dimension is set to 2
84 if (fN == 0)
85 {
86 fDim=2;
87 fNames[0]='X';
88 fNames[1]='Y';
89 fNames[2]='-';
90 }
91 if (fDim != 2)
92 {
93 cout << " *AliSample::enter* Error : Not a 2-dim sample." << endl;
94 }
95 else
96 {
97 fN+=1;
98 fSum[0]+=x;
99 fSum[1]+=y;
100 fSum2[0][0]+=x*x;
101 fSum2[0][1]+=x*y;
102 fSum2[1][0]+=y*x;
103 fSum2[1][1]+=y*y;
104 Compute();
105 }
106}
107///////////////////////////////////////////////////////////////////////////
108void AliSample::Remove(Float_t x,Float_t y)
109{
110// Removing a pair (x,y) from a 2-dim. sample
111 if (fDim != 2)
112 {
113 cout << " *AliSample::remove* Error : Not a 2-dim sample." << endl;
114 }
115 else
116 {
117 fN-=1;
118 fSum[0]-=x;
119 fSum[1]-=y;
120 fSum2[0][0]-=x*x;
121 fSum2[0][1]-=x*y;
122 fSum2[1][0]-=y*x;
123 fSum2[1][1]-=y*y;
124 Compute();
125 }
126}
127///////////////////////////////////////////////////////////////////////////
128void AliSample::Enter(Float_t x,Float_t y,Float_t z)
129{
130// Entering a set (x,y,z) into a 3-dim. sample
131// In case of first entry the dimension is set to 3
132 if (fN == 0)
133 {
134 fDim=3;
135 fNames[0]='X';
136 fNames[1]='Y';
137 fNames[2]='Z';
138 }
139 if (fDim != 3)
140 {
141 cout << " *AliSample::enter* Error : Not a 3-dim sample." << endl;
142 }
143 else
144 {
145 fN+=1;
146 fSum[0]+=x;
147 fSum[1]+=y;
148 fSum[2]+=z;
149 fSum2[0][0]+=x*x;
150 fSum2[0][1]+=x*y;
151 fSum2[0][2]+=x*z;
152 fSum2[1][0]+=y*x;
153 fSum2[1][1]+=y*y;
154 fSum2[1][2]+=y*z;
155 fSum2[2][0]+=z*x;
156 fSum2[2][1]+=z*y;
157 fSum2[2][2]+=z*z;
158 Compute();
159 }
160}
161///////////////////////////////////////////////////////////////////////////
162void AliSample::Remove(Float_t x,Float_t y,Float_t z)
163{
164// Removing a set (x,y,z) from a 3-dim. sample
165 if (fDim != 3)
166 {
167 cout << " *AliSample::remove* Error : Not a 3-dim sample." << endl;
168 }
169 else
170 {
171 fN-=1;
172 fSum[0]-=x;
173 fSum[1]-=y;
174 fSum[2]-=z;
175 fSum2[0][0]-=x*x;
176 fSum2[0][1]-=x*y;
177 fSum2[0][2]-=x*z;
178 fSum2[1][0]-=y*x;
179 fSum2[1][1]-=y*y;
180 fSum2[1][2]-=y*z;
181 fSum2[2][0]-=z*x;
182 fSum2[2][1]-=z*y;
183 fSum2[2][2]-=z*z;
184 Compute();
185 }
186}
187///////////////////////////////////////////////////////////////////////////
188void AliSample::Compute()
189{
190// Computation of the various statistical values
191// after each entering or removing action on a certain sample
192 Float_t rn=fN;
193 for (Int_t k=0; k<fDim; k++)
194 {
195 fMean[k]=fSum[k]/rn;
196 fVar[k]=(fSum2[k][k]/rn)-(fMean[k]*fMean[k]);
197 if (fVar[k] < 0.) fVar[k]=0.;
198 fSigma[k]=sqrt(fVar[k]);
199 }
200 for (Int_t i=0; i<fDim; i++)
201 {
202 for (Int_t j=0; j<fDim; j++)
203 {
204 fCov[i][j]=(fSum2[i][j]/rn)-(fMean[i]*fMean[j]);
205 Float_t sigij=fSigma[i]*fSigma[j];
206 if (sigij != 0.) fCor[i][j]=fCov[i][j]/sigij;
207 }
208 }
209}
210///////////////////////////////////////////////////////////////////////////
211Int_t AliSample::GetDimension()
212{
213// Provide the dimension of a certain sample
214 return fDim;
215}
216///////////////////////////////////////////////////////////////////////////
217Int_t AliSample::GetN()
218{
219// Provide the number of entries of a certain sample
220 return fN;
221}
222///////////////////////////////////////////////////////////////////////////
223Float_t AliSample::GetSum(Int_t i)
224{
225// Provide the sum of a certain variable
226 if (fDim < i)
227 {
228 cout << " *AliSample::sum* Error : Dimension less than " << i << endl;
229 return 0.;
230 }
231 else
232 {
233 return fSum[i-1];
234 }
235}
236///////////////////////////////////////////////////////////////////////////
237Float_t AliSample::GetMean(Int_t i)
238{
239// Provide the mean of a certain variable
240 if (fDim < i)
241 {
242 cout << " *AliSample::mean* Error : Dimension less than " << i << endl;
243 return 0.;
244 }
245 else
246 {
247 return fMean[i-1];
248 }
249}
250///////////////////////////////////////////////////////////////////////////
251Float_t AliSample::GetVar(Int_t i)
252{
253// Provide the variance of a certain variable
254 if (fDim < i)
255 {
256 cout << " *AliSample::var* Error : Dimension less than " << i << endl;
257 return 0.;
258 }
259 else
260 {
261 return fVar[i-1];
262 }
263}
264///////////////////////////////////////////////////////////////////////////
265Float_t AliSample::GetSigma(Int_t i)
266{
267// Provide the standard deviation of a certain variable
268 if (fDim < i)
269 {
270 cout << " *AliSample::sigma* Error : Dimension less than " << i << endl;
271 return 0.;
272 }
273 else
274 {
275 return fSigma[i-1];
276 }
277}
278///////////////////////////////////////////////////////////////////////////
279Float_t AliSample::GetCov(Int_t i,Int_t j)
280{
281// Provide the covariance between variables i and j
282 if ((fDim < i) || (fDim < j))
283 {
284 Int_t k=i;
285 if (j > i) k=j;
286 cout << " *AliSample::cov* Error : Dimension less than " << k << endl;
287 return 0.;
288 }
289 else
290 {
291 return fCov[i-1][j-1];
292 }
293}
294///////////////////////////////////////////////////////////////////////////
295Float_t AliSample::GetCor(Int_t i,Int_t j)
296{
297// Provide the correlation between variables i and j
298 if ((fDim < i) || (fDim < j))
299 {
300 Int_t k=i;
301 if (j > i) k=j;
302 cout << " *AliSample::cor* Error : Dimension less than " << k << endl;
303 return 0.;
304 }
305 else
306 {
307 return fCor[i-1][j-1];
308 }
309}
310///////////////////////////////////////////////////////////////////////////
311void AliSample::Info()
312{
313// Printing of statistics of all variables
314 for (Int_t i=0; i<fDim; i++)
315 {
316 cout << " " << fNames[i] << " : N = " << fN;
317 cout << " Sum = " << fSum[i] << " Mean = " << fMean[i];
318 cout << " Var = " << fVar[i] << " Sigma = " << fSigma[i] << endl;
319 }
320}
321///////////////////////////////////////////////////////////////////////////
322void AliSample::Info(Int_t i)
323{
324// Printing of statistics of ith variable
325 if (fDim < i)
326 {
327 cout << " *AliSample::Info(i)* Error : Dimension less than " << i << endl;
328 }
329 else
330 {
331 cout << " " << fNames[i-1] << " : N = " << fN;
332 cout << " Sum = " << fSum[i-1] << " Mean = " << fMean[i-1];
333 cout << " Var = " << fVar[i-1] << " Sigma = " << fSigma[i-1] << endl;
334 }
335}
336///////////////////////////////////////////////////////////////////////////
337void AliSample::Info(Int_t i,Int_t j)
338{
339// Printing of covariance and correlation between variables i and j
340 if ((fDim < i) || (fDim < j))
341 {
342 Int_t k=i;
343 if (j > i) k=j;
344 cout << " *AliSample::Info(i,j)* Error : Dimension less than " << k << endl;
345 }
346 else
347 {
348 cout << " " << fNames[i-1] << "-" << fNames[j-1] << " correlation :";
349 cout << " Cov. = " << fCov[i-1][j-1] << " Cor. = " << fCor[i-1][j-1] << endl;
350 }
351}
352///////////////////////////////////////////////////////////////////////////