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