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