]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliSample.cxx
removed unused variables warnings
[u/mrichter/AliRoot.git] / RALICE / AliSample.cxx
CommitLineData
4c039060 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
f531a546 16// $Id$
4c039060 17
959fbac5 18///////////////////////////////////////////////////////////////////////////
19// Class AliSample
6516b62d 20// Perform statistics on various multi-dimensional data samples.
959fbac5 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.
84bb7c66 25// The "Data" function provides all statistics data for a certain sample.
959fbac5 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
30//
31// Example :
32// ---------
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
35// via s.GetMean(2).
36// The correlation between x and y is available via s.GetCor(1,2).
84bb7c66 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().
959fbac5 40//
41//--- Author: Nick van Eijndhoven 30-mar-1996 CERN Geneva
f531a546 42//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 43///////////////////////////////////////////////////////////////////////////
44
d88f97cc 45#include "AliSample.h"
46
6516b62d 47ClassImp(AliSample) // Class implementation to enable ROOT I/O
48
d88f97cc 49AliSample::AliSample()
50{
51// Creation of an Aliample object and resetting the statistics values
52// The dimension is initialised to maximum
53 fDim=fMaxdim;
54 fNames[0]='X';
55 fNames[1]='Y';
56 fNames[2]='Z';
57 fN=0;
58 Reset();
59}
60///////////////////////////////////////////////////////////////////////////
61AliSample::~AliSample()
62{
63// Default destructor
64}
65///////////////////////////////////////////////////////////////////////////
66void AliSample::Reset()
67{
68// Resetting the statistics values for a certain Sample object
69// Dimension is NOT changed
70 fN=0;
71 for (Int_t i=0; i<fDim; i++)
72 {
73 fSum[i]=0.;
74 fMean[i]=0.;
75 fVar[i]=0.;
76 fSigma[i]=0.;
77 for (Int_t j=0; j<fDim; j++)
78 {
79 fSum2[i][j]=0.;
80 fCov[i][j]=0.;
81 fCor[i][j]=0.;
82 }
83 }
84}
85///////////////////////////////////////////////////////////////////////////
86void AliSample::Enter(Float_t x)
87{
88// Entering a value into a 1-dim. sample
89// In case of first entry the dimension is set to 1
90 if (fN == 0)
91 {
92 fDim=1;
93 fNames[0]='X';
94 fNames[1]='-';
95 fNames[2]='-';
96 }
97 if (fDim != 1)
98 {
99 cout << " *AliSample::enter* Error : Not a 1-dim sample." << endl;
100 }
101 else
102 {
103 fN+=1;
104 fSum[0]+=x;
105 fSum2[0][0]+=x*x;
106 Compute();
107 }
108}
109///////////////////////////////////////////////////////////////////////////
110void AliSample::Remove(Float_t x)
111{
112// Removing a value from a 1-dim. sample
113 if (fDim != 1)
114 {
115 cout << " *AliSample::remove* Error : Not a 1-dim sample." << endl;
116 }
117 else
118 {
119 fN-=1;
120 fSum[0]-=x;
121 fSum2[0][0]-=x*x;
122 Compute();
123 }
124}
125///////////////////////////////////////////////////////////////////////////
126void AliSample::Enter(Float_t x,Float_t y)
127{
128// Entering a pair (x,y) into a 2-dim. sample
129// In case of first entry the dimension is set to 2
130 if (fN == 0)
131 {
132 fDim=2;
133 fNames[0]='X';
134 fNames[1]='Y';
135 fNames[2]='-';
136 }
137 if (fDim != 2)
138 {
139 cout << " *AliSample::enter* Error : Not a 2-dim sample." << endl;
140 }
141 else
142 {
143 fN+=1;
144 fSum[0]+=x;
145 fSum[1]+=y;
146 fSum2[0][0]+=x*x;
147 fSum2[0][1]+=x*y;
148 fSum2[1][0]+=y*x;
149 fSum2[1][1]+=y*y;
150 Compute();
151 }
152}
153///////////////////////////////////////////////////////////////////////////
154void AliSample::Remove(Float_t x,Float_t y)
155{
156// Removing a pair (x,y) from a 2-dim. sample
157 if (fDim != 2)
158 {
159 cout << " *AliSample::remove* Error : Not a 2-dim sample." << endl;
160 }
161 else
162 {
163 fN-=1;
164 fSum[0]-=x;
165 fSum[1]-=y;
166 fSum2[0][0]-=x*x;
167 fSum2[0][1]-=x*y;
168 fSum2[1][0]-=y*x;
169 fSum2[1][1]-=y*y;
170 Compute();
171 }
172}
173///////////////////////////////////////////////////////////////////////////
174void AliSample::Enter(Float_t x,Float_t y,Float_t z)
175{
176// Entering a set (x,y,z) into a 3-dim. sample
177// In case of first entry the dimension is set to 3
178 if (fN == 0)
179 {
180 fDim=3;
181 fNames[0]='X';
182 fNames[1]='Y';
183 fNames[2]='Z';
184 }
185 if (fDim != 3)
186 {
187 cout << " *AliSample::enter* Error : Not a 3-dim sample." << endl;
188 }
189 else
190 {
191 fN+=1;
192 fSum[0]+=x;
193 fSum[1]+=y;
194 fSum[2]+=z;
195 fSum2[0][0]+=x*x;
196 fSum2[0][1]+=x*y;
197 fSum2[0][2]+=x*z;
198 fSum2[1][0]+=y*x;
199 fSum2[1][1]+=y*y;
200 fSum2[1][2]+=y*z;
201 fSum2[2][0]+=z*x;
202 fSum2[2][1]+=z*y;
203 fSum2[2][2]+=z*z;
204 Compute();
205 }
206}
207///////////////////////////////////////////////////////////////////////////
208void AliSample::Remove(Float_t x,Float_t y,Float_t z)
209{
210// Removing a set (x,y,z) from a 3-dim. sample
211 if (fDim != 3)
212 {
213 cout << " *AliSample::remove* Error : Not a 3-dim sample." << endl;
214 }
215 else
216 {
217 fN-=1;
218 fSum[0]-=x;
219 fSum[1]-=y;
220 fSum[2]-=z;
221 fSum2[0][0]-=x*x;
222 fSum2[0][1]-=x*y;
223 fSum2[0][2]-=x*z;
224 fSum2[1][0]-=y*x;
225 fSum2[1][1]-=y*y;
226 fSum2[1][2]-=y*z;
227 fSum2[2][0]-=z*x;
228 fSum2[2][1]-=z*y;
229 fSum2[2][2]-=z*z;
230 Compute();
231 }
232}
233///////////////////////////////////////////////////////////////////////////
234void AliSample::Compute()
235{
236// Computation of the various statistical values
237// after each entering or removing action on a certain sample
238 Float_t rn=fN;
239 for (Int_t k=0; k<fDim; k++)
240 {
241 fMean[k]=fSum[k]/rn;
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]);
245 }
246 for (Int_t i=0; i<fDim; i++)
247 {
248 for (Int_t j=0; j<fDim; j++)
249 {
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;
253 }
254 }
255}
256///////////////////////////////////////////////////////////////////////////
257Int_t AliSample::GetDimension()
258{
259// Provide the dimension of a certain sample
260 return fDim;
261}
262///////////////////////////////////////////////////////////////////////////
263Int_t AliSample::GetN()
264{
265// Provide the number of entries of a certain sample
266 return fN;
267}
268///////////////////////////////////////////////////////////////////////////
269Float_t AliSample::GetSum(Int_t i)
270{
271// Provide the sum of a certain variable
272 if (fDim < i)
273 {
274 cout << " *AliSample::sum* Error : Dimension less than " << i << endl;
275 return 0.;
276 }
277 else
278 {
279 return fSum[i-1];
280 }
281}
282///////////////////////////////////////////////////////////////////////////
283Float_t AliSample::GetMean(Int_t i)
284{
285// Provide the mean of a certain variable
286 if (fDim < i)
287 {
288 cout << " *AliSample::mean* Error : Dimension less than " << i << endl;
289 return 0.;
290 }
291 else
292 {
293 return fMean[i-1];
294 }
295}
296///////////////////////////////////////////////////////////////////////////
297Float_t AliSample::GetVar(Int_t i)
298{
299// Provide the variance of a certain variable
300 if (fDim < i)
301 {
302 cout << " *AliSample::var* Error : Dimension less than " << i << endl;
303 return 0.;
304 }
305 else
306 {
307 return fVar[i-1];
308 }
309}
310///////////////////////////////////////////////////////////////////////////
311Float_t AliSample::GetSigma(Int_t i)
312{
313// Provide the standard deviation of a certain variable
314 if (fDim < i)
315 {
316 cout << " *AliSample::sigma* Error : Dimension less than " << i << endl;
317 return 0.;
318 }
319 else
320 {
321 return fSigma[i-1];
322 }
323}
324///////////////////////////////////////////////////////////////////////////
325Float_t AliSample::GetCov(Int_t i,Int_t j)
326{
327// Provide the covariance between variables i and j
328 if ((fDim < i) || (fDim < j))
329 {
330 Int_t k=i;
331 if (j > i) k=j;
332 cout << " *AliSample::cov* Error : Dimension less than " << k << endl;
333 return 0.;
334 }
335 else
336 {
337 return fCov[i-1][j-1];
338 }
339}
340///////////////////////////////////////////////////////////////////////////
341Float_t AliSample::GetCor(Int_t i,Int_t j)
342{
343// Provide the correlation between variables i and j
344 if ((fDim < i) || (fDim < j))
345 {
346 Int_t k=i;
347 if (j > i) k=j;
348 cout << " *AliSample::cor* Error : Dimension less than " << k << endl;
349 return 0.;
350 }
351 else
352 {
353 return fCor[i-1][j-1];
354 }
355}
356///////////////////////////////////////////////////////////////////////////
84bb7c66 357void AliSample::Data()
d88f97cc 358{
359// Printing of statistics of all variables
360 for (Int_t i=0; i<fDim; i++)
361 {
362 cout << " " << fNames[i] << " : N = " << fN;
363 cout << " Sum = " << fSum[i] << " Mean = " << fMean[i];
364 cout << " Var = " << fVar[i] << " Sigma = " << fSigma[i] << endl;
365 }
366}
367///////////////////////////////////////////////////////////////////////////
84bb7c66 368void AliSample::Data(Int_t i)
d88f97cc 369{
370// Printing of statistics of ith variable
371 if (fDim < i)
372 {
84bb7c66 373 cout << " *AliSample::Data(i)* Error : Dimension less than " << i << endl;
d88f97cc 374 }
375 else
376 {
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;
380 }
381}
382///////////////////////////////////////////////////////////////////////////
84bb7c66 383void AliSample::Data(Int_t i,Int_t j)
d88f97cc 384{
385// Printing of covariance and correlation between variables i and j
386 if ((fDim < i) || (fDim < j))
387 {
388 Int_t k=i;
389 if (j > i) k=j;
84bb7c66 390 cout << " *AliSample::Data(i,j)* Error : Dimension less than " << k << endl;
d88f97cc 391 }
392 else
393 {
394 cout << " " << fNames[i-1] << "-" << fNames[j-1] << " correlation :";
395 cout << " Cov. = " << fCov[i-1][j-1] << " Cor. = " << fCor[i-1][j-1] << endl;
396 }
397}
398///////////////////////////////////////////////////////////////////////////