| [3756] | 1 | //  Classes to compute Multi-Dish or CRT-like radio interferometer response | 
|---|
|  | 2 | //  R. Ansari - Avril-Mai 2010 | 
|---|
|  | 3 |  | 
|---|
|  | 4 | #ifndef MDISH_SEEN | 
|---|
|  | 5 | #define MDISH_SEEN | 
|---|
|  | 6 |  | 
|---|
|  | 7 | #include "machdefs.h"      // SOPHYA .h | 
|---|
|  | 8 | #include "sopnamsp.h"      // SOPHYA .h | 
|---|
|  | 9 | #include <math.h> | 
|---|
|  | 10 | #include <iostream> | 
|---|
|  | 11 | #include <vector> | 
|---|
|  | 12 | #include <string> | 
|---|
|  | 13 |  | 
|---|
|  | 14 | #include "genericfunc.h"   // SOPHYA .h | 
|---|
|  | 15 | #include "array.h"         // SOPHYA .h | 
|---|
| [3783] | 16 | #include "qhist.h" | 
|---|
| [3756] | 17 |  | 
|---|
| [3783] | 18 | #ifndef DeuxPI | 
|---|
| [3756] | 19 | #define DeuxPI 2.*M_PI | 
|---|
| [3783] | 20 | #endif | 
|---|
| [3756] | 21 |  | 
|---|
| [3796] | 22 | // -- Four2DResponse : Reponse instrumentale ds le plan k_x,k_y (frequences angulaires theta,phi) | 
|---|
| [3973] | 23 | // typ=1 : Reponse gaussienne parabole diametre D exp[ - 2  (lambda  k_g / D )^2 ] | 
|---|
| [3756] | 24 | // typ=2 : Reponse parabole diametre D  Triangle <= kmax= 2 pi D / lambda | 
|---|
|  | 25 | // typ=3 : Reponse rectangle Dx x Dy  Triangle (|kx|,|k_y|) <= (2 pi Dx / lambda, 2 pi Dx / lambda) | 
|---|
| [3796] | 26 | // typ=22 : Reponse parabole diametre D  Triangle <= kmax= 2 pi D / lambda  avec un trou au centre | 
|---|
|  | 27 |  | 
|---|
| [3756] | 28 | class Four2DResponse  { | 
|---|
|  | 29 | public: | 
|---|
|  | 30 | // On donne dx=D/lambda=Dx/lambda , dy=Dy/lambda | 
|---|
| [3789] | 31 | Four2DResponse(int typ, double dx, double dy, double lambda=1.); | 
|---|
| [3756] | 32 |  | 
|---|
|  | 33 | Four2DResponse(Four2DResponse const& a) | 
|---|
| [3789] | 34 | { typ_ = a.typ_; dx_=a.dx_; dy_=a.dy_; lambdaref_=a.lambdaref_; | 
|---|
|  | 35 | lambda_=a.lambda_; lambda_ratio_=a.lambda_ratio_; } | 
|---|
| [3756] | 36 | Four2DResponse& operator=(Four2DResponse const& a) | 
|---|
| [3789] | 37 | { typ_ = a.typ_; dx_=a.dx_; dy_=a.dy_; lambdaref_=a.lambdaref_; | 
|---|
|  | 38 | lambda_=a.lambda_; lambda_ratio_=a.lambda_ratio_;  return (*this); } | 
|---|
| [3756] | 39 |  | 
|---|
| [3787] | 40 | inline void setLambdaRef(double lambda=1.) | 
|---|
|  | 41 | { lambdaref_ = lambda; } | 
|---|
|  | 42 | inline void setLambda(double lambda=1.) | 
|---|
| [3789] | 43 | { lambda_ = lambda;   lambda_ratio_ = lambda_/lambdaref_; } | 
|---|
| [3947] | 44 |  | 
|---|
|  | 45 | inline double getLambdaRef()   { return lambdaref_; } | 
|---|
|  | 46 | inline double getLambda()  { return lambda_; } | 
|---|
| [3787] | 47 |  | 
|---|
| [3756] | 48 | // Return the 2D response for wave vector (kx,ky) | 
|---|
|  | 49 | virtual double Value(double kx, double ky); | 
|---|
|  | 50 | inline  double operator()(double kx, double ky) | 
|---|
|  | 51 | { return Value(kx, ky); } | 
|---|
| [4030] | 52 | // Retourne l'histo de reponse en fonction de k_x,k_y | 
|---|
| [3930] | 53 | virtual Histo2D GetResponse(int nx=255, int ny=255); | 
|---|
| [4030] | 54 | // Retourne l'histo de reponse en fonction de u=k_x/2 pi, v=k_y/2 pi | 
|---|
|  | 55 | virtual Histo2D GetResponseUV(int nx=255, int ny=255); | 
|---|
|  | 56 |  | 
|---|
| [3947] | 57 | // Retourne le niveau moyen du bruit projete 1D en fonction (sqrt(u^2+v^2) | 
|---|
|  | 58 | HProf GetProjNoiseLevel(int nbin=128, bool fgnorm1=true); | 
|---|
|  | 59 | // Retourne la reponse moyenne projetee 1D en fonction (sqrt(u^2+v^2) | 
|---|
|  | 60 | HProf GetProjResponse(int nbin=128, bool fgnorm1=true); | 
|---|
|  | 61 |  | 
|---|
| [3756] | 62 | inline double D() { return dx_; } ; | 
|---|
|  | 63 | inline double Dx() { return dx_; } ; | 
|---|
|  | 64 | inline double Dy() { return dy_; } ; | 
|---|
|  | 65 |  | 
|---|
|  | 66 | int typ_; | 
|---|
|  | 67 | double dx_, dy_; | 
|---|
| [3787] | 68 | double lambdaref_, lambda_; | 
|---|
|  | 69 | double lambda_ratio_;     // lambdaref_/lambda_; | 
|---|
|  | 70 |  | 
|---|
| [3756] | 71 | }; | 
|---|
|  | 72 |  | 
|---|
| [3788] | 73 |  | 
|---|
| [3756] | 74 | // -- Four2DRespTable : Reponse tabulee instrumentale ds le plan k_x,k_y (angles theta,phi) | 
|---|
|  | 75 | class Four2DRespTable : public  Four2DResponse { | 
|---|
|  | 76 | public: | 
|---|
| [3792] | 77 | // Constructeur sans argument, utilise pour lire depuis un fichier | 
|---|
|  | 78 | Four2DRespTable(); | 
|---|
| [3756] | 79 | // On donne dx=D/lambda=Dx/lambda , dy=Dy/lambda | 
|---|
| [3792] | 80 | Four2DRespTable(Histo2D const & hrep, double d, double lambda=1.); | 
|---|
| [3796] | 81 | // Apres renormalisaton Value(kx,ky) <= max | 
|---|
|  | 82 | double renormalize(double max=1.); | 
|---|
| [3756] | 83 | // Return the 2D response for wave vector (kx,ky) | 
|---|
|  | 84 | virtual double Value(double kx, double ky); | 
|---|
| [3792] | 85 |  | 
|---|
|  | 86 | void writeToPPF(string flnm); | 
|---|
|  | 87 | void readFromPPF(string flnm); | 
|---|
|  | 88 |  | 
|---|
| [3756] | 89 | Histo2D hrep_; | 
|---|
|  | 90 | }; | 
|---|
|  | 91 |  | 
|---|
| [3788] | 92 |  | 
|---|
|  | 93 | // -- Four2DRespRatio: Retourne le rapport de la reponse entre deux objets Four2DResponse | 
|---|
|  | 94 | class Four2DRespRatio : public  Four2DResponse { | 
|---|
|  | 95 | public: | 
|---|
| [3986] | 96 | Four2DRespRatio(Four2DResponse& a, Four2DResponse& b, double maxratio=10.); | 
|---|
| [3788] | 97 | // Return the ratio a.Value(kx,ky) / b.Value(kx, ky) - with protection against divide by zero | 
|---|
|  | 98 | virtual double Value(double kx, double ky); | 
|---|
|  | 99 | Four2DResponse& a_; | 
|---|
|  | 100 | Four2DResponse& b_; | 
|---|
| [3991] | 101 | double maxratio_, zerothr_; | 
|---|
| [3788] | 102 | }; | 
|---|
|  | 103 |  | 
|---|
| [3756] | 104 | // Classe toute simple pour representer un element de reception de type dish | 
|---|
|  | 105 | class Dish { | 
|---|
|  | 106 | public: | 
|---|
|  | 107 | // Circular dish | 
|---|
|  | 108 | Dish(int id, double x, double y, double diam) | 
|---|
| [3947] | 109 | :  id_(id), X(x), Y(y), D(diam), Dx(D), Dy(D), fgcirc_(true), gain_(1.)   {   } | 
|---|
| [3756] | 110 | // Receiver with rectangular type answer in kx,ky plane | 
|---|
|  | 111 | Dish(int id, double x, double y, double dx, double dy) | 
|---|
| [3947] | 112 | :  id_(id), X(x), Y(y), D(sqrt(dx*dy)), Dx(dx), Dy(dy), fgcirc_(false), gain_(1.)    {   } | 
|---|
| [3756] | 113 | Dish(Dish const& a) | 
|---|
| [3947] | 114 | :  id_(a.id_), X(a.X), Y(a.Y), D(a.D), Dx(a.Dx), Dy(a.Dy), fgcirc_(a.fgcirc_), gain_(a.gain_)  {   } | 
|---|
|  | 115 | inline void setGain(double gain) { gain_=gain; return; } | 
|---|
| [3756] | 116 | inline bool isCircular() { return fgcirc_; } | 
|---|
|  | 117 | inline int ReflectorId() { return id_; } | 
|---|
| [3769] | 118 | inline double Diameter() { return D; } | 
|---|
|  | 119 | inline double DiameterX() { return Dx; } | 
|---|
| [3930] | 120 | inline double DiameterY() { return Dy; } | 
|---|
| [3947] | 121 | inline double Gain() { return gain_; } | 
|---|
| [3756] | 122 |  | 
|---|
|  | 123 | int id_;   // numero de reflecteur | 
|---|
| [3988] | 124 | double X,Y,D; | 
|---|
| [3756] | 125 | double Dx, Dy; | 
|---|
|  | 126 | bool fgcirc_;  // false -> rectangular dish | 
|---|
| [3947] | 127 | double gain_; | 
|---|
| [3756] | 128 | }; | 
|---|
|  | 129 |  | 
|---|
|  | 130 |  | 
|---|
|  | 131 | // ------------------------------------------------------------------- | 
|---|
|  | 132 | // -- Pour calculer la reponse ds le plan kx,ky d'un system MultiDish | 
|---|
|  | 133 | class MultiDish { | 
|---|
|  | 134 | public: | 
|---|
|  | 135 | MultiDish(double lambda, double dmax, vector<Dish>& dishes, bool fgnoauto=false); | 
|---|
|  | 136 |  | 
|---|
| [3932] | 137 | // Pour phi, les angles phi, -phi, phi+pi, -(phi+pi) sont prises en compte | 
|---|
| [3756] | 138 | inline void SetThetaPhiRange(double thetamax=0., int ntet=1, double phimax=0., int nphi=1) | 
|---|
|  | 139 | { thetamax_=thetamax; ntet_=ntet; phimax_=phimax; nphi_=nphi; } | 
|---|
|  | 140 |  | 
|---|
| [3932] | 141 | inline int SetPrtLevel(int lev=0, int prtmod=10) | 
|---|
|  | 142 | { int olev=prtlev_; prtlev_=lev; prtmodulo_=prtmod; return olev; } | 
|---|
|  | 143 |  | 
|---|
| [3756] | 144 | inline void SetRespHisNBins(int nx=128, int ny=128) | 
|---|
|  | 145 | { nx_=nx; ny_=ny; } | 
|---|
| [3933] | 146 | inline void SetBeamNSamples(int nx=128, int ny=128) | 
|---|
|  | 147 | { beamnx_=nx; beamny_=ny; } | 
|---|
|  | 148 |  | 
|---|
| [3947] | 149 | // Calcul la reponse ds le plan 2D  (u,v) = (kx,ky) | 
|---|
|  | 150 | void ComputeResponse(); | 
|---|
|  | 151 | // Retourne la reponse 2D ds le plan (u,v) = (kx,ky) sous forme d'histo 2D | 
|---|
| [3756] | 152 | Histo2D GetResponse(); | 
|---|
|  | 153 |  | 
|---|
| [3947] | 154 | // Retourne le niveau moyen du bruit projete 1D en fonction (sqrt(u^2+v^2) | 
|---|
|  | 155 | HProf GetProjNoiseLevel(int nbin=128, bool fgnorm1=true); | 
|---|
|  | 156 | // Retourne la reponse moyenne projetee 1D en fonction (sqrt(u^2+v^2) | 
|---|
|  | 157 | HProf GetProjResponse(int nbin=128, bool fgnorm1=true); | 
|---|
|  | 158 |  | 
|---|
| [3756] | 159 | double CumulResp(Four2DResponse& rd, double theta=0., double phi=0.); | 
|---|
|  | 160 | inline size_t NbDishes() { return dishes_.size(); } | 
|---|
| [3769] | 161 | inline Dish&  operator[](size_t k) { return dishes_[k]; } | 
|---|
| [3756] | 162 |  | 
|---|
| [3769] | 163 | virtual Histo2D PosDist(int nx=30, int ny=30, double dmax=0.); | 
|---|
|  | 164 |  | 
|---|
|  | 165 | protected: | 
|---|
| [3756] | 166 | double AddToHisto(double kx0, double ky0, double x, double y, double w, bool fgfh); | 
|---|
|  | 167 |  | 
|---|
| [3947] | 168 | double lambda_, dmax_, kmax_; | 
|---|
| [3756] | 169 | vector<Dish> dishes_; | 
|---|
|  | 170 | bool fgnoauto_; | 
|---|
|  | 171 | double thetamax_, phimax_; | 
|---|
|  | 172 | int ntet_,nphi_; | 
|---|
| [3933] | 173 | int nx_, ny_;   // nb de bins de l'histo de reponse | 
|---|
|  | 174 | int beamnx_, beamny_; // nb de points d'echantillonnage du beam | 
|---|
|  | 175 |  | 
|---|
| [3756] | 176 | //   Histo2D h2w_, h2cnt_; | 
|---|
|  | 177 | QHis2D h2w_; | 
|---|
| [3947] | 178 | bool fgcomputedone_; | 
|---|
| [3756] | 179 | int mcnt_; | 
|---|
| [3932] | 180 | int prtlev_,prtmodulo_; | 
|---|
| [3756] | 181 | }; | 
|---|
|  | 182 |  | 
|---|
|  | 183 |  | 
|---|
|  | 184 | #endif | 
|---|