X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=RALICE%2FAliSample.cxx;h=174d01115aca51aefb316555abc44fc7b05c9d30;hb=25eefd00f9a19172db2788b84c94a9bec47b4148;hp=62aa9c41e067e0c5b23090f84279005cc5c2d086;hpb=261c0cafb78614564d53e4b802440bae991f116f;p=u%2Fmrichter%2FAliRoot.git diff --git a/RALICE/AliSample.cxx b/RALICE/AliSample.cxx index 62aa9c41e06..174d01115ac 100644 --- a/RALICE/AliSample.cxx +++ b/RALICE/AliSample.cxx @@ -56,25 +56,54 @@ AliSample::AliSample() fNames[1]='Y'; fNames[2]='Z'; fN=0; + fRemove=0; + fStore=0; + fX=0; + fY=0; + fZ=0; + fArr=0; Reset(); } /////////////////////////////////////////////////////////////////////////// AliSample::~AliSample() { // Default destructor + if (fX) + { + delete fX; + fX=0; + } + if (fY) + { + delete fY; + fY=0; + } + if (fZ) + { + delete fZ; + fZ=0; + } + if (fArr) + { + delete fArr; + fArr=0; + } } /////////////////////////////////////////////////////////////////////////// void AliSample::Reset() { // Resetting the statistics values for a certain Sample object -// Dimension is NOT changed +// Dimension and storage flag are NOT changed fN=0; + fRemove=0; for (Int_t i=0; iSet(10); + if (fY) fY->Set(10); + if (fZ) fZ->Set(10); } /////////////////////////////////////////////////////////////////////////// void AliSample::Enter(Float_t x) @@ -104,6 +138,27 @@ void AliSample::Enter(Float_t x) fN+=1; fSum[0]+=x; fSum2[0][0]+=x*x; + + if (fN==1) + { + fMin[0]=x; + fMax[0]=x; + } + else + { + if (xfMax[0]) fMax[0]=x; + } + + // Store all entered data when storage mode has been selected + if (fStore) + { + if (!fX) fX=new TArrayF(10); + if (fX->GetSize() < fN) fX->Set(fN+10); + fX->AddAt(x,fN-1); + } + + // Compute the various statistics Compute(); } } @@ -111,15 +166,38 @@ void AliSample::Enter(Float_t x) void AliSample::Remove(Float_t x) { // Removing a value from a 1-dim. sample + + if (!fN) return; + if (fDim != 1) { cout << " *AliSample::remove* Error : Not a 1-dim sample." << endl; } else { + fRemove=1; fN-=1; fSum[0]-=x; fSum2[0][0]-=x*x; + + // Remove data entry from the storage + if (fStore && fX) + { + Float_t val=0; + for (Int_t i=0; i<=fN; i++) + { + val=fX->At(i); + if (fabs(x-val)>1.e-10) continue; + + for (Int_t j=i+1; j<=fN; j++) + { + val=fX->At(j); + fX->AddAt(val,j-1); + } + } + } + + // Compute the various statistics Compute(); } } @@ -148,6 +226,34 @@ void AliSample::Enter(Float_t x,Float_t y) fSum2[0][1]+=x*y; fSum2[1][0]+=y*x; fSum2[1][1]+=y*y; + + if (fN==1) + { + fMin[0]=x; + fMax[0]=x; + fMin[1]=y; + fMax[1]=y; + } + else + { + if (xfMax[0]) fMax[0]=x; + if (yfMax[1]) fMax[1]=y; + } + + // Store all entered data when storage mode has been selected + if (fStore) + { + if (!fX) fX=new TArrayF(10); + if (fX->GetSize() < fN) fX->Set(fN+10); + fX->AddAt(x,fN-1); + if (!fY) fY=new TArrayF(10); + if (fY->GetSize() < fN) fY->Set(fN+10); + fY->AddAt(y,fN-1); + } + + // Compute the various statistics Compute(); } } @@ -155,12 +261,16 @@ void AliSample::Enter(Float_t x,Float_t y) void AliSample::Remove(Float_t x,Float_t y) { // Removing a pair (x,y) from a 2-dim. sample + + if (!fN) return; + if (fDim != 2) { cout << " *AliSample::remove* Error : Not a 2-dim sample." << endl; } else { + fRemove=1; fN-=1; fSum[0]-=x; fSum[1]-=y; @@ -168,6 +278,29 @@ void AliSample::Remove(Float_t x,Float_t y) fSum2[0][1]-=x*y; fSum2[1][0]-=y*x; fSum2[1][1]-=y*y; + + // Remove data entry from the storage + if (fStore && fX && fY) + { + Float_t val=0; + for (Int_t i=0; i<=fN; i++) + { + val=fX->At(i); + if (fabs(x-val)>1.e-10) continue; + val=fY->At(i); + if (fabs(y-val)>1.e-10) continue; + + for (Int_t j=i+1; j<=fN; j++) + { + val=fX->At(j); + fX->AddAt(val,j-1); + val=fY->At(j); + fY->AddAt(val,j-1); + } + } + } + + // Compute the various statistics Compute(); } } @@ -202,6 +335,41 @@ void AliSample::Enter(Float_t x,Float_t y,Float_t z) fSum2[2][0]+=z*x; fSum2[2][1]+=z*y; fSum2[2][2]+=z*z; + + if (fN==1) + { + fMin[0]=x; + fMax[0]=x; + fMin[1]=y; + fMax[1]=y; + fMin[2]=z; + fMax[2]=z; + } + else + { + if (xfMax[0]) fMax[0]=x; + if (yfMax[1]) fMax[1]=y; + if (zfMax[2]) fMax[2]=z; + } + + // Store all entered data when storage mode has been selected + if (fStore) + { + if (!fX) fX=new TArrayF(10); + if (fX->GetSize() < fN) fX->Set(fN+10); + fX->AddAt(x,fN-1); + if (!fY) fY=new TArrayF(10); + if (fY->GetSize() < fN) fY->Set(fN+10); + fY->AddAt(y,fN-1); + if (!fZ) fZ=new TArrayF(10); + if (fZ->GetSize() < fN) fZ->Set(fN+10); + fZ->AddAt(z,fN-1); + } + + // Compute the various statistics Compute(); } } @@ -209,12 +377,16 @@ void AliSample::Enter(Float_t x,Float_t y,Float_t z) void AliSample::Remove(Float_t x,Float_t y,Float_t z) { // Removing a set (x,y,z) from a 3-dim. sample + + if (!fN) return; + if (fDim != 3) { cout << " *AliSample::remove* Error : Not a 3-dim sample." << endl; } else { + fRemove=1; fN-=1; fSum[0]-=x; fSum[1]-=y; @@ -228,6 +400,33 @@ void AliSample::Remove(Float_t x,Float_t y,Float_t z) fSum2[2][0]-=z*x; fSum2[2][1]-=z*y; fSum2[2][2]-=z*z; + + // Remove data entry from the storage + if (fStore && fX && fY && fZ) + { + Float_t val=0; + for (Int_t i=0; i<=fN; i++) + { + val=fX->At(i); + if (fabs(x-val)>1.e-10) continue; + val=fY->At(i); + if (fabs(y-val)>1.e-10) continue; + val=fZ->At(i); + if (fabs(z-val)>1.e-10) continue; + + for (Int_t j=i+1; j<=fN; j++) + { + val=fX->At(j); + fX->AddAt(val,j-1); + val=fY->At(j); + fY->AddAt(val,j-1); + val=fZ->At(j); + fZ->AddAt(val,j-1); + } + } + } + + // Compute the various statistics Compute(); } } @@ -355,18 +554,26 @@ Float_t AliSample::GetCor(Int_t i,Int_t j) const } } /////////////////////////////////////////////////////////////////////////// -void AliSample::Data() const +void AliSample::Data() { // Printing of statistics of all variables for (Int_t i=0; iAt(0); + if (i==2) median=fY->At(0); + if (i==3) median=fZ->At(0); + return median; + } + + // Prepare temp. array to hold the ordered values + if (!fArr) + { + fArr=new TArrayF(fN); + } + else + { + if (fArr->GetSize() < fN) fArr->Set(fN); + } + + // Order the values of the specified variable + Float_t val=0; + Int_t iadd=0; + for (Int_t j=0; jAt(j); + if (i==2) val=fY->At(j); + if (i==3) val=fZ->At(j); + + iadd=0; + if (j==0) + { + fArr->AddAt(val,j); + iadd=1; + } + else + { + for (Int_t k=0; k=fArr->At(k)) continue; + // Put value in between the existing ones + for (Int_t m=j-1; m>=k; m--) + { + fArr->AddAt(fArr->At(m),m+1); + } + fArr->AddAt(val,k); + iadd=1; + break; + } + + if (!iadd) + { + fArr->AddAt(val,j); + } + } + } + + median=0; + Int_t index=fN/2; + if (fN%2) // Odd number of entries + { + median=fArr->At(index); + } + else // Even number of entries + { + median=(fArr->At(index-1)+fArr->At(index))/2.; + } + return median; +} +/////////////////////////////////////////////////////////////////////////// +Float_t AliSample::GetSpread(Int_t i) +{ +// Provide the spread w.r.t. the median of a certain variable. +// The spread is defined as the average of |median-val(i)|. +// For this functionality the storage mode has to be activated. + + if (fDim < i) + { + cout << " *AliSample::GetSpread* Error : Dimension less than " << i << endl; + return 0; + } + + if (!fStore) + { + cout << " *AliSample::GetSpread* Error : Storage of data entries was not activated." << endl; + return 0; + } + + if (fN<=1) return 0; + + Float_t median=GetMedian(i); + + Float_t spread=0; + for (Int_t j=0; jAt(j))); + } + + spread=spread/float(fN); + + return spread; +} +/////////////////////////////////////////////////////////////////////////// +Float_t AliSample::GetMinimum(Int_t i) const +{ +// Provide the minimum value of a certain variable. +// In case entries have been removed from the sample, a correct value can +// only be obtained if the storage mode has been activated. + + if (fDim < i) + { + cout << " *AliSample::GetMinimum* Error : Dimension less than " << i << endl; + return 0; + } + + if (!fRemove) return fMin[i-1]; + + if (!fStore) + { + cout << " *AliSample::GetMinimum* Error : Storage of data entries was not activated." << endl; + return 0; + } + + if (fN<=0) return 0; + + Float_t min=0; + + if (i==1) min=fX->At(0); + if (i==2) min=fY->At(0); + if (i==3) min=fZ->At(0); + + for (Int_t k=1; kAt(k)At(k); + if (i==2 && fY->At(k)At(k); + if (i==3 && fZ->At(k)At(k); + } + + return min; +} +/////////////////////////////////////////////////////////////////////////// +Float_t AliSample::GetMaximum(Int_t i) const +{ +// Provide the maxmum value of a certain variable. +// In case entries have been removed from the sample, a correct value can +// only be obtained if the storage mode has been activated. + + if (fDim < i) + { + cout << " *AliSample::GetMaximum* Error : Dimension less than " << i << endl; + return 0; + } + + if (!fRemove) return fMax[i-1]; + + if (!fStore) + { + cout << " *AliSample::GetMaximum* Error : Storage of data entries was not activated." << endl; + return 0; + } + + if (fN<=0) return 0; + + Float_t max=0; + + if (i==1) max=fX->At(0); + if (i==2) max=fY->At(0); + if (i==3) max=fZ->At(0); + + for (Int_t k=1; kAt(k)>max) max=fX->At(k); + if (i==2 && fY->At(k)>max) max=fY->At(k); + if (i==3 && fZ->At(k)>max) max=fZ->At(k); + } + + return max; +} +///////////////////////////////////////////////////////////////////////////