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

Last change on this file since 4013 was 3653, checked in by cmv, 16 years ago

add hshs EW, cmv 16/07/2009

File size: 3.3 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 double _ymin,_ymax;
74 vector<double>& _x;
75 vector<double>& _y;
76};
77
78//----------------------------------------------------
79double InterpTab(double x0,vector<double>& X,vector<double>& Y,unsigned short typint=0);
80
81//----------------------------------------------------
82int FuncToHisto(GenericFunc& func,Histo& h,bool logaxex=false);
83int FuncToVec(GenericFunc& func,TVector<r_8>& h,double xmin,double xmax,bool logaxex=false);
84
85//----------------------------------------------------
86double AngSol(double dtheta,double dphi,double theta0=M_PI/2.);
87double AngSol(double dtheta);
88double FrAngSol(double angsol);
89
90double SinXsX(double x,bool app=false);
91double SinXsX_Sqr(double x,bool app=false);
92
93double SinNXsX(double x,unsigned long N,bool app=false);
94double SinNXsX_Sqr(double x,unsigned long N,bool app=false);
95
96double AntCentFed(double L, double trad);
97double AntDipole(double L, double trad);
98double LobeSinc(double L, double trad);
99
100//----------------------------------------------------
101double IntegrateFunc(GenericFunc& func,double xmin,double xmax
102 ,double perc=0.1,double dxinc=-1.,double dxmax=-1.,unsigned short glorder=4);
103
104double IntegrateFuncLog(GenericFunc& func,double lxmin,double lxmax
105 ,double perc=0.1,double dlxinc=-1.,double dlxmax=-1.,unsigned short glorder=4);
106
107void Compute_GaussLeg(unsigned short glorder,vector<double>& x,vector<double>& w,double x1=0.,double x2=1.);
108
109} // Fin namespace SOPHYA
110
111#endif
Note: See TracBrowser for help on using the repository browser.