1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////
20 // Subset of matheamtical functions not included in the TMath
23 ///////////////////////////////////////////////////////////////////////////
25 #include "AliMathBase.h"
26 #include "Riostream.h"
28 ClassImp(AliMathBase) // Class implementation to enable ROOT I/O
30 AliMathBase::AliMathBase() : TObject()
32 // Default constructor
34 ///////////////////////////////////////////////////////////////////////////
35 AliMathBase::~AliMathBase()
41 //_____________________________________________________________________________
42 void AliMathBase::EvaluateUni(Int_t nvectors, Double_t *data, Double_t &mean
43 , Double_t &sigma, Int_t hh)
46 // Robust estimator in 1D case MI version - (faster than ROOT version)
48 // For the univariate case
49 // estimates of location and scatter are returned in mean and sigma parameters
50 // the algorithm works on the same principle as in multivariate case -
51 // it finds a subset of size hh with smallest sigma, and then returns mean and
52 // sigma of this subset
57 Double_t faclts[]={2.6477,2.5092,2.3826,2.2662,2.1587,2.0589,1.9660,1.879,1.7973,1.7203,1.6473};
58 Int_t *index=new Int_t[nvectors];
59 TMath::Sort(nvectors, data, index, kFALSE);
61 Int_t nquant = TMath::Min(Int_t(Double_t(((hh*1./nvectors)-0.5)*40))+1, 11);
62 Double_t factor = faclts[nquant-1];
67 Double_t bestmean = 0;
68 Double_t bestsigma = data[index[nvectors-1]]-data[index[0]]; // maximal possible sigma
69 for (Int_t i=0; i<hh; i++){
70 sumx += data[index[i]];
71 sumx2 += data[index[i]]*data[index[i]];
74 Double_t norm = 1./Double_t(hh);
75 Double_t norm2 = 1./Double_t(hh-1);
76 for (Int_t i=hh; i<nvectors; i++){
77 Double_t cmean = sumx*norm;
78 Double_t csigma = (sumx2 - hh*cmean*cmean)*norm2;
79 if (csigma<bestsigma){
85 sumx += data[index[i]]-data[index[i-hh]];
86 sumx2 += data[index[i]]*data[index[i]]-data[index[i-hh]]*data[index[i-hh]];
89 Double_t bstd=factor*TMath::Sqrt(TMath::Abs(bestsigma));
98 void AliMathBase::EvaluateUniExternal(Int_t nvectors, Double_t *data, Double_t &mean, Double_t &sigma, Int_t hh, Float_t externalfactor)
100 // Modified version of ROOT robust EvaluateUni
101 // robust estimator in 1D case MI version
102 // added external factor to include precision of external measurement
107 Double_t faclts[]={2.6477,2.5092,2.3826,2.2662,2.1587,2.0589,1.9660,1.879,1.7973,1.7203,1.6473};
108 Int_t *index=new Int_t[nvectors];
109 TMath::Sort(nvectors, data, index, kFALSE);
111 Int_t nquant = TMath::Min(Int_t(Double_t(((hh*1./nvectors)-0.5)*40))+1, 11);
112 Double_t factor = faclts[0];
114 // fix proper normalization - Anja
115 factor = faclts[nquant-1];
122 Int_t bestindex = -1;
123 Double_t bestmean = 0;
124 Double_t bestsigma = -1;
125 for (Int_t i=0; i<hh; i++){
126 sumx += data[index[i]];
127 sumx2 += data[index[i]]*data[index[i]];
130 Double_t kfactor = 2.*externalfactor - externalfactor*externalfactor;
131 Double_t norm = 1./Double_t(hh);
132 for (Int_t i=hh; i<nvectors; i++){
133 Double_t cmean = sumx*norm;
134 Double_t csigma = (sumx2*norm - cmean*cmean*kfactor);
135 if (csigma<bestsigma || bestsigma<0){
142 sumx += data[index[i]]-data[index[i-hh]];
143 sumx2 += data[index[i]]*data[index[i]]-data[index[i-hh]]*data[index[i-hh]];
146 Double_t bstd=factor*TMath::Sqrt(TMath::Abs(bestsigma));
153 //_____________________________________________________________________________
154 Int_t AliMathBase::Freq(Int_t n, const Int_t *inlist
155 , Int_t *outlist, Bool_t down)
158 // Sort eleements according occurancy
159 // The size of output array has is 2*n
162 Int_t * sindexS = new Int_t[n]; // temp array for sorting
163 Int_t * sindexF = new Int_t[2*n];
164 for (Int_t i=0;i<n;i++) sindexF[i]=0;
166 TMath::Sort(n,inlist, sindexS, down);
167 Int_t last = inlist[sindexS[0]];
174 for(Int_t i=1;i<n; i++){
175 val = inlist[sindexS[i]];
176 if (last == val) sindexF[countPos]++;
179 sindexF[countPos+n] = val;
184 if (last==val) countPos++;
185 // sort according frequency
186 TMath::Sort(countPos, sindexF, sindexS, kTRUE);
187 for (Int_t i=0;i<countPos;i++){
188 outlist[2*i ] = sindexF[sindexS[i]+n];
189 outlist[2*i+1] = sindexF[sindexS[i]];