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"
|
---|
9 | #include "cspline.h"
|
---|
10 |
|
---|
11 | #include <vector>
|
---|
12 |
|
---|
13 | namespace SOPHYA {
|
---|
14 |
|
---|
15 | //----------------------------------------------------
|
---|
16 | class InterpFunc {
|
---|
17 | public:
|
---|
18 | InterpFunc(double xmin,double xmax,vector<double>& y);
|
---|
19 | virtual ~InterpFunc(void) { }
|
---|
20 |
|
---|
21 | double XMin(void) {return _xmin;}
|
---|
22 | double XMax(void) {return _xmax;}
|
---|
23 | inline double X(long i) {return _xmin + i*_dx;}
|
---|
24 |
|
---|
25 | //! Retourne l'element le plus proche de f donnant y=f(x)
|
---|
26 | inline double operator()(double x)
|
---|
27 | {
|
---|
28 | x -= _xmin;
|
---|
29 | long i = long(x/_dx+0.5); // On prend le "i" le plus proche
|
---|
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:
|
---|
48 | double _xmin,_xmax,_dx;
|
---|
49 | long _nm1; // n-1
|
---|
50 | vector<double>& _y;
|
---|
51 | };
|
---|
52 |
|
---|
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 |
|
---|
73 | double _ymin,_ymax;
|
---|
74 | vector<double>& _x;
|
---|
75 | vector<double>& _y;
|
---|
76 | };
|
---|
77 |
|
---|
78 | //----------------------------------------------------
|
---|
79 | double InterpTab(double x0,vector<double>& X,vector<double>& Y,unsigned short typint=0);
|
---|
80 |
|
---|
81 | //----------------------------------------------------
|
---|
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 |
|
---|
85 | //----------------------------------------------------
|
---|
86 | double AngSol(double dtheta,double dphi,double theta0=M_PI/2.);
|
---|
87 | double AngSol(double dtheta);
|
---|
88 | double FrAngSol(double angsol);
|
---|
89 |
|
---|
90 | double SinXsX(double x,bool app=false);
|
---|
91 | double SinXsX_Sqr(double x,bool app=false);
|
---|
92 |
|
---|
93 | double SinNXsX(double x,unsigned long N,bool app=false);
|
---|
94 | double SinNXsX_Sqr(double x,unsigned long N,bool app=false);
|
---|
95 |
|
---|
96 | double AntCentFed(double L, double trad);
|
---|
97 | double AntDipole(double L, double trad);
|
---|
98 |
|
---|
99 | //----------------------------------------------------
|
---|
100 | double IntegrateFunc(GenericFunc& func,double xmin,double xmax
|
---|
101 | ,double perc=0.1,double dxinc=-1.,double dxmax=-1.,unsigned short glorder=4);
|
---|
102 |
|
---|
103 | double IntegrateFuncLog(GenericFunc& func,double lxmin,double lxmax
|
---|
104 | ,double perc=0.1,double dlxinc=-1.,double dlxmax=-1.,unsigned short glorder=4);
|
---|
105 |
|
---|
106 | void Compute_GaussLeg(unsigned short glorder,vector<double>& x,vector<double>& w,double x1=0.,double x2=1.);
|
---|
107 |
|
---|
108 | } // Fin namespace SOPHYA
|
---|
109 |
|
---|
110 | #endif
|
---|