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 "Info" 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.Info(1), y-statistics via s.Info(2),
38 // and the covariance and correlation between x and y via s.Info(1,2).
39 // All statistics of a sample are obtained via s.Info().
41 //--- Author: Nick van Eijndhoven 30-mar-1996 CERN Geneva
42 //- Modified: NvE $Date$ UU-SAP Utrecht
43 ///////////////////////////////////////////////////////////////////////////
45 #include "AliSample.h"
47 ClassImp(AliSample) // Class implementation to enable ROOT I/O
49 AliSample::AliSample()
51 // Creation of an Aliample object and resetting the statistics values
52 // The dimension is initialised to maximum
60 ///////////////////////////////////////////////////////////////////////////
61 AliSample::~AliSample()
65 ///////////////////////////////////////////////////////////////////////////
66 void AliSample::Reset()
68 // Resetting the statistics values for a certain Sample object
69 // Dimension is NOT changed
71 for (Int_t i=0; i<fDim; i++)
77 for (Int_t j=0; j<fDim; j++)
85 ///////////////////////////////////////////////////////////////////////////
86 void AliSample::Enter(Float_t x)
88 // Entering a value into a 1-dim. sample
89 // In case of first entry the dimension is set to 1
99 cout << " *AliSample::enter* Error : Not a 1-dim sample." << endl;
109 ///////////////////////////////////////////////////////////////////////////
110 void AliSample::Remove(Float_t x)
112 // Removing a value from a 1-dim. sample
115 cout << " *AliSample::remove* Error : Not a 1-dim sample." << endl;
125 ///////////////////////////////////////////////////////////////////////////
126 void AliSample::Enter(Float_t x,Float_t y)
128 // Entering a pair (x,y) into a 2-dim. sample
129 // In case of first entry the dimension is set to 2
139 cout << " *AliSample::enter* Error : Not a 2-dim sample." << endl;
153 ///////////////////////////////////////////////////////////////////////////
154 void AliSample::Remove(Float_t x,Float_t y)
156 // Removing a pair (x,y) from a 2-dim. sample
159 cout << " *AliSample::remove* Error : Not a 2-dim sample." << endl;
173 ///////////////////////////////////////////////////////////////////////////
174 void AliSample::Enter(Float_t x,Float_t y,Float_t z)
176 // Entering a set (x,y,z) into a 3-dim. sample
177 // In case of first entry the dimension is set to 3
187 cout << " *AliSample::enter* Error : Not a 3-dim sample." << endl;
207 ///////////////////////////////////////////////////////////////////////////
208 void AliSample::Remove(Float_t x,Float_t y,Float_t z)
210 // Removing a set (x,y,z) from a 3-dim. sample
213 cout << " *AliSample::remove* Error : Not a 3-dim sample." << endl;
233 ///////////////////////////////////////////////////////////////////////////
234 void AliSample::Compute()
236 // Computation of the various statistical values
237 // after each entering or removing action on a certain sample
239 for (Int_t k=0; k<fDim; k++)
242 fVar[k]=(fSum2[k][k]/rn)-(fMean[k]*fMean[k]);
243 if (fVar[k] < 0.) fVar[k]=0.;
244 fSigma[k]=sqrt(fVar[k]);
246 for (Int_t i=0; i<fDim; i++)
248 for (Int_t j=0; j<fDim; j++)
250 fCov[i][j]=(fSum2[i][j]/rn)-(fMean[i]*fMean[j]);
251 Float_t sigij=fSigma[i]*fSigma[j];
252 if (sigij != 0.) fCor[i][j]=fCov[i][j]/sigij;
256 ///////////////////////////////////////////////////////////////////////////
257 Int_t AliSample::GetDimension()
259 // Provide the dimension of a certain sample
262 ///////////////////////////////////////////////////////////////////////////
263 Int_t AliSample::GetN()
265 // Provide the number of entries of a certain sample
268 ///////////////////////////////////////////////////////////////////////////
269 Float_t AliSample::GetSum(Int_t i)
271 // Provide the sum of a certain variable
274 cout << " *AliSample::sum* Error : Dimension less than " << i << endl;
282 ///////////////////////////////////////////////////////////////////////////
283 Float_t AliSample::GetMean(Int_t i)
285 // Provide the mean of a certain variable
288 cout << " *AliSample::mean* Error : Dimension less than " << i << endl;
296 ///////////////////////////////////////////////////////////////////////////
297 Float_t AliSample::GetVar(Int_t i)
299 // Provide the variance of a certain variable
302 cout << " *AliSample::var* Error : Dimension less than " << i << endl;
310 ///////////////////////////////////////////////////////////////////////////
311 Float_t AliSample::GetSigma(Int_t i)
313 // Provide the standard deviation of a certain variable
316 cout << " *AliSample::sigma* Error : Dimension less than " << i << endl;
324 ///////////////////////////////////////////////////////////////////////////
325 Float_t AliSample::GetCov(Int_t i,Int_t j)
327 // Provide the covariance between variables i and j
328 if ((fDim < i) || (fDim < j))
332 cout << " *AliSample::cov* Error : Dimension less than " << k << endl;
337 return fCov[i-1][j-1];
340 ///////////////////////////////////////////////////////////////////////////
341 Float_t AliSample::GetCor(Int_t i,Int_t j)
343 // Provide the correlation between variables i and j
344 if ((fDim < i) || (fDim < j))
348 cout << " *AliSample::cor* Error : Dimension less than " << k << endl;
353 return fCor[i-1][j-1];
356 ///////////////////////////////////////////////////////////////////////////
357 void AliSample::Info()
359 // Printing of statistics of all variables
360 for (Int_t i=0; i<fDim; i++)
362 cout << " " << fNames[i] << " : N = " << fN;
363 cout << " Sum = " << fSum[i] << " Mean = " << fMean[i];
364 cout << " Var = " << fVar[i] << " Sigma = " << fSigma[i] << endl;
367 ///////////////////////////////////////////////////////////////////////////
368 void AliSample::Info(Int_t i)
370 // Printing of statistics of ith variable
373 cout << " *AliSample::Info(i)* Error : Dimension less than " << i << endl;
377 cout << " " << fNames[i-1] << " : N = " << fN;
378 cout << " Sum = " << fSum[i-1] << " Mean = " << fMean[i-1];
379 cout << " Var = " << fVar[i-1] << " Sigma = " << fSigma[i-1] << endl;
382 ///////////////////////////////////////////////////////////////////////////
383 void AliSample::Info(Int_t i,Int_t j)
385 // Printing of covariance and correlation between variables i and j
386 if ((fDim < i) || (fDim < j))
390 cout << " *AliSample::Info(i,j)* Error : Dimension less than " << k << endl;
394 cout << " " << fNames[i-1] << "-" << fNames[j-1] << " correlation :";
395 cout << " Cov. = " << fCov[i-1][j-1] << " Cor. = " << fCor[i-1][j-1] << endl;
398 ///////////////////////////////////////////////////////////////////////////