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 Revision 1.2 1999/09/29 09:24:28 fca
19 Introduction of the Copyright and cvs Log
23 ///////////////////////////////////////////////////////////////////////////
25 // Perform statistics on various multi-dimensional data samples
26 // A data sample can be filled using the "Enter" and/or "Remove" functions,
27 // whereas the "Reset" function resets the complete sample to 'empty'.
28 // The info which can be extracted from a certain data sample are the
29 // sum, mean, variance, sigma, covariance and correlation.
30 // The "Info" function provides all statistics data for a certain sample.
31 // The variables for which these stat. parameters have to be calculated
32 // are indicated by the index of the variable which is passed as an
33 // argument to the various member functions.
34 // The index convention for a data point (x,y) is : x=1 y=2
38 // For an AliSample s a data point (x,y) can be entered as s.Enter(x,y) and
39 // the mean_x can be obtained as s.GetMean(1) whereas the mean_y is obtained
41 // The correlation between x and y is available via s.GetCor(1,2).
42 // The x-statistics are obtained via s.Info(1), y-statistics via s.Info(2),
43 // and the covariance and correlation between x and y via s.Info(1,2).
44 // All statistics of a sample are obtained via s.Info().
46 //--- Author: Nick van Eijndhoven 30-mar-1996 CERN Geneva
47 ///////////////////////////////////////////////////////////////////////////
49 #include "AliSample.h"
51 AliSample::AliSample()
53 // Creation of an Aliample object and resetting the statistics values
54 // The dimension is initialised to maximum
62 ///////////////////////////////////////////////////////////////////////////
63 AliSample::~AliSample()
67 ///////////////////////////////////////////////////////////////////////////
68 void AliSample::Reset()
70 // Resetting the statistics values for a certain Sample object
71 // Dimension is NOT changed
73 for (Int_t i=0; i<fDim; i++)
79 for (Int_t j=0; j<fDim; j++)
87 ///////////////////////////////////////////////////////////////////////////
88 void AliSample::Enter(Float_t x)
90 // Entering a value into a 1-dim. sample
91 // In case of first entry the dimension is set to 1
101 cout << " *AliSample::enter* Error : Not a 1-dim sample." << endl;
111 ///////////////////////////////////////////////////////////////////////////
112 void AliSample::Remove(Float_t x)
114 // Removing a value from a 1-dim. sample
117 cout << " *AliSample::remove* Error : Not a 1-dim sample." << endl;
127 ///////////////////////////////////////////////////////////////////////////
128 void AliSample::Enter(Float_t x,Float_t y)
130 // Entering a pair (x,y) into a 2-dim. sample
131 // In case of first entry the dimension is set to 2
141 cout << " *AliSample::enter* Error : Not a 2-dim sample." << endl;
155 ///////////////////////////////////////////////////////////////////////////
156 void AliSample::Remove(Float_t x,Float_t y)
158 // Removing a pair (x,y) from a 2-dim. sample
161 cout << " *AliSample::remove* Error : Not a 2-dim sample." << endl;
175 ///////////////////////////////////////////////////////////////////////////
176 void AliSample::Enter(Float_t x,Float_t y,Float_t z)
178 // Entering a set (x,y,z) into a 3-dim. sample
179 // In case of first entry the dimension is set to 3
189 cout << " *AliSample::enter* Error : Not a 3-dim sample." << endl;
209 ///////////////////////////////////////////////////////////////////////////
210 void AliSample::Remove(Float_t x,Float_t y,Float_t z)
212 // Removing a set (x,y,z) from a 3-dim. sample
215 cout << " *AliSample::remove* Error : Not a 3-dim sample." << endl;
235 ///////////////////////////////////////////////////////////////////////////
236 void AliSample::Compute()
238 // Computation of the various statistical values
239 // after each entering or removing action on a certain sample
241 for (Int_t k=0; k<fDim; k++)
244 fVar[k]=(fSum2[k][k]/rn)-(fMean[k]*fMean[k]);
245 if (fVar[k] < 0.) fVar[k]=0.;
246 fSigma[k]=sqrt(fVar[k]);
248 for (Int_t i=0; i<fDim; i++)
250 for (Int_t j=0; j<fDim; j++)
252 fCov[i][j]=(fSum2[i][j]/rn)-(fMean[i]*fMean[j]);
253 Float_t sigij=fSigma[i]*fSigma[j];
254 if (sigij != 0.) fCor[i][j]=fCov[i][j]/sigij;
258 ///////////////////////////////////////////////////////////////////////////
259 Int_t AliSample::GetDimension()
261 // Provide the dimension of a certain sample
264 ///////////////////////////////////////////////////////////////////////////
265 Int_t AliSample::GetN()
267 // Provide the number of entries of a certain sample
270 ///////////////////////////////////////////////////////////////////////////
271 Float_t AliSample::GetSum(Int_t i)
273 // Provide the sum of a certain variable
276 cout << " *AliSample::sum* Error : Dimension less than " << i << endl;
284 ///////////////////////////////////////////////////////////////////////////
285 Float_t AliSample::GetMean(Int_t i)
287 // Provide the mean of a certain variable
290 cout << " *AliSample::mean* Error : Dimension less than " << i << endl;
298 ///////////////////////////////////////////////////////////////////////////
299 Float_t AliSample::GetVar(Int_t i)
301 // Provide the variance of a certain variable
304 cout << " *AliSample::var* Error : Dimension less than " << i << endl;
312 ///////////////////////////////////////////////////////////////////////////
313 Float_t AliSample::GetSigma(Int_t i)
315 // Provide the standard deviation of a certain variable
318 cout << " *AliSample::sigma* Error : Dimension less than " << i << endl;
326 ///////////////////////////////////////////////////////////////////////////
327 Float_t AliSample::GetCov(Int_t i,Int_t j)
329 // Provide the covariance between variables i and j
330 if ((fDim < i) || (fDim < j))
334 cout << " *AliSample::cov* Error : Dimension less than " << k << endl;
339 return fCov[i-1][j-1];
342 ///////////////////////////////////////////////////////////////////////////
343 Float_t AliSample::GetCor(Int_t i,Int_t j)
345 // Provide the correlation between variables i and j
346 if ((fDim < i) || (fDim < j))
350 cout << " *AliSample::cor* Error : Dimension less than " << k << endl;
355 return fCor[i-1][j-1];
358 ///////////////////////////////////////////////////////////////////////////
359 void AliSample::Info()
361 // Printing of statistics of all variables
362 for (Int_t i=0; i<fDim; i++)
364 cout << " " << fNames[i] << " : N = " << fN;
365 cout << " Sum = " << fSum[i] << " Mean = " << fMean[i];
366 cout << " Var = " << fVar[i] << " Sigma = " << fSigma[i] << endl;
369 ///////////////////////////////////////////////////////////////////////////
370 void AliSample::Info(Int_t i)
372 // Printing of statistics of ith variable
375 cout << " *AliSample::Info(i)* Error : Dimension less than " << i << endl;
379 cout << " " << fNames[i-1] << " : N = " << fN;
380 cout << " Sum = " << fSum[i-1] << " Mean = " << fMean[i-1];
381 cout << " Var = " << fVar[i-1] << " Sigma = " << fSigma[i-1] << endl;
384 ///////////////////////////////////////////////////////////////////////////
385 void AliSample::Info(Int_t i,Int_t j)
387 // Printing of covariance and correlation between variables i and j
388 if ((fDim < i) || (fDim < j))
392 cout << " *AliSample::Info(i,j)* Error : Dimension less than " << k << endl;
396 cout << " " << fNames[i-1] << "-" << fNames[j-1] << " correlation :";
397 cout << " Cov. = " << fCov[i-1][j-1] << " Cor. = " << fCor[i-1][j-1] << endl;
400 ///////////////////////////////////////////////////////////////////////////