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 |
|
---|
10 | #include <vector>
|
---|
11 |
|
---|
12 | namespace SOPHYA {
|
---|
13 |
|
---|
14 | class InterpFunc {
|
---|
15 | public:
|
---|
16 | InterpFunc(double xmin,double xmax,vector<double>& y);
|
---|
17 | virtual ~InterpFunc(void) { }
|
---|
18 |
|
---|
19 | //! Retourne l'element le plus proche de f donnant y=f(x)
|
---|
20 | inline double operator()(double x)
|
---|
21 | {
|
---|
22 | x -= _xmin;
|
---|
23 | long i = long(x/_xlarg*_nm1+0.5); // On prend le "i" le plus proche
|
---|
24 | if(i<0) i=0; else if(i>=_nm1) i=_nm1-1;
|
---|
25 | return _y[i];
|
---|
26 | }
|
---|
27 |
|
---|
28 | // idem operator(double) et retourne
|
---|
29 | // ok==0 si valeur trouvee, 1 si x<xmin, 2 si x>xmax
|
---|
30 | inline double operator()(double x,unsigned short& ok)
|
---|
31 | {ok=0; if(x<_xmin) ok=1; else if(x>_xmax) ok=2; return (*this)(x);}
|
---|
32 |
|
---|
33 | //! Retourne l'interpolation lineaire de f donnant y=f(x)
|
---|
34 | // ok==0 si valeur trouvee, 1 si x<xmin, 2 si x>xmax
|
---|
35 | double Linear(double x,unsigned short& ok);
|
---|
36 |
|
---|
37 | //! Retourne l'interpolation parabolique de f donnant y=f(x)
|
---|
38 | // ok==0 si valeur trouvee, 1 si x<xmin, 2 si x>xmax
|
---|
39 | double Parab(double x,unsigned short& ok);
|
---|
40 |
|
---|
41 | protected:
|
---|
42 | double _xmin,_xmax,_xlarg,_dx;
|
---|
43 | vector<double>& _y;
|
---|
44 | long _nm1; // n-1
|
---|
45 | };
|
---|
46 |
|
---|
47 | }
|
---|
48 |
|
---|
49 | int FuncToHisto(GenericFunc& func,Histo& h,bool logaxex=false);
|
---|
50 | int FuncToVec(GenericFunc& func,TVector<r_8>& h,double xmin,double xmax,bool logaxex=false);
|
---|
51 |
|
---|
52 | double AngSol(double dtheta,double dphi,double theta0=M_PI/2.);
|
---|
53 | double AngSol(double dtheta);
|
---|
54 |
|
---|
55 | unsigned long PoissRandLimit(double mu,double mumax=10.);
|
---|
56 |
|
---|
57 | #endif
|
---|