| [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); } | 
|---|
| [3930] | 52 | virtual Histo2D GetResponse(int nx=255, int ny=255); | 
|---|
| [3947] | 53 | // Retourne le niveau moyen du bruit projete 1D en fonction (sqrt(u^2+v^2) | 
|---|
|  | 54 | HProf GetProjNoiseLevel(int nbin=128, bool fgnorm1=true); | 
|---|
|  | 55 | // Retourne la reponse moyenne projetee 1D en fonction (sqrt(u^2+v^2) | 
|---|
|  | 56 | HProf GetProjResponse(int nbin=128, bool fgnorm1=true); | 
|---|
|  | 57 |  | 
|---|
| [3756] | 58 | inline double D() { return dx_; } ; | 
|---|
|  | 59 | inline double Dx() { return dx_; } ; | 
|---|
|  | 60 | inline double Dy() { return dy_; } ; | 
|---|
|  | 61 |  | 
|---|
|  | 62 | int typ_; | 
|---|
|  | 63 | double dx_, dy_; | 
|---|
| [3787] | 64 | double lambdaref_, lambda_; | 
|---|
|  | 65 | double lambda_ratio_;     // lambdaref_/lambda_; | 
|---|
|  | 66 |  | 
|---|
| [3756] | 67 | }; | 
|---|
|  | 68 |  | 
|---|
| [3788] | 69 |  | 
|---|
| [3756] | 70 | // -- Four2DRespTable : Reponse tabulee instrumentale ds le plan k_x,k_y (angles theta,phi) | 
|---|
|  | 71 | class Four2DRespTable : public  Four2DResponse { | 
|---|
|  | 72 | public: | 
|---|
| [3792] | 73 | // Constructeur sans argument, utilise pour lire depuis un fichier | 
|---|
|  | 74 | Four2DRespTable(); | 
|---|
| [3756] | 75 | // On donne dx=D/lambda=Dx/lambda , dy=Dy/lambda | 
|---|
| [3792] | 76 | Four2DRespTable(Histo2D const & hrep, double d, double lambda=1.); | 
|---|
| [3796] | 77 | // Apres renormalisaton Value(kx,ky) <= max | 
|---|
|  | 78 | double renormalize(double max=1.); | 
|---|
| [3756] | 79 | // Return the 2D response for wave vector (kx,ky) | 
|---|
|  | 80 | virtual double Value(double kx, double ky); | 
|---|
| [3792] | 81 |  | 
|---|
|  | 82 | void writeToPPF(string flnm); | 
|---|
|  | 83 | void readFromPPF(string flnm); | 
|---|
|  | 84 |  | 
|---|
| [3756] | 85 | Histo2D hrep_; | 
|---|
|  | 86 | }; | 
|---|
|  | 87 |  | 
|---|
| [3788] | 88 |  | 
|---|
|  | 89 | // -- Four2DRespRatio: Retourne le rapport de la reponse entre deux objets Four2DResponse | 
|---|
|  | 90 | class Four2DRespRatio : public  Four2DResponse { | 
|---|
|  | 91 | public: | 
|---|
| [3986] | 92 | Four2DRespRatio(Four2DResponse& a, Four2DResponse& b, double maxratio=10.); | 
|---|
| [3788] | 93 | // Return the ratio a.Value(kx,ky) / b.Value(kx, ky) - with protection against divide by zero | 
|---|
|  | 94 | virtual double Value(double kx, double ky); | 
|---|
|  | 95 | Four2DResponse& a_; | 
|---|
|  | 96 | Four2DResponse& b_; | 
|---|
| [3991] | 97 | double maxratio_, zerothr_; | 
|---|
| [3788] | 98 | }; | 
|---|
|  | 99 |  | 
|---|
| [3756] | 100 | // Classe toute simple pour representer un element de reception de type dish | 
|---|
|  | 101 | class Dish { | 
|---|
|  | 102 | public: | 
|---|
|  | 103 | // Circular dish | 
|---|
|  | 104 | Dish(int id, double x, double y, double diam) | 
|---|
| [3947] | 105 | :  id_(id), X(x), Y(y), D(diam), Dx(D), Dy(D), fgcirc_(true), gain_(1.)   {   } | 
|---|
| [3756] | 106 | // Receiver with rectangular type answer in kx,ky plane | 
|---|
|  | 107 | Dish(int id, double x, double y, double dx, double dy) | 
|---|
| [3947] | 108 | :  id_(id), X(x), Y(y), D(sqrt(dx*dy)), Dx(dx), Dy(dy), fgcirc_(false), gain_(1.)    {   } | 
|---|
| [3756] | 109 | Dish(Dish const& a) | 
|---|
| [3947] | 110 | :  id_(a.id_), X(a.X), Y(a.Y), D(a.D), Dx(a.Dx), Dy(a.Dy), fgcirc_(a.fgcirc_), gain_(a.gain_)  {   } | 
|---|
|  | 111 | inline void setGain(double gain) { gain_=gain; return; } | 
|---|
| [3756] | 112 | inline bool isCircular() { return fgcirc_; } | 
|---|
|  | 113 | inline int ReflectorId() { return id_; } | 
|---|
| [3769] | 114 | inline double Diameter() { return D; } | 
|---|
|  | 115 | inline double DiameterX() { return Dx; } | 
|---|
| [3930] | 116 | inline double DiameterY() { return Dy; } | 
|---|
| [3947] | 117 | inline double Gain() { return gain_; } | 
|---|
| [3756] | 118 |  | 
|---|
|  | 119 | int id_;   // numero de reflecteur | 
|---|
| [3988] | 120 | double X,Y,D; | 
|---|
| [3756] | 121 | double Dx, Dy; | 
|---|
|  | 122 | bool fgcirc_;  // false -> rectangular dish | 
|---|
| [3947] | 123 | double gain_; | 
|---|
| [3756] | 124 | }; | 
|---|
|  | 125 |  | 
|---|
|  | 126 |  | 
|---|
|  | 127 | // ------------------------------------------------------------------- | 
|---|
|  | 128 | // -- Pour calculer la reponse ds le plan kx,ky d'un system MultiDish | 
|---|
|  | 129 | class MultiDish { | 
|---|
|  | 130 | public: | 
|---|
|  | 131 | MultiDish(double lambda, double dmax, vector<Dish>& dishes, bool fgnoauto=false); | 
|---|
|  | 132 |  | 
|---|
| [3932] | 133 | // Pour phi, les angles phi, -phi, phi+pi, -(phi+pi) sont prises en compte | 
|---|
| [3756] | 134 | inline void SetThetaPhiRange(double thetamax=0., int ntet=1, double phimax=0., int nphi=1) | 
|---|
|  | 135 | { thetamax_=thetamax; ntet_=ntet; phimax_=phimax; nphi_=nphi; } | 
|---|
|  | 136 |  | 
|---|
| [3932] | 137 | inline int SetPrtLevel(int lev=0, int prtmod=10) | 
|---|
|  | 138 | { int olev=prtlev_; prtlev_=lev; prtmodulo_=prtmod; return olev; } | 
|---|
|  | 139 |  | 
|---|
| [3756] | 140 | inline void SetRespHisNBins(int nx=128, int ny=128) | 
|---|
|  | 141 | { nx_=nx; ny_=ny; } | 
|---|
| [3933] | 142 | inline void SetBeamNSamples(int nx=128, int ny=128) | 
|---|
|  | 143 | { beamnx_=nx; beamny_=ny; } | 
|---|
|  | 144 |  | 
|---|
| [3947] | 145 | // Calcul la reponse ds le plan 2D  (u,v) = (kx,ky) | 
|---|
|  | 146 | void ComputeResponse(); | 
|---|
|  | 147 | // Retourne la reponse 2D ds le plan (u,v) = (kx,ky) sous forme d'histo 2D | 
|---|
| [3756] | 148 | Histo2D GetResponse(); | 
|---|
|  | 149 |  | 
|---|
| [3947] | 150 | // Retourne le niveau moyen du bruit projete 1D en fonction (sqrt(u^2+v^2) | 
|---|
|  | 151 | HProf GetProjNoiseLevel(int nbin=128, bool fgnorm1=true); | 
|---|
|  | 152 | // Retourne la reponse moyenne projetee 1D en fonction (sqrt(u^2+v^2) | 
|---|
|  | 153 | HProf GetProjResponse(int nbin=128, bool fgnorm1=true); | 
|---|
|  | 154 |  | 
|---|
| [3756] | 155 | double CumulResp(Four2DResponse& rd, double theta=0., double phi=0.); | 
|---|
|  | 156 | inline size_t NbDishes() { return dishes_.size(); } | 
|---|
| [3769] | 157 | inline Dish&  operator[](size_t k) { return dishes_[k]; } | 
|---|
| [3756] | 158 |  | 
|---|
| [3769] | 159 | virtual Histo2D PosDist(int nx=30, int ny=30, double dmax=0.); | 
|---|
|  | 160 |  | 
|---|
|  | 161 | protected: | 
|---|
| [3756] | 162 | double AddToHisto(double kx0, double ky0, double x, double y, double w, bool fgfh); | 
|---|
|  | 163 |  | 
|---|
| [3947] | 164 | double lambda_, dmax_, kmax_; | 
|---|
| [3756] | 165 | vector<Dish> dishes_; | 
|---|
|  | 166 | bool fgnoauto_; | 
|---|
|  | 167 | double thetamax_, phimax_; | 
|---|
|  | 168 | int ntet_,nphi_; | 
|---|
| [3933] | 169 | int nx_, ny_;   // nb de bins de l'histo de reponse | 
|---|
|  | 170 | int beamnx_, beamny_; // nb de points d'echantillonnage du beam | 
|---|
|  | 171 |  | 
|---|
| [3756] | 172 | //   Histo2D h2w_, h2cnt_; | 
|---|
|  | 173 | QHis2D h2w_; | 
|---|
| [3947] | 174 | bool fgcomputedone_; | 
|---|
| [3756] | 175 | int mcnt_; | 
|---|
| [3932] | 176 | int prtlev_,prtmodulo_; | 
|---|
| [3756] | 177 | }; | 
|---|
|  | 178 |  | 
|---|
|  | 179 |  | 
|---|
|  | 180 | #endif | 
|---|