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 //////////////////////////////////////////////////////////////////////////
12 #include "AliITSstatistics2.h"
14 ClassImp(AliITSstatistics2)
17 AliITSstatistics2::AliITSstatistics2() : TObject(){
19 // default constructor
31 AliITSstatistics2::AliITSstatistics2(Int_t order) : TObject(){
33 // constructor to maximum moment/order order
36 fX = new Double_t[order];
37 fY = new Double_t[order];
38 fYx = new Double_t[order];
39 fW = new Double_t[order];
40 for(Int_t i=0;i<order;i++) {fX[i] = 0.0;fY[i] = 0.0;
41 fYx[i] = 0.0; fW[i] = 0.0;}
46 AliITSstatistics2::~AliITSstatistics2(){
50 if(fX!=0) delete[] fX;
51 if(fY!=0) delete[] fY;
52 if(fYx!=0) delete[] fYx;
53 if(fW!=0) delete[] fW;
62 //_______________________________________________________________
63 AliITSstatistics2& AliITSstatistics2::operator=(AliITSstatistics2 &source){
66 if(this==&source) return *this;
68 this->fOrder = source.fOrder;
70 this->fX = new Double_t[this->fOrder];
71 this->fW = new Double_t[this->fOrder];
72 for(Int_t i=0;i<source.fOrder;i++){
73 this->fX[i] = source.fX[i];
74 this->fW[i] = source.fW[i];
81 }// end if source.fOrder!=0
84 //_______________________________________________________________
85 AliITSstatistics2::AliITSstatistics2(AliITSstatistics2 &source):
89 if(this==&source) return;
91 this->fOrder = source.fOrder;
93 this->fX = new Double_t[this->fOrder];
94 this->fW = new Double_t[this->fOrder];
95 for(Int_t i=0;i<source.fOrder;i++){
96 this->fX[i] = source.fX[i];
97 this->fW[i] = source.fW[i];
104 }// end if source.fOrder!=0
107 void AliITSstatistics2::Reset(){
109 // Reset/zero statistics
111 for(Int_t i=0;i<fOrder;i++) {fX[i] = 0.0;fY[i] = 0.0;
112 fYx[i] = 0.0; fW[i] = 0.0;}
117 void AliITSstatistics2::AddValue(Double_t y,Double_t x,Double_t w=1.0){
119 // add next x,y pair to statistics
121 Double_t xs=1.0,ys=1.0,yxs=1.0,ws=1.0;
124 const Double_t kBig=1.0e+38;
126 if(y>kBig || x>kBig || w>kBig) return;
130 for(i=0;i<fOrder;i++){
142 Double_t AliITSstatistics2::GetXNth(Int_t order){
144 // This give the unbiased estimator for the RMS.
149 if(fW[0]!=0.0&&order<=fOrder) s = fX[order-1]/fW[0];
152 printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fW[0]=%f\n",
157 Double_t AliITSstatistics2::GetYNth(Int_t order){
159 // This give the unbiased estimator for the RMS.
163 if(fW[0]!=0.0&&order<=fOrder) s = fY[order-1]/fW[0];
166 printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fW[0]=%f\n",
171 Double_t AliITSstatistics2::GetYXNth(Int_t order){
172 // This give the unbiased estimator for the RMS.
175 if(fW[0]!=0.0&&order<=fOrder) s = fYx[order-1]/fW[0];
178 printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fW[0]=%f\n",
183 Double_t AliITSstatistics2::GetRMSX(){
184 // This give the unbiased estimator for the RMS.
185 Double_t x,x2,w,ww,s;
187 x = GetMeanX(); // first order
188 x2 = GetXNth(2); // second order
189 w = fW[0]; // first order - 1.
190 ww = fW[1]; // second order - 1.
192 if(w*w==ww) return (-1.0);
193 s = (x2-x*x)*w*w/(w*w-ww);
194 return TMath::Sqrt(s);
196 Double_t AliITSstatistics2::GetRMSY(){
197 // This give the unbiased estimator for the RMS.
198 Double_t x,x2,w,ww,s;
200 x = GetMeanY(); // first order
201 x2 = GetYNth(2); // second order
202 w = fW[0]; // first order - 1.
203 ww = fW[1]; // second order - 1.
205 if(w*w==ww) return (-1.0);
206 s = (x2-x*x)*w*w/(w*w-ww);
207 return TMath::Sqrt(s);
209 Double_t AliITSstatistics2::GetRMSYX(){
210 // This give the unbiased estimator for the RMS.
211 Double_t x,x2,w,ww,s;
213 x = GetMeanYX(); // first order
214 x2 = GetYXNth(2); // second order
215 w = fW[0]; // first order - 1.
216 ww = fW[1]; // second order - 1.
218 if(w*w==ww) return (-1.0);
219 s = (x2-x*x)*w*w/(w*w-ww);
220 return TMath::Sqrt(s);
222 Double_t AliITSstatistics2::GetErrorMeanY(){
223 //This is the error in the mean or the square root of the variance of the mean.
229 s = rms*rms*ww/(w*w);
230 return TMath::Sqrt(s);
232 Double_t AliITSstatistics2::GetErrorMeanX(){
233 //This is the error in the mean or the square root of the variance of the mean.
239 s = rms*rms*ww/(w*w);
240 return TMath::Sqrt(s);
242 Double_t AliITSstatistics2::GetErrorMeanYX(){
243 //This is the error in the mean or the square root of the variance of the mean.
249 s = rms*rms*ww/(w*w);
250 return TMath::Sqrt(s);
254 Double_t AliITSstatistics2::GetErrorRMSY(){
255 //This is the error in the mean or the square root of the variance of the mean.
256 // at this moment this routine is only defined for weights=1.
257 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
259 if(fW[0]!=(Double_t)fN||GetN()<4) return (-1.);
260 x = GetMeanY(); // first order
261 x2 = GetYNth(2); // second order
262 w = fW[0]; // first order - 1.
263 ww = fW[1]; // second order - 1.
264 if(w*w==ww) return (-1.0);
265 s = (x2-x*x)*w*w/(w*w-ww);
268 n = (Double_t) GetN();
271 // This equation assumes that all of the weights are equal to 1.
272 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
273 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
274 return TMath::Sqrt(s);
276 Double_t AliITSstatistics2::GetErrorRMSX(){
277 //This is the error in the mean or the square root of the variance of the mean.
278 // at this moment this routine is only defined for weights=1.
279 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
281 if(fW[0]!=(Double_t)fN||GetN()<4) return (-1.);
282 x = GetMeanX(); // first order
283 x2 = GetXNth(2); // second order
284 w = fW[0]; // first order - 1.
285 ww = fW[1]; // second order - 1.
286 if(w*w==ww) return (-1.0);
287 s = (x2-x*x)*w*w/(w*w-ww);
290 n = (Double_t) GetN();
293 // This equation assumes that all of the weights are equal to 1.
294 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
295 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
296 return TMath::Sqrt(s);
298 Double_t AliITSstatistics2::GetErrorRMSYX(){
299 //This is the error in the mean or the square root of the variance of the mean.
300 // at this moment this routine is only defined for weights=1.
301 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
303 if(fW[0]!=(Double_t)fN||GetN()<4) return (-1.);
304 x = GetMeanYX(); // first order
305 x2 = GetYXNth(2); // second order
306 w = fW[0]; // first order - 1.
307 ww = fW[1]; // second order - 1.
308 if(w*w==ww) return (-1.0);
309 s = (x2-x*x)*w*w/(w*w-ww);
312 n = (Double_t) GetN();
315 // This equation assumes that all of the weights are equal to 1.
316 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
317 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
318 return TMath::Sqrt(s);
320 //_______________________________________________________________________
321 Double_t AliITSstatistics2::FitToLine(Double_t &a,Double_t &b){
322 // fit to y = a+bx returns Chi squared or -1.0 if an error
323 Double_t c,d,e,f,g,h;
326 if(fOrder<2 || fN<3) return -1.0;
339 printf("AliITSstatistics2: Error in FitToLine vertical line\n");
342 h = GetYN(2)+a*a*c+b*b*g-2.0*a*d-2.0*b*f+2.0*a*b*e;
343 h /= (Double_t)fN - 2.0;