-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& cheb):
- TNamed("", ""),
- fNCoefs(0),
- fNRows(0),
- fNCols(0),
- fNElemBound2D(0),
- fNColsAtRow(0),
- fColAtRowBg(0),
- fCoefBound2D0(0),
- fCoefBound2D1(0),
- fCoefs(0),
- fTmpCf1(0),
- fTmpCf0(0)
-{
- // Copy constructor
- cheb.Copy(*this);
-}
-
-void AliCheb3DCalc::Copy(TObject &) const
-{
- //dummy Copy function
- AliFatal("Not implemented!");
-}
-
-//__________________________________________________________________________________________
-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():
LoadData(stream);
}
-AliCheb3D::AliCheb3D(const AliCheb3D& cheb):
- TNamed("", ""),
- fDimOut(0),
- fPrec(0.),
- fChebCalc(),
- fMaxCoefs(0),
- fResTmp(0),
- fGrid(0),
- fUsrFunName(),
- fUsrMacro(0)
+AliCheb3D::AliCheb3D(const AliCheb3D& src) :
+ TNamed(src),
+ fDimOut(src.fDimOut),
+ fPrec(src.fPrec),
+ fChebCalc(1),
+ fMaxCoefs(src.fMaxCoefs),
+ fResTmp(0),
+ fGrid(0),
+ fUsrFunName(src.fUsrFunName),
+ fUsrMacro(0)
{
// Copy constructor
- cheb.Copy(*this);
+ // read coefs from text file
+ for (int i=3;i--;) {
+ fBMin[i] = src.fBMin[i];
+ fBMax[i] = src.fBMax[i];
+ fBScale[i] = src.fBScale[i];
+ fBOffset[i] = src.fBOffset[i];
+ fNPoints[i] = src.fNPoints[i];
+ }
+ for (int i=0;i<fDimOut;i++) {
+ AliCheb3DCalc* cbc = src.GetChebCalc(i);
+ if (cbc) fChebCalc.AddAtAndExpand(new AliCheb3DCalc(*cbc),i);
+ }
}
+AliCheb3D& AliCheb3D::operator=(const AliCheb3D& rhs)
+{
+ // Assignment operator
+ if (this != &rhs) {
+ Clear();
+ fDimOut = rhs.fDimOut;
+ fPrec = rhs.fPrec;
+ fMaxCoefs = rhs.fMaxCoefs;
+ fUsrFunName = rhs.fUsrFunName;
+ fUsrMacro = 0;
+ for (int i=3;i--;) {
+ fBMin[i] = rhs.fBMin[i];
+ fBMax[i] = rhs.fBMax[i];
+ fBScale[i] = rhs.fBScale[i];
+ fBOffset[i] = rhs.fBOffset[i];
+ fNPoints[i] = rhs.fNPoints[i];
+ }
+ for (int i=0;i<fDimOut;i++) {
+ AliCheb3DCalc* cbc = rhs.GetChebCalc(i);
+ if (cbc) fChebCalc.AddAtAndExpand(new AliCheb3DCalc(*cbc),i);
+ }
+ }
+ return *this;
+ //
+}
+
+
//__________________________________________________________________________________________
#ifdef _INC_CREATION_ALICHEB3D_
AliCheb3D::AliCheb3D(const char* funName, int DimOut, Float_t *bmin,Float_t *bmax, Int_t *npoints, Float_t prec) : TNamed(funName,funName)
#endif
-void AliCheb3D::Copy(TObject &) const
-{
- //dummy Copy function
- AliFatal("Not implemented!");
-}
-
//__________________________________________________________________________________________
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;