1 | #include "machdefs.h"
|
---|
2 | #include "sopnamsp.h"
|
---|
3 | #include <iostream>
|
---|
4 | #include <string>
|
---|
5 | #include <math.h>
|
---|
6 |
|
---|
7 | #include <typeinfo>
|
---|
8 |
|
---|
9 | #include "mdish.h"
|
---|
10 | #include "specpk.h"
|
---|
11 | #include "histinit.h"
|
---|
12 | // #include "fiosinit.h"
|
---|
13 | // #include "fitsioserver.h"
|
---|
14 |
|
---|
15 | #include "randr48.h"
|
---|
16 |
|
---|
17 | #include "timing.h"
|
---|
18 | #include "ctimer.h"
|
---|
19 |
|
---|
20 | typedef DR48RandGen RandomGenerator ;
|
---|
21 |
|
---|
22 | // ---------------------------------------------------------------------
|
---|
23 | // Test main program for computing interferometer noise power spectrum
|
---|
24 | // R. Ansari - Avril 2010
|
---|
25 | // ---------------------------------------------------------------------
|
---|
26 |
|
---|
27 | class PkNoiseCalculator
|
---|
28 | {
|
---|
29 | public:
|
---|
30 | PkNoiseCalculator(Four3DPk& pk3, Four2DResponse& rep,
|
---|
31 | double s2cut=100., int ngen=1, const char* tit="PkNoise")
|
---|
32 | : pkn3d(pk3), frep(rep), S2CUT(s2cut), NGEN(ngen), title(tit)
|
---|
33 | { }
|
---|
34 | inline void SetS2Cut(double s2cut=100.)
|
---|
35 | { S2CUT=s2cut; }
|
---|
36 | HProf Compute()
|
---|
37 | {
|
---|
38 | Timer tm(title.c_str());
|
---|
39 | tm.Nop();
|
---|
40 | HProf hnd;
|
---|
41 | cout << "PkNoiseCalculator::Compute() " << title << " NGEN=" << NGEN << " S2CUT=" << S2CUT << endl;
|
---|
42 | for(int igen=0; igen<NGEN; igen++) {
|
---|
43 | pkn3d.ComputeNoiseFourierAmp(frep);
|
---|
44 | if (igen==0) hnd = pkn3d.ComputePk(S2CUT);
|
---|
45 | else pkn3d.ComputePkCumul(hnd,S2CUT);
|
---|
46 | }
|
---|
47 | return hnd;
|
---|
48 | }
|
---|
49 |
|
---|
50 | Four3DPk& pkn3d;
|
---|
51 | Four2DResponse& frep;
|
---|
52 | double S2CUT;
|
---|
53 | int NGEN;
|
---|
54 | string title;
|
---|
55 | };
|
---|
56 |
|
---|
57 | int main(int narg, const char* arg[])
|
---|
58 | {
|
---|
59 | if ((narg>1)&&(strcmp(arg[1],"-h")==0)) {
|
---|
60 | cout<< " Usage: pknoise [OutPPFName NGen S2Cut Lambda] " << endl;
|
---|
61 | cout<< " Default: OutPPFName=pknoise.ppf, NGen=1 " << endl;
|
---|
62 | cout<< " S2CUT=0. , Lambda=0.357 \n" << endl;
|
---|
63 |
|
---|
64 | return 1;
|
---|
65 | }
|
---|
66 | cout << " ==== pknoise.cc program , test of SpectralShape and MassDist2D classes ==== " << endl;
|
---|
67 | // make sure SOPHYA modules are initialized
|
---|
68 | SophyaInit();
|
---|
69 | // FitsIOServerInit();
|
---|
70 | InitTim();
|
---|
71 | //--- decoding command line arguments
|
---|
72 | string outfile = "pknoise.ppf";
|
---|
73 | if (narg>1) outfile = arg[1];
|
---|
74 | if (outfile==".") outfile = "pknoise.ppf";
|
---|
75 | int NMAX = 1;
|
---|
76 | if (narg>2) NMAX = atoi(arg[2]);
|
---|
77 | double SCut=0.;
|
---|
78 | if (narg>3) SCut = atof(arg[3]);
|
---|
79 | double LAMBDA=0.357 ; // 21 cm at z=0.7
|
---|
80 | if (narg>4) LAMBDA = atof(arg[4]);
|
---|
81 |
|
---|
82 | //-- end command line arguments
|
---|
83 |
|
---|
84 | int rc = 1;
|
---|
85 | try { // exception handling try bloc at top level
|
---|
86 | cout << "0/ pknoise.cc: Executing, output file= " << outfile << endl;
|
---|
87 | POutPersist po(outfile);
|
---|
88 | cout << " 1.a/ Instanciating object type SpectralShape " << endl;
|
---|
89 | SpectralShape spec(2);
|
---|
90 | cout << " 1.b/ Wrinting spectral shape vector (name= Pk) to output PPF " << endl;
|
---|
91 | Histo hpk = spec.GetPk(1024);
|
---|
92 | po << PPFNameTag("Pk") << hpk;
|
---|
93 |
|
---|
94 | double D = 100.;
|
---|
95 | double lambda = LAMBDA;
|
---|
96 | double Dol = D/lambda;
|
---|
97 | cout << " 2.a/ Instanciating Four2DResponse(1/2/3...) " << endl;
|
---|
98 | Four2DResponse dishg(1,Dol,Dol);
|
---|
99 | Four2DResponse dish(2,Dol,Dol);
|
---|
100 | Four2DResponse dish2(2,Dol*2.,Dol*2.);
|
---|
101 | Four2DResponse dishsq(3,Dol,Dol/5.);
|
---|
102 | cout << " 2.b/ Writing Four2DResponse Histo2D to output ppf " << endl;
|
---|
103 | Histo2D hdg = dishg.GetResponse();
|
---|
104 | Histo2D hd = dish.GetResponse();
|
---|
105 | Histo2D hd2 = dish2.GetResponse();
|
---|
106 | Histo2D hdsq = dishsq.GetResponse();
|
---|
107 | po << PPFNameTag("dishg") << hdg;
|
---|
108 | po << PPFNameTag("dish") << hd;
|
---|
109 | po << PPFNameTag("dish2") << hd2;
|
---|
110 | po << PPFNameTag("dishsq") << hdsq;
|
---|
111 |
|
---|
112 | cout << " 2.c/ Creating MultiDish Filled Array " << endl;
|
---|
113 | double Ddish = 5.;
|
---|
114 | double Ddish2 = 7.5;
|
---|
115 | double Eta=0.95;
|
---|
116 | int cnt=0;
|
---|
117 | vector<Dish> vdplein;
|
---|
118 | for(int i=0; i<20; i++)
|
---|
119 | for(int j=0; j<20; j++) {
|
---|
120 | cnt++;
|
---|
121 | vdplein.push_back(Dish(i*20+j+1, i*Ddish, j*Ddish, Eta*Ddish));
|
---|
122 | }
|
---|
123 | vector<Dish> vdsparse;
|
---|
124 | vector<Dish> vdsparseD7;
|
---|
125 |
|
---|
126 | cnt=0;
|
---|
127 | for(int i=0; i<=18; i++) {
|
---|
128 | cnt++; vdsparse.push_back(Dish(cnt, i*Ddish,0.,Eta*Ddish));
|
---|
129 | vdsparseD7.push_back(Dish(cnt, i*Ddish2,0.,Eta*Ddish2));
|
---|
130 | }
|
---|
131 | for(int i=-18; i<=18; i++) {
|
---|
132 | if (i==0) continue;
|
---|
133 | cnt++; vdsparse.push_back(Dish(cnt, 0.,i*Ddish,Eta*Ddish));
|
---|
134 | vdsparseD7.push_back(Dish(cnt, 0.,i*Ddish2,Eta*Ddish2));
|
---|
135 | }
|
---|
136 | for(int i=0; i<4; i++) {
|
---|
137 | cnt++; vdsparse.push_back(Dish(cnt, (3+2*i)*Ddish,(3+2*i)*Ddish,Eta*Ddish));
|
---|
138 | vdsparseD7.push_back(Dish(cnt, (3+2*i)*Ddish2,(3+2*i)*Ddish2,Eta*Ddish2));
|
---|
139 | cnt++; vdsparse.push_back(Dish(cnt, (3+2*i)*Ddish,-(3+2*i)*Ddish,Eta*Ddish));
|
---|
140 | vdsparseD7.push_back(Dish(cnt, (3+2*i)*Ddish2,-(3+2*i)*Ddish2,Eta*Ddish2));
|
---|
141 | /*
|
---|
142 | if ((i>0)||(j>0)) {
|
---|
143 | cnt++; vdsparse.push_back(Dish(cnt, (5+3*i)*Ddish,(3+2*j)*Ddish,Eta*Ddish));
|
---|
144 | cnt++; vdsparse.push_back(Dish(cnt, (5+3*i)*Ddish,-(3+2*j)*Ddish,Eta*Ddish));
|
---|
145 | }
|
---|
146 | */
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | vector<Dish> vcylplein, vcylplP;
|
---|
151 | cnt=0;
|
---|
152 | double cylW=12.; // Largeur des cylindres
|
---|
153 | double cylRL=0.5; // Longeur des elements de reception le long du cylindre
|
---|
154 | for(int i=0; i<8; i++)
|
---|
155 | for(int j=0; j<192; j++) {
|
---|
156 | vcylplein.push_back(Dish(i+1, i*cylW, j*cylRL, 0.9*cylW, 0.9*cylRL));
|
---|
157 | cnt++; vcylplP.push_back(Dish(cnt, i*cylW, j*cylRL, 1.*cylW, 1.*cylRL));
|
---|
158 | }
|
---|
159 | vector<Dish> v2cyl, v2cylP;
|
---|
160 | cnt=0;
|
---|
161 | for(int i=0; i<2; i++)
|
---|
162 | for(int j=0; j<32; j++) {
|
---|
163 | v2cyl.push_back(Dish(i+1, i*25, j*cylRL, 0.9*9., 0.9*cylRL));
|
---|
164 | cnt++; v2cylP.push_back(Dish(cnt, i*25, j*cylRL, 0.9*9., 1.*cylRL));
|
---|
165 | }
|
---|
166 | double LMAX = D;
|
---|
167 | bool fgnoauto = true;
|
---|
168 | int NRX=160;
|
---|
169 | int NRY=160;
|
---|
170 |
|
---|
171 | MultiDish mdfill(lambda, LMAX, vdplein, fgnoauto);
|
---|
172 | mdfill.SetRespHisNBins(NRX,NRY);
|
---|
173 | Histo2D hrfill = mdfill.GetResponse();
|
---|
174 | PrtTim("Apres mdfill.GetResponse()");
|
---|
175 |
|
---|
176 | MultiDish mdsparse(lambda, LMAX, vdsparse, fgnoauto);
|
---|
177 | mdsparse.SetThetaPhiRange(M_PI/4.,16, M_PI/4., 16);
|
---|
178 | mdsparse.SetRespHisNBins(NRX,NRY);
|
---|
179 | Histo2D hrsp = mdsparse.GetResponse();
|
---|
180 | PrtTim("Apres mdsparse.GetResponse()");
|
---|
181 |
|
---|
182 | MultiDish mdsparsefp(lambda, LMAX, vdsparse, fgnoauto);
|
---|
183 | mdsparsefp.SetRespHisNBins(NRX,NRY);
|
---|
184 | Histo2D hrspfp = mdsparsefp.GetResponse();
|
---|
185 | PrtTim("Apres mdsparsefp.GetResponse()");
|
---|
186 |
|
---|
187 | MultiDish mdsparseD7(lambda, LMAX, vdsparseD7, fgnoauto);
|
---|
188 | mdsparseD7.SetThetaPhiRange(M_PI/4.,16, M_PI/4., 16);
|
---|
189 | mdsparseD7.SetRespHisNBins(NRX,NRY);
|
---|
190 | Histo2D hrspd7 = mdsparseD7.GetResponse();
|
---|
191 | PrtTim("Apres mdsparseD7.GetResponse()");
|
---|
192 |
|
---|
193 | MultiDish mcylfill(lambda, LMAX, vcylplein, fgnoauto);
|
---|
194 | mcylfill.SetRespHisNBins(NRX,NRY);
|
---|
195 | Histo2D hfcyl = mcylfill.GetResponse();
|
---|
196 | PrtTim("Apres mcylfill.GetResponse()");
|
---|
197 | MultiDish mcylfillP(lambda, LMAX, vcylplP, fgnoauto);
|
---|
198 | mcylfillP.SetRespHisNBins(NRX,NRY);
|
---|
199 | Histo2D hfcylP = mcylfillP.GetResponse();
|
---|
200 |
|
---|
201 | MultiDish md2cyl(lambda, LMAX, v2cyl, fgnoauto);
|
---|
202 | md2cyl.SetRespHisNBins(NRX,NRY);
|
---|
203 | Histo2D h2cyl = md2cyl.GetResponse();
|
---|
204 | MultiDish md2cylP(lambda, LMAX, v2cylP, fgnoauto);
|
---|
205 | md2cylP.SetRespHisNBins(NRX,NRY);
|
---|
206 | Histo2D h2cylP = md2cylP.GetResponse();
|
---|
207 |
|
---|
208 | po << PPFNameTag("mfill") << hrfill;
|
---|
209 | po << PPFNameTag("mspars") << hrsp;
|
---|
210 | po << PPFNameTag("msparsfp") << hrspfp;
|
---|
211 | po << PPFNameTag("msparsd7") << hrspd7;
|
---|
212 | po << PPFNameTag("mcylf") << hfcyl;
|
---|
213 | po << PPFNameTag("m2cyl") << h2cyl;
|
---|
214 | po << PPFNameTag("mcylfP") << hfcylP;
|
---|
215 | po << PPFNameTag("m2cylP") << h2cylP;
|
---|
216 |
|
---|
217 | PrtTim("Done computing multi-dish response");
|
---|
218 |
|
---|
219 |
|
---|
220 | Four2DRespTable mdf(hrfill, Dol);
|
---|
221 | Four2DRespTable mds(hrsp, Dol);
|
---|
222 | Four2DRespTable mdsfp(hrspfp, Dol);
|
---|
223 | Four2DRespTable mdsd7(hrspd7, Dol);
|
---|
224 |
|
---|
225 | Four2DRespTable mcylf(hfcyl, Dol);
|
---|
226 | Four2DRespTable m2cyl(h2cyl, Dol);
|
---|
227 | Four2DRespTable mcylfP(hfcylP, Dol);
|
---|
228 | Four2DRespTable m2cylP(h2cylP, Dol);
|
---|
229 |
|
---|
230 |
|
---|
231 | cout << " 3.a/ Instanciating object type Four3DPk " << endl;
|
---|
232 | RandomGenerator rg;
|
---|
233 | Four3DPk m3d(rg);
|
---|
234 | m3d.SetCellSize(2.*DeuxPI, 2.*DeuxPI, 2.*DeuxPI);
|
---|
235 | cout << " 3.b/ call ComputeFourierAmp() NGEN=" << NMAX << endl;
|
---|
236 | HProf hrpk;
|
---|
237 | for(int igen=0; igen<NMAX; igen++) {
|
---|
238 | m3d.ComputeFourierAmp(spec);
|
---|
239 | if (igen==0) hrpk = m3d.ComputePk();
|
---|
240 | else m3d.ComputePkCumul(hrpk);
|
---|
241 | }
|
---|
242 | PrtTim("md.ComputeFourierAmp() done");
|
---|
243 | po << PPFNameTag("recPk") << hrpk;
|
---|
244 |
|
---|
245 | cout << " 4/ Computing Noise P(k) using PkNoiseCalculator ..." << endl;
|
---|
246 | #define NCONFIG 10
|
---|
247 | Four2DResponse* f2rep[NCONFIG]={&dish, &dish2, &mdf, &mds, &mdsfp, &mdsd7, &mcylf, &mcylfP, &m2cyl, &m2cylP};
|
---|
248 | const char* tits[NCONFIG]={"Dish100m", "Dish200m","F20x20Dish5m","S63Dish5m","S63Dish5mFP","S63Dish7m",
|
---|
249 | "F8Cyl","F8CylP","BiCyl","BiCylP"};
|
---|
250 | const char* tags[NCONFIG]={"noiseD", "noiseD2","noisemdf","noisemds","noisemdsfp","noisemdsd7",
|
---|
251 | "noisefcyl","noisefcylP","noise2cyl","noise2cylP"};
|
---|
252 | vector<int> nbdishes;
|
---|
253 | nbdishes.push_back(1);
|
---|
254 | nbdishes.push_back(1);
|
---|
255 | nbdishes.push_back(vdplein.size());
|
---|
256 | nbdishes.push_back(vdsparse.size());
|
---|
257 | nbdishes.push_back(vdsparse.size());
|
---|
258 | nbdishes.push_back(vdsparseD7.size());
|
---|
259 | nbdishes.push_back(vcylplein.size());
|
---|
260 | nbdishes.push_back(vcylplP.size());
|
---|
261 | nbdishes.push_back(v2cyl.size());
|
---|
262 | nbdishes.push_back(v2cylP.size());
|
---|
263 |
|
---|
264 | for(int lc=0; lc<NCONFIG; lc++) {
|
---|
265 | PkNoiseCalculator pkn(m3d, *(f2rep[lc]), SCut/(double)nbdishes[lc], NMAX, tits[lc]);
|
---|
266 | HProf hpn = pkn.Compute();
|
---|
267 | po << PPFNameTag(tags[lc]) << hpn;
|
---|
268 | }
|
---|
269 | rc = 0;
|
---|
270 | } // End of try bloc
|
---|
271 | catch (PThrowable & exc) { // catching SOPHYA exceptions
|
---|
272 | cerr << " pknoise.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
273 | << "\n...exc.Msg= " << exc.Msg() << endl;
|
---|
274 | rc = 99;
|
---|
275 | }
|
---|
276 | catch (std::exception & e) { // catching standard C++ exceptions
|
---|
277 | cerr << " pknoise.cc: Catched std::exception " << " - what()= " << e.what() << endl;
|
---|
278 | rc = 98;
|
---|
279 | }
|
---|
280 | catch (...) { // catching other exceptions
|
---|
281 | cerr << " pknoise.cc: some other exception (...) was caught ! " << endl;
|
---|
282 | rc = 97;
|
---|
283 | }
|
---|
284 | PrtTim("End-pknoise");
|
---|
285 | cout << " ==== End of pknoise.cc program Rc= " << rc << endl;
|
---|
286 | return rc;
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|