X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=ITS%2FAliITSstatistics2.cxx;h=13d9869548109bb24ad5120f399f2464f0bb0c72;hb=54af1addac9b317077543cb8f3e5e13eeff8bcec;hp=4dbb867b84b7dbbc706c5d0ae96e7a6fd213551b;hpb=b0f5e3fcf84ecedb50df35ebe629b44bafc15bc0;p=u%2Fmrichter%2FAliRoot.git diff --git a/ITS/AliITSstatistics2.cxx b/ITS/AliITSstatistics2.cxx index 4dbb867b84b..13d98695481 100644 --- a/ITS/AliITSstatistics2.cxx +++ b/ITS/AliITSstatistics2.cxx @@ -1,266 +1,446 @@ +/************************************************************************** + * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ + ////////////////////////////////////////////////////////////////////////// -// Alice ITS class to help keep statistical information // +// Alice ITS class to help keep statistical information. Can also be // +// used to fit data to lines and other 2 dimentional sytistical // +// operations. // // // // version: 0.0.0 Draft. // // Date: April 18 1999 // // By: Bjorn S. Nilsen // +// Updated: 1.0.0, Date: September 6 2007, By: Bjorn S. Nilsen // // // ////////////////////////////////////////////////////////////////////////// -#include -#include -#include "TMath.h" -#include "AliITSstatistics2.h" +#include // ios::fmtflags fmt used in PrintAscii +#include "Riostream.h" // IO functions. +#include "TMath.h" // TMath::Sqrt() function used. +#include "AliITSstatistics2.h" // Also defined TObject {base class} ClassImp(AliITSstatistics2) // -AliITSstatistics2::AliITSstatistics2() : TObject(){ -// -// default constructor -// - fx = 0; - fy = 0; - fyx = 0; - fw = 0; - fN = 0; - fOrder = 0; +AliITSstatistics2::AliITSstatistics2() : +TObject(), // Base Class +fN(-1), // number of enetries -1 => Uninitilized +fOrder(0), // maximum moment of distributions (^n) +fX(0), //[fOrder] array of sums of x^n +fYx(0), //[fOrder] array of sums of (xy)^n +fY(0), //[fOrder] array of sums of y^n +fW(0) //[fOrder] array of sums of w^n (weights) +//,fDig(5) // The number of significant digits to keep +//,fOver(0) //! In case of numerical precistion problems +{ + // default constructor + // Inputs: + // none. + // Outputs: + // none. + // Return: + // A default constructed AliITSstatistics class + return; } - - -AliITSstatistics2::AliITSstatistics2(Int_t order) : TObject(){ -// -// constructor to maximum moment/order order -// +//______________________________________________________________________ +AliITSstatistics2::AliITSstatistics2(Int_t order) : +TObject(), // Base Class +fN(0), // number of enetries -1 => Uninitilized +fOrder(order), // maximum moment of distributions (^n) +fX(new Double_t[order]), //[fOrder] array of sums of x^n +fYx(new Double_t[order]), //[fOrder] array of sums of (xy)^n +fY(new Double_t[order]), //[fOrder] array of sums of y^n +fW(new Double_t[order]) //[fOrder] array of sums of w^n (weights) +//,fDig(5) // The number of significant digits to keep +//,fOver(0) //! In case of numeerical precistion problems +{ // constructor to maximum moment/order order + // Inputs: + // Int_t order The maximum moment of distributions {for example x^n} Int_t i; - fOrder = order; - fx = new Double_t[order]; - fy = new Double_t[order]; - fyx = new Double_t[order]; - fw = new Double_t[order]; - for(i=0;ifOrder = source.fOrder; - this->fN = source.fN; - this->fx = new Double_t[this->fOrder]; - this->fw = new Double_t[this->fOrder]; - for(i=0;ifx[i] = source.fx[i]; - this->fw[i] = source.fw[i]; + // operator = + // Inputs: + // AliITSstaticstics2 &source The source of this copy. + // Outputs: + // none. + // Return: + // A copy of the source class + + if(this==&source) return *this; + TObject::operator=(source); + Reset(source.GetOrder()); + fN = source.GetN(); + fOrder=source.GetOrder(); + for(Int_t i=0;ifX[i] = source.fX[i]; + this->fYx[i] = source.fYx[i]; + this->fY[i] = source.fY[i]; + this->fW[i] = source.fW[i]; } // end for i - }else{ - this->fx = 0; - this->fw = 0; - this->fN = 0; - this->fOrder = 0; - }// end if source.fOrder!=0 - return *this; + // this->fDig = source.fDig; + // if(fOver!=0) this->fOver = new AliITSstatistics2(*(source.fOver)); + // else fOver=0; + return *this; } //_______________________________________________________________ -AliITSstatistics2::AliITSstatistics2(AliITSstatistics2 &source){ -// Copy constructor - - Int_t i; - if(this==&source) return; - if(source.fOrder!=0){ - this->fOrder = source.fOrder; - this->fN = source.fN; - this->fx = new Double_t[this->fOrder]; - this->fw = new Double_t[this->fOrder]; - for(i=0;ifx[i] = source.fx[i]; - this->fw[i] = source.fw[i]; +AliITSstatistics2::AliITSstatistics2(AliITSstatistics2 &source): +TObject(source), // Base Class +fN(source.GetN()), // number of enetries -1 => Uninitilized +fOrder(source.GetOrder()),// maximum moment of distributions (^n) +fX(new Double_t[source.GetOrder()]),//[fOrder] array of sums of x^n +fYx(new Double_t[source.GetOrder()]),//[fOrder] array of sums of (xy)^n +fY(new Double_t[source.GetOrder()]),//[fOrder] array of sums of y^n +fW(new Double_t[source.GetOrder()]) //[fOrder] array of sums of w^n (weights) +//,fDig(source.fDig) // The number of significant digits to keep +//,fOver(0) //! In case of numerical precistion problems +{ + // Copy constructor + // Inputs: + // AliITSstatistics2 & source the source of this copy + // Outputs: + // none. + // Return: + // A copy of the source. + + for(Int_t i=0;ifX[i] = source.fX[i]; + this->fYx[i] = source.fYx[i]; + this->fY[i] = source.fY[i]; + this->fW[i] = source.fW[i]; } // end for i - }else{ - this->fx = 0; - this->fw = 0; - this->fN = 0; - this->fOrder = 0; - }// end if source.fOrder!=0 + //if(fOver!=0) this->fOver = new AliITSstatistics2(*(source.fOver)); + return; } - -void AliITSstatistics2::Reset(){ -// -// Reset/zero statistics -// +//______________________________________________________________________ +void AliITSstatistics2::Reset(Int_t order){ + // Reset/zero all statistics variables statistics + // Inputs: + // none. + // Outputs: + // none. + // Return: + // none. Int_t i; - for(i=0;ikBig || x>kBig || w>kBig) return; + /* If problem with precision, then creat/fill fOver + as a partical sum to be added to "this" later. + if(????fDig){ + if(fOver==0){ + fOver = new AliITSstatistics2(fOrder); + } // end if fOver==0 + fOver->AddValue(y,x,w); + return; + } // end if(???) + */ fN++; - for(i=0;i> fN; - R__b >> fOrder; - R__b.ReadArray(fy); - R__b.ReadArray(fx); - R__b.ReadArray(fyx); - R__b.ReadArray(fw); - } else { - R__b.WriteVersion(AliITSstatistics2::IsA()); - TObject::Streamer(R__b); - R__b << fN; - R__b << fOrder; - R__b.WriteArray(fy,fOrder); - R__b.WriteArray(fx,fOrder); - R__b.WriteArray(fyx,fOrder); - R__b.WriteArray(fw,fOrder); - } +Double_t AliITSstatistics2::GetChiSquared(Double_t a,Double_t b)const{ + // Returns Chi^2 value of data to line y=ax+b with given a,b. + /* + Begin_Latex + Note: The Chi^2 value is computed from the expression + \begin{equation*} + \chi^{2}=\sum_{i}{w_{i}y_{i}^{2}} + b^{2}\sum_{i}{w_{i}} + -2b\sum_{i}{w_{i}y_{i}}-2a\sum_{i}{w_{i}y_{i}x_{i}} + +2ab\sum_{i}{w_{i}x_{i}} + +a^{2}\sum_{i}w_{i}x_{i}^{2} + \end{equation*} + and not form the expression + \begin{equation*} + \chi^{2}= \sum_{i}{(y_{i}-ax_{i}-b)^{2}w_{i}. + \end{equation*} + Consiquently, there are occations when numerically these + two expressions will not agree. In fact the form code here + can give negitive values. This happens when the numerical + significance is larger than the $\chi^{2}$ value. This should + not be confused the the error values which can be returned. + At present there is no check on the numberical significance + of any results. + End_Latex + */ + // Inputs: + // Double_t a The slope parameter + // Double_t b The intercept paramter + // Outputs:: + // none. + // Return: + // The Chi^2 of the fit + Double_t c2; + + c2 = GetYN(2)+b*b*GetWN(1)+ + a*a*GetXN(2)-2.0*b*GetYN(1)-2.0*a*GetYXN(1)+2.0*b*a*GetXN(1); + c2 /= (Double_t)GetN() - 2.0; + return c2; +} +//______________________________________________________________________ +void AliITSstatistics2::PrintAscii(ostream *os)const{ + // Print out class data values in Ascii Form to output stream + // Inputs: + // ostream *os Output stream where Ascii data is to be writen + // Outputs: + // none. + // Return: + // none. + Int_t i; +#if defined __GNUC__ +#if __GNUC__ > 2 + ios::fmtflags fmt; // Standard IO format object, required for output. +#else + Int_t fmt; +#endif +#else +#if defined __ICC || defined __ECC || defined __xlC__ + ios::fmtflags fmt; +#else + Int_t fmt; +#endif +#endif + + *os << fN <<" "<< GetOrder(); + fmt = os->setf(ios::scientific); // set scientific floating point output + for(i=0;iflags(fmt); // reset back to old Formating. + return; } +//______________________________________________________________________ +void AliITSstatistics2::ReadAscii(istream *is){ + // Read in class data values in Ascii Form to output stream + // Inputs: + // istream *is Input stream where Ascii data is to be read in from + // Outputs: + // none. + // Return: + // none. + Int_t i; + + *is >> i >> fOrder; + Reset(fOrder); + fN = i; + for(i=0;i> fX[i]; + for(i=0;i> fYx[i]; + for(i=0;i> fY[i]; + for(i=0;i> fW[i]; + //*is >> fDig; + // if(fDig>0) *is >> fOver; + // else fDig *= -1; +} +//______________________________________________________________________ +ostream &operator<<(ostream &os,const AliITSstatistics2 &s){ + // Standard output streaming function + // Inputs: + // ostream &os output steam + // AliITSstatistics2 &s class to be streamed. + // Output: + // none. + // Return: + // ostream &os The stream pointer + + s.PrintAscii(&os); + return os; +} +//______________________________________________________________________ +istream &operator>>(istream &is,AliITSstatistics2 &s){ + // Standard inputput streaming function + // Inputs: + // istream &is input steam + // AliITSstatistics2 &s class to be streamed. + // Output: + // none. + // Return: + // ostream &os The stream pointer + + s.ReadAscii(&is); + return is; +} +