// $Id: LookupTable.hh,v 1.2 2002/08/18 23:15:01 kamland0 Exp $ #ifndef __LookupTable_hh__ #define __LookupTable_hh__ #include #include "TObject.h" class TKLLookupTableFixedBin : public TObject { public: TKLLookupTableFixedBin() : fY(0) { } virtual ~TKLLookupTableFixedBin() {} void Initialize( Int_t nsamp, Double_t xlow, Double_t xhigh, Double_t(*f)(Double_t)=0 ); void SetPoint( Double_t x, Double_t y ); inline Double_t Interpolate1( Double_t x ); inline Double_t Interpolate1( Double_t x, Double_t &dydx ); // Other interpolations can be added, but linear interpolation is // best for many purposes, particularly when memory is cheap enough to // allow fine sampling and speed is paramount. protected: Int_t fNsamp; Double_t fXlow; Double_t fDX; Double_t *fY; ClassDef(TKLLookupTableFixedBin, 1) // numeric lookup table }; inline Double_t TKLLookupTableFixedBin::Interpolate1( Double_t x ) { // linear interpolation, inlined for speed. Note linear // interpolation is best for many purposes, particularly when memory // is cheap enough to allow fine sampling and speed is paramount. Double_t di= (x-fXlow)/fDX; Int_t i= (Int_t)di; if (i<0) i=0; else if (i>=fNsamp-1) i= fNsamp-2; di -= i; return fY[i] + di * (fY[i+1]-fY[i]); } inline Double_t TKLLookupTableFixedBin::Interpolate1( Double_t x, Double_t &dydx ) { // linear interpolation with derivative, inlined for speed. Note linear // interpolation is best for many purposes, particularly when memory // is cheap enough to allow fine sampling and speed is paramount. Double_t di= (x-fXlow)/fDX; Int_t i= (Int_t)di; if (i<0) i=0; else if (i>=fNsamp-1) i= fNsamp-2; di -= i; dydx= (fY[i+1]-fY[i])/fDX; return fY[i] + di * (fY[i+1]-fY[i]); } #endif