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

Last change on this file since 3115 was 3115, checked in by ansari, 19 years ago

Creation initiale du groupe Cosmo avec le repertoire SimLSS de
simulation de distribution de masse 3D des galaxies par CMV+Rz
18/12/2006

File size: 1.5 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 //! 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
41protected:
42 double _xmin,_xmax,_xlarg,_dx;
43 vector<double>& _y;
44 long _nm1; // n-1
45};
46
47}
48
49int FuncToHisto(GenericFunc& func,Histo& h,bool logaxex=false);
50int FuncToVec(GenericFunc& func,TVector<r_8>& h,double xmin,double xmax,bool logaxex=false);
51
52double AngSol(double dtheta,double dphi,double theta0=M_PI/2.);
53double AngSol(double dtheta);
54
55unsigned long PoissRandLimit(double mu,double mumax=10.);
56
57#endif
Note: See TracBrowser for help on using the repository browser.