]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliMathBase.cxx
AliESDHeader: AliTriggerConfiguration and more trigger scalers added
[u/mrichter/AliRoot.git] / STEER / AliMathBase.cxx
index 79cb3c24edbd256e99f971144abcbabb96a383ab..e4ae101c0e58df395e9c94dcb399d0b1aa41676b 100644 (file)
@@ -29,6 +29,8 @@
 #include "TF1.h"
 #include "TLinearFitter.h"
 
+#include "AliExternalTrackParam.h"
+
 //
 // includes neccessary for test functions
 //
@@ -275,7 +277,7 @@ void AliMathBase::LTM(TH1F * his, TVectorD *param , Float_t fraction,  Bool_t ve
   }
 }
 
-Double_t  AliMathBase::FitGaus(TH1F* his, TVectorD *param, TMatrixD *matrix, Float_t xmin, Float_t xmax, Bool_t verbose){
+Double_t  AliMathBase::FitGaus(TH1F* his, TVectorD *param, TMatrixD */*matrix*/, Float_t xmin, Float_t xmax, Bool_t verbose){
   //
   //  Fit histogram with gaussian function
   //  
@@ -353,7 +355,7 @@ Double_t  AliMathBase::FitGaus(TH1F* his, TVectorD *param, TMatrixD *matrix, Flo
   Double_t chi2 = fitter.GetChisquare()/Float_t(npoints);
   //fitter.GetParameters();
   if (!param)  param  = new TVectorD(3);
-  if (!matrix) matrix = new TMatrixD(3,3);
+  //if (!matrix) matrix = new TMatrixD(3,3);
   (*param)[1] = par[1]/(-2.*par[2]);
   (*param)[2] = 1./TMath::Sqrt(TMath::Abs(-2.*par[2]));
   (*param)[0] = TMath::Exp(par[0]+ par[1]* (*param)[1] +  par[2]*(*param)[1]*(*param)[1]);
@@ -371,7 +373,7 @@ Double_t  AliMathBase::FitGaus(TH1F* his, TVectorD *param, TMatrixD *matrix, Flo
   return chi2;
 }
 
-Double_t  AliMathBase::FitGaus(Float_t *arr, Int_t nBins, Float_t xMin, Float_t xMax, TVectorD *param, TMatrixD *matrix, Bool_t verbose){
+Double_t  AliMathBase::FitGaus(Float_t *arr, Int_t nBins, Float_t xMin, Float_t xMax, TVectorD *param, TMatrixD */*matrix*/, Bool_t verbose){
   //
   //  Fit histogram with gaussian function
   //  
@@ -412,6 +414,8 @@ Double_t  AliMathBase::FitGaus(Float_t *arr, Int_t nBins, Float_t xMin, Float_t
   Float_t entries = 0;
   Int_t nfilled=0;
 
+  if (!param)  param  = new TVectorD(4);
+
   for (Int_t i=0; i<nBins; i++){
       entries+=arr[i];
       if (arr[i]>0) nfilled++;
@@ -469,9 +473,9 @@ Double_t  AliMathBase::FitGaus(Float_t *arr, Int_t nBins, Float_t xMin, Float_t
       if (TMath::Abs(par[1])<kTol) return -4;
       if (TMath::Abs(par[2])<kTol) return -4;
 
-      if (!param)  param  = new TVectorD(4);
+      //if (!param)  param  = new TVectorD(4);
       if ( param->GetNrows()<4 ) param->ResizeTo(4);
-      if (!matrix) matrix = new TMatrixD(3,3);  // !!!!might be a memory leek. use dummy matrix pointer to call this function!
+      //if (!matrix) matrix = new TMatrixD(3,3);  // !!!!might be a memory leek. use dummy matrix pointer to call this function!
 
       (*param)[1] = par[1]/(-2.*par[2]);
       (*param)[2] = 1./TMath::Sqrt(TMath::Abs(-2.*par[2]));
@@ -552,6 +556,19 @@ Float_t AliMathBase::GetCOG(Short_t *arr, Int_t nBins, Float_t xMin, Float_t xMa
 }
 
 
+Double_t AliMathBase::ErfcFast(Double_t x){
+  // Fast implementation of the complementary error function
+  // The error of the approximation is |eps(x)| < 5E-4
+  // See Abramowitz and Stegun, p.299, 7.1.27
+
+  Double_t z = TMath::Abs(x);
+  Double_t ans = 1+z*(0.278393+z*(0.230389+z*(0.000972+z*0.078108)));
+  ans = 1.0/ans;
+  ans *= ans;
+  ans *= ans;
+
+  return (x>=0.0 ? ans : 2.0 - ans);
+}
 
 ///////////////////////////////////////////////////////////////
 //////////////         TEST functions /////////////////////////
@@ -656,7 +673,8 @@ TGraph2D * AliMathBase::MakeStat2D(TH3 * his, Int_t delta0, Int_t delta1, Int_t
   //  TAxis * zaxis  = his->GetZaxis();
   Int_t   nbinx  = xaxis->GetNbins();
   Int_t   nbiny  = yaxis->GetNbins();
-  char name[1000];
+  const Int_t nc=1000;
+  char name[nc];
   Int_t icount=0;
   TGraph2D  *graph = new TGraph2D(nbinx*nbiny);
   TF1 f1("f1","gaus");
@@ -664,7 +682,7 @@ TGraph2D * AliMathBase::MakeStat2D(TH3 * his, Int_t delta0, Int_t delta1, Int_t
     for (Int_t iy=0; iy<nbiny;iy++){
       Float_t xcenter = xaxis->GetBinCenter(ix); 
       Float_t ycenter = yaxis->GetBinCenter(iy); 
-      sprintf(name,"%s_%d_%d",his->GetName(), ix,iy);
+      snprintf(name,nc,"%s_%d_%d",his->GetName(), ix,iy);
       TH1 *projection = his->ProjectionZ(name,ix-delta0,ix+delta0,iy-delta1,iy+delta1);
       Float_t stat= 0;
       if (type==0) stat = projection->GetMean();
@@ -699,14 +717,15 @@ TGraph * AliMathBase::MakeStat1D(TH3 * his, Int_t delta1, Int_t type){
   //  TAxis * zaxis  = his->GetZaxis();
   Int_t   nbinx  = xaxis->GetNbins();
   Int_t   nbiny  = yaxis->GetNbins();
-  char name[1000];
+  const Int_t nc=1000;
+  char name[nc];
   Int_t icount=0;
   TGraph  *graph = new TGraph(nbinx);
   TF1 f1("f1","gaus");
   for (Int_t ix=0; ix<nbinx;ix++){
     Float_t xcenter = xaxis->GetBinCenter(ix); 
     //    Float_t ycenter = yaxis->GetBinCenter(iy); 
-    sprintf(name,"%s_%d",his->GetName(), ix);
+    snprintf(name,nc,"%s_%d",his->GetName(), ix);
     TH1 *projection = his->ProjectionZ(name,ix-delta1,ix+delta1,0,nbiny);
     Float_t stat= 0;
     if (type==0) stat = projection->GetMean();
@@ -739,3 +758,34 @@ Double_t AliMathBase::TruncatedGaus(Double_t mean, Double_t sigma, Double_t cuta
   }while(TMath::Abs(value-mean)>cutat);
   return value;
 }
+
+Double_t AliMathBase::TruncatedGaus(Double_t mean, Double_t sigma, Double_t leftCut, Double_t rightCut)
+{
+  // return number generated according to a gaussian distribution N(mean,sigma)
+  // truncated at leftCut and rightCut
+  //
+  Double_t value;
+  do{
+    value=gRandom->Gaus(mean,sigma);
+  }while((value-mean)<-leftCut || (value-mean)>rightCut);
+  return value;
+}
+
+Double_t AliMathBase::BetheBlochAleph(Double_t bg,
+         Double_t kp1,
+         Double_t kp2,
+         Double_t kp3,
+         Double_t kp4,
+         Double_t kp5) {
+  //
+  // This is the empirical ALEPH parameterization of the Bethe-Bloch formula.
+  // It is normalized to 1 at the minimum.
+  //
+  // bg - beta*gamma
+  // 
+  // The default values for the kp* parameters are for ALICE TPC.
+  // The returned value is in MIP units
+  //
+
+  return AliExternalTrackParam::BetheBlochAleph(bg,kp1,kp2,kp3,kp4,kp5);
+}