1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Perform statistics on various multi-dimensional data samples.
21 // A data sample can be filled using the "Enter" and/or "Remove" functions,
22 // whereas the "Reset" function resets the complete sample to 'empty'.
23 // The info which can be extracted from a certain data sample are the
24 // sum, mean, variance, sigma, covariance and correlation.
25 // The "Data" function provides all statistics data for a certain sample.
26 // The variables for which these stat. parameters have to be calculated
27 // are indicated by the index of the variable which is passed as an
28 // argument to the various member functions.
29 // The index convention for a data point (x,y) is : x=1 y=2
33 // For an AliSample s a data point (x,y) can be entered as s.Enter(x,y) and
34 // the mean_x can be obtained as s.GetMean(1) whereas the mean_y is obtained
36 // The correlation between x and y is available via s.GetCor(1,2).
37 // The x-statistics are obtained via s.Data(1), y-statistics via s.Data(2),
38 // and the covariance and correlation between x and y via s.Data(1,2).
39 // All statistics of a sample are obtained via s.Data().
41 //--- Author: Nick van Eijndhoven 30-mar-1996 CERN Geneva
42 //- Modified: NvE $Date$ UU-SAP Utrecht
43 ///////////////////////////////////////////////////////////////////////////
45 #include "AliSample.h"
46 #include "Riostream.h"
48 ClassImp(AliSample) // Class implementation to enable ROOT I/O
50 AliSample::AliSample()
52 // Creation of an Aliample object and resetting the statistics values
53 // The dimension is initialised to maximum
61 ///////////////////////////////////////////////////////////////////////////
62 AliSample::~AliSample()
66 ///////////////////////////////////////////////////////////////////////////
67 void AliSample::Reset()
69 // Resetting the statistics values for a certain Sample object
70 // Dimension is NOT changed
72 for (Int_t i=0; i<fDim; i++)
78 for (Int_t j=0; j<fDim; j++)
86 ///////////////////////////////////////////////////////////////////////////
87 void AliSample::Enter(Float_t x)
89 // Entering a value into a 1-dim. sample
90 // In case of first entry the dimension is set to 1
100 cout << " *AliSample::enter* Error : Not a 1-dim sample." << endl;
110 ///////////////////////////////////////////////////////////////////////////
111 void AliSample::Remove(Float_t x)
113 // Removing a value from a 1-dim. sample
116 cout << " *AliSample::remove* Error : Not a 1-dim sample." << endl;
126 ///////////////////////////////////////////////////////////////////////////
127 void AliSample::Enter(Float_t x,Float_t y)
129 // Entering a pair (x,y) into a 2-dim. sample
130 // In case of first entry the dimension is set to 2
140 cout << " *AliSample::enter* Error : Not a 2-dim sample." << endl;
154 ///////////////////////////////////////////////////////////////////////////
155 void AliSample::Remove(Float_t x,Float_t y)
157 // Removing a pair (x,y) from a 2-dim. sample
160 cout << " *AliSample::remove* Error : Not a 2-dim sample." << endl;
174 ///////////////////////////////////////////////////////////////////////////
175 void AliSample::Enter(Float_t x,Float_t y,Float_t z)
177 // Entering a set (x,y,z) into a 3-dim. sample
178 // In case of first entry the dimension is set to 3
188 cout << " *AliSample::enter* Error : Not a 3-dim sample." << endl;
208 ///////////////////////////////////////////////////////////////////////////
209 void AliSample::Remove(Float_t x,Float_t y,Float_t z)
211 // Removing a set (x,y,z) from a 3-dim. sample
214 cout << " *AliSample::remove* Error : Not a 3-dim sample." << endl;
234 ///////////////////////////////////////////////////////////////////////////
235 void AliSample::Compute()
237 // Computation of the various statistical values
238 // after each entering or removing action on a certain sample
240 for (Int_t k=0; k<fDim; k++)
243 fVar[k]=(fSum2[k][k]/rn)-(fMean[k]*fMean[k]);
244 if (fVar[k] < 0.) fVar[k]=0.;
245 fSigma[k]=sqrt(fVar[k]);
247 for (Int_t i=0; i<fDim; i++)
249 for (Int_t j=0; j<fDim; j++)
251 fCov[i][j]=(fSum2[i][j]/rn)-(fMean[i]*fMean[j]);
252 Float_t sigij=fSigma[i]*fSigma[j];
253 if (sigij != 0.) fCor[i][j]=fCov[i][j]/sigij;
257 ///////////////////////////////////////////////////////////////////////////
258 Int_t AliSample::GetDimension() const
260 // Provide the dimension of a certain sample
263 ///////////////////////////////////////////////////////////////////////////
264 Int_t AliSample::GetN() const
266 // Provide the number of entries of a certain sample
269 ///////////////////////////////////////////////////////////////////////////
270 Float_t AliSample::GetSum(Int_t i) const
272 // Provide the sum of a certain variable
275 cout << " *AliSample::sum* Error : Dimension less than " << i << endl;
283 ///////////////////////////////////////////////////////////////////////////
284 Float_t AliSample::GetMean(Int_t i) const
286 // Provide the mean of a certain variable
289 cout << " *AliSample::mean* Error : Dimension less than " << i << endl;
297 ///////////////////////////////////////////////////////////////////////////
298 Float_t AliSample::GetVar(Int_t i) const
300 // Provide the variance of a certain variable
303 cout << " *AliSample::var* Error : Dimension less than " << i << endl;
311 ///////////////////////////////////////////////////////////////////////////
312 Float_t AliSample::GetSigma(Int_t i) const
314 // Provide the standard deviation of a certain variable
317 cout << " *AliSample::sigma* Error : Dimension less than " << i << endl;
325 ///////////////////////////////////////////////////////////////////////////
326 Float_t AliSample::GetCov(Int_t i,Int_t j) const
328 // Provide the covariance between variables i and j
329 if ((fDim < i) || (fDim < j))
333 cout << " *AliSample::cov* Error : Dimension less than " << k << endl;
338 return fCov[i-1][j-1];
341 ///////////////////////////////////////////////////////////////////////////
342 Float_t AliSample::GetCor(Int_t i,Int_t j) const
344 // Provide the correlation between variables i and j
345 if ((fDim < i) || (fDim < j))
349 cout << " *AliSample::cor* Error : Dimension less than " << k << endl;
354 return fCor[i-1][j-1];
357 ///////////////////////////////////////////////////////////////////////////
358 void AliSample::Data() const
360 // Printing of statistics of all variables
361 for (Int_t i=0; i<fDim; i++)
363 cout << " " << fNames[i] << " : N = " << fN;
364 cout << " Sum = " << fSum[i] << " Mean = " << fMean[i];
365 cout << " Var = " << fVar[i] << " Sigma = " << fSigma[i] << endl;
368 ///////////////////////////////////////////////////////////////////////////
369 void AliSample::Data(Int_t i) const
371 // Printing of statistics of ith variable
374 cout << " *AliSample::Data(i)* Error : Dimension less than " << i << endl;
378 cout << " " << fNames[i-1] << " : N = " << fN;
379 cout << " Sum = " << fSum[i-1] << " Mean = " << fMean[i-1];
380 cout << " Var = " << fVar[i-1] << " Sigma = " << fSigma[i-1] << endl;
383 ///////////////////////////////////////////////////////////////////////////
384 void AliSample::Data(Int_t i,Int_t j) const
386 // Printing of covariance and correlation between variables i and j
387 if ((fDim < i) || (fDim < j))
391 cout << " *AliSample::Data(i,j)* Error : Dimension less than " << k << endl;
395 cout << " " << fNames[i-1] << "-" << fNames[j-1] << " correlation :";
396 cout << " Cov. = " << fCov[i-1][j-1] << " Cor. = " << fCor[i-1][j-1] << endl;
399 ///////////////////////////////////////////////////////////////////////////