source: Sophya/trunk/Cosmo/SimLSS/geneutils.h@ 3248

Last change on this file since 3248 was 3196, checked in by cmv, 18 years ago

les AGN selon C.Jackson, une premiere approche simplifiee, recodage from Jim Rich. cmv 03/04/2007

File size: 3.1 KB
Line 
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
13namespace SOPHYA {
14
15//----------------------------------------------------
16class InterpFunc {
17public:
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
47protected:
48 double _xmin,_xmax,_dx;
49 long _nm1; // n-1
50 vector<double>& _y;
51};
52
53//----------------------------------------------------
54class InverseFunc {
55public:
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;}
62protected:
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 vector<double>& _x;
74 vector<double>& _y;
75 double _ymin,_ymax,_dy;
76};
77
78}
79
80//----------------------------------------------------
81double InterpTab(double x0,vector<double>& X,vector<double>& Y,unsigned short typint=0);
82
83//----------------------------------------------------
84int FuncToHisto(GenericFunc& func,Histo& h,bool logaxex=false);
85int FuncToVec(GenericFunc& func,TVector<r_8>& h,double xmin,double xmax,bool logaxex=false);
86
87//----------------------------------------------------
88double AngSol(double dtheta,double dphi,double theta0=M_PI/2.);
89double AngSol(double dtheta);
90
91//----------------------------------------------------
92unsigned long PoissRandLimit(double mu,double mumax=10.);
93
94//----------------------------------------------------
95double IntegrateFunc(GenericFunc& func,double xmin,double xmax
96 ,double perc=0.1,double dxinc=-1.,double dxmax=-1.,unsigned short glorder=4);
97
98double IntegrateFuncLog(GenericFunc& func,double lxmin,double lxmax
99 ,double perc=0.1,double dlxinc=-1.,double dlxmax=-1.,unsigned short glorder=4);
100
101void Compute_GaussLeg(unsigned short glorder,vector<double>& x,vector<double>& w,double x1=0.,double x2=1.);
102
103#endif
Note: See TracBrowser for help on using the repository browser.