| 1 | /*  ------------------------ Projet BAORadio -------------------- 
 | 
|---|
| 2 |   Calcul de la reponse 2D (plan (u,v) d'un interferometre 
 | 
|---|
| 3 |     R. Ansari , C. Magneville - Juin-Dec 2010 
 | 
|---|
| 4 | 
 | 
|---|
| 5 |   Usage:  repicon [-parname value] configId OutPPFName 
 | 
|---|
| 6 | ---------------------------------------------------------------  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "machdefs.h"
 | 
|---|
| 9 | #include "sopnamsp.h"
 | 
|---|
| 10 | #include <iostream>
 | 
|---|
| 11 | #include <string>
 | 
|---|
| 12 | #include <math.h>
 | 
|---|
| 13 | 
 | 
|---|
| 14 | #include <typeinfo>
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "mdish.h"
 | 
|---|
| 17 | #include "specpk.h"
 | 
|---|
| 18 | #include "interfconfigs.h"
 | 
|---|
| 19 | #include "radutil.h"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "ntuple.h"
 | 
|---|
| 22 | #include "histinit.h"
 | 
|---|
| 23 | // #include "fiosinit.h"
 | 
|---|
| 24 | // #include "fitsioserver.h"
 | 
|---|
| 25 | 
 | 
|---|
| 26 | #include "randr48.h"      
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #include "timing.h"
 | 
|---|
| 29 | #include "ctimer.h"
 | 
|---|
| 30 | 
 | 
|---|
| 31 | typedef DR48RandGen RandomGenerator ;
 | 
|---|
| 32 | 
 | 
|---|
| 33 | // pour sauver la reponse mdresp et la config des dishes dans un fichier PPF 
 | 
|---|
| 34 | void SaveDTVecDishesH2Resp(string& outfile, vector<Dish>& vdishes, Four2DRespTable& mdresp);
 | 
|---|
| 35 | 
 | 
|---|
| 36 | // ---------------------------------------------------------------------
 | 
|---|
| 37 | // main program for computing interferometer response un (u,v) plane
 | 
|---|
| 38 | // R. Ansari  - Avril-Juin 2010 
 | 
|---|
| 39 | // ---------------------------------------------------------------------
 | 
|---|
| 40 | 
 | 
|---|
| 41 | void Usage() 
 | 
|---|
| 42 | {
 | 
|---|
| 43 |   cout << " Usage: repicon [-parname Value] configId OutPPFName \n" 
 | 
|---|
| 44 |        << " configIds: f4x4,f8x8,f20x20, confA,confB,confC,confD, hex12,cross11, f3cyl,f8cyl,f3cylp,f8cylp \n"
 | 
|---|
| 45 |        << "   f4x4 , f8x8 , f20x20 Filled array of nxn dishes  \n" 
 | 
|---|
| 46 |        << "   confA , confB, confC, confD : semi-filled array of dishes \n"
 | 
|---|
| 47 |        << "   hex12,cross11 : ASKAP like double hexagonal (12xD=12m), cross config (11xD=12m) \n"
 | 
|---|
| 48 |        << "   f3cyl, f8cyl , f3cylp, f8cylp : filled array of non perfect/perfect of n cylinders \n"
 | 
|---|
| 49 |        << "   f4cylw : filled array of 4 perfect of wide cylinders \n"
 | 
|---|
| 50 |        << "  [ -parname value] : -renmax -z -prt -D -lmax \n" 
 | 
|---|
| 51 |        << "    -renmax MaxValue (default : Do NOT renormalize 2D response value \n"   
 | 
|---|
| 52 |        << "    -z redshift (default=0.7) --> determines Lambda \n"
 | 
|---|
| 53 |        << "    -D DishDiameter (default=5 m) \n"
 | 
|---|
| 54 |        << "    -lmax array extension (default=100 m ) for response calculation kmax \n" 
 | 
|---|
| 55 |        << "    -repnxy Nx,Ny (default=200,200) ResponseTable binning \n"
 | 
|---|
| 56 |        << "    -beamnxy Nx,Ny (default=200,200) Beam sampling \n"
 | 
|---|
| 57 |        << "    -rot ThetaMaxDeg,NTheta,PhiMaxDeg,NPhi (default NO-rotate/pointing -> 23,10,30,15 ) \n" 
 | 
|---|
| 58 |        << "    -prt PrtLev,PrtModulo (default=0,10) \n" 
 | 
|---|
| 59 |        << endl; 
 | 
|---|
| 60 |   return;
 | 
|---|
| 61 | }
 | 
|---|
| 62 | 
 | 
|---|
| 63 | //      ------------------ MAIN PROGRAM ------------------------------
 | 
|---|
| 64 | int main(int narg, const char* arg[])
 | 
|---|
| 65 | {
 | 
|---|
| 66 |   if (((narg>1)&&(strcmp(arg[1],"-h")==0))||(narg<3))  {
 | 
|---|
| 67 |     Usage();
 | 
|---|
| 68 |     return 1;
 | 
|---|
| 69 |   }
 | 
|---|
| 70 |   // make sure SOPHYA modules are initialized 
 | 
|---|
| 71 |   SophyaInit();  
 | 
|---|
| 72 |   //  FitsIOServerInit();
 | 
|---|
| 73 |   InitTim();
 | 
|---|
| 74 |   //--- decoding command line arguments 
 | 
|---|
| 75 |   string config = "f8x8" ;
 | 
|---|
| 76 |   string outfile = "repicon.ppf";  
 | 
|---|
| 77 |   bool fgrenorm=false;
 | 
|---|
| 78 |   double rmax=1.;
 | 
|---|
| 79 |   double z_Redshift=0.7 ;  // 21 cm at z=0.7 -> 0.357 m  
 | 
|---|
| 80 |   int prtlev=0;
 | 
|---|
| 81 |   int prtmod=10;
 | 
|---|
| 82 |   
 | 
|---|
| 83 |   double Ddish=5.;
 | 
|---|
| 84 |   bool fgDfixed=false;
 | 
|---|
| 85 |   double LMAX = 100.;  // taille de la zone, pour calcul kmax 
 | 
|---|
| 86 |   bool fgLMAXfixed=false;
 | 
|---|
| 87 |   double thetamxdeg=23.;  // 23 degres : angle d'inclinaison de l'orbite terrestre
 | 
|---|
| 88 |   double phimxdeg=30.;
 | 
|---|
| 89 |   int nteta=10;
 | 
|---|
| 90 |   int nphi=15;
 | 
|---|
| 91 |   bool fgpoint=false;
 | 
|---|
| 92 |   int NRX=200;
 | 
|---|
| 93 |   int NRY=200;
 | 
|---|
| 94 |   int NBX=200;
 | 
|---|
| 95 |   int NBY=200;
 | 
|---|
| 96 |   
 | 
|---|
| 97 |   int ka=1;
 | 
|---|
| 98 |   while (ka<(narg-1)) {
 | 
|---|
| 99 |     if (strcmp(arg[ka],"-renmax")==0) {
 | 
|---|
| 100 |       rmax=atof(arg[ka+1]);  fgrenorm=true;   ka+=2;
 | 
|---|
| 101 |     }
 | 
|---|
| 102 |     else if (strcmp(arg[ka],"-z")==0) {
 | 
|---|
| 103 |       z_Redshift=atof(arg[ka+1]);  ka+=2;
 | 
|---|
| 104 |     }
 | 
|---|
| 105 |     else if (strcmp(arg[ka],"-D")==0) {
 | 
|---|
| 106 |       Ddish=atof(arg[ka+1]);  fgDfixed=true;  ka+=2;
 | 
|---|
| 107 |     }
 | 
|---|
| 108 |     else if (strcmp(arg[ka],"-lmax")==0) {
 | 
|---|
| 109 |       LMAX=atof(arg[ka+1]);  fgLMAXfixed=true;  ka+=2;
 | 
|---|
| 110 |     }
 | 
|---|
| 111 |     else if (strcmp(arg[ka],"-repnxy")==0) {
 | 
|---|
| 112 |       sscanf(arg[ka+1],"%d,%d",&NRX,&NRY);   ka+=2;
 | 
|---|
| 113 |     }
 | 
|---|
| 114 |     else if (strcmp(arg[ka],"-beamnxy")==0) {
 | 
|---|
| 115 |       sscanf(arg[ka+1],"%d,%d",&NBX,&NBY);   ka+=2;
 | 
|---|
| 116 |     }
 | 
|---|
| 117 |     else if (strcmp(arg[ka],"-rot")==0) {
 | 
|---|
| 118 |       sscanf(arg[ka+1],"%lg,%d,%lg,%d",&thetamxdeg,&nteta,&phimxdeg,&nphi);  fgpoint=true;  ka+=2;
 | 
|---|
| 119 |     }
 | 
|---|
| 120 |     else if (strcmp(arg[ka],"-prt")==0) {
 | 
|---|
| 121 |       sscanf(arg[ka+1],"%d,%d",&prtlev,&prtmod);   ka+=2;
 | 
|---|
| 122 |     }
 | 
|---|
| 123 |     else break; 
 | 
|---|
| 124 |   }
 | 
|---|
| 125 | 
 | 
|---|
| 126 |   if ((ka+1)>=narg) {
 | 
|---|
| 127 |     cout << " repicon / Argument error " << endl;
 | 
|---|
| 128 |     Usage();
 | 
|---|
| 129 |     return 2;
 | 
|---|
| 130 |   }
 | 
|---|
| 131 | 
 | 
|---|
| 132 |   config = arg[ka];
 | 
|---|
| 133 |   outfile = arg[ka+1];
 | 
|---|
| 134 |   //-- end command line arguments
 | 
|---|
| 135 |   
 | 
|---|
| 136 |   int rc = 1;  
 | 
|---|
| 137 |   try {  // exception handling try bloc at top level
 | 
|---|
| 138 |     cout << " ==== repicon.cc program , (u,v) plane response ==== " << endl;
 | 
|---|
| 139 | 
 | 
|---|
| 140 |     H21Conversions conv;
 | 
|---|
| 141 |     double LAMBDA=0.357 ;  // 21 cm at z=0.7 
 | 
|---|
| 142 |     conv.setRedshift(z_Redshift);
 | 
|---|
| 143 |     LAMBDA = conv.getLambda();
 | 
|---|
| 144 |     
 | 
|---|
| 145 |     double Eta=0.95;
 | 
|---|
| 146 |     double cylW=12.;   // Largeur des cylindres 
 | 
|---|
| 147 |     double cylRL=2*LAMBDA;  // Longeur des elements de reception le long du cylindre
 | 
|---|
| 148 |     double etaW=0.95;   // Efficacite de couverture en largeur
 | 
|---|
| 149 |     double etaRL=0.9;   // Efficacite de couverture le long du cylindre
 | 
|---|
| 150 | 
 | 
|---|
| 151 |     vector<Dish> vdishes;
 | 
|---|
| 152 |     cout << " repicon[1] : creating dish vector/ MultiDish for configuration: " << config << endl;
 | 
|---|
| 153 | 
 | 
|---|
| 154 |     if (config=="f4x4") {
 | 
|---|
| 155 |       vdishes=CreateFilledSqConfig(4,Ddish, Eta);
 | 
|---|
| 156 |     }
 | 
|---|
| 157 |     else if (config=="f8x8") {
 | 
|---|
| 158 |       vdishes=CreateFilledSqConfig(8,Ddish, Eta);
 | 
|---|
| 159 |     }
 | 
|---|
| 160 |     else if (config=="f20x20") {
 | 
|---|
| 161 |       vdishes=CreateFilledSqConfig(20,Ddish, Eta);
 | 
|---|
| 162 |     }
 | 
|---|
| 163 |     else if (config=="f3cyl") {
 | 
|---|
| 164 |       cylW=10.;   cylRL=2*LAMBDA; 
 | 
|---|
| 165 |       vdishes=CreateFilledCylConfig(3, 92, cylW, cylRL, etaW, etaRL, true);
 | 
|---|
| 166 |     }
 | 
|---|
| 167 |     else if (config=="f3cylp") {
 | 
|---|
| 168 |       cylW=10.;   cylRL=2*LAMBDA; 
 | 
|---|
| 169 |       vdishes=CreateFilledCylConfig(3, 92, cylW, cylRL, etaW, etaRL, false);
 | 
|---|
| 170 |     }
 | 
|---|
| 171 |     else if (config=="f4cylw") {
 | 
|---|
| 172 |       cylW=25.;   cylRL=3*LAMBDA; 
 | 
|---|
| 173 |       vdishes=CreateFilledCylConfig(4, 100, cylW, cylRL, etaW, etaRL, false);
 | 
|---|
| 174 |     }
 | 
|---|
| 175 |     else if (config=="f8cyl") {
 | 
|---|
| 176 |       cylW=12.;   cylRL=2*LAMBDA; 
 | 
|---|
| 177 |       vdishes=CreateFilledCylConfig(8, 160, cylW, cylRL, etaW, etaRL, true);
 | 
|---|
| 178 |     }
 | 
|---|
| 179 |     else if (config=="f8cylp") {
 | 
|---|
| 180 |       cylW=12.;   cylRL=2*LAMBDA; 
 | 
|---|
| 181 |       vdishes=CreateFilledCylConfig(8, 160, cylW, cylRL, etaW, etaRL, false);
 | 
|---|
| 182 |     }
 | 
|---|
| 183 |     else if (config=="confA") {
 | 
|---|
| 184 |       vdishes=CreateConfigA(Ddish, Eta);
 | 
|---|
| 185 |     }
 | 
|---|
| 186 |     else if (config=="confB") {
 | 
|---|
| 187 |       vdishes=CreateConfigB(Ddish, Eta);
 | 
|---|
| 188 |     }
 | 
|---|
| 189 |     else if (config=="confC") {
 | 
|---|
| 190 |       vdishes=CreateConfigC(Ddish, Eta);
 | 
|---|
| 191 |     }
 | 
|---|
| 192 |     else if (config=="confD") {
 | 
|---|
| 193 |       vdishes=CreateConfigD(Ddish, Eta);
 | 
|---|
| 194 |     }
 | 
|---|
| 195 |     else if (config=="cross11") {
 | 
|---|
| 196 |       if (!fgDfixed) Ddish = 12.;
 | 
|---|
| 197 |       double base=20.;
 | 
|---|
| 198 |       Eta=0.95;
 | 
|---|
| 199 |       if (!fgLMAXfixed) LMAX = 250.;
 | 
|---|
| 200 |       vdishes=CreateCrossConfig(Ddish,base,Eta);
 | 
|---|
| 201 |     }
 | 
|---|
| 202 |     else if (config=="hex12") {
 | 
|---|
| 203 |       if (!fgDfixed) Ddish = 12.;
 | 
|---|
| 204 |       Eta=0.95;
 | 
|---|
| 205 |       if (!fgLMAXfixed) LMAX = 350.;
 | 
|---|
| 206 |       vdishes=CreateDoubleHexagonConfig(Ddish);
 | 
|---|
| 207 |     }
 | 
|---|
| 208 |     else {
 | 
|---|
| 209 |       cout << " NON valid configuration option -> exit" << endl;
 | 
|---|
| 210 |       return 99;
 | 
|---|
| 211 |     }
 | 
|---|
| 212 |         
 | 
|---|
| 213 |     double Dol = LMAX/LAMBDA;
 | 
|---|
| 214 |     bool fgnoauto = true;
 | 
|---|
| 215 |     
 | 
|---|
| 216 |     cout << " repicon[1] : Lambda=" << LAMBDA << " LMAX= " << LMAX << " NDishes=" << vdishes.size() 
 | 
|---|
| 217 |          << " D-Dish=" << Ddish << " m." << endl;
 | 
|---|
| 218 |  
 | 
|---|
| 219 |     MultiDish mdish(LAMBDA, LMAX, vdishes, fgnoauto);
 | 
|---|
| 220 |     mdish.SetPrtLevel(prtlev,prtmod);
 | 
|---|
| 221 |     mdish.SetRespHisNBins(NRX,NRY); 
 | 
|---|
| 222 |     mdish.SetBeamNSamples(NBX,NBY);
 | 
|---|
| 223 |     if (fgpoint)  {
 | 
|---|
| 224 |       cout << " repicon[1.b] : activating pointing , ThetaMaxDeg=" << thetamxdeg << " NTheta=" << nteta
 | 
|---|
| 225 |            << "  PhiMaxDeg= " << phimxdeg << " NPhi=" << nphi << endl;
 | 
|---|
| 226 |       mdish.SetThetaPhiRange(Angle(thetamxdeg,Angle::Degree).ToRadian(),nteta,Angle(phimxdeg,Angle::Degree).ToRadian(), nphi);
 | 
|---|
| 227 |     }
 | 
|---|
| 228 |     cout << " repicon[2] : calling mdish.GetResponse() ..."<< endl;
 | 
|---|
| 229 | 
 | 
|---|
| 230 |     Histo2D hrep = mdish.GetResponse();
 | 
|---|
| 231 |     PrtTim("Apres mdish.GetResponse()");
 | 
|---|
| 232 | 
 | 
|---|
| 233 |     Four2DRespTable mdresp(hrep, Dol, LAMBDA);
 | 
|---|
| 234 |     if (fgrenorm) {
 | 
|---|
| 235 |       cout << " repicon[2.b] call to mdresp.renormalize(" << rmax << ")"; 
 | 
|---|
| 236 |       double omax=mdresp.renormalize(rmax);
 | 
|---|
| 237 |       cout << " Old Max=" << omax << endl;
 | 
|---|
| 238 |     }
 | 
|---|
| 239 |     cout << " repicon[3] : saving Four2DRespTable for config " << config << " to PPF file " << outfile << endl;
 | 
|---|
| 240 |     mdresp.writeToPPF(outfile);
 | 
|---|
| 241 | 
 | 
|---|
| 242 |     string outfile2 = "hdt_"+outfile;
 | 
|---|
| 243 |     cout << " repicon[4] : saving H2D-response, multidish config to PPF file " << outfile2 << endl;
 | 
|---|
| 244 |     SaveDTVecDishesH2Resp(outfile2, vdishes, mdresp);
 | 
|---|
| 245 | 
 | 
|---|
| 246 |     rc = 0;
 | 
|---|
| 247 |   }  // End of try bloc 
 | 
|---|
| 248 |   catch (PThrowable & exc) {  // catching SOPHYA exceptions
 | 
|---|
| 249 |     cerr << " repicon.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name() 
 | 
|---|
| 250 |          << "\n...exc.Msg= " << exc.Msg() << endl;
 | 
|---|
| 251 |     rc = 99;
 | 
|---|
| 252 |   }
 | 
|---|
| 253 |   catch (std::exception & e) {  // catching standard C++ exceptions
 | 
|---|
| 254 |     cerr << " repicon.cc: Catched std::exception "  << " - what()= " << e.what() << endl;
 | 
|---|
| 255 |     rc = 98;
 | 
|---|
| 256 |   }
 | 
|---|
| 257 |   catch (...) {  // catching other exceptions
 | 
|---|
| 258 |     cerr << " repicon.cc: some other exception (...) was caught ! " << endl;
 | 
|---|
| 259 |     rc = 97;
 | 
|---|
| 260 |   }
 | 
|---|
| 261 |   PrtTim("End-repicon");
 | 
|---|
| 262 |   cout << " ==== End of repicon.cc program  Rc= " << rc << endl;
 | 
|---|
| 263 |   return rc;    
 | 
|---|
| 264 | }
 | 
|---|
| 265 | 
 | 
|---|
| 266 | /*-- Nouvelle-Fonction --*/
 | 
|---|
| 267 | void SaveDTVecDishesH2Resp(string& outfile, vector<Dish>& vdishes, Four2DRespTable& mdresp)
 | 
|---|
| 268 | {
 | 
|---|
| 269 |   char* names[5]={"did","posx","posy","diam","diamy"};
 | 
|---|
| 270 |   NTuple ntvd(5,names,64,false);
 | 
|---|
| 271 |   r_4 xnt[10];
 | 
|---|
| 272 |   for(size_t i=0; i<vdishes.size(); i++) {
 | 
|---|
| 273 |     xnt[0]=vdishes[i].ReflectorId();
 | 
|---|
| 274 |     xnt[1]=vdishes[i].X;
 | 
|---|
| 275 |     xnt[2]=vdishes[i].Y;
 | 
|---|
| 276 |     if (vdishes[i].isCircular()) {
 | 
|---|
| 277 |       xnt[3]=vdishes[i].Diameter();
 | 
|---|
| 278 |       xnt[4]=0.;
 | 
|---|
| 279 |     }
 | 
|---|
| 280 |     else {
 | 
|---|
| 281 |       xnt[3]=vdishes[i].DiameterX();
 | 
|---|
| 282 |       xnt[4]=vdishes[i].DiameterY();      
 | 
|---|
| 283 |     }
 | 
|---|
| 284 |     ntvd.Fill(xnt);
 | 
|---|
| 285 |   }
 | 
|---|
| 286 |   Histo2D h2rep=mdresp.GetResponse();
 | 
|---|
| 287 |   POutPersist po(outfile);
 | 
|---|
| 288 |   po << PPFNameTag("mdish") << ntvd;
 | 
|---|
| 289 |   po << PPFNameTag("h2rep") << h2rep;
 | 
|---|
| 290 |   return;
 | 
|---|
| 291 | }
 | 
|---|
| 292 | 
 | 
|---|