| 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 configId OutPPFName [z_Redshift=0.7] [RenormalizeMax]
|
|---|
| 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 | // ------------------ MAIN PROGRAM ------------------------------
|
|---|
| 42 | int main(int narg, const char* arg[])
|
|---|
| 43 | {
|
|---|
| 44 | if (((narg>1)&&(strcmp(arg[1],"-h")==0))||(narg<3)) {
|
|---|
| 45 | cout << " Usage: repicon configId OutPPFName [z_redshift=0.7] [RenormalizeMax] \n"
|
|---|
| 46 | << " configs: f4x4 , f8x8 , f20x20 Filled array of nxn dishes \n"
|
|---|
| 47 | << " confA , confB, confC, confD : semi-filled array of dishes \n"
|
|---|
| 48 | << " hex12 : ASKAP like double hexagonal array of dishes \n"
|
|---|
| 49 | << " f3cyl, f8cyl , f3cylp, f8cylp : filled array of non perfect/perfect of n cylinders " << endl;
|
|---|
| 50 | return 1;
|
|---|
| 51 | }
|
|---|
| 52 | cout << " ==== repicon.cc program , (u,v) plane response ==== " << endl;
|
|---|
| 53 | // make sure SOPHYA modules are initialized
|
|---|
| 54 | SophyaInit();
|
|---|
| 55 | // FitsIOServerInit();
|
|---|
| 56 | InitTim();
|
|---|
| 57 | //--- decoding command line arguments
|
|---|
| 58 | string config = "f8x8" ;
|
|---|
| 59 | if (narg>1) config = arg[1];
|
|---|
| 60 | string outfile = "repicon.ppf";
|
|---|
| 61 | if (narg>2) outfile = arg[2];
|
|---|
| 62 | if (outfile==".") outfile = "repicon.ppf";
|
|---|
| 63 | double LAMBDA=0.357 ; // 21 cm at z=0.7
|
|---|
| 64 | if (narg>3) LAMBDA = atof(arg[3]);
|
|---|
| 65 | bool fgrenorm=false;
|
|---|
| 66 | double rmax=1.;
|
|---|
| 67 | if (narg>4) {
|
|---|
| 68 | rmax=atof(arg[4]);
|
|---|
| 69 | fgrenorm=true;
|
|---|
| 70 | }
|
|---|
| 71 | //-- end command line arguments
|
|---|
| 72 |
|
|---|
| 73 | int rc = 1;
|
|---|
| 74 | try { // exception handling try bloc at top level
|
|---|
| 75 |
|
|---|
| 76 | double Ddish = 5.;
|
|---|
| 77 | double Ddish2 = 7.5;
|
|---|
| 78 | double Eta=0.95;
|
|---|
| 79 | double cylW=12.; // Largeur des cylindres
|
|---|
| 80 | double cylRL=0.5; // Longeur des elements de reception le long du cylindre
|
|---|
| 81 | double etaW=0.95; // Efficacite de couverture en largeur
|
|---|
| 82 | double etaRL=0.9; // Efficacite de couverture le long du cylindre
|
|---|
| 83 |
|
|---|
| 84 | double D = 100.; // Taille de la zone
|
|---|
| 85 |
|
|---|
| 86 | int cnt=0;
|
|---|
| 87 |
|
|---|
| 88 | vector<Dish> vdishes;
|
|---|
| 89 | cout << " repicon[1] : creating dish vector/ MultiDish for configuration: " << config << endl;
|
|---|
| 90 |
|
|---|
| 91 | bool fgpoint=false;
|
|---|
| 92 | if (config=="f4x4") {
|
|---|
| 93 | vdishes=CreateFilledSqConfig(4,Ddish, Eta);
|
|---|
| 94 | }
|
|---|
| 95 | else if (config=="f8x8") {
|
|---|
| 96 | vdishes=CreateFilledSqConfig(8,Ddish, Eta);
|
|---|
| 97 | }
|
|---|
| 98 | else if (config=="f20x20") {
|
|---|
| 99 | vdishes=CreateFilledSqConfig(20,Ddish, Eta);
|
|---|
| 100 | }
|
|---|
| 101 | else if (config=="f3cyl") {
|
|---|
| 102 | cylW=10.; cylRL=0.5;
|
|---|
| 103 | vdishes=CreateFilledCylConfig(3, 128, cylW, cylRL, etaW, etaRL, true);
|
|---|
| 104 | }
|
|---|
| 105 | else if (config=="f3cylp") {
|
|---|
| 106 | cylW=10.; cylRL=0.5;
|
|---|
| 107 | vdishes=CreateFilledCylConfig(3, 128, cylW, cylRL, etaW, etaRL, false);
|
|---|
| 108 | }
|
|---|
| 109 | else if (config=="f8cyl") {
|
|---|
| 110 | cylW=12.; cylRL=0.5;
|
|---|
| 111 | vdishes=CreateFilledCylConfig(8, 192, cylW, cylRL, etaW, etaRL, true);
|
|---|
| 112 | }
|
|---|
| 113 | else if (config=="f8cylp") {
|
|---|
| 114 | cylW=12.; cylRL=0.5;
|
|---|
| 115 | vdishes=CreateFilledCylConfig(8, 192, cylW, cylRL, etaW, etaRL, false);
|
|---|
| 116 | }
|
|---|
| 117 | else if (config=="confA") {
|
|---|
| 118 | fgpoint=true;
|
|---|
| 119 | vdishes=CreateConfigA(Ddish, Eta);
|
|---|
| 120 | }
|
|---|
| 121 | else if (config=="confB") {
|
|---|
| 122 | fgpoint=true;
|
|---|
| 123 | vdishes=CreateConfigB(Ddish, Eta);
|
|---|
| 124 | }
|
|---|
| 125 | else if (config=="confC") {
|
|---|
| 126 | fgpoint=true;
|
|---|
| 127 | vdishes=CreateConfigC(Ddish, Eta);
|
|---|
| 128 | }
|
|---|
| 129 | else if (config=="confD") {
|
|---|
| 130 | fgpoint=true;
|
|---|
| 131 | vdishes=CreateConfigD(Ddish, Eta);
|
|---|
| 132 | }
|
|---|
| 133 | else if (config=="hex12") {
|
|---|
| 134 | fgpoint=true;
|
|---|
| 135 | Ddish = 12.;
|
|---|
| 136 | Eta=0.95;
|
|---|
| 137 | D=350.;
|
|---|
| 138 | vdishes=CreateDoubleHexagonConfig();
|
|---|
| 139 | }
|
|---|
| 140 | else {
|
|---|
| 141 | cout << " NON valid configuration option -> exit" << endl;
|
|---|
| 142 | return 99;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | double Dol = D/LAMBDA;
|
|---|
| 146 | double LMAX = D;
|
|---|
| 147 | bool fgnoauto = true;
|
|---|
| 148 | int NRX=200;
|
|---|
| 149 | int NRY=200;
|
|---|
| 150 |
|
|---|
| 151 | MultiDish mdish(LAMBDA, LMAX, vdishes, fgnoauto);
|
|---|
| 152 | mdish.SetRespHisNBins(NRX,NRY);
|
|---|
| 153 | if (fgpoint)
|
|---|
| 154 | mdish.SetThetaPhiRange(M_PI/6.,12, M_PI/6., 12);
|
|---|
| 155 | cout << " repicon[2] : calling mdish.GetResponse() ..."<< endl;
|
|---|
| 156 |
|
|---|
| 157 | Histo2D hrep = mdish.GetResponse();
|
|---|
| 158 | PrtTim("Apres mdish.GetResponse()");
|
|---|
| 159 |
|
|---|
| 160 | Four2DRespTable mdresp(hrep, Dol, LAMBDA);
|
|---|
| 161 | if (fgrenorm) {
|
|---|
| 162 | cout << " repicon[2.b] call to mdresp.renormalize(" << rmax << ")";
|
|---|
| 163 | double omax=mdresp.renormalize(rmax);
|
|---|
| 164 | cout << " Old Max=" << omax << endl;
|
|---|
| 165 | }
|
|---|
| 166 | cout << " repicon[3] : saving Four2DRespTable for config " << config << " to PPF file " << outfile << endl;
|
|---|
| 167 | mdresp.writeToPPF(outfile);
|
|---|
| 168 |
|
|---|
| 169 | string outfile2 = "hdt_"+outfile;
|
|---|
| 170 | cout << " repicon[4] : saving H2D-response, multidish config to PPF file " << outfile2 << endl;
|
|---|
| 171 | SaveDTVecDishesH2Resp(outfile2, vdishes, mdresp);
|
|---|
| 172 |
|
|---|
| 173 | rc = 0;
|
|---|
| 174 | } // End of try bloc
|
|---|
| 175 | catch (PThrowable & exc) { // catching SOPHYA exceptions
|
|---|
| 176 | cerr << " repicon.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
|---|
| 177 | << "\n...exc.Msg= " << exc.Msg() << endl;
|
|---|
| 178 | rc = 99;
|
|---|
| 179 | }
|
|---|
| 180 | catch (std::exception & e) { // catching standard C++ exceptions
|
|---|
| 181 | cerr << " repicon.cc: Catched std::exception " << " - what()= " << e.what() << endl;
|
|---|
| 182 | rc = 98;
|
|---|
| 183 | }
|
|---|
| 184 | catch (...) { // catching other exceptions
|
|---|
| 185 | cerr << " repicon.cc: some other exception (...) was caught ! " << endl;
|
|---|
| 186 | rc = 97;
|
|---|
| 187 | }
|
|---|
| 188 | PrtTim("End-repicon");
|
|---|
| 189 | cout << " ==== End of repicon.cc program Rc= " << rc << endl;
|
|---|
| 190 | return rc;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | /*-- Nouvelle-Fonction --*/
|
|---|
| 194 | void SaveDTVecDishesH2Resp(string& outfile, vector<Dish>& vdishes, Four2DRespTable& mdresp)
|
|---|
| 195 | {
|
|---|
| 196 | char* names[5]={"did","posx","posy","diam","diamy"};
|
|---|
| 197 | NTuple ntvd(5,names,64,false);
|
|---|
| 198 | r_4 xnt[10];
|
|---|
| 199 | for(size_t i=0; i<vdishes.size(); i++) {
|
|---|
| 200 | xnt[0]=vdishes[i].ReflectorId();
|
|---|
| 201 | xnt[1]=vdishes[i].X;
|
|---|
| 202 | xnt[2]=vdishes[i].Y;
|
|---|
| 203 | if (vdishes[i].isCircular()) {
|
|---|
| 204 | xnt[3]=vdishes[i].Diameter();
|
|---|
| 205 | xnt[4]=0.;
|
|---|
| 206 | }
|
|---|
| 207 | else {
|
|---|
| 208 | xnt[3]=vdishes[i].DiameterX();
|
|---|
| 209 | xnt[4]=vdishes[i].DiameterY();
|
|---|
| 210 | }
|
|---|
| 211 | ntvd.Fill(xnt);
|
|---|
| 212 | }
|
|---|
| 213 | Histo2D h2rep=mdresp.GetResponse();
|
|---|
| 214 | POutPersist po(outfile);
|
|---|
| 215 | po << PPFNameTag("mdish") << ntvd;
|
|---|
| 216 | po << PPFNameTag("h2rep") << h2rep;
|
|---|
| 217 | return;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|