]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliCheb3DCalc.cxx
Bug fixed.
[u/mrichter/AliRoot.git] / STEER / AliCheb3DCalc.cxx
index 4eec5102a608b2e8b2a495cbfb5ef0033c4d94d6..0982bdbd15270968a4313cc7334e9fed7c5f9484 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-
-// Author: ruben.shahoyan@cern.ch   09/09/2006
-//
 #include <cstdlib>
+#include <TSystem.h>
 #include "AliCheb3DCalc.h"
 
 ClassImp(AliCheb3DCalc)
@@ -34,7 +32,9 @@ AliCheb3DCalc::AliCheb3DCalc() :
   fCoefs(0), 
   fTmpCf1(0), 
   fTmpCf0(0)
-{}
+{
+  // default constructor
+}
 
 //__________________________________________________________________________________________
 AliCheb3DCalc::AliCheb3DCalc(const AliCheb3DCalc& src) :
@@ -51,20 +51,22 @@ AliCheb3DCalc::AliCheb3DCalc(const AliCheb3DCalc& src) :
   fTmpCf1(0), 
   fTmpCf0(0)
 {
+  // copy constructor
+  //
   if (src.fNColsAtRow) {
-    fNColsAtRow = new Int_t[fNRows]; 
+    fNColsAtRow = new UShort_t[fNRows]; 
     for (int i=fNRows;i--;) fNColsAtRow[i] = src.fNColsAtRow[i];
   }
   if (src.fColAtRowBg) {
-    fColAtRowBg = new Int_t[fNRows]; 
+    fColAtRowBg = new UShort_t[fNRows]; 
     for (int i=fNRows;i--;) fColAtRowBg[i] = src.fColAtRowBg[i];
   }
   if (src.fCoefBound2D0) {
-    fCoefBound2D0 = new Int_t[fNElemBound2D];
+    fCoefBound2D0 = new UShort_t[fNElemBound2D];
     for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = src.fCoefBound2D0[i];
   }
   if (src.fCoefBound2D1) {
-    fCoefBound2D1 = new Int_t[fNElemBound2D];
+    fCoefBound2D1 = new UShort_t[fNElemBound2D];
     for (int i=fNElemBound2D;i--;) fCoefBound2D1[i] = src.fCoefBound2D1[i];
   }
   if (src.fCoefs) {
@@ -89,12 +91,14 @@ AliCheb3DCalc::AliCheb3DCalc(FILE* stream) :
   fTmpCf1(0), 
   fTmpCf0(0)
 {
+  // constructor from coeffs. streem
   LoadData(stream);
 }
 
 //__________________________________________________________________________________________
 AliCheb3DCalc& AliCheb3DCalc::operator=(const AliCheb3DCalc& rhs)
 {
+  // assignment operator
   if (this != &rhs) {
     Clear();
     SetName(rhs.GetName());
@@ -103,19 +107,19 @@ AliCheb3DCalc& AliCheb3DCalc::operator=(const AliCheb3DCalc& rhs)
     fNRows  = rhs.fNRows;
     fNCols  = rhs.fNCols;    
     if (rhs.fNColsAtRow) {
-      fNColsAtRow = new Int_t[fNRows]; 
+      fNColsAtRow = new UShort_t[fNRows]; 
       for (int i=fNRows;i--;) fNColsAtRow[i] = rhs.fNColsAtRow[i];
     }
     if (rhs.fColAtRowBg) {
-      fColAtRowBg = new Int_t[fNRows]; 
+      fColAtRowBg = new UShort_t[fNRows]; 
       for (int i=fNRows;i--;) fColAtRowBg[i] = rhs.fColAtRowBg[i];
     }
     if (rhs.fCoefBound2D0) {
-      fCoefBound2D0 = new Int_t[fNElemBound2D];
+      fCoefBound2D0 = new UShort_t[fNElemBound2D];
       for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = rhs.fCoefBound2D0[i];
     }
     if (rhs.fCoefBound2D1) {
-      fCoefBound2D1 = new Int_t[fNElemBound2D];
+      fCoefBound2D1 = new UShort_t[fNElemBound2D];
       for (int i=fNElemBound2D;i--;) fCoefBound2D1[i] = rhs.fCoefBound2D1[i];
     }
     if (rhs.fCoefs) {
@@ -129,7 +133,7 @@ AliCheb3DCalc& AliCheb3DCalc::operator=(const AliCheb3DCalc& rhs)
 }
 
 //__________________________________________________________________________________________
-void AliCheb3DCalc::Clear(Option_t*)
+void AliCheb3DCalc::Clear(const Option_t*)
 {
   // delete all dynamycally allocated structures
   if (fTmpCf1)       { delete[] fTmpCf1;  fTmpCf1 = 0;}
@@ -143,8 +147,9 @@ void AliCheb3DCalc::Clear(Option_t*)
 }
 
 //__________________________________________________________________________________________
-void AliCheb3DCalc::Print(Option_t* ) const
+void AliCheb3DCalc::Print(const Option_t* ) const
 {
+  // print info
   printf("Chebyshev parameterization data %s for 3D->1 function.\n",GetName());
   int nmax3d = 0; 
   for (int i=fNElemBound2D;i--;) if (fCoefBound2D0[i]>nmax3d) nmax3d = fCoefBound2D0[i];
@@ -153,64 +158,35 @@ void AliCheb3DCalc::Print(Option_t* ) const
 }
 
 //__________________________________________________________________________________________
-Float_t  AliCheb3DCalc::Eval(Float_t  *par) const
-{
-  // evaluate Chebyshev parameterization for 3D function.
-  // VERY IMPORTANT: par must contain the function arguments ALREADY MAPPED to [-1:1] interval
-  Float_t  &z = par[2];
-  Float_t  &y = par[1];
-  Float_t  &x = par[0];
-  //
-  int ncfRC;
-  for (int id0=fNRows;id0--;) {
-    int nCLoc = fNColsAtRow[id0];                   // number of significant coefs on this row
-    int Col0  = fColAtRowBg[id0];                   // beginning of local column in the 2D boundary matrix
-    for (int id1=nCLoc;id1--;) {
-      int id = id1+Col0;
-      fTmpCf1[id1] = (ncfRC=fCoefBound2D0[id]) ? ChebEval1D(z,fCoefs + fCoefBound2D1[id], ncfRC) : 0.0;
-    }
-    fTmpCf0[id0] = nCLoc>0 ? ChebEval1D(y,fTmpCf1,nCLoc):0.0;
-  }
-  return ChebEval1D(x,fTmpCf0,fNRows);
-  //
-}
-
-//__________________________________________________________________________________________
-Float_t  AliCheb3DCalc::EvalDeriv(int dim, Float_t  *par) const
+Float_t  AliCheb3DCalc::EvalDeriv(int dim, const Float_t  *par) const
 {
   // evaluate Chebyshev parameterization derivative in given dimension  for 3D function.
   // VERY IMPORTANT: par must contain the function arguments ALREADY MAPPED to [-1:1] interval
-  Float_t  &z = par[2];
-  Float_t  &y = par[1];
-  Float_t  &x = par[0];
   //
   int ncfRC;
   for (int id0=fNRows;id0--;) {
     int nCLoc = fNColsAtRow[id0];                   // number of significant coefs on this row
     if (!nCLoc) {fTmpCf0[id0]=0; continue;}
     // 
-    int Col0  = fColAtRowBg[id0];                   // beginning of local column in the 2D boundary matrix
+    int col0  = fColAtRowBg[id0];                   // beginning of local column in the 2D boundary matrix
     for (int id1=nCLoc;id1--;) {
-      int id = id1+Col0;
+      int id = id1+col0;
       if (!(ncfRC=fCoefBound2D0[id])) { fTmpCf1[id1]=0; continue;}
-      if (dim==2) fTmpCf1[id1] = ChebEval1Deriv(z,fCoefs + fCoefBound2D1[id], ncfRC);
-      else        fTmpCf1[id1] = ChebEval1D(z,fCoefs + fCoefBound2D1[id], ncfRC);
+      if (dim==2) fTmpCf1[id1] = ChebEval1Deriv(par[2],fCoefs + fCoefBound2D1[id], ncfRC);
+      else        fTmpCf1[id1] = ChebEval1D(par[2],fCoefs + fCoefBound2D1[id], ncfRC);
     }
-    if (dim==1)   fTmpCf0[id0] = ChebEval1Deriv(y,fTmpCf1,nCLoc);
-    else          fTmpCf0[id0] = ChebEval1D(y,fTmpCf1,nCLoc);
+    if (dim==1)   fTmpCf0[id0] = ChebEval1Deriv(par[1],fTmpCf1,nCLoc);
+    else          fTmpCf0[id0] = ChebEval1D(par[1],fTmpCf1,nCLoc);
   }
-  return (dim==0) ? ChebEval1Deriv(x,fTmpCf0,fNRows) : ChebEval1D(x,fTmpCf0,fNRows);
+  return (dim==0) ? ChebEval1Deriv(par[0],fTmpCf0,fNRows) : ChebEval1D(par[0],fTmpCf0,fNRows);
   //
 }
 
 //__________________________________________________________________________________________
-Float_t  AliCheb3DCalc::EvalDeriv2(int dim1,int dim2, Float_t  *par) const
+Float_t  AliCheb3DCalc::EvalDeriv2(int dim1,int dim2, const Float_t  *par) const
 {
   // evaluate Chebyshev parameterization 2n derivative in given dimensions  for 3D function.
   // VERY IMPORTANT: par must contain the function arguments ALREADY MAPPED to [-1:1] interval
-  Float_t  &z = par[2];
-  Float_t  &y = par[1];
-  Float_t  &x = par[0];
   //
   Bool_t same = dim1==dim2;
   int ncfRC;
@@ -218,18 +194,19 @@ Float_t  AliCheb3DCalc::EvalDeriv2(int dim1,int dim2, Float_t  *par) const
     int nCLoc = fNColsAtRow[id0];                   // number of significant coefs on this row
     if (!nCLoc) {fTmpCf0[id0]=0; continue;}
     //
-    int Col0  = fColAtRowBg[id0];                   // beginning of local column in the 2D boundary matrix
+    int col0  = fColAtRowBg[id0];                   // beginning of local column in the 2D boundary matrix
     for (int id1=nCLoc;id1--;) {
-      int id = id1+Col0;
+      int id = id1+col0;
       if (!(ncfRC=fCoefBound2D0[id])) { fTmpCf1[id1]=0; continue;}
-      if (dim1==2||dim2==2) fTmpCf1[id1] = same ? ChebEval1Deriv2(z,fCoefs + fCoefBound2D1[id], ncfRC) 
-                             :                   ChebEval1Deriv(z,fCoefs + fCoefBound2D1[id], ncfRC);
-      else        fTmpCf1[id1] = ChebEval1D(z,fCoefs + fCoefBound2D1[id], ncfRC);
+      if (dim1==2||dim2==2) fTmpCf1[id1] = same ? ChebEval1Deriv2(par[2],fCoefs + fCoefBound2D1[id], ncfRC) 
+                             :                   ChebEval1Deriv(par[2],fCoefs + fCoefBound2D1[id], ncfRC);
+      else        fTmpCf1[id1] = ChebEval1D(par[2],fCoefs + fCoefBound2D1[id], ncfRC);
     }
-    if (dim1==1||dim2==1) fTmpCf0[id0] = same ? ChebEval1Deriv2(y,fTmpCf1,nCLoc):ChebEval1Deriv(y,fTmpCf1,nCLoc);
-    else                  fTmpCf0[id0] = ChebEval1D(y,fTmpCf1,nCLoc);
+    if (dim1==1||dim2==1) fTmpCf0[id0] = same ? ChebEval1Deriv2(par[1],fTmpCf1,nCLoc):ChebEval1Deriv(par[1],fTmpCf1,nCLoc);
+    else                  fTmpCf0[id0] = ChebEval1D(par[1],fTmpCf1,nCLoc);
   }
-  return (dim1==0||dim2==0) ? (same ? ChebEval1Deriv2(x,fTmpCf0,fNRows):ChebEval1Deriv(x,fTmpCf0,fNRows)) : ChebEval1D(x,fTmpCf0,fNRows);
+  return (dim1==0||dim2==0) ? (same ? ChebEval1Deriv2(par[0],fTmpCf0,fNRows):ChebEval1Deriv(par[0],fTmpCf0,fNRows)) : 
+    ChebEval1D(par[0],fTmpCf0,fNRows);
   //
 }
 
@@ -352,9 +329,9 @@ void AliCheb3DCalc::InitRows(int nr)
   if (fColAtRowBg) delete[] fColAtRowBg;
   if (fTmpCf0)     delete[] fTmpCf0;
   fNRows = nr;
-  fNColsAtRow = new Int_t[fNRows];
+  fNColsAtRow = new UShort_t[fNRows];
   fTmpCf0     = new Float_t [fNRows];
-  fColAtRowBg = new Int_t[fNRows];
+  fColAtRowBg = new UShort_t[fNRows];
   for (int i=fNRows;i--;) fNColsAtRow[i] = fColAtRowBg[i] = 0;
 }
 
@@ -365,8 +342,8 @@ void AliCheb3DCalc::InitElemBound2D(int ne)
   if (fCoefBound2D0) delete[] fCoefBound2D0; 
   if (fCoefBound2D1) delete[] fCoefBound2D1; 
   fNElemBound2D = ne;
-  fCoefBound2D0 = new Int_t[fNElemBound2D];
-  fCoefBound2D1 = new Int_t[fNElemBound2D];
+  fCoefBound2D0 = new UShort_t[fNElemBound2D];
+  fCoefBound2D1 = new UShort_t[fNElemBound2D];
   for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = fCoefBound2D1[i] = 0;
 }
 
@@ -441,3 +418,10 @@ Float_t AliCheb3DCalc::ChebEval1Deriv2(Float_t  x, const Float_t * array, int nc
   return b0 - x*b1 - ddcf0/2;
 }
 
+//__________________________________________________________________________________________
+Int_t AliCheb3DCalc::GetMaxColsAtRow() const
+{
+  int nmax3d = 0; 
+  for (int i=fNElemBound2D;i--;) if (fCoefBound2D0[i]>nmax3d) nmax3d = fCoefBound2D0[i];
+  return nmax3d;
+}