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];
38 for(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=(AliITSstatistics &source){
59 if(this==&source) return *this;
61 this->fOrder = source.fOrder;
63 this->fx = new Double_t[this->fOrder];
64 this->fw = new Double_t[this->fOrder];
65 for(i=0;i<source.fOrder;i++){
66 this->fx[i] = source.fx[i];
67 this->fw[i] = source.fw[i];
74 }// end if source.fOrder!=0
77 //_______________________________________________________________
78 AliITSstatistics::AliITSstatistics(AliITSstatistics &source){
82 if(this==&source) return;
84 this->fOrder = source.fOrder;
86 this->fx = new Double_t[this->fOrder];
87 this->fw = new Double_t[this->fOrder];
88 for(i=0;i<source.fOrder;i++){
89 this->fx[i] = source.fx[i];
90 this->fw[i] = source.fw[i];
97 }// end if source.fOrder!=0
99 //_______________________________________________________________
100 void AliITSstatistics::Reset(){
102 // reset all values to zero
105 for(i=0;i<fOrder;i++) {fx[i] = 0.0; fw[i] = 0.0;}
110 void AliITSstatistics::AddValue(Double_t x,Double_t w=1.0){
112 // accumulate element x with weight w.
114 Double_t y=1.0,z=1.0;
118 if(isinf(y)!=0||isinf(x)!=0||isinf(w)!=0) return;
119 if(isnan(y)!=0||isnan(x)!=0||isnan(w)!=0) return;
121 for(i=0;i<fOrder;i++){
129 Double_t AliITSstatistics::GetNth(Int_t order){
130 // This give the unbiased estimator for the RMS.
133 if(fw[0]!=0.0&&order<=fOrder) s = fx[order-1]/fw[0];
136 printf("AliITSstatistics: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
142 Double_t AliITSstatistics::GetRMS(){
143 // This give the unbiased estimator for the RMS.
144 Double_t x,x2,w,ww,s;
146 x = GetMean(); // first order
147 x2 = GetNth(2); // second order
148 w = fw[0]; // first order - 1.
149 ww = fw[1]; // second order - 1.
151 if(w*w==ww) return (-1.0);
152 s = (x2-x*x)*w*w/(w*w-ww);
153 return TMath::Sqrt(s);
156 Double_t AliITSstatistics::GetErrorMean(){
157 //This is the error in the mean or the square root of the variance of the mean.
163 s = rms*rms*ww/(w*w);
164 return TMath::Sqrt(s);
168 Double_t AliITSstatistics::GetErrorRMS(){
169 //This is the error in the mean or the square root of the variance of the mean.
170 // at this moment this routine is only defined for weights=1.
171 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
173 if(fw[0]!=(Double_t)fN||GetN()<4) return (-1.);
174 x = GetMean(); // first order
175 x2 = GetNth(2); // second order
176 w = fw[0]; // first order - 1.
177 ww = fw[1]; // second order - 1.
178 if(w*w==ww) return (-1.0);
179 s = (x2-x*x)*w*w/(w*w-ww);
182 n = (Double_t) GetN();
185 // This equation assumes that all of the weights are equal to 1.
186 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
187 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
188 return TMath::Sqrt(s);
190 //_______________________________________________________________________
191 void AliITSstatistics::Streamer(TBuffer &R__b){
192 // Stream an object of class AliITSstatistics.
194 if (R__b.IsReading()) {
195 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
196 TObject::Streamer(R__b);
202 R__b.WriteVersion(AliITSstatistics::IsA());
203 TObject::Streamer(R__b);
206 R__b.WriteArray(fx,fOrder);
207 R__b.WriteArray(fw,fOrder);