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
37 fx = new Double_t[order];
38 fy = new Double_t[order];
39 fyx = new Double_t[order];
40 fw = new Double_t[order];
41 for(i=0;i<order;i++) {fx[i] = 0.0;fy[i] = 0.0;
42 fyx[i] = 0.0; fw[i] = 0.0;}
47 AliITSstatistics2::~AliITSstatistics2(){
51 if(fx!=0) delete[] fx;
52 if(fy!=0) delete[] fy;
53 if(fyx!=0) delete[] fyx;
54 if(fw!=0) delete[] fw;
63 //_______________________________________________________________
64 AliITSstatistics2& AliITSstatistics2::operator=(AliITSstatistics2 &source){
68 if(this==&source) return *this;
70 this->fOrder = source.fOrder;
72 this->fx = new Double_t[this->fOrder];
73 this->fw = new Double_t[this->fOrder];
74 for(i=0;i<source.fOrder;i++){
75 this->fx[i] = source.fx[i];
76 this->fw[i] = source.fw[i];
83 }// end if source.fOrder!=0
86 //_______________________________________________________________
87 AliITSstatistics2::AliITSstatistics2(AliITSstatistics2 &source){
91 if(this==&source) return;
93 this->fOrder = source.fOrder;
95 this->fx = new Double_t[this->fOrder];
96 this->fw = new Double_t[this->fOrder];
97 for(i=0;i<source.fOrder;i++){
98 this->fx[i] = source.fx[i];
99 this->fw[i] = source.fw[i];
106 }// end if source.fOrder!=0
109 void AliITSstatistics2::Reset(){
111 // Reset/zero statistics
114 for(i=0;i<fOrder;i++) {fx[i] = 0.0;fy[i] = 0.0;
115 fyx[i] = 0.0; fw[i] = 0.0;}
120 void AliITSstatistics2::AddValue(Double_t y,Double_t x,Double_t w=1.0){
122 // add next x,y pair to statistics
124 Double_t xs=1.0,ys=1.0,yxs=1.0,ws=1.0;
127 if(isinf(y)!=0||isinf(x)!=0||isinf(w)!=0) return;
128 if(isnan(y)!=0||isnan(x)!=0||isnan(w)!=0) 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;
346 //_______________________________________________________________________
347 void AliITSstatistics2::Streamer(TBuffer &R__b){
348 // Stream an object of class AliITSstatistics2.
350 if (R__b.IsReading()) {
351 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
352 TObject::Streamer(R__b);
360 R__b.WriteVersion(AliITSstatistics2::IsA());
361 TObject::Streamer(R__b);
364 R__b.WriteArray(fy,fOrder);
365 R__b.WriteArray(fx,fOrder);
366 R__b.WriteArray(fyx,fOrder);
367 R__b.WriteArray(fw,fOrder);