-ClassImp(AliCheb3DCalc)
-
-
-AliCheb3DCalc::AliCheb3DCalc():
- TNamed("", ""),
- fNCoefs(0),
- fNRows(0),
- fNCols(0),
- fNElemBound2D(0),
- fNColsAtRow(0),
- fColAtRowBg(0),
- fCoefBound2D0(0),
- fCoefBound2D1(0),
- fCoefs(0),
- fTmpCf1(0),
- fTmpCf0(0)
-{
- // Default constructor
- Init0();
-}
-
-AliCheb3DCalc::AliCheb3DCalc(FILE* stream):
- TNamed("", ""),
- fNCoefs(0),
- fNRows(0),
- fNCols(0),
- fNElemBound2D(0),
- fNColsAtRow(0),
- fColAtRowBg(0),
- fCoefBound2D0(0),
- fCoefBound2D1(0),
- fCoefs(0),
- fTmpCf1(0),
- fTmpCf0(0)
-{
- // Default constructor
- Init0();
- LoadData(stream);
-}
-
-
-AliCheb3DCalc::AliCheb3DCalc(const AliCheb3DCalc& src) :
- TNamed(src),
- fNCoefs(src.fNCoefs),
- fNRows(src.fNRows),
- fNCols(src.fNCols),
- fNElemBound2D(src.fNElemBound2D),
- fNColsAtRow(0),
- fColAtRowBg(0),
- fCoefBound2D0(0),
- fCoefBound2D1(0),
- fCoefs(0),
- fTmpCf1(0),
- fTmpCf0(0)
-{
- // Copy constructor
- if (src.fNColsAtRow) {
- fNColsAtRow = new Int_t[fNRows];
- for (int i=fNRows;i--;) fNColsAtRow[i] = src.fNColsAtRow[i];
- }
- if (src.fColAtRowBg) {
- fColAtRowBg = new Int_t[fNRows];
- for (int i=fNRows;i--;) fColAtRowBg[i] = src.fColAtRowBg[i];
- }
- if (src.fCoefBound2D0) {
- fCoefBound2D0 = new Int_t[fNElemBound2D];
- for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = src.fCoefBound2D0[i];
- }
- if (src.fCoefBound2D1) {
- fCoefBound2D1 = new Int_t[fNElemBound2D];
- for (int i=fNElemBound2D;i--;) fCoefBound2D1[i] = src.fCoefBound2D1[i];
- }
- if (src.fCoefs) {
- fCoefs = new Float_t[fNCoefs];
- for (int i=fNCoefs;i--;) fCoefs[i] = src.fCoefs[i];
- }
- if (src.fTmpCf1) fTmpCf1 = new Float_t[fNCols];
- if (src.fTmpCf0) fTmpCf0 = new Float_t[fNRows];
-}
-
-AliCheb3DCalc& AliCheb3DCalc::operator=(const AliCheb3DCalc& rhs)
-{
- // Assignment operator
- if (this != &rhs) {
- Clear();
- SetName(rhs.GetName());
- SetTitle(rhs.GetTitle());
- fNCoefs = rhs.fNCoefs;
- fNRows = rhs.fNRows;
- fNCols = rhs.fNCols;
- if (rhs.fNColsAtRow) {
- fNColsAtRow = new Int_t[fNRows];
- for (int i=fNRows;i--;) fNColsAtRow[i] = rhs.fNColsAtRow[i];
- }
- if (rhs.fColAtRowBg) {
- fColAtRowBg = new Int_t[fNRows];
- for (int i=fNRows;i--;) fColAtRowBg[i] = rhs.fColAtRowBg[i];
- }
- if (rhs.fCoefBound2D0) {
- fCoefBound2D0 = new Int_t[fNElemBound2D];
- for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = rhs.fCoefBound2D0[i];
- }
- if (rhs.fCoefBound2D1) {
- fCoefBound2D1 = new Int_t[fNElemBound2D];
- for (int i=fNElemBound2D;i--;) fCoefBound2D1[i] = rhs.fCoefBound2D1[i];
- }
- if (rhs.fCoefs) {
- fCoefs = new Float_t[fNCoefs];
- for (int i=fNCoefs;i--;) fCoefs[i] = rhs.fCoefs[i];
- }
- if (rhs.fTmpCf1) fTmpCf1 = new Float_t[fNCols];
- if (rhs.fTmpCf0) fTmpCf0 = new Float_t[fNRows];
- }
- return *this;
-}
-
-//__________________________________________________________________________________________
-void AliCheb3DCalc::Clear(Option_t*)
-{
- // delete all dynamycally allocated structures
- if (fTmpCf1) { delete[] fTmpCf1; fTmpCf1 = 0;}
- if (fTmpCf0) { delete[] fTmpCf0; fTmpCf0 = 0;}
- if (fCoefs) { delete[] fCoefs; fCoefs = 0;}
- if (fCoefBound2D0) { delete[] fCoefBound2D0; fCoefBound2D0 = 0; }
- if (fCoefBound2D1) { delete[] fCoefBound2D1; fCoefBound2D1 = 0; }
- if (fNColsAtRow) { delete[] fNColsAtRow; fNColsAtRow = 0; }
- if (fColAtRowBg) { delete[] fColAtRowBg; fColAtRowBg = 0; }
- //
-}
-
-//__________________________________________________________________________________________
-void AliCheb3DCalc::Init0()
-{
- // reset everything to 0
- fNCoefs = fNRows = fNCols = fNElemBound2D = 0;
- fCoefs = 0;
- fCoefBound2D0 = fCoefBound2D1 = 0;
- fNColsAtRow = fColAtRowBg = 0;
- fTmpCf0 = fTmpCf1 = 0;
-}
-
-//__________________________________________________________________________________________
-void AliCheb3DCalc::Print(Option_t* ) const
-{
- 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];
- printf("%d coefficients in %dx%dx%d matrix\n",fNCoefs,fNRows,fNCols,nmax3d);
- //
-}
-
-//__________________________________________________________________________________________
-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);
- //
-}
-
-//_______________________________________________
-#ifdef _INC_CREATION_ALICHEB3D_
-void AliCheb3DCalc::SaveData(const char* outfile,Bool_t append) const
-{
- // writes coefficients data to output text file, optionallt appending on the end of existing file
- TString strf = outfile;
- gSystem->ExpandPathName(strf);
- FILE* stream = fopen(strf,append ? "a":"w");
- SaveData(stream);
- fclose(stream);
- //
-}
-#endif
-
-//_______________________________________________
-#ifdef _INC_CREATION_ALICHEB3D_
-void AliCheb3DCalc::SaveData(FILE* stream) const
-{
- // writes coefficients data to existing output stream
- // Note: fNCols, fNElemBound2D and fColAtRowBg is not stored, will be computed on fly during the loading of this file
- fprintf(stream,"#\nSTART %s\n",GetName());
- fprintf(stream,"# Number of rows\n%d\n",fNRows);
- //
- fprintf(stream,"# Number of columns per row\n");
- for (int i=0;i<fNRows;i++) fprintf(stream,"%d\n",fNColsAtRow[i]);
- //
- fprintf(stream,"# Number of Coefs in each significant block of third dimension\n");
- for (int i=0;i<fNElemBound2D;i++) fprintf(stream,"%d\n",fCoefBound2D0[i]);
- //
- fprintf(stream,"# Coefficients\n");
- for (int i=0;i<fNCoefs;i++) fprintf(stream,"%+.8e\n",fCoefs[i]);
- fprintf(stream,"END %s\n",GetName());
- //
-}
-#endif
-
-//_______________________________________________
-void AliCheb3DCalc::LoadData(FILE* stream)
-{
- // Load coefs. from the stream
- if (!stream) {Error("LoadData","No stream provided.\nStop"); exit(1);}
- TString buffs;
- Clear();
- ReadLine(buffs,stream);
- if (!buffs.BeginsWith("START")) {Error("LoadData","Expected: \"START <fit_name>\", found \"%s\"\nStop\n",buffs.Data());exit(1);}
- if (buffs.First(' ')>0) SetName(buffs.Data()+buffs.First(' ')+1);
- //
- ReadLine(buffs,stream); // NRows
- fNRows = buffs.Atoi();
- if (fNRows<1) {Error("LoadData","Expected: '<number_of_rows>', found \"%s\"\nStop\n",buffs.Data());exit(1);}
- //
- fNCols = 0;
- fNElemBound2D = 0;
- InitRows(fNRows);
- //
- for (int id0=0;id0<fNRows;id0++) {
- ReadLine(buffs,stream); // n.cols at this row
- fNColsAtRow[id0] = buffs.Atoi();
- fColAtRowBg[id0] = fNElemBound2D; // begining of this row in 2D boundary surface
- fNElemBound2D += fNColsAtRow[id0];
- if (fNCols<fNColsAtRow[id0]) fNCols = fNColsAtRow[id0];
- }
- InitCols(fNCols);
- //
- fNCoefs = 0;
- InitElemBound2D(fNElemBound2D);
- //
- for (int i=0;i<fNElemBound2D;i++) {
- ReadLine(buffs,stream); // n.coeffs at 3-d dimension for the given column/row
- fCoefBound2D0[i] = buffs.Atoi();
- fCoefBound2D1[i] = fNCoefs;
- fNCoefs += fCoefBound2D0[i];
- }
- //
- if (fNCoefs<=0) {Error("LoadData","Negtive (%d) number of Chebychef coeffs. is obtained.\nStop\n",fNCoefs);exit(1);}
- //
- InitCoefs(fNCoefs);
- for (int i=0;i<fNCoefs;i++) {
- ReadLine(buffs,stream);
- fCoefs[i] = buffs.Atof();
- }
- // check end_of_data record
- ReadLine(buffs,stream);
- if (!buffs.BeginsWith("END") || !buffs.Contains(GetName())) {
- Error("LoadData","Expected \"END %s\", found \"%s\".\nStop\n",GetName(),buffs.Data());
- exit(1);
- }
- //
-}
-
-//_______________________________________________
-void AliCheb3DCalc::ReadLine(TString& str,FILE* stream)
-{
- // read single line from the stream, skipping empty and commented lines. EOF is not expected
- while (str.Gets(stream)) {
- str = str.Strip(TString::kBoth,' ');
- if (str.IsNull()||str.BeginsWith("#")) continue;
- return;
- }
- fprintf(stderr,"AliCheb3D::ReadLine: Failed to read from stream.\nStop");exit(1); // normally, should not reach here
-}
-
-//_______________________________________________
-void AliCheb3DCalc::InitCols(int nc)
-{
- // Set max.number of significant columns in the coefs matrix
- fNCols = nc;
- if (fTmpCf1) delete[] fTmpCf1;
- fTmpCf1 = new Float_t [fNCols];
-}
-
-//_______________________________________________
-void AliCheb3DCalc::InitRows(int nr)
-{
- // Set max.number of significant rows in the coefs matrix
- if (fNColsAtRow) delete[] fNColsAtRow;
- if (fColAtRowBg) delete[] fColAtRowBg;
- if (fTmpCf0) delete[] fTmpCf0;
- fNRows = nr;
- fNColsAtRow = new Int_t[fNRows];
- fTmpCf0 = new Float_t [fNRows];
- fColAtRowBg = new Int_t[fNRows];
- for (int i=fNRows;i--;) fNColsAtRow[i] = fColAtRowBg[i] = 0;
-}
-
-//_______________________________________________
-void AliCheb3DCalc::InitElemBound2D(int ne)
-{
- // Set max number of significant coefs for given row/column of coefs 3D matrix
- if (fCoefBound2D0) delete[] fCoefBound2D0;
- if (fCoefBound2D1) delete[] fCoefBound2D1;
- fNElemBound2D = ne;
- fCoefBound2D0 = new Int_t[fNElemBound2D];
- fCoefBound2D1 = new Int_t[fNElemBound2D];
- for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = fCoefBound2D1[i] = 0;
-}
-
-//_______________________________________________
-void AliCheb3DCalc::InitCoefs(int nc)
-{
- // Set total number of significant coefs
- if (fCoefs) delete[] fCoefs;
- fNCoefs = nc;
- fCoefs = new Float_t [fNCoefs];
- for (int i=fNCoefs;i--;) fCoefs[i] = 0.0;
-}
-
-
-
-
ClassImp(AliCheb3D)
AliCheb3D::AliCheb3D():
//__________________________________________________________________________________________
void AliCheb3D::Clear(Option_t*)
{
+// Clean-up
if (fResTmp) { delete[] fResTmp; fResTmp = 0; }
if (fGrid) { delete[] fGrid; fGrid = 0; }
if (fUsrMacro) { delete fUsrMacro; fUsrMacro = 0;}
//__________________________________________________________________________________________
void AliCheb3D::Print(Option_t* opt) const
{
+ // Print Chebyshev parameterisation data
printf("%s: Chebyshev parameterization for 3D->%dD function. Precision: %e\n",GetName(),fDimOut,fPrec);
printf("Region of validity: [%+.5e:%+.5e] [%+.5e:%+.5e] [%+.5e:%+.5e]\n",fBMin[0],fBMax[0],fBMin[1],fBMax[1],fBMin[2],fBMax[2]);
TString opts = opt; opts.ToLower();
//__________________________________________________________________________________________
void AliCheb3D::Init0()
{
+ // Initialisation
for (int i=3;i--;) fBMin[i] = fBMax[i] = fBScale[i] = fBOffset[i] = 0;
fMaxCoefs = 0;
fGrid = 0;
fMaxCoefs = 0; // redefine number of coeffs
for (int id0=0;id0<NRows;id0++) {
int nCLoc = NColsAtRow[id0];
- int Col0 = ColAtRowBg[id0];
+ int col0 = ColAtRowBg[id0];
for (int id1=0;id1<nCLoc;id1++) {
- CoefBound2D0[Col0 + id1] = tmpCoefSurf[id1+id0*fNPoints[1]]; // number of coefs to store for 3-d dimension
- CoefBound2D1[Col0 + id1] = fMaxCoefs;
- fMaxCoefs += CoefBound2D0[Col0 + id1];
+ CoefBound2D0[col0 + id1] = tmpCoefSurf[id1+id0*fNPoints[1]]; // number of coefs to store for 3-d dimension
+ CoefBound2D1[col0 + id1] = fMaxCoefs;
+ fMaxCoefs += CoefBound2D0[col0 + id1];
}
}
//
int count = 0;
for (int id0=0;id0<NRows;id0++) {
int ncLoc = NColsAtRow[id0];
- int Col0 = ColAtRowBg[id0];
+ int col0 = ColAtRowBg[id0];
for (int id1=0;id1<ncLoc;id1++) {
- int ncf2 = CoefBound2D0[Col0 + id1];
+ int ncf2 = CoefBound2D0[col0 + id1];
for (int id2=0;id2<ncf2;id2++) {
Coefs[count++] = tmpCoef3D[id2 + fNPoints[2]*(id1+id0*fNPoints[1])];
}
//_______________________________________________
void AliCheb3D::LoadData(const char* inpFile)
{
+ // Load data from input file
TString strf = inpFile;
gSystem->ExpandPathName(strf);
FILE* stream = fopen(strf.Data(),"r");
//_______________________________________________
void AliCheb3D::LoadData(FILE* stream)
{
+ // Load data from input stream stream
if (!stream) {Error("LoadData","No stream provided.\nStop"); exit(1);}
TString buffs;
Clear();
//_______________________________________________
void AliCheb3D::SetDimOut(int d)
{
+ // Set the dimension of the output array
fDimOut = d;
if (fResTmp) delete fResTmp;
fResTmp = new Float_t[fDimOut]; // RRR
//_______________________________________________
void AliCheb3D::ShiftBound(int id,float dif)
{
+ //Shift the boundary of dimension id
if (id<0||id>2) {printf("Maximum 3 dimensions are supported\n"); return;}
fBMin[id] += dif;
fBMax[id] += dif;
#include <TH1.h>
#include <TObjArray.h>
+#include "AliCheb3DCalc.h"
+
class TString;
class TSystem;
class TRandom;
-
-
// to decrease the compilable code size comment this define. This will exclude the routines
// used for the calculation and saving of the coefficients.
// #define _INC_CREATION_ALICHEB3D_
-
-class AliCheb3DCalc: public TNamed
-{
- public:
- AliCheb3DCalc();
- AliCheb3DCalc(FILE* stream); // read coefs from text file
- AliCheb3DCalc(const AliCheb3DCalc &src);
- AliCheb3DCalc& operator= (const AliCheb3DCalc &rhs);
- ~AliCheb3DCalc() {Clear();}
- //
- void Print(Option_t* opt="") const;
- void LoadData(FILE* stream);
- Float_t Eval(Float_t *par) const;
- //
-#ifdef _INC_CREATION_ALICHEB3D_
- void SaveData(const char* outfile,Bool_t append=kFALSE) const;
- void SaveData(FILE* stream=stdout) const;
-#endif
- //
- static void ReadLine(TString& str,FILE* stream);
- //
- protected:
- //
- void Clear(Option_t* option = "");
- void Init0();
- Float_t ChebEval1D(Float_t x, const Float_t * array, int ncf) const;
- void InitRows(int nr);
- void InitCols(int nc);
- void InitElemBound2D(int ne);
- void InitCoefs(int nc);
- Int_t* GetNColsAtRow() const {return fNColsAtRow;}
- Int_t* GetColAtRowBg() const {return fColAtRowBg;}
- Int_t* GetCoefBound2D0() const {return fCoefBound2D0;}
- Int_t* GetCoefBound2D1() const {return fCoefBound2D1;}
- Float_t * GetCoefs() const {return fCoefs;}
- //
- protected:
- Int_t fNCoefs; // total number of coeeficients
- Int_t fNRows; // number of significant rows in the 3D coeffs matrix
- Int_t fNCols; // max number of significant cols in the 3D coeffs matrix
- Int_t fNElemBound2D; // number of elements (fNRows*fNCols) to store for the 2D boundary of significant coeffs
- Int_t* fNColsAtRow; //[fNRows] number of sighificant columns (2nd dim) at each row of 3D coefs matrix
- Int_t* fColAtRowBg; //[fNRows] beginnig of significant columns (2nd dim) for row in the 2D boundary matrix
- Int_t* fCoefBound2D0; //[fNElemBound2D] 2D matrix defining the boundary of significance for 3D coeffs.matrix (Ncoefs for col/row)
- Int_t* fCoefBound2D1; //[fNElemBound2D] 2D matrix defining the start beginnig of significant coeffs for col/row
- Float_t * fCoefs; //[fNCoefs] array of Chebyshev coefficients
- //
- Float_t * fTmpCf1; //[fNCols] temp. coeffs for 2d summation
- Float_t * fTmpCf0; //[fNRows] temp. coeffs for 1d summation
- //
- ClassDef(AliCheb3DCalc,1) // Class for interpolation of 3D->1 function by Chebyshev parametrization
-};
-
-
class AliCheb3D: public TNamed
{
public:
AliCheb3D();
- AliCheb3D(const char* inpFile); // read coefs from text file
- AliCheb3D(FILE*); // read coefs from stream
+ AliCheb3D(const char* inpFile); // read coefs from text file
+ AliCheb3D(FILE* file); // read coefs from stream
AliCheb3D(const AliCheb3D &src);
AliCheb3D& operator= (const AliCheb3D &rhs);
return kTRUE;
}
-//__________________________________________________________________________________________
-inline Float_t AliCheb3DCalc::ChebEval1D(Float_t x, const Float_t * array, int ncf ) const
-{
- // evaluate 1D Chebyshev parameterization. x is the argument mapped to [-1:1] interval
- Float_t b0, b1, b2;
- Float_t x2 = x+x;
- b0 = array[--ncf];
- b1 = b2 = 0;
- for (int i=ncf;i--;) {
- b2 = b1;
- b1 = b0;
- b0 = array[i] + x2*b1 -b2;
- }
- return b0 - x*b1;
-}
-
//__________________________________________________________________________________________
inline void AliCheb3D::Eval(Float_t *par, Float_t *res)
{
--- /dev/null
+/**************************************************************************
+ * Copyright(c) 1998-1999, 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$ */
+
+// Author: ruben.shahoyan@cern.ch 09/09/2006
+//
+////////////////////////////////////////////////////////////////////////////////
+// //
+// AliCheb3D produces the interpolation of the user 3D->NDimOut arbitrary //
+// function supplied in "void (*fcn)(float* inp,float* out)" format //
+// either in a separate macro file or as a function pointer. //
+// Only coefficients needed to guarantee the requested precision are kept. //
+// //
+// The user-callable methods are: //
+// To create the interpolation use: //
+// AliCheb3D(const char* funName, // name of the file with user function //
+// or //
+// AliCheb3D(void (*ptr)(float*,float*),// pointer on the user function //
+// Int_t DimOut, // dimensionality of the function's output //
+// Float_t *bmin, // lower 3D bounds of interpolation domain //
+// Float_t *bmax, // upper 3D bounds of interpolation domain //
+// Int_t *npoints, // number of points in each of 3 input //
+// // dimension, defining the interpolation grid //
+// Float_t prec=1E-6); // requested max.absolute difference between //
+// // the interpolation and any point on grid //
+// //
+// To test obtained parameterization use the method //
+// TH1* TestRMS(int idim,int npoints = 1000,TH1* histo=0); //
+// it will compare the user output of the user function and interpolation //
+// for idim-th output dimension and fill the difference in the supplied //
+// histogram. If no histogram is supplied, it will be created. //
+// //
+// To save the interpolation data: //
+// SaveData(const char* filename, Bool_t append ) //
+// write text file with data. If append is kTRUE and the output file already //
+// exists, data will be added in the end of the file. //
+// Alternatively, SaveData(FILE* stream) will write the data to //
+// already existing stream. //
+// //
+// To read back already stored interpolation use either the constructor //
+// AliCheb3D(const char* inpFile); //
+// or the default constructor AliCheb3D() followed by //
+// AliCheb3D::LoadData(const char* inpFile); //
+// //
+// To compute the interpolation use Eval(float* par,float *res) method, with //
+// par being 3D vector of arguments (inside the validity region) and res is //
+// the array of DimOut elements for the output. //
+// //
+// If only one component (say, idim-th) of the output is needed, use faster //
+// Float_t Eval(Float_t *par,int idim) method. //
+// //
+// void Print(option="") will print the name, the ranges of validity and //
+// the absolute precision of the parameterization. Option "l" will also print //
+// the information about the number of coefficients for each output //
+// dimension. //
+// //
+// NOTE: during the evaluation no check is done for parameter vector being //
+// outside the interpolation region. If there is such a risk, use //
+// Bool_t IsInside(float *par) method. Chebyshev parameterization is not //
+// good for extrapolation! //
+// //
+// For the properties of Chebyshev parameterization see: //
+// H.Wind, CERN EP Internal Report, 81-12/Rev. //
+// //
+////////////////////////////////////////////////////////////////////////////////
+
+#include "AliCheb3DCalc.h"
+
+ClassImp(AliCheb3DCalc)
+
+
+AliCheb3DCalc::AliCheb3DCalc():
+ TNamed("", ""),
+ fNCoefs(0),
+ fNRows(0),
+ fNCols(0),
+ fNElemBound2D(0),
+ fNColsAtRow(0),
+ fColAtRowBg(0),
+ fCoefBound2D0(0),
+ fCoefBound2D1(0),
+ fCoefs(0),
+ fTmpCf1(0),
+ fTmpCf0(0)
+{
+ // Default constructor
+ Init0();
+}
+
+AliCheb3DCalc::AliCheb3DCalc(FILE* stream):
+ TNamed("", ""),
+ fNCoefs(0),
+ fNRows(0),
+ fNCols(0),
+ fNElemBound2D(0),
+ fNColsAtRow(0),
+ fColAtRowBg(0),
+ fCoefBound2D0(0),
+ fCoefBound2D1(0),
+ fCoefs(0),
+ fTmpCf1(0),
+ fTmpCf0(0)
+{
+ // Default constructor
+ Init0();
+ LoadData(stream);
+}
+
+
+AliCheb3DCalc::AliCheb3DCalc(const AliCheb3DCalc& src) :
+ TNamed(src),
+ fNCoefs(src.fNCoefs),
+ fNRows(src.fNRows),
+ fNCols(src.fNCols),
+ fNElemBound2D(src.fNElemBound2D),
+ fNColsAtRow(0),
+ fColAtRowBg(0),
+ fCoefBound2D0(0),
+ fCoefBound2D1(0),
+ fCoefs(0),
+ fTmpCf1(0),
+ fTmpCf0(0)
+{
+ // Copy constructor
+ if (src.fNColsAtRow) {
+ fNColsAtRow = new Int_t[fNRows];
+ for (int i=fNRows;i--;) fNColsAtRow[i] = src.fNColsAtRow[i];
+ }
+ if (src.fColAtRowBg) {
+ fColAtRowBg = new Int_t[fNRows];
+ for (int i=fNRows;i--;) fColAtRowBg[i] = src.fColAtRowBg[i];
+ }
+ if (src.fCoefBound2D0) {
+ fCoefBound2D0 = new Int_t[fNElemBound2D];
+ for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = src.fCoefBound2D0[i];
+ }
+ if (src.fCoefBound2D1) {
+ fCoefBound2D1 = new Int_t[fNElemBound2D];
+ for (int i=fNElemBound2D;i--;) fCoefBound2D1[i] = src.fCoefBound2D1[i];
+ }
+ if (src.fCoefs) {
+ fCoefs = new Float_t[fNCoefs];
+ for (int i=fNCoefs;i--;) fCoefs[i] = src.fCoefs[i];
+ }
+ if (src.fTmpCf1) fTmpCf1 = new Float_t[fNCols];
+ if (src.fTmpCf0) fTmpCf0 = new Float_t[fNRows];
+}
+
+AliCheb3DCalc& AliCheb3DCalc::operator=(const AliCheb3DCalc& rhs)
+{
+ // Assignment operator
+ if (this != &rhs) {
+ Clear();
+ SetName(rhs.GetName());
+ SetTitle(rhs.GetTitle());
+ fNCoefs = rhs.fNCoefs;
+ fNRows = rhs.fNRows;
+ fNCols = rhs.fNCols;
+ if (rhs.fNColsAtRow) {
+ fNColsAtRow = new Int_t[fNRows];
+ for (int i=fNRows;i--;) fNColsAtRow[i] = rhs.fNColsAtRow[i];
+ }
+ if (rhs.fColAtRowBg) {
+ fColAtRowBg = new Int_t[fNRows];
+ for (int i=fNRows;i--;) fColAtRowBg[i] = rhs.fColAtRowBg[i];
+ }
+ if (rhs.fCoefBound2D0) {
+ fCoefBound2D0 = new Int_t[fNElemBound2D];
+ for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = rhs.fCoefBound2D0[i];
+ }
+ if (rhs.fCoefBound2D1) {
+ fCoefBound2D1 = new Int_t[fNElemBound2D];
+ for (int i=fNElemBound2D;i--;) fCoefBound2D1[i] = rhs.fCoefBound2D1[i];
+ }
+ if (rhs.fCoefs) {
+ fCoefs = new Float_t[fNCoefs];
+ for (int i=fNCoefs;i--;) fCoefs[i] = rhs.fCoefs[i];
+ }
+ if (rhs.fTmpCf1) fTmpCf1 = new Float_t[fNCols];
+ if (rhs.fTmpCf0) fTmpCf0 = new Float_t[fNRows];
+ }
+ return *this;
+}
+
+//__________________________________________________________________________________________
+void AliCheb3DCalc::Clear(Option_t*)
+{
+ // delete all dynamycally allocated structures
+ if (fTmpCf1) { delete[] fTmpCf1; fTmpCf1 = 0;}
+ if (fTmpCf0) { delete[] fTmpCf0; fTmpCf0 = 0;}
+ if (fCoefs) { delete[] fCoefs; fCoefs = 0;}
+ if (fCoefBound2D0) { delete[] fCoefBound2D0; fCoefBound2D0 = 0; }
+ if (fCoefBound2D1) { delete[] fCoefBound2D1; fCoefBound2D1 = 0; }
+ if (fNColsAtRow) { delete[] fNColsAtRow; fNColsAtRow = 0; }
+ if (fColAtRowBg) { delete[] fColAtRowBg; fColAtRowBg = 0; }
+ //
+}
+
+//__________________________________________________________________________________________
+void AliCheb3DCalc::Init0()
+{
+ // reset everything to 0
+ fNCoefs = fNRows = fNCols = fNElemBound2D = 0;
+ fCoefs = 0;
+ fCoefBound2D0 = fCoefBound2D1 = 0;
+ fNColsAtRow = fColAtRowBg = 0;
+ fTmpCf0 = fTmpCf1 = 0;
+}
+
+//__________________________________________________________________________________________
+void AliCheb3DCalc::Print(Option_t* ) const
+{
+ // Print the Chebychev paramterization data
+ 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];
+ printf("%d coefficients in %dx%dx%d matrix\n",fNCoefs,fNRows,fNCols,nmax3d);
+ //
+}
+
+//__________________________________________________________________________________________
+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);
+ //
+}
+
+//_______________________________________________
+#ifdef _INC_CREATION_ALICHEB3D_
+void AliCheb3DCalc::SaveData(const char* outfile,Bool_t append) const
+{
+ // writes coefficients data to output text file, optionallt appending on the end of existing file
+ TString strf = outfile;
+ gSystem->ExpandPathName(strf);
+ FILE* stream = fopen(strf,append ? "a":"w");
+ SaveData(stream);
+ fclose(stream);
+ //
+}
+#endif
+
+//_______________________________________________
+#ifdef _INC_CREATION_ALICHEB3D_
+void AliCheb3DCalc::SaveData(FILE* stream) const
+{
+ // writes coefficients data to existing output stream
+ // Note: fNCols, fNElemBound2D and fColAtRowBg is not stored, will be computed on fly during the loading of this file
+ fprintf(stream,"#\nSTART %s\n",GetName());
+ fprintf(stream,"# Number of rows\n%d\n",fNRows);
+ //
+ fprintf(stream,"# Number of columns per row\n");
+ for (int i=0;i<fNRows;i++) fprintf(stream,"%d\n",fNColsAtRow[i]);
+ //
+ fprintf(stream,"# Number of Coefs in each significant block of third dimension\n");
+ for (int i=0;i<fNElemBound2D;i++) fprintf(stream,"%d\n",fCoefBound2D0[i]);
+ //
+ fprintf(stream,"# Coefficients\n");
+ for (int i=0;i<fNCoefs;i++) fprintf(stream,"%+.8e\n",fCoefs[i]);
+ fprintf(stream,"END %s\n",GetName());
+ //
+}
+#endif
+
+//_______________________________________________
+void AliCheb3DCalc::LoadData(FILE* stream)
+{
+ // Load coefs. from the stream
+ if (!stream) {Error("LoadData","No stream provided.\nStop"); exit(1);}
+ TString buffs;
+ Clear();
+ ReadLine(buffs,stream);
+ if (!buffs.BeginsWith("START")) {Error("LoadData","Expected: \"START <fit_name>\", found \"%s\"\nStop\n",buffs.Data());exit(1);}
+ if (buffs.First(' ')>0) SetName(buffs.Data()+buffs.First(' ')+1);
+ //
+ ReadLine(buffs,stream); // NRows
+ fNRows = buffs.Atoi();
+ if (fNRows<1) {Error("LoadData","Expected: '<number_of_rows>', found \"%s\"\nStop\n",buffs.Data());exit(1);}
+ //
+ fNCols = 0;
+ fNElemBound2D = 0;
+ InitRows(fNRows);
+ //
+ for (int id0=0;id0<fNRows;id0++) {
+ ReadLine(buffs,stream); // n.cols at this row
+ fNColsAtRow[id0] = buffs.Atoi();
+ fColAtRowBg[id0] = fNElemBound2D; // begining of this row in 2D boundary surface
+ fNElemBound2D += fNColsAtRow[id0];
+ if (fNCols<fNColsAtRow[id0]) fNCols = fNColsAtRow[id0];
+ }
+ InitCols(fNCols);
+ //
+ fNCoefs = 0;
+ InitElemBound2D(fNElemBound2D);
+ //
+ for (int i=0;i<fNElemBound2D;i++) {
+ ReadLine(buffs,stream); // n.coeffs at 3-d dimension for the given column/row
+ fCoefBound2D0[i] = buffs.Atoi();
+ fCoefBound2D1[i] = fNCoefs;
+ fNCoefs += fCoefBound2D0[i];
+ }
+ //
+ if (fNCoefs<=0) {Error("LoadData","Negtive (%d) number of Chebychef coeffs. is obtained.\nStop\n",fNCoefs);exit(1);}
+ //
+ InitCoefs(fNCoefs);
+ for (int i=0;i<fNCoefs;i++) {
+ ReadLine(buffs,stream);
+ fCoefs[i] = buffs.Atof();
+ }
+ // check end_of_data record
+ ReadLine(buffs,stream);
+ if (!buffs.BeginsWith("END") || !buffs.Contains(GetName())) {
+ Error("LoadData","Expected \"END %s\", found \"%s\".\nStop\n",GetName(),buffs.Data());
+ exit(1);
+ }
+ //
+}
+
+//_______________________________________________
+void AliCheb3DCalc::ReadLine(TString& str,FILE* stream)
+{
+ // read single line from the stream, skipping empty and commented lines. EOF is not expected
+ while (str.Gets(stream)) {
+ str = str.Strip(TString::kBoth,' ');
+ if (str.IsNull()||str.BeginsWith("#")) continue;
+ return;
+ }
+ fprintf(stderr,"AliCheb3D::ReadLine: Failed to read from stream.\nStop");exit(1); // normally, should not reach here
+}
+
+//_______________________________________________
+void AliCheb3DCalc::InitCols(int nc)
+{
+ // Set max.number of significant columns in the coefs matrix
+ fNCols = nc;
+ if (fTmpCf1) delete[] fTmpCf1;
+ fTmpCf1 = new Float_t [fNCols];
+}
+
+//_______________________________________________
+void AliCheb3DCalc::InitRows(int nr)
+{
+ // Set max.number of significant rows in the coefs matrix
+ if (fNColsAtRow) delete[] fNColsAtRow;
+ if (fColAtRowBg) delete[] fColAtRowBg;
+ if (fTmpCf0) delete[] fTmpCf0;
+ fNRows = nr;
+ fNColsAtRow = new Int_t[fNRows];
+ fTmpCf0 = new Float_t [fNRows];
+ fColAtRowBg = new Int_t[fNRows];
+ for (int i=fNRows;i--;) fNColsAtRow[i] = fColAtRowBg[i] = 0;
+}
+
+//_______________________________________________
+void AliCheb3DCalc::InitElemBound2D(int ne)
+{
+ // Set max number of significant coefs for given row/column of coefs 3D matrix
+ if (fCoefBound2D0) delete[] fCoefBound2D0;
+ if (fCoefBound2D1) delete[] fCoefBound2D1;
+ fNElemBound2D = ne;
+ fCoefBound2D0 = new Int_t[fNElemBound2D];
+ fCoefBound2D1 = new Int_t[fNElemBound2D];
+ for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = fCoefBound2D1[i] = 0;
+}
+
+//_______________________________________________
+void AliCheb3DCalc::InitCoefs(int nc)
+{
+ // Set total number of significant coefs
+ if (fCoefs) delete[] fCoefs;
+ fNCoefs = nc;
+ fCoefs = new Float_t [fNCoefs];
+ for (int i=fNCoefs;i--;) fCoefs[i] = 0.0;
+}
+
+
--- /dev/null
+#ifndef ALICHEB3DCALC_H
+#define ALICHEB3DCALC_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+
+/* $Id$ */
+
+//
+// Author: Ruben Shahoyan
+// ruben.shahoyan@cern.ch 09/09/2006
+// See Comments in AliCheb3D.h
+//
+#include <TNamed.h>
+
+class AliCheb3DCalc: public TNamed
+{
+ public:
+ AliCheb3DCalc();
+ AliCheb3DCalc(FILE* stream); // read coefs from text file
+ AliCheb3DCalc(const AliCheb3DCalc &src);
+ AliCheb3DCalc& operator= (const AliCheb3DCalc &rhs);
+ ~AliCheb3DCalc() {Clear();}
+ //
+ void Print(Option_t* opt="") const;
+ void LoadData(FILE* stream);
+ Float_t Eval(Float_t *par) const;
+ //
+#ifdef _INC_CREATION_ALICHEB3D_
+ void SaveData(const char* outfile,Bool_t append=kFALSE) const;
+ void SaveData(FILE* stream=stdout) const;
+#endif
+ //
+ static void ReadLine(TString& str,FILE* stream);
+ //
+ protected:
+ //
+ void Clear(Option_t* option = "");
+ void Init0();
+ Float_t ChebEval1D(Float_t x, const Float_t * array, int ncf) const;
+ void InitRows(int nr);
+ void InitCols(int nc);
+ void InitElemBound2D(int ne);
+ void InitCoefs(int nc);
+ Int_t* GetNColsAtRow() const {return fNColsAtRow;}
+ Int_t* GetColAtRowBg() const {return fColAtRowBg;}
+ Int_t* GetCoefBound2D0() const {return fCoefBound2D0;}
+ Int_t* GetCoefBound2D1() const {return fCoefBound2D1;}
+ Float_t * GetCoefs() const {return fCoefs;}
+ //
+ protected:
+ Int_t fNCoefs; // total number of coeeficients
+ Int_t fNRows; // number of significant rows in the 3D coeffs matrix
+ Int_t fNCols; // max number of significant cols in the 3D coeffs matrix
+ Int_t fNElemBound2D; // number of elements (fNRows*fNCols) to store for the 2D boundary of significant coeffs
+ Int_t* fNColsAtRow; //[fNRows] number of sighificant columns (2nd dim) at each row of 3D coefs matrix
+ Int_t* fColAtRowBg; //[fNRows] beginnig of significant columns (2nd dim) for row in the 2D boundary matrix
+ Int_t* fCoefBound2D0; //[fNElemBound2D] 2D matrix defining the boundary of significance for 3D coeffs.matrix (Ncoefs for col/row)
+ Int_t* fCoefBound2D1; //[fNElemBound2D] 2D matrix defining the start beginnig of significant coeffs for col/row
+ Float_t * fCoefs; //[fNCoefs] array of Chebyshev coefficients
+ //
+ Float_t * fTmpCf1; //[fNCols] temp. coeffs for 2d summation
+ Float_t * fTmpCf0; //[fNRows] temp. coeffs for 1d summation
+ //
+ ClassDef(AliCheb3DCalc,1) // Class for interpolation of 3D->1 function by Chebyshev parametrization
+};
+
+inline Float_t AliCheb3DCalc::ChebEval1D(Float_t x, const Float_t * array, int ncf ) const
+{
+ // evaluate 1D Chebyshev parameterization. x is the argument mapped to [-1:1] interval
+ Float_t b0, b1, b2;
+ Float_t x2 = x+x;
+ b0 = array[--ncf];
+ b1 = b2 = 0;
+ for (int i=ncf;i--;) {
+ b2 = b1;
+ b1 = b0;
+ b0 = array[i] + x2*b1 -b2;
+ }
+ return b0 - x*b1;
+}
+
+#endif
#include <TSystem.h>
#include <TNamed.h>
#include "AliCheb3D.h"
+#include "AliCheb3DCalc.h"
class AliMagFCheb: public TNamed
{
AliConfig.cxx \
AliRunDigitizer.cxx AliDigitizer.cxx AliStream.cxx \
AliMergeCombi.cxx AliMagFMaps.cxx AliFieldMap.cxx \
-AliMagFCheb.cxx AliCheb3D.cxx \
+AliMagFCheb.cxx AliCheb3D.cxx AliCheb3DCalc.cxx\
AliGausCorr.cxx \
AliTrackMap.cxx AliTrackMapper.cxx \
AliMemoryWatcher.cxx \