source: Sophya/trunk/Cosmo/RadioBeam/repicon.cc@ 3934

Last change on this file since 3934 was 3933, checked in by ansari, 15 years ago

correction/amelioration calcul reponse multi-dish ds plan (u,v), Reza 24/12/2010

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