[3115] | 1 | #ifndef GENEUTILS_SEEN
|
---|
| 2 | #define GENEUTILS_SEEN
|
---|
| 3 |
|
---|
| 4 | #include "machdefs.h"
|
---|
| 5 | #include <math.h>
|
---|
| 6 | #include "genericfunc.h"
|
---|
| 7 | #include "histos.h"
|
---|
| 8 | #include "tvector.h"
|
---|
[3157] | 9 | #include "cspline.h"
|
---|
[3115] | 10 |
|
---|
| 11 | #include <vector>
|
---|
| 12 |
|
---|
| 13 | namespace SOPHYA {
|
---|
| 14 |
|
---|
[3157] | 15 | //----------------------------------------------------
|
---|
[3115] | 16 | class InterpFunc {
|
---|
| 17 | public:
|
---|
| 18 | InterpFunc(double xmin,double xmax,vector<double>& y);
|
---|
| 19 | virtual ~InterpFunc(void) { }
|
---|
| 20 |
|
---|
[3120] | 21 | double XMin(void) {return _xmin;}
|
---|
| 22 | double XMax(void) {return _xmax;}
|
---|
[3157] | 23 | inline double X(long i) {return _xmin + i*_dx;}
|
---|
[3120] | 24 |
|
---|
[3115] | 25 | //! Retourne l'element le plus proche de f donnant y=f(x)
|
---|
| 26 | inline double operator()(double x)
|
---|
| 27 | {
|
---|
| 28 | x -= _xmin;
|
---|
[3157] | 29 | long i = long(x/_dx+0.5); // On prend le "i" le plus proche
|
---|
[3115] | 30 | if(i<0) i=0; else if(i>=_nm1) i=_nm1-1;
|
---|
| 31 | return _y[i];
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | // idem operator(double) et retourne
|
---|
| 35 | // ok==0 si valeur trouvee, 1 si x<xmin, 2 si x>xmax
|
---|
| 36 | inline double operator()(double x,unsigned short& ok)
|
---|
| 37 | {ok=0; if(x<_xmin) ok=1; else if(x>_xmax) ok=2; return (*this)(x);}
|
---|
| 38 |
|
---|
| 39 | //! Retourne l'interpolation lineaire de f donnant y=f(x)
|
---|
| 40 | // ok==0 si valeur trouvee, 1 si x<xmin, 2 si x>xmax
|
---|
| 41 | double Linear(double x,unsigned short& ok);
|
---|
| 42 |
|
---|
| 43 | //! Retourne l'interpolation parabolique de f donnant y=f(x)
|
---|
| 44 | // ok==0 si valeur trouvee, 1 si x<xmin, 2 si x>xmax
|
---|
| 45 | double Parab(double x,unsigned short& ok);
|
---|
| 46 |
|
---|
| 47 | protected:
|
---|
[3157] | 48 | double _xmin,_xmax,_dx;
|
---|
| 49 | long _nm1; // n-1
|
---|
[3115] | 50 | vector<double>& _y;
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[3157] | 53 | //----------------------------------------------------
|
---|
| 54 | class InverseFunc {
|
---|
| 55 | public:
|
---|
| 56 | InverseFunc(vector<double>& x,vector<double>& y);
|
---|
| 57 | virtual ~InverseFunc(void);
|
---|
| 58 | int ComputeLinear(long n,vector<double>& xfcty);
|
---|
| 59 | int ComputeParab(long n,vector<double>& xfcty);
|
---|
| 60 | double YMin(void) {return _ymin;}
|
---|
| 61 | double YMax(void) {return _ymax;}
|
---|
| 62 | protected:
|
---|
| 63 | inline void find_in_y(double x,long& klo,long& khi)
|
---|
| 64 | {
|
---|
| 65 | long k;
|
---|
| 66 | klo=0, khi=_y.size()-1;
|
---|
| 67 | while (khi-klo > 1) {
|
---|
| 68 | k = (khi+klo) >> 1;
|
---|
| 69 | if (_y[k] > x) khi=k; else klo=k;
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[3330] | 73 | double _ymin,_ymax;
|
---|
[3157] | 74 | vector<double>& _x;
|
---|
| 75 | vector<double>& _y;
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | //----------------------------------------------------
|
---|
[3196] | 79 | double InterpTab(double x0,vector<double>& X,vector<double>& Y,unsigned short typint=0);
|
---|
| 80 |
|
---|
| 81 | //----------------------------------------------------
|
---|
[3115] | 82 | int FuncToHisto(GenericFunc& func,Histo& h,bool logaxex=false);
|
---|
| 83 | int FuncToVec(GenericFunc& func,TVector<r_8>& h,double xmin,double xmax,bool logaxex=false);
|
---|
| 84 |
|
---|
[3157] | 85 | //----------------------------------------------------
|
---|
[3115] | 86 | double AngSol(double dtheta,double dphi,double theta0=M_PI/2.);
|
---|
| 87 | double AngSol(double dtheta);
|
---|
| 88 |
|
---|
[3157] | 89 | //----------------------------------------------------
|
---|
[3115] | 90 | unsigned long PoissRandLimit(double mu,double mumax=10.);
|
---|
| 91 |
|
---|
[3196] | 92 | //----------------------------------------------------
|
---|
| 93 | double IntegrateFunc(GenericFunc& func,double xmin,double xmax
|
---|
| 94 | ,double perc=0.1,double dxinc=-1.,double dxmax=-1.,unsigned short glorder=4);
|
---|
| 95 |
|
---|
| 96 | double IntegrateFuncLog(GenericFunc& func,double lxmin,double lxmax
|
---|
| 97 | ,double perc=0.1,double dlxinc=-1.,double dlxmax=-1.,unsigned short glorder=4);
|
---|
| 98 |
|
---|
| 99 | void Compute_GaussLeg(unsigned short glorder,vector<double>& x,vector<double>& w,double x1=0.,double x2=1.);
|
---|
| 100 |
|
---|
[3325] | 101 | } // Fin namespace SOPHYA
|
---|
| 102 |
|
---|
[3115] | 103 | #endif
|
---|