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(),
29 AliITSstatistics::AliITSstatistics(Int_t order) : TObject(),
35 // contructor to a specific order in the moments
37 fX = new Double_t[order];
38 fW = new Double_t[order];
39 for(Int_t i=0;i<order;i++) {fX[i] = 0.0; fW[i] = 0.0;}
43 AliITSstatistics::~AliITSstatistics(){
47 if(fX!=0) delete[] fX;
48 if(fW!=0) delete[] fW;
54 //_______________________________________________________________
55 AliITSstatistics& AliITSstatistics::operator=(const AliITSstatistics &source){
58 if(this==&source) return *this;
60 this->fOrder = source.fOrder;
62 this->fX = new Double_t[this->fOrder];
63 this->fW = new Double_t[this->fOrder];
64 for(Int_t i=0;i<source.fOrder;i++){
65 this->fX[i] = source.fX[i];
66 this->fW[i] = source.fW[i];
73 }// end if source.fOrder!=0
76 //_______________________________________________________________
77 AliITSstatistics::AliITSstatistics(const AliITSstatistics &source) : TObject(source),
84 if(this==&source) return;
86 this->fOrder = source.fOrder;
88 this->fX = new Double_t[this->fOrder];
89 this->fW = new Double_t[this->fOrder];
90 for(Int_t i=0;i<source.fOrder;i++){
91 this->fX[i] = source.fX[i];
92 this->fW[i] = source.fW[i];
99 }// end if source.fOrder!=0
101 //_______________________________________________________________
102 void AliITSstatistics::Reset(){
104 // reset all values to zero
106 for(Int_t i=0;i<fOrder;i++) {fX[i] = 0.0; fW[i] = 0.0;}
111 //_______________________________________________________________
112 void AliITSstatistics::AddValue(Double_t x,Double_t w){
114 // accumulate element x with weight w.
117 //it was AddValue(Double_t x,Double_t w=1.0);
119 Double_t y=1.0,z=1.0;
122 const Double_t kBig=1.0e+38;
124 if(y>kBig || x>kBig || w>kBig) return;
127 for(i=0;i<fOrder;i++){
135 Double_t AliITSstatistics::GetNth(Int_t order){
136 // This give the unbiased estimator for the RMS.
139 if(fW[0]!=0.0&&order<=fOrder) s = fX[order-1]/fW[0];
142 printf("AliITSstatistics: error in GetNth: fOrder=%d fN=%d fW[0]=%f\n",
148 Double_t AliITSstatistics::GetRMS(){
149 // This give the unbiased estimator for the RMS.
150 Double_t x,x2,w,ww,s;
152 x = GetMean(); // first order
153 x2 = GetNth(2); // second order
154 w = fW[0]; // first order - 1.
155 ww = fW[1]; // second order - 1.
157 if(w*w==ww) return (-1.0);
158 s = (x2-x*x)*w*w/(w*w-ww);
159 return TMath::Sqrt(s);
162 Double_t AliITSstatistics::GetErrorMean(){
163 //This is the error in the mean or the square root of the variance of the mean.
169 s = rms*rms*ww/(w*w);
170 return TMath::Sqrt(s);
174 Double_t AliITSstatistics::GetErrorRMS(){
175 //This is the error in the mean or the square root of the variance of the mean.
176 // at this moment this routine is only defined for weights=1.
177 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
179 if(fW[0]!=(Double_t)fN||GetN()<4) return (-1.);
180 x = GetMean(); // first order
181 x2 = GetNth(2); // second order
182 w = fW[0]; // first order - 1.
183 ww = fW[1]; // second order - 1.
184 if(w*w==ww) return (-1.0);
185 s = (x2-x*x)*w*w/(w*w-ww);
188 n = (Double_t) GetN();
191 // This equation assumes that all of the weights are equal to 1.
192 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
193 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
194 return TMath::Sqrt(s);