]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSstatistics.cxx
Updated for coding convenstions compilation errors and warnings and the like.
[u/mrichter/AliRoot.git] / ITS / AliITSstatistics.cxx
1 //////////////////////////////////////////////////////////////////////////
2 //  Alice ITS class to help keep statistical information                //
3 //                                                                      //
4 // version: 0.0.0 Draft.                                                //
5 // Date: April 18 1999                                                  //
6 // By: Bjorn S. Nilsen                                                  //
7 //                                                                      //
8 //////////////////////////////////////////////////////////////////////////
9 #include <stdio.h>
10 #include <math.h>
11 #include <TMath.h>
12
13 #include "AliITSstatistics.h"
14
15 ClassImp(AliITSstatistics)
16
17 //
18 AliITSstatistics::AliITSstatistics() : TObject(){
19 //
20 // default contructor
21 //
22     fx = 0;
23     fw = 0;
24     fN = 0;
25     fOrder = 0;
26     return;
27 }
28
29
30 AliITSstatistics::AliITSstatistics(Int_t order) : TObject(){
31 //
32 // contructor to a specific order in the moments
33 //
34     fOrder = order;
35     fx = new Double_t[order];
36     fw = new Double_t[order];
37     Int_t i;
38     for(i=0;i<order;i++) {fx[i] = 0.0; fw[i] = 0.0;}
39     fN = 0;
40     return;
41 }
42
43 AliITSstatistics::~AliITSstatistics(){
44 //
45 // default destructor
46 //
47     if(fx!=0) delete[] fx;
48     if(fw!=0) delete[] fw;
49     fx = 0;
50     fw = 0;
51     fN = 0;
52     fOrder = 0;
53 }
54 //_______________________________________________________________
55 AliITSstatistics& AliITSstatistics::operator=(AliITSstatistics &source){
56 // operator =
57
58      Int_t i;
59      if(this==&source) return *this;
60      if(source.fOrder!=0){
61        this->fOrder = source.fOrder;
62        this->fN = source.fN;
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];
68        } // end for i
69      }else{
70        this->fx = 0;
71        this->fw = 0;
72        this->fN = 0;
73        this->fOrder = 0;
74      }// end if source.fOrder!=0
75      return *this;
76 }
77 //_______________________________________________________________
78 AliITSstatistics::AliITSstatistics(AliITSstatistics &source){
79 // Copy constructor
80
81   Int_t i;
82   if(this==&source) return;
83   if(source.fOrder!=0){
84     this->fOrder = source.fOrder;
85     this->fN = source.fN;
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];
91     } // end for i
92   }else{
93     this->fx = 0;
94     this->fw = 0;
95     this->fN = 0;
96     this->fOrder = 0;
97   }// end if source.fOrder!=0
98 }
99 //_______________________________________________________________
100 void AliITSstatistics::Reset(){
101 //
102 // reset all values to zero
103 //
104     Int_t i;
105     for(i=0;i<fOrder;i++) {fx[i] = 0.0; fw[i] = 0.0;}
106     fN = 0;
107     return;
108 }
109
110 void AliITSstatistics::AddValue(Double_t x,Double_t w=1.0){
111 //
112 // accumulate element x with weight w.
113 //
114     Double_t y=1.0,z=1.0;
115     Int_t i;
116
117
118     if(isinf(y)!=0||isinf(x)!=0||isinf(w)!=0) return;
119     if(isnan(y)!=0||isnan(x)!=0||isnan(w)!=0) return;
120     fN++;
121     for(i=0;i<fOrder;i++){
122         y *= x;
123         z *= w;
124         fx[i] += y*w;
125         fw[i] += z;
126     } // end for i
127 }
128
129 Double_t AliITSstatistics::GetNth(Int_t order){
130 // This give the unbiased estimator for the RMS.
131     Double_t s;
132
133     if(fw[0]!=0.0&&order<=fOrder) s = fx[order-1]/fw[0];
134     else {
135         s = 0.0;
136         printf("AliITSstatistics: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
137                fOrder,fN,fw[0]);
138     } // end else
139     return s;
140 }
141
142 Double_t AliITSstatistics::GetRMS(){
143 // This give the unbiased estimator for the RMS.
144     Double_t x,x2,w,ww,s;
145
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.
150
151     if(w*w==ww) return (-1.0);
152     s = (x2-x*x)*w*w/(w*w-ww);
153     return TMath::Sqrt(s);
154 }
155
156 Double_t AliITSstatistics::GetErrorMean(){
157 //This is the error in the mean or the square root of the variance of the mean.
158     Double_t rms,w,ww,s;
159
160     rms = GetRMS();
161     w   = fw[0];
162     ww  = fw[1];
163     s   = rms*rms*ww/(w*w);
164     return TMath::Sqrt(s);
165 }
166
167
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;
172
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);
180
181     m2  = s;
182     n   = (Double_t) GetN();
183     x3  = GetNth(3);
184     x4  = GetNth(4);
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);
189 }
190 //_______________________________________________________________________
191 void AliITSstatistics::Streamer(TBuffer &R__b){
192    // Stream an object of class AliITSstatistics.
193
194    if (R__b.IsReading()) {
195       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
196       TObject::Streamer(R__b);
197       R__b >> fN;
198       R__b >> fOrder;
199       R__b.ReadArray(fx);
200       R__b.ReadArray(fw);
201    } else {
202       R__b.WriteVersion(AliITSstatistics::IsA());
203       TObject::Streamer(R__b);
204       R__b << fN;
205       R__b << fOrder;
206       R__b.WriteArray(fx,fOrder);
207       R__b.WriteArray(fw,fOrder);
208    }
209 }