Line data Source code
1 : #ifndef ALICHEB3DCALC_H
2 : #define ALICHEB3DCALC_H
3 : /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 : * See cxx source for full Copyright notice */
5 : #include <TNamed.h>
6 : class TSystem;
7 : //
8 : // Author: Ruben Shahoyan
9 : // ruben.shahoyan@cern.ch 09/09/2006
10 : // See Comments in AliCheb3D.h
11 : //
12 :
13 :
14 : // to decrease the compilable code size comment this define. This will exclude the routines
15 : // used for the calculation and saving of the coefficients.
16 : #define _INC_CREATION_ALICHEB3D_
17 :
18 : // when _BRING_TO_BOUNDARY_ is defined, the point outside of the fitted folume is assumed
19 : // to be on the surface
20 : // #define _BRING_TO_BOUNDARY_
21 : //
22 :
23 :
24 : class AliCheb3DCalc: public TNamed
25 : {
26 : public:
27 : AliCheb3DCalc();
28 : AliCheb3DCalc(const AliCheb3DCalc& src);
29 : AliCheb3DCalc(FILE* stream);
30 481320 : ~AliCheb3DCalc() {Clear();}
31 : //
32 : AliCheb3DCalc& operator=(const AliCheb3DCalc& rhs);
33 : void Print(const Option_t* opt="") const;
34 : void LoadData(FILE* stream);
35 : Float_t EvalDeriv(int dim, const Float_t *par) const;
36 : Float_t EvalDeriv2(int dim1,int dim2, const Float_t *par) const;
37 : //
38 : #ifdef _INC_CREATION_ALICHEB3D_
39 : void SaveData(const char* outfile,Bool_t append=kFALSE) const;
40 : void SaveData(FILE* stream=stdout) const;
41 : #endif
42 : //
43 : void InitRows(int nr);
44 : void InitCols(int nc);
45 0 : void SetPrecision(Float_t prc=1e-6) {fPrec = prc;}
46 0 : Float_t GetPrecision() const {return fPrec;}
47 0 : Int_t GetNCoefs() const {return fNCoefs;}
48 0 : Int_t GetNCols() const {return (Int_t)fNCols;}
49 0 : Int_t GetNRows() const {return (Int_t)fNRows;}
50 0 : Int_t GetNElemBound2D() const {return (Int_t)fNElemBound2D;}
51 : Int_t GetMaxColsAtRow() const;
52 0 : UShort_t* GetNColsAtRow() const {return fNColsAtRow;}
53 0 : UShort_t* GetColAtRowBg() const {return fColAtRowBg;}
54 : void InitElemBound2D(int ne);
55 0 : UShort_t* GetCoefBound2D0() const {return fCoefBound2D0;}
56 0 : UShort_t* GetCoefBound2D1() const {return fCoefBound2D1;}
57 : void Clear(const Option_t* option = "");
58 : static Float_t ChebEval1D(Float_t x, const Float_t * array, int ncf);
59 : static Float_t ChebEval1Deriv(Float_t x, const Float_t * array, int ncf);
60 : static Float_t ChebEval1Deriv2(Float_t x, const Float_t * array, int ncf);
61 : void InitCoefs(int nc);
62 0 : Float_t * GetCoefs() const {return fCoefs;}
63 : //
64 : static void ReadLine(TString& str,FILE* stream);
65 : //
66 : Float_t Eval(const Float_t *par) const;
67 : Double_t Eval(const Double_t *par) const;
68 : //
69 : protected:
70 : Int_t fNCoefs; // total number of coeeficients
71 : Int_t fNRows; // number of significant rows in the 3D coeffs matrix
72 : Int_t fNCols; // max number of significant cols in the 3D coeffs matrix
73 : Int_t fNElemBound2D; // number of elements (fNRows*fNCols) to store for the 2D boundary of significant coeffs
74 : UShort_t* fNColsAtRow; //[fNRows] number of sighificant columns (2nd dim) at each row of 3D coefs matrix
75 : UShort_t* fColAtRowBg; //[fNRows] beginnig of significant columns (2nd dim) for row in the 2D boundary matrix
76 : UShort_t* fCoefBound2D0; //[fNElemBound2D] 2D matrix defining the boundary of significance for 3D coeffs.matrix (Ncoefs for col/row)
77 : UShort_t* fCoefBound2D1; //[fNElemBound2D] 2D matrix defining the start beginnig of significant coeffs for col/row
78 : Float_t * fCoefs; //[fNCoefs] array of Chebyshev coefficients
79 : //
80 : Float_t * fTmpCf1; //[fNCols] temp. coeffs for 2d summation
81 : Float_t * fTmpCf0; //[fNRows] temp. coeffs for 1d summation
82 : //
83 : Float_t fPrec; // Requested precision
84 137706 : ClassDef(AliCheb3DCalc,4) // Class for interpolation of 3D->1 function by Chebyshev parametrization
85 : };
86 :
87 : //__________________________________________________________________________________________
88 : inline Float_t AliCheb3DCalc::ChebEval1D(Float_t x, const Float_t * array, int ncf )
89 : {
90 : // evaluate 1D Chebyshev parameterization. x is the argument mapped to [-1:1] interval
91 177643096 : if (ncf<=0) return 0;
92 88821548 : Float_t b0, b1, b2, x2 = x+x;
93 88821548 : b0 = array[--ncf];
94 : b1 = b2 = 0;
95 464608056 : for (int i=ncf;i--;) {
96 : b2 = b1;
97 : b1 = b0;
98 143482480 : b0 = array[i] + x2*b1 -b2;
99 : }
100 88821548 : return b0 - x*b1;
101 : //
102 88821548 : }
103 :
104 : //__________________________________________________________________________________________
105 : inline Float_t AliCheb3DCalc::Eval(const Float_t *par) const
106 : {
107 : // evaluate Chebyshev parameterization for 3D function.
108 : // VERY IMPORTANT: par must contain the function arguments ALREADY MAPPED to [-1:1] interval
109 17637982 : if (!fNRows) return 0.;
110 : int ncfRC;
111 57167964 : for (int id0=fNRows;id0--;) {
112 19765390 : int nCLoc = fNColsAtRow[id0]; // number of significant coefs on this row
113 19765390 : int col0 = fColAtRowBg[id0]; // beginning of local column in the 2D boundary matrix
114 165356460 : for (int id1=nCLoc;id1--;) {
115 62912840 : int id = id1+col0;
116 186069182 : fTmpCf1[id1] = (ncfRC=fCoefBound2D0[id]) ? ChebEval1D(par[2],fCoefs + fCoefBound2D1[id], ncfRC) : 0.0;
117 : }
118 59281702 : fTmpCf0[id0] = nCLoc>0 ? ChebEval1D(par[1],fTmpCf1,nCLoc):0.0;
119 : }
120 8818592 : return ChebEval1D(par[0],fTmpCf0,fNRows);
121 8818858 : }
122 :
123 : //__________________________________________________________________________________________
124 : inline Double_t AliCheb3DCalc::Eval(const Double_t *par) const
125 : {
126 : // evaluate Chebyshev parameterization for 3D function.
127 : // VERY IMPORTANT: par must contain the function arguments ALREADY MAPPED to [-1:1] interval
128 0 : if (!fNRows) return 0.;
129 : int ncfRC;
130 0 : for (int id0=fNRows;id0--;) {
131 0 : int nCLoc = fNColsAtRow[id0]; // number of significant coefs on this row
132 0 : int col0 = fColAtRowBg[id0]; // beginning of local column in the 2D boundary matrix
133 0 : for (int id1=nCLoc;id1--;) {
134 0 : int id = id1+col0;
135 0 : fTmpCf1[id1] = (ncfRC=fCoefBound2D0[id]) ? ChebEval1D(par[2],fCoefs + fCoefBound2D1[id], ncfRC) : 0.0;
136 : }
137 0 : fTmpCf0[id0] = nCLoc>0 ? ChebEval1D(par[1],fTmpCf1,nCLoc):0.0;
138 : }
139 0 : return ChebEval1D(par[0],fTmpCf0,fNRows);
140 0 : }
141 :
142 : #endif
|