1 //////////////////////////////////////////////////////////////////////////
2 // Alice ITS class to help keep statistical information //
4 // version: 0.0.0 Draft. //
5 // Date: April 18 1999 //
6 // By: Bjorn S. Nilsen //
8 //////////////////////////////////////////////////////////////////////////
13 #include "AliITSstatistics.h"
15 ClassImp(AliITSstatistics)
18 AliITSstatistics::AliITSstatistics() : TObject(){
30 AliITSstatistics::AliITSstatistics(Int_t order) : TObject(){
32 // contructor to a specific order in the moments
35 fX = new Double_t[order];
36 fW = new Double_t[order];
37 for(Int_t i=0;i<order;i++) {fX[i] = 0.0; fW[i] = 0.0;}
42 AliITSstatistics::~AliITSstatistics(){
46 if(fX!=0) delete[] fX;
47 if(fW!=0) delete[] fW;
53 //_______________________________________________________________
54 AliITSstatistics& AliITSstatistics::operator=(AliITSstatistics &source){
57 if(this==&source) return *this;
59 this->fOrder = source.fOrder;
61 this->fX = new Double_t[this->fOrder];
62 this->fW = new Double_t[this->fOrder];
63 for(Int_t i=0;i<source.fOrder;i++){
64 this->fX[i] = source.fX[i];
65 this->fW[i] = source.fW[i];
72 }// end if source.fOrder!=0
75 //_______________________________________________________________
76 AliITSstatistics::AliITSstatistics(AliITSstatistics &source){
79 if(this==&source) return;
81 this->fOrder = source.fOrder;
83 this->fX = new Double_t[this->fOrder];
84 this->fW = new Double_t[this->fOrder];
85 for(Int_t i=0;i<source.fOrder;i++){
86 this->fX[i] = source.fX[i];
87 this->fW[i] = source.fW[i];
94 }// end if source.fOrder!=0
96 //_______________________________________________________________
97 void AliITSstatistics::Reset(){
99 // reset all values to zero
101 for(Int_t i=0;i<fOrder;i++) {fX[i] = 0.0; fW[i] = 0.0;}
106 //_______________________________________________________________
107 void AliITSstatistics::AddValue(Double_t x,Double_t w){
109 // accumulate element x with weight w.
112 //it was AddValue(Double_t x,Double_t w=1.0);
114 Double_t y=1.0,z=1.0;
117 const Double_t kBig=1.0e+38;
119 if(y>kBig || x>kBig || w>kBig) return;
122 for(i=0;i<fOrder;i++){
130 Double_t AliITSstatistics::GetNth(Int_t order){
131 // This give the unbiased estimator for the RMS.
134 if(fW[0]!=0.0&&order<=fOrder) s = fX[order-1]/fW[0];
137 printf("AliITSstatistics: error in GetNth: fOrder=%d fN=%d fW[0]=%f\n",
143 Double_t AliITSstatistics::GetRMS(){
144 // This give the unbiased estimator for the RMS.
145 Double_t x,x2,w,ww,s;
147 x = GetMean(); // first order
148 x2 = GetNth(2); // second order
149 w = fW[0]; // first order - 1.
150 ww = fW[1]; // second order - 1.
152 if(w*w==ww) return (-1.0);
153 s = (x2-x*x)*w*w/(w*w-ww);
154 return TMath::Sqrt(s);
157 Double_t AliITSstatistics::GetErrorMean(){
158 //This is the error in the mean or the square root of the variance of the mean.
164 s = rms*rms*ww/(w*w);
165 return TMath::Sqrt(s);
169 Double_t AliITSstatistics::GetErrorRMS(){
170 //This is the error in the mean or the square root of the variance of the mean.
171 // at this moment this routine is only defined for weights=1.
172 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
174 if(fW[0]!=(Double_t)fN||GetN()<4) return (-1.);
175 x = GetMean(); // first order
176 x2 = GetNth(2); // second order
177 w = fW[0]; // first order - 1.
178 ww = fW[1]; // second order - 1.
179 if(w*w==ww) return (-1.0);
180 s = (x2-x*x)*w*w/(w*w-ww);
183 n = (Double_t) GetN();
186 // This equation assumes that all of the weights are equal to 1.
187 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
188 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
189 return TMath::Sqrt(s);