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

Last change on this file since 3154 was 3120, checked in by cmv, 19 years ago

Suite de la mise dans la base cvs cmv 21/12/2006

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