]>
Commit | Line | Data |
---|---|---|
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" |
c72198f1 | 46 | #include "Riostream.h" |
d88f97cc | 47 | |
6516b62d | 48 | ClassImp(AliSample) // Class implementation to enable ROOT I/O |
49 | ||
d88f97cc | 50 | AliSample::AliSample() |
51 | { | |
52 | // Creation of an Aliample object and resetting the statistics values | |
53 | // The dimension is initialised to maximum | |
54 | fDim=fMaxdim; | |
55 | fNames[0]='X'; | |
56 | fNames[1]='Y'; | |
57 | fNames[2]='Z'; | |
58 | fN=0; | |
25eefd00 | 59 | fRemove=0; |
219e9b7e | 60 | fStore=0; |
61 | fX=0; | |
62 | fY=0; | |
63 | fZ=0; | |
64 | fArr=0; | |
d88f97cc | 65 | Reset(); |
66 | } | |
67 | /////////////////////////////////////////////////////////////////////////// | |
68 | AliSample::~AliSample() | |
69 | { | |
70 | // Default destructor | |
219e9b7e | 71 | if (fX) |
72 | { | |
73 | delete fX; | |
74 | fX=0; | |
75 | } | |
76 | if (fY) | |
77 | { | |
78 | delete fY; | |
79 | fY=0; | |
80 | } | |
81 | if (fZ) | |
82 | { | |
83 | delete fZ; | |
84 | fZ=0; | |
85 | } | |
86 | if (fArr) | |
87 | { | |
88 | delete fArr; | |
89 | fArr=0; | |
90 | } | |
d88f97cc | 91 | } |
92 | /////////////////////////////////////////////////////////////////////////// | |
93 | void AliSample::Reset() | |
94 | { | |
95 | // Resetting the statistics values for a certain Sample object | |
219e9b7e | 96 | // Dimension and storage flag are NOT changed |
d88f97cc | 97 | fN=0; |
25eefd00 | 98 | fRemove=0; |
d88f97cc | 99 | for (Int_t i=0; i<fDim; i++) |
100 | { | |
101 | fSum[i]=0.; | |
102 | fMean[i]=0.; | |
103 | fVar[i]=0.; | |
104 | fSigma[i]=0.; | |
25eefd00 | 105 | fMin[i]=0; |
106 | fMax[i]=0; | |
d88f97cc | 107 | for (Int_t j=0; j<fDim; j++) |
108 | { | |
109 | fSum2[i][j]=0.; | |
110 | fCov[i][j]=0.; | |
111 | fCor[i][j]=0.; | |
112 | } | |
113 | } | |
219e9b7e | 114 | |
115 | // Set storage arrays to initial size | |
116 | if (fX) fX->Set(10); | |
117 | if (fY) fY->Set(10); | |
118 | if (fZ) fZ->Set(10); | |
d88f97cc | 119 | } |
120 | /////////////////////////////////////////////////////////////////////////// | |
121 | void AliSample::Enter(Float_t x) | |
122 | { | |
123 | // Entering a value into a 1-dim. sample | |
124 | // In case of first entry the dimension is set to 1 | |
125 | if (fN == 0) | |
126 | { | |
127 | fDim=1; | |
128 | fNames[0]='X'; | |
129 | fNames[1]='-'; | |
130 | fNames[2]='-'; | |
131 | } | |
132 | if (fDim != 1) | |
133 | { | |
134 | cout << " *AliSample::enter* Error : Not a 1-dim sample." << endl; | |
135 | } | |
136 | else | |
137 | { | |
138 | fN+=1; | |
139 | fSum[0]+=x; | |
140 | fSum2[0][0]+=x*x; | |
219e9b7e | 141 | |
25eefd00 | 142 | if (fN==1) |
143 | { | |
144 | fMin[0]=x; | |
145 | fMax[0]=x; | |
146 | } | |
147 | else | |
148 | { | |
149 | if (x<fMin[0]) fMin[0]=x; | |
150 | if (x>fMax[0]) fMax[0]=x; | |
151 | } | |
152 | ||
219e9b7e | 153 | // Store all entered data when storage mode has been selected |
154 | if (fStore) | |
155 | { | |
156 | if (!fX) fX=new TArrayF(10); | |
157 | if (fX->GetSize() < fN) fX->Set(fN+10); | |
158 | fX->AddAt(x,fN-1); | |
159 | } | |
160 | ||
161 | // Compute the various statistics | |
d88f97cc | 162 | Compute(); |
163 | } | |
164 | } | |
165 | /////////////////////////////////////////////////////////////////////////// | |
166 | void AliSample::Remove(Float_t x) | |
167 | { | |
168 | // Removing a value from a 1-dim. sample | |
219e9b7e | 169 | |
170 | if (!fN) return; | |
171 | ||
d88f97cc | 172 | if (fDim != 1) |
173 | { | |
174 | cout << " *AliSample::remove* Error : Not a 1-dim sample." << endl; | |
175 | } | |
176 | else | |
177 | { | |
25eefd00 | 178 | fRemove=1; |
d88f97cc | 179 | fN-=1; |
180 | fSum[0]-=x; | |
181 | fSum2[0][0]-=x*x; | |
219e9b7e | 182 | |
183 | // Remove data entry from the storage | |
184 | if (fStore && fX) | |
185 | { | |
186 | Float_t val=0; | |
187 | for (Int_t i=0; i<=fN; i++) | |
188 | { | |
189 | val=fX->At(i); | |
190 | if (fabs(x-val)>1.e-10) continue; | |
191 | ||
192 | for (Int_t j=i+1; j<=fN; j++) | |
193 | { | |
194 | val=fX->At(j); | |
195 | fX->AddAt(val,j-1); | |
196 | } | |
197 | } | |
198 | } | |
199 | ||
200 | // Compute the various statistics | |
d88f97cc | 201 | Compute(); |
202 | } | |
203 | } | |
204 | /////////////////////////////////////////////////////////////////////////// | |
205 | void AliSample::Enter(Float_t x,Float_t y) | |
206 | { | |
207 | // Entering a pair (x,y) into a 2-dim. sample | |
208 | // In case of first entry the dimension is set to 2 | |
209 | if (fN == 0) | |
210 | { | |
211 | fDim=2; | |
212 | fNames[0]='X'; | |
213 | fNames[1]='Y'; | |
214 | fNames[2]='-'; | |
215 | } | |
216 | if (fDim != 2) | |
217 | { | |
218 | cout << " *AliSample::enter* Error : Not a 2-dim sample." << endl; | |
219 | } | |
220 | else | |
221 | { | |
222 | fN+=1; | |
223 | fSum[0]+=x; | |
224 | fSum[1]+=y; | |
225 | fSum2[0][0]+=x*x; | |
226 | fSum2[0][1]+=x*y; | |
227 | fSum2[1][0]+=y*x; | |
228 | fSum2[1][1]+=y*y; | |
219e9b7e | 229 | |
25eefd00 | 230 | if (fN==1) |
231 | { | |
232 | fMin[0]=x; | |
233 | fMax[0]=x; | |
234 | fMin[1]=y; | |
235 | fMax[1]=y; | |
236 | } | |
237 | else | |
238 | { | |
239 | if (x<fMin[0]) fMin[0]=x; | |
240 | if (x>fMax[0]) fMax[0]=x; | |
241 | if (y<fMin[1]) fMin[1]=y; | |
242 | if (y>fMax[1]) fMax[1]=y; | |
243 | } | |
244 | ||
219e9b7e | 245 | // Store all entered data when storage mode has been selected |
246 | if (fStore) | |
247 | { | |
248 | if (!fX) fX=new TArrayF(10); | |
249 | if (fX->GetSize() < fN) fX->Set(fN+10); | |
250 | fX->AddAt(x,fN-1); | |
251 | if (!fY) fY=new TArrayF(10); | |
252 | if (fY->GetSize() < fN) fY->Set(fN+10); | |
253 | fY->AddAt(y,fN-1); | |
254 | } | |
255 | ||
256 | // Compute the various statistics | |
d88f97cc | 257 | Compute(); |
258 | } | |
259 | } | |
260 | /////////////////////////////////////////////////////////////////////////// | |
261 | void AliSample::Remove(Float_t x,Float_t y) | |
262 | { | |
263 | // Removing a pair (x,y) from a 2-dim. sample | |
219e9b7e | 264 | |
265 | if (!fN) return; | |
266 | ||
d88f97cc | 267 | if (fDim != 2) |
268 | { | |
269 | cout << " *AliSample::remove* Error : Not a 2-dim sample." << endl; | |
270 | } | |
271 | else | |
272 | { | |
25eefd00 | 273 | fRemove=1; |
d88f97cc | 274 | fN-=1; |
275 | fSum[0]-=x; | |
276 | fSum[1]-=y; | |
277 | fSum2[0][0]-=x*x; | |
278 | fSum2[0][1]-=x*y; | |
279 | fSum2[1][0]-=y*x; | |
280 | fSum2[1][1]-=y*y; | |
219e9b7e | 281 | |
282 | // Remove data entry from the storage | |
283 | if (fStore && fX && fY) | |
284 | { | |
285 | Float_t val=0; | |
286 | for (Int_t i=0; i<=fN; i++) | |
287 | { | |
288 | val=fX->At(i); | |
289 | if (fabs(x-val)>1.e-10) continue; | |
290 | val=fY->At(i); | |
291 | if (fabs(y-val)>1.e-10) continue; | |
292 | ||
293 | for (Int_t j=i+1; j<=fN; j++) | |
294 | { | |
295 | val=fX->At(j); | |
296 | fX->AddAt(val,j-1); | |
297 | val=fY->At(j); | |
298 | fY->AddAt(val,j-1); | |
299 | } | |
300 | } | |
301 | } | |
302 | ||
303 | // Compute the various statistics | |
d88f97cc | 304 | Compute(); |
305 | } | |
306 | } | |
307 | /////////////////////////////////////////////////////////////////////////// | |
308 | void AliSample::Enter(Float_t x,Float_t y,Float_t z) | |
309 | { | |
310 | // Entering a set (x,y,z) into a 3-dim. sample | |
311 | // In case of first entry the dimension is set to 3 | |
312 | if (fN == 0) | |
313 | { | |
314 | fDim=3; | |
315 | fNames[0]='X'; | |
316 | fNames[1]='Y'; | |
317 | fNames[2]='Z'; | |
318 | } | |
319 | if (fDim != 3) | |
320 | { | |
321 | cout << " *AliSample::enter* Error : Not a 3-dim sample." << endl; | |
322 | } | |
323 | else | |
324 | { | |
325 | fN+=1; | |
326 | fSum[0]+=x; | |
327 | fSum[1]+=y; | |
328 | fSum[2]+=z; | |
329 | fSum2[0][0]+=x*x; | |
330 | fSum2[0][1]+=x*y; | |
331 | fSum2[0][2]+=x*z; | |
332 | fSum2[1][0]+=y*x; | |
333 | fSum2[1][1]+=y*y; | |
334 | fSum2[1][2]+=y*z; | |
335 | fSum2[2][0]+=z*x; | |
336 | fSum2[2][1]+=z*y; | |
337 | fSum2[2][2]+=z*z; | |
219e9b7e | 338 | |
25eefd00 | 339 | if (fN==1) |
340 | { | |
341 | fMin[0]=x; | |
342 | fMax[0]=x; | |
343 | fMin[1]=y; | |
344 | fMax[1]=y; | |
345 | fMin[2]=z; | |
346 | fMax[2]=z; | |
347 | } | |
348 | else | |
349 | { | |
350 | if (x<fMin[0]) fMin[0]=x; | |
351 | if (x>fMax[0]) fMax[0]=x; | |
352 | if (y<fMin[1]) fMin[1]=y; | |
353 | if (y>fMax[1]) fMax[1]=y; | |
354 | if (z<fMin[2]) fMin[2]=z; | |
355 | if (z>fMax[2]) fMax[2]=z; | |
356 | } | |
357 | ||
219e9b7e | 358 | // Store all entered data when storage mode has been selected |
359 | if (fStore) | |
360 | { | |
361 | if (!fX) fX=new TArrayF(10); | |
362 | if (fX->GetSize() < fN) fX->Set(fN+10); | |
363 | fX->AddAt(x,fN-1); | |
364 | if (!fY) fY=new TArrayF(10); | |
365 | if (fY->GetSize() < fN) fY->Set(fN+10); | |
366 | fY->AddAt(y,fN-1); | |
367 | if (!fZ) fZ=new TArrayF(10); | |
368 | if (fZ->GetSize() < fN) fZ->Set(fN+10); | |
369 | fZ->AddAt(z,fN-1); | |
370 | } | |
371 | ||
372 | // Compute the various statistics | |
d88f97cc | 373 | Compute(); |
374 | } | |
375 | } | |
376 | /////////////////////////////////////////////////////////////////////////// | |
377 | void AliSample::Remove(Float_t x,Float_t y,Float_t z) | |
378 | { | |
379 | // Removing a set (x,y,z) from a 3-dim. sample | |
219e9b7e | 380 | |
381 | if (!fN) return; | |
382 | ||
d88f97cc | 383 | if (fDim != 3) |
384 | { | |
385 | cout << " *AliSample::remove* Error : Not a 3-dim sample." << endl; | |
386 | } | |
387 | else | |
388 | { | |
25eefd00 | 389 | fRemove=1; |
d88f97cc | 390 | fN-=1; |
391 | fSum[0]-=x; | |
392 | fSum[1]-=y; | |
393 | fSum[2]-=z; | |
394 | fSum2[0][0]-=x*x; | |
395 | fSum2[0][1]-=x*y; | |
396 | fSum2[0][2]-=x*z; | |
397 | fSum2[1][0]-=y*x; | |
398 | fSum2[1][1]-=y*y; | |
399 | fSum2[1][2]-=y*z; | |
400 | fSum2[2][0]-=z*x; | |
401 | fSum2[2][1]-=z*y; | |
402 | fSum2[2][2]-=z*z; | |
219e9b7e | 403 | |
404 | // Remove data entry from the storage | |
405 | if (fStore && fX && fY && fZ) | |
406 | { | |
407 | Float_t val=0; | |
408 | for (Int_t i=0; i<=fN; i++) | |
409 | { | |
410 | val=fX->At(i); | |
411 | if (fabs(x-val)>1.e-10) continue; | |
412 | val=fY->At(i); | |
413 | if (fabs(y-val)>1.e-10) continue; | |
414 | val=fZ->At(i); | |
415 | if (fabs(z-val)>1.e-10) continue; | |
416 | ||
417 | for (Int_t j=i+1; j<=fN; j++) | |
418 | { | |
419 | val=fX->At(j); | |
420 | fX->AddAt(val,j-1); | |
421 | val=fY->At(j); | |
422 | fY->AddAt(val,j-1); | |
423 | val=fZ->At(j); | |
424 | fZ->AddAt(val,j-1); | |
425 | } | |
426 | } | |
427 | } | |
428 | ||
429 | // Compute the various statistics | |
d88f97cc | 430 | Compute(); |
431 | } | |
432 | } | |
433 | /////////////////////////////////////////////////////////////////////////// | |
434 | void AliSample::Compute() | |
435 | { | |
436 | // Computation of the various statistical values | |
437 | // after each entering or removing action on a certain sample | |
438 | Float_t rn=fN; | |
439 | for (Int_t k=0; k<fDim; k++) | |
440 | { | |
441 | fMean[k]=fSum[k]/rn; | |
442 | fVar[k]=(fSum2[k][k]/rn)-(fMean[k]*fMean[k]); | |
443 | if (fVar[k] < 0.) fVar[k]=0.; | |
444 | fSigma[k]=sqrt(fVar[k]); | |
445 | } | |
446 | for (Int_t i=0; i<fDim; i++) | |
447 | { | |
448 | for (Int_t j=0; j<fDim; j++) | |
449 | { | |
450 | fCov[i][j]=(fSum2[i][j]/rn)-(fMean[i]*fMean[j]); | |
451 | Float_t sigij=fSigma[i]*fSigma[j]; | |
452 | if (sigij != 0.) fCor[i][j]=fCov[i][j]/sigij; | |
453 | } | |
454 | } | |
455 | } | |
456 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 457 | Int_t AliSample::GetDimension() const |
d88f97cc | 458 | { |
459 | // Provide the dimension of a certain sample | |
460 | return fDim; | |
461 | } | |
462 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 463 | Int_t AliSample::GetN() const |
d88f97cc | 464 | { |
465 | // Provide the number of entries of a certain sample | |
466 | return fN; | |
467 | } | |
468 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 469 | Float_t AliSample::GetSum(Int_t i) const |
d88f97cc | 470 | { |
471 | // Provide the sum of a certain variable | |
472 | if (fDim < i) | |
473 | { | |
474 | cout << " *AliSample::sum* Error : Dimension less than " << i << endl; | |
475 | return 0.; | |
476 | } | |
477 | else | |
478 | { | |
479 | return fSum[i-1]; | |
480 | } | |
481 | } | |
482 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 483 | Float_t AliSample::GetMean(Int_t i) const |
d88f97cc | 484 | { |
485 | // Provide the mean of a certain variable | |
486 | if (fDim < i) | |
487 | { | |
488 | cout << " *AliSample::mean* Error : Dimension less than " << i << endl; | |
489 | return 0.; | |
490 | } | |
491 | else | |
492 | { | |
493 | return fMean[i-1]; | |
494 | } | |
495 | } | |
496 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 497 | Float_t AliSample::GetVar(Int_t i) const |
d88f97cc | 498 | { |
499 | // Provide the variance of a certain variable | |
500 | if (fDim < i) | |
501 | { | |
502 | cout << " *AliSample::var* Error : Dimension less than " << i << endl; | |
503 | return 0.; | |
504 | } | |
505 | else | |
506 | { | |
507 | return fVar[i-1]; | |
508 | } | |
509 | } | |
510 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 511 | Float_t AliSample::GetSigma(Int_t i) const |
d88f97cc | 512 | { |
513 | // Provide the standard deviation of a certain variable | |
514 | if (fDim < i) | |
515 | { | |
516 | cout << " *AliSample::sigma* Error : Dimension less than " << i << endl; | |
517 | return 0.; | |
518 | } | |
519 | else | |
520 | { | |
521 | return fSigma[i-1]; | |
522 | } | |
523 | } | |
524 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 525 | Float_t AliSample::GetCov(Int_t i,Int_t j) const |
d88f97cc | 526 | { |
527 | // Provide the covariance between variables i and j | |
528 | if ((fDim < i) || (fDim < j)) | |
529 | { | |
530 | Int_t k=i; | |
531 | if (j > i) k=j; | |
532 | cout << " *AliSample::cov* Error : Dimension less than " << k << endl; | |
533 | return 0.; | |
534 | } | |
535 | else | |
536 | { | |
537 | return fCov[i-1][j-1]; | |
538 | } | |
539 | } | |
540 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 541 | Float_t AliSample::GetCor(Int_t i,Int_t j) const |
d88f97cc | 542 | { |
543 | // Provide the correlation between variables i and j | |
544 | if ((fDim < i) || (fDim < j)) | |
545 | { | |
546 | Int_t k=i; | |
547 | if (j > i) k=j; | |
548 | cout << " *AliSample::cor* Error : Dimension less than " << k << endl; | |
549 | return 0.; | |
550 | } | |
551 | else | |
552 | { | |
553 | return fCor[i-1][j-1]; | |
554 | } | |
555 | } | |
556 | /////////////////////////////////////////////////////////////////////////// | |
219e9b7e | 557 | void AliSample::Data() |
d88f97cc | 558 | { |
559 | // Printing of statistics of all variables | |
560 | for (Int_t i=0; i<fDim; i++) | |
561 | { | |
562 | cout << " " << fNames[i] << " : N = " << fN; | |
563 | cout << " Sum = " << fSum[i] << " Mean = " << fMean[i]; | |
219e9b7e | 564 | cout << " Var = " << fVar[i] << " Sigma = " << fSigma[i]; |
35e721bf | 565 | if (fStore) |
566 | { | |
567 | cout << endl; | |
568 | cout << " Minimum = " << GetMinimum(i+1); | |
569 | cout << " Maximum = " << GetMaximum(i+1); | |
570 | cout << " Median = " << GetMedian(i+1); | |
571 | } | |
219e9b7e | 572 | cout << endl; |
d88f97cc | 573 | } |
574 | } | |
575 | /////////////////////////////////////////////////////////////////////////// | |
219e9b7e | 576 | void AliSample::Data(Int_t i) |
d88f97cc | 577 | { |
578 | // Printing of statistics of ith variable | |
579 | if (fDim < i) | |
580 | { | |
84bb7c66 | 581 | cout << " *AliSample::Data(i)* Error : Dimension less than " << i << endl; |
d88f97cc | 582 | } |
583 | else | |
584 | { | |
585 | cout << " " << fNames[i-1] << " : N = " << fN; | |
586 | cout << " Sum = " << fSum[i-1] << " Mean = " << fMean[i-1]; | |
219e9b7e | 587 | cout << " Var = " << fVar[i-1] << " Sigma = " << fSigma[i-1]; |
35e721bf | 588 | if (fStore) |
589 | { | |
590 | cout << endl; | |
591 | cout << " Minimum = " << GetMinimum(i); | |
592 | cout << " Maximum = " << GetMaximum(i); | |
593 | cout << " Median = " << GetMedian(i); | |
594 | } | |
219e9b7e | 595 | cout << endl; |
d88f97cc | 596 | } |
597 | } | |
598 | /////////////////////////////////////////////////////////////////////////// | |
261c0caf | 599 | void AliSample::Data(Int_t i,Int_t j) const |
d88f97cc | 600 | { |
601 | // Printing of covariance and correlation between variables i and j | |
602 | if ((fDim < i) || (fDim < j)) | |
603 | { | |
604 | Int_t k=i; | |
605 | if (j > i) k=j; | |
84bb7c66 | 606 | cout << " *AliSample::Data(i,j)* Error : Dimension less than " << k << endl; |
d88f97cc | 607 | } |
608 | else | |
609 | { | |
610 | cout << " " << fNames[i-1] << "-" << fNames[j-1] << " correlation :"; | |
611 | cout << " Cov. = " << fCov[i-1][j-1] << " Cor. = " << fCor[i-1][j-1] << endl; | |
612 | } | |
613 | } | |
614 | /////////////////////////////////////////////////////////////////////////// | |
219e9b7e | 615 | void AliSample::SetStoreMode(Int_t mode) |
616 | { | |
617 | // Set storage mode for all entered data. | |
618 | // | |
619 | // mode = 0 : Entered data will not be stored | |
620 | // 1 : All data will be stored as entered | |
621 | // | |
622 | // By default the storage mode is set to 0 in the constructor of this class. | |
623 | // The default at invokation of this memberfunction is mode=1. | |
624 | // | |
625 | // For normal statistics evaluation (e.g. mean, sigma, covariance etc...) | |
626 | // storage of entered data is not needed. This is the default mode | |
627 | // of operation and is the most efficient w.r.t. cpu time and memory. | |
35e721bf | 628 | // However, when calculation of a median, minimum or maximum is required, |
629 | // then the data storage mode has be activated. | |
219e9b7e | 630 | // |
631 | // Note : Activation of storage mode can only be performed before the | |
632 | // first data item is entered. | |
633 | ||
634 | if (fN) | |
635 | { | |
636 | cout << " *AliSample::SetStore* Storage mode can only be set before first data." << endl; | |
637 | } | |
638 | else | |
639 | { | |
640 | if (mode==0 || mode==1) fStore=mode; | |
641 | } | |
642 | } | |
643 | /////////////////////////////////////////////////////////////////////////// | |
644 | Int_t AliSample::GetStoreMode() const | |
645 | { | |
646 | // Provide the storage mode | |
647 | return fStore; | |
648 | } | |
649 | /////////////////////////////////////////////////////////////////////////// | |
650 | Float_t AliSample::GetMedian(Int_t i) | |
651 | { | |
35e721bf | 652 | // Provide the median of a certain variable. |
653 | // For this functionality the storage mode has to be activated. | |
219e9b7e | 654 | |
655 | if (fDim < i) | |
656 | { | |
35e721bf | 657 | cout << " *AliSample::GetMedian* Error : Dimension less than " << i << endl; |
219e9b7e | 658 | return 0; |
659 | } | |
660 | ||
661 | if (!fStore) | |
662 | { | |
663 | cout << " *AliSample::GetMedian* Error : Storage of data entries was not activated." << endl; | |
664 | return 0; | |
665 | } | |
666 | ||
35e721bf | 667 | if (fN<=0) return 0; |
668 | ||
669 | Float_t median=0; | |
670 | ||
671 | if (fN==1) | |
672 | { | |
673 | if (i==1) median=fX->At(0); | |
674 | if (i==2) median=fY->At(0); | |
675 | if (i==3) median=fZ->At(0); | |
676 | return median; | |
677 | } | |
678 | ||
219e9b7e | 679 | // Prepare temp. array to hold the ordered values |
680 | if (!fArr) | |
681 | { | |
682 | fArr=new TArrayF(fN); | |
683 | } | |
684 | else | |
685 | { | |
686 | if (fArr->GetSize() < fN) fArr->Set(fN); | |
687 | } | |
688 | ||
689 | // Order the values of the specified variable | |
690 | Float_t val=0; | |
691 | Int_t iadd=0; | |
692 | for (Int_t j=0; j<fN; j++) | |
693 | { | |
694 | if (i==1) val=fX->At(j); | |
695 | if (i==2) val=fY->At(j); | |
696 | if (i==3) val=fZ->At(j); | |
697 | ||
698 | iadd=0; | |
699 | if (j==0) | |
700 | { | |
701 | fArr->AddAt(val,j); | |
702 | iadd=1; | |
703 | } | |
704 | else | |
705 | { | |
706 | for (Int_t k=0; k<j; k++) | |
707 | { | |
708 | if (val>=fArr->At(k)) continue; | |
709 | // Put value in between the existing ones | |
710 | for (Int_t m=j-1; m>=k; m--) | |
711 | { | |
712 | fArr->AddAt(fArr->At(m),m+1); | |
713 | } | |
714 | fArr->AddAt(val,k); | |
715 | iadd=1; | |
716 | break; | |
717 | } | |
718 | ||
719 | if (!iadd) | |
720 | { | |
721 | fArr->AddAt(val,j); | |
722 | } | |
723 | } | |
724 | } | |
725 | ||
35e721bf | 726 | median=0; |
219e9b7e | 727 | Int_t index=fN/2; |
728 | if (fN%2) // Odd number of entries | |
729 | { | |
730 | median=fArr->At(index); | |
731 | } | |
732 | else // Even number of entries | |
733 | { | |
734 | median=(fArr->At(index-1)+fArr->At(index))/2.; | |
735 | } | |
736 | return median; | |
737 | } | |
738 | /////////////////////////////////////////////////////////////////////////// | |
25eefd00 | 739 | Float_t AliSample::GetSpread(Int_t i) |
740 | { | |
741 | // Provide the spread w.r.t. the median of a certain variable. | |
742 | // The spread is defined as the average of |median-val(i)|. | |
743 | // For this functionality the storage mode has to be activated. | |
744 | ||
745 | if (fDim < i) | |
746 | { | |
747 | cout << " *AliSample::GetSpread* Error : Dimension less than " << i << endl; | |
748 | return 0; | |
749 | } | |
750 | ||
751 | if (!fStore) | |
752 | { | |
753 | cout << " *AliSample::GetSpread* Error : Storage of data entries was not activated." << endl; | |
754 | return 0; | |
755 | } | |
756 | ||
757 | if (fN<=1) return 0; | |
758 | ||
759 | Float_t median=GetMedian(i); | |
760 | ||
761 | Float_t spread=0; | |
762 | for (Int_t j=0; j<fN; j++) | |
763 | { | |
764 | spread+=fabs(median-(fArr->At(j))); | |
765 | } | |
766 | ||
767 | spread=spread/float(fN); | |
768 | ||
769 | return spread; | |
770 | } | |
771 | /////////////////////////////////////////////////////////////////////////// | |
35e721bf | 772 | Float_t AliSample::GetMinimum(Int_t i) const |
773 | { | |
774 | // Provide the minimum value of a certain variable. | |
25eefd00 | 775 | // In case entries have been removed from the sample, a correct value can |
776 | // only be obtained if the storage mode has been activated. | |
35e721bf | 777 | |
778 | if (fDim < i) | |
779 | { | |
780 | cout << " *AliSample::GetMinimum* Error : Dimension less than " << i << endl; | |
781 | return 0; | |
782 | } | |
783 | ||
25eefd00 | 784 | if (!fRemove) return fMin[i-1]; |
785 | ||
35e721bf | 786 | if (!fStore) |
787 | { | |
788 | cout << " *AliSample::GetMinimum* Error : Storage of data entries was not activated." << endl; | |
789 | return 0; | |
790 | } | |
791 | ||
792 | if (fN<=0) return 0; | |
793 | ||
794 | Float_t min=0; | |
795 | ||
796 | if (i==1) min=fX->At(0); | |
797 | if (i==2) min=fY->At(0); | |
798 | if (i==3) min=fZ->At(0); | |
799 | ||
800 | for (Int_t k=1; k<fN; k++) | |
801 | { | |
802 | if (i==1 && fX->At(k)<min) min=fX->At(k); | |
803 | if (i==2 && fY->At(k)<min) min=fY->At(k); | |
804 | if (i==3 && fZ->At(k)<min) min=fZ->At(k); | |
805 | } | |
806 | ||
807 | return min; | |
808 | } | |
809 | /////////////////////////////////////////////////////////////////////////// | |
810 | Float_t AliSample::GetMaximum(Int_t i) const | |
811 | { | |
812 | // Provide the maxmum value of a certain variable. | |
25eefd00 | 813 | // In case entries have been removed from the sample, a correct value can |
814 | // only be obtained if the storage mode has been activated. | |
35e721bf | 815 | |
816 | if (fDim < i) | |
817 | { | |
818 | cout << " *AliSample::GetMaximum* Error : Dimension less than " << i << endl; | |
819 | return 0; | |
820 | } | |
821 | ||
25eefd00 | 822 | if (!fRemove) return fMax[i-1]; |
823 | ||
35e721bf | 824 | if (!fStore) |
825 | { | |
826 | cout << " *AliSample::GetMaximum* Error : Storage of data entries was not activated." << endl; | |
827 | return 0; | |
828 | } | |
829 | ||
830 | if (fN<=0) return 0; | |
831 | ||
832 | Float_t max=0; | |
833 | ||
834 | if (i==1) max=fX->At(0); | |
835 | if (i==2) max=fY->At(0); | |
836 | if (i==3) max=fZ->At(0); | |
837 | ||
838 | for (Int_t k=1; k<fN; k++) | |
839 | { | |
840 | if (i==1 && fX->At(k)>max) max=fX->At(k); | |
841 | if (i==2 && fY->At(k)>max) max=fY->At(k); | |
842 | if (i==3 && fZ->At(k)>max) max=fZ->At(k); | |
843 | } | |
844 | ||
845 | return max; | |
846 | } | |
847 | /////////////////////////////////////////////////////////////////////////// |