]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSstatistics.cxx
Use for PID in ITS the Bethe Bloch from AliExternalTrackParam
[u/mrichter/AliRoot.git] / ITS / AliITSstatistics.cxx
CommitLineData
b0f5e3fc 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
15ClassImp(AliITSstatistics)
16
17//
7537d03c 18AliITSstatistics::AliITSstatistics() : TObject(),
19fN(0),
20fOrder(0),
21fX(0),
22fW(0){
b0f5e3fc 23//
24// default contructor
25//
b0f5e3fc 26}
27
28
7537d03c 29AliITSstatistics::AliITSstatistics(Int_t order) : TObject(),
30fN(0),
31fOrder(order),
32fX(0),
33fW(0){
b0f5e3fc 34//
35// contructor to a specific order in the moments
36//
07025d6d 37 fX = new Double_t[order];
38 fW = new Double_t[order];
39 for(Int_t i=0;i<order;i++) {fX[i] = 0.0; fW[i] = 0.0;}
b0f5e3fc 40 return;
41}
42
43AliITSstatistics::~AliITSstatistics(){
44//
45// default destructor
46//
07025d6d 47 if(fX!=0) delete[] fX;
48 if(fW!=0) delete[] fW;
49 fX = 0;
50 fW = 0;
b0f5e3fc 51 fN = 0;
52 fOrder = 0;
53}
54//_______________________________________________________________
7537d03c 55AliITSstatistics& AliITSstatistics::operator=(const AliITSstatistics &source){
b0f5e3fc 56// operator =
57
b0f5e3fc 58 if(this==&source) return *this;
e8189707 59 if(source.fOrder!=0){
60 this->fOrder = source.fOrder;
61 this->fN = source.fN;
07025d6d 62 this->fX = new Double_t[this->fOrder];
63 this->fW = new Double_t[this->fOrder];
e8189707 64 for(Int_t i=0;i<source.fOrder;i++){
07025d6d 65 this->fX[i] = source.fX[i];
66 this->fW[i] = source.fW[i];
e8189707 67 } // end for i
68 }else{
07025d6d 69 this->fX = 0;
70 this->fW = 0;
e8189707 71 this->fN = 0;
72 this->fOrder = 0;
73 }// end if source.fOrder!=0
74 return *this;
b0f5e3fc 75}
76//_______________________________________________________________
7537d03c 77AliITSstatistics::AliITSstatistics(const AliITSstatistics &source) : TObject(source),
78fN(0),
79fOrder(0),
80fX(0),
81fW(0){
b0f5e3fc 82// Copy constructor
83
e8189707 84 if(this==&source) return;
85 if(source.fOrder!=0){
86 this->fOrder = source.fOrder;
87 this->fN = source.fN;
07025d6d 88 this->fX = new Double_t[this->fOrder];
89 this->fW = new Double_t[this->fOrder];
e8189707 90 for(Int_t i=0;i<source.fOrder;i++){
07025d6d 91 this->fX[i] = source.fX[i];
92 this->fW[i] = source.fW[i];
e8189707 93 } // end for i
94 }else{
07025d6d 95 this->fX = 0;
96 this->fW = 0;
e8189707 97 this->fN = 0;
98 this->fOrder = 0;
99 }// end if source.fOrder!=0
b0f5e3fc 100}
101//_______________________________________________________________
102void AliITSstatistics::Reset(){
103//
104// reset all values to zero
105//
07025d6d 106 for(Int_t i=0;i<fOrder;i++) {fX[i] = 0.0; fW[i] = 0.0;}
b0f5e3fc 107 fN = 0;
108 return;
109}
110
e8189707 111//_______________________________________________________________
112void AliITSstatistics::AddValue(Double_t x,Double_t w){
b0f5e3fc 113//
114// accumulate element x with weight w.
115//
e8189707 116
117 //it was AddValue(Double_t x,Double_t w=1.0);
118
b0f5e3fc 119 Double_t y=1.0,z=1.0;
e8189707 120
b0f5e3fc 121 Int_t i;
e8189707 122 const Double_t kBig=1.0e+38;
b0f5e3fc 123
e8189707 124 if(y>kBig || x>kBig || w>kBig) return;
b0f5e3fc 125
b0f5e3fc 126 fN++;
127 for(i=0;i<fOrder;i++){
128 y *= x;
129 z *= w;
07025d6d 130 fX[i] += y*w;
131 fW[i] += z;
b0f5e3fc 132 } // end for i
133}
134
135Double_t AliITSstatistics::GetNth(Int_t order){
136// This give the unbiased estimator for the RMS.
137 Double_t s;
138
07025d6d 139 if(fW[0]!=0.0&&order<=fOrder) s = fX[order-1]/fW[0];
b0f5e3fc 140 else {
141 s = 0.0;
07025d6d 142 printf("AliITSstatistics: error in GetNth: fOrder=%d fN=%d fW[0]=%f\n",
143 fOrder,fN,fW[0]);
b0f5e3fc 144 } // end else
145 return s;
146}
147
148Double_t AliITSstatistics::GetRMS(){
149// This give the unbiased estimator for the RMS.
150 Double_t x,x2,w,ww,s;
151
152 x = GetMean(); // first order
153 x2 = GetNth(2); // second order
07025d6d 154 w = fW[0]; // first order - 1.
155 ww = fW[1]; // second order - 1.
b0f5e3fc 156
157 if(w*w==ww) return (-1.0);
158 s = (x2-x*x)*w*w/(w*w-ww);
159 return TMath::Sqrt(s);
160}
161
162Double_t AliITSstatistics::GetErrorMean(){
163//This is the error in the mean or the square root of the variance of the mean.
164 Double_t rms,w,ww,s;
165
166 rms = GetRMS();
07025d6d 167 w = fW[0];
168 ww = fW[1];
b0f5e3fc 169 s = rms*rms*ww/(w*w);
170 return TMath::Sqrt(s);
171}
172
173
174Double_t AliITSstatistics::GetErrorRMS(){
175//This is the error in the mean or the square root of the variance of the mean.
176// at this moment this routine is only defined for weights=1.
177 Double_t x,x2,x3,x4,w,ww,m2,m4,n,s;
178
07025d6d 179 if(fW[0]!=(Double_t)fN||GetN()<4) return (-1.);
b0f5e3fc 180 x = GetMean(); // first order
181 x2 = GetNth(2); // second order
07025d6d 182 w = fW[0]; // first order - 1.
183 ww = fW[1]; // second order - 1.
b0f5e3fc 184 if(w*w==ww) return (-1.0);
185 s = (x2-x*x)*w*w/(w*w-ww);
186
187 m2 = s;
188 n = (Double_t) GetN();
189 x3 = GetNth(3);
190 x4 = GetNth(4);
191// This equation assumes that all of the weights are equal to 1.
192 m4 = (n/(n-1.))*(x4-3.*x*x3+6.*x*x*x2-2.*x*x*x*x);
193 s = (m4-(n-3.)*m2*m2/(n-1.))/n;
194 return TMath::Sqrt(s);
195}