/************************************************************************** * 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. * **************************************************************************/ #include #include #include "AliCheb3DCalc.h" ClassImp(AliCheb3DCalc) //__________________________________________________________________________________________ AliCheb3DCalc::AliCheb3DCalc() : fNCoefs(0), fNRows(0), fNCols(0), fNElemBound2D(0), fNColsAtRow(0), fColAtRowBg(0), fCoefBound2D0(0), fCoefBound2D1(0), fCoefs(0), fTmpCf1(0), fTmpCf0(0) { // default constructor } //__________________________________________________________________________________________ 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 UShort_t[fNRows]; for (int i=fNRows;i--;) fNColsAtRow[i] = src.fNColsAtRow[i]; } if (src.fColAtRowBg) { fColAtRowBg = new UShort_t[fNRows]; for (int i=fNRows;i--;) fColAtRowBg[i] = src.fColAtRowBg[i]; } if (src.fCoefBound2D0) { fCoefBound2D0 = new UShort_t[fNElemBound2D]; for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = src.fCoefBound2D0[i]; } if (src.fCoefBound2D1) { fCoefBound2D1 = new UShort_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(FILE* stream) : fNCoefs(0), fNRows(0), fNCols(0), fNElemBound2D(0), fNColsAtRow(0), fColAtRowBg(0), fCoefBound2D0(0), fCoefBound2D1(0), fCoefs(0), 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()); SetTitle(rhs.GetTitle()); fNCoefs = rhs.fNCoefs; fNRows = rhs.fNRows; fNCols = rhs.fNCols; if (rhs.fNColsAtRow) { fNColsAtRow = new UShort_t[fNRows]; for (int i=fNRows;i--;) fNColsAtRow[i] = rhs.fNColsAtRow[i]; } if (rhs.fColAtRowBg) { fColAtRowBg = new UShort_t[fNRows]; for (int i=fNRows;i--;) fColAtRowBg[i] = rhs.fColAtRowBg[i]; } if (rhs.fCoefBound2D0) { fCoefBound2D0 = new UShort_t[fNElemBound2D]; for (int i=fNElemBound2D;i--;) fCoefBound2D0[i] = rhs.fCoefBound2D0[i]; } if (rhs.fCoefBound2D1) { fCoefBound2D1 = new UShort_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(const 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::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]; printf("%d coefficients in %dx%dx%d matrix\n",fNCoefs,fNRows,fNCols,nmax3d); // } //__________________________________________________________________________________________ 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 // 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 for (int id1=nCLoc;id1--;) { int id = id1+col0; if (!(ncfRC=fCoefBound2D0[id])) { fTmpCf1[id1]=0; continue;} 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(par[1],fTmpCf1,nCLoc); else fTmpCf0[id0] = ChebEval1D(par[1],fTmpCf1,nCLoc); } return (dim==0) ? ChebEval1Deriv(par[0],fTmpCf0,fNRows) : ChebEval1D(par[0],fTmpCf0,fNRows); // } //__________________________________________________________________________________________ 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 // Bool_t same = dim1==dim2; 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 for (int id1=nCLoc;id1--;) { int id = id1+col0; if (!(ncfRC=fCoefBound2D0[id])) { fTmpCf1[id1]=0; continue;} 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(par[1],fTmpCf1,nCLoc):ChebEval1Deriv(par[1],fTmpCf1,nCLoc); else fTmpCf0[id0] = ChebEval1D(par[1],fTmpCf1,nCLoc); } return (dim1==0||dim2==0) ? (same ? ChebEval1Deriv2(par[0],fTmpCf0,fNRows):ChebEval1Deriv(par[0],fTmpCf0,fNRows)) : ChebEval1D(par[0],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\", 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: '', found \"%s\"\nStop\n",buffs.Data());exit(1);} // fNCols = 0; fNElemBound2D = 0; InitRows(fNRows); // for (int id0=0;id0nmax3d) nmax3d = fCoefBound2D0[i]; return nmax3d; }