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){
88 if(this==&source) return;
90 this->fOrder = source.fOrder;
92 this->fx = new Double_t[this->fOrder];
93 this->fw = new Double_t[this->fOrder];
94 for(Int_t i=0;i<source.fOrder;i++){
95 this->fx[i] = source.fx[i];
96 this->fw[i] = source.fw[i];
103 }// end if source.fOrder!=0
106 void AliITSstatistics2::Reset(){
108 // Reset/zero statistics
110 for(Int_t i=0;i<fOrder;i++) {fx[i] = 0.0;fy[i] = 0.0;
111 fyx[i] = 0.0; fw[i] = 0.0;}
116 void AliITSstatistics2::AddValue(Double_t y,Double_t x,Double_t w=1.0){
118 // add next x,y pair to statistics
120 Double_t xs=1.0,ys=1.0,yxs=1.0,ws=1.0;
123 const Double_t kBig=1.0e+38;
125 if(y>kBig || x>kBig || w>kBig) return;
129 for(i=0;i<fOrder;i++){
141 Double_t AliITSstatistics2::GetXNth(Int_t order){
143 // This give the unbiased estimator for the RMS.
148 if(fw[0]!=0.0&&order<=fOrder) s = fx[order-1]/fw[0];
151 printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
156 Double_t AliITSstatistics2::GetYNth(Int_t order){
158 // This give the unbiased estimator for the RMS.
162 if(fw[0]!=0.0&&order<=fOrder) s = fy[order-1]/fw[0];
165 printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
170 Double_t AliITSstatistics2::GetYXNth(Int_t order){
171 // This give the unbiased estimator for the RMS.
174 if(fw[0]!=0.0&&order<=fOrder) s = fyx[order-1]/fw[0];
177 printf("AliITSstatistics2: error in GetNth: fOrder=%d fN=%d fw[0]=%f\n",
182 Double_t AliITSstatistics2::GetRMSX(){
183 // This give the unbiased estimator for the RMS.
184 Double_t x,x2,w,ww,s;
186 x = GetMeanX(); // first order
187 x2 = GetXNth(2); // second order
188 w = fw[0]; // first order - 1.
189 ww = fw[1]; // second order - 1.
191 if(w*w==ww) return (-1.0);
192 s = (x2-x*x)*w*w/(w*w-ww);
193 return TMath::Sqrt(s);
195 Double_t AliITSstatistics2::GetRMSY(){
196 // This give the unbiased estimator for the RMS.
197 Double_t x,x2,w,ww,s;
199 x = GetMeanY(); // first order
200 x2 = GetYNth(2); // second order
201 w = fw[0]; // first order - 1.
202 ww = fw[1]; // second order - 1.
204 if(w*w==ww) return (-1.0);
205 s = (x2-x*x)*w*w/(w*w-ww);
206 return TMath::Sqrt(s);
208 Double_t AliITSstatistics2::GetRMSYX(){
209 // This give the unbiased estimator for the RMS.
210 Double_t x,x2,w,ww,s;
212 x = GetMeanYX(); // first order
213 x2 = GetYXNth(2); // second order
214 w = fw[0]; // first order - 1.
215 ww = fw[1]; // second order - 1.
217 if(w*w==ww) return (-1.0);
218 s = (x2-x*x)*w*w/(w*w-ww);
219 return TMath::Sqrt(s);
221 Double_t AliITSstatistics2::GetErrorMeanY(){
222 //This is the error in the mean or the square root of the variance of the mean.
228 s = rms*rms*ww/(w*w);
229 return TMath::Sqrt(s);
231 Double_t AliITSstatistics2::GetErrorMeanX(){
232 //This is the error in the mean or the square root of the variance of the mean.
238 s = rms*rms*ww/(w*w);
239 return TMath::Sqrt(s);
241 Double_t AliITSstatistics2::GetErrorMeanYX(){
242 //This is the error in the mean or the square root of the variance of the mean.
248 s = rms*rms*ww/(w*w);
249 return TMath::Sqrt(s);
253 Double_t AliITSstatistics2::GetErrorRMSY(){
254 //This is the error in the mean or the square root of the variance of the mean.
255 // at this moment this routine is only defined for weights=1.
256 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
258 if(fw[0]!=(Double_t)fN||GetN()<4) return (-1.);
259 x = GetMeanY(); // first order
260 x2 = GetYNth(2); // second order
261 w = fw[0]; // first order - 1.
262 ww = fw[1]; // second order - 1.
263 if(w*w==ww) return (-1.0);
264 s = (x2-x*x)*w*w/(w*w-ww);
267 n = (Double_t) GetN();
270 // This equation assumes that all of the weights are equal to 1.
271 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
272 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
273 return TMath::Sqrt(s);
275 Double_t AliITSstatistics2::GetErrorRMSX(){
276 //This is the error in the mean or the square root of the variance of the mean.
277 // at this moment this routine is only defined for weights=1.
278 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
280 if(fw[0]!=(Double_t)fN||GetN()<4) return (-1.);
281 x = GetMeanX(); // first order
282 x2 = GetXNth(2); // second order
283 w = fw[0]; // first order - 1.
284 ww = fw[1]; // second order - 1.
285 if(w*w==ww) return (-1.0);
286 s = (x2-x*x)*w*w/(w*w-ww);
289 n = (Double_t) GetN();
292 // This equation assumes that all of the weights are equal to 1.
293 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
294 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
295 return TMath::Sqrt(s);
297 Double_t AliITSstatistics2::GetErrorRMSYX(){
298 //This is the error in the mean or the square root of the variance of the mean.
299 // at this moment this routine is only defined for weights=1.
300 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
302 if(fw[0]!=(Double_t)fN||GetN()<4) return (-1.);
303 x = GetMeanYX(); // first order
304 x2 = GetYXNth(2); // second order
305 w = fw[0]; // first order - 1.
306 ww = fw[1]; // second order - 1.
307 if(w*w==ww) return (-1.0);
308 s = (x2-x*x)*w*w/(w*w-ww);
311 n = (Double_t) GetN();
314 // This equation assumes that all of the weights are equal to 1.
315 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
316 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
317 return TMath::Sqrt(s);
319 //_______________________________________________________________________
320 Double_t AliITSstatistics2::FitToLine(Double_t &a,Double_t &b){
321 // fit to y = a+bx returns Chi squared or -1.0 if an error
322 Double_t c,d,e,f,g,h;
325 if(fOrder<2 || fN<3) return -1.0;
338 printf("AliITSstatistics2: Error in FitToLine vertical line\n");
341 h = GetYN(2)+a*a*c+b*b*g-2.0*a*d-2.0*b*f+2.0*a*b*e;
342 h /= (Double_t)fN - 2.0;
345 //_______________________________________________________________________
346 void AliITSstatistics2::Streamer(TBuffer &R__b){
347 // Stream an object of class AliITSstatistics2.
349 if (R__b.IsReading()) {
350 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
351 TObject::Streamer(R__b);
359 R__b.WriteVersion(AliITSstatistics2::IsA());
360 TObject::Streamer(R__b);
363 R__b.WriteArray(fy,fOrder);
364 R__b.WriteArray(fx,fOrder);
365 R__b.WriteArray(fyx,fOrder);
366 R__b.WriteArray(fw,fOrder);