1 | #include "sopnamsp.h"
|
---|
2 | #include "machdefs.h"
|
---|
3 | #include <math.h>
|
---|
4 | #include <iostream>
|
---|
5 | #include <typeinfo>
|
---|
6 |
|
---|
7 | #include "tvector.h"
|
---|
8 | #include "srandgen.h"
|
---|
9 | #include "fioarr.h"
|
---|
10 | #include "sopemtx.h"
|
---|
11 | #include "pexceptions.h"
|
---|
12 | #include "matharr.h"
|
---|
13 |
|
---|
14 | #include "sambainit.h"
|
---|
15 |
|
---|
16 | // #include "tarrinit.h"
|
---|
17 |
|
---|
18 | #include "timing.h"
|
---|
19 | #include "datacards.h"
|
---|
20 | #include <dvlist.h>
|
---|
21 |
|
---|
22 | #include "multicyl.h"
|
---|
23 | #include "mbeamcyl.h"
|
---|
24 | #define LENGTH 1024
|
---|
25 |
|
---|
26 | /*
|
---|
27 | Projet BAORadio / HSHS
|
---|
28 | Programme de simulation pour reconstruction de lobe radio.
|
---|
29 | programme principal de test
|
---|
30 |
|
---|
31 | R. Ansari - LAL Jan 2007
|
---|
32 |
|
---|
33 | */
|
---|
34 |
|
---|
35 | // Declaration des fonctions de ce fichier
|
---|
36 | static int test1cyl(string& ppfname);
|
---|
37 | static int testmulticyl(string& ppfname);
|
---|
38 | int ReadParam(const char* fileName);
|
---|
39 |
|
---|
40 | //-----------------------------------------------------------
|
---|
41 | // -------------- Parametres de simulation -----------------
|
---|
42 | //-----------------------------------------------------------
|
---|
43 | static double tClock = 2.; // should come from param file !!!!
|
---|
44 | static double cLight=0.3; // in 1E9 m/s
|
---|
45 | //static double tClock = 1.; // should come from param file !!!!
|
---|
46 | //static double cLight=1.; // in 1E9 m/s
|
---|
47 | //
|
---|
48 | static int MR = 256; // Nombre de recepteur
|
---|
49 | static int NE = 64; // Nombre d'echantillon en temps;
|
---|
50 | static double freq0 = 2.; // frequence de base
|
---|
51 | static double da = 0.25; // pas des antennes le long du cylindre
|
---|
52 | // ATTENTION : les parametres suivants sont relies a MR/da
|
---|
53 | static double maxangX = M_PI/3.; // angle max en X ( +/- )
|
---|
54 | static double maxangY = M_PI/60.; // angle max en Y ( +/- )
|
---|
55 | static int halfNY;
|
---|
56 | static int NX;
|
---|
57 | static int nsrcmax = 50; // Nb total de sources - en un plan
|
---|
58 |
|
---|
59 | static double snoise = 1.0; // sigma du bruit
|
---|
60 | static double tjit = 0.05; // sigma du jitter en temps
|
---|
61 | static double tos = 0.02; // sigma des offsets en temps
|
---|
62 | static double gmean = 1.; // gain moyen
|
---|
63 | static double gsig = 0.; // sigma des gains
|
---|
64 | static int nantgz = 0; // nb d'antennes morts (-> gain=0)
|
---|
65 | static int prtlevel = 0; // niveau de print
|
---|
66 |
|
---|
67 | static int nCyl;
|
---|
68 | static double xCyl[1000];
|
---|
69 | static double yCyl[1000];
|
---|
70 | //-----------------------------------------------------------
|
---|
71 |
|
---|
72 |
|
---|
73 | /* --------------------------------------------------------
|
---|
74 | Le main programme de test des classes de reconstruction
|
---|
75 | multilobe radio - R. Ansari , Sep06 -- 2007
|
---|
76 | --------------------------------------------------------- */
|
---|
77 |
|
---|
78 | int main(int narg, char* arg[])
|
---|
79 | {
|
---|
80 |
|
---|
81 | SophyaInit();
|
---|
82 | InitTim(); // Initializing the CPU timer
|
---|
83 | ReadParam("telescope.in");
|
---|
84 | cout <<"MR="<< MR <<" NE="<<NE<<" freq0="<<freq0<<" "<<da<<" "<<maxangX <<endl;
|
---|
85 | cout << maxangY<<" "<<nsrcmax <<" "<< snoise<<" "<< tjit<<" "<< tos<<" "<<gmean <<endl;
|
---|
86 | cout << gsig<<" "<<nantgz <<" "<< prtlevel<<endl;
|
---|
87 | // return 1;
|
---|
88 |
|
---|
89 | string ppfname = "treccyl.ppf";
|
---|
90 | int act = 1;
|
---|
91 | // int ncyl = 5;
|
---|
92 | if (narg < 2) {
|
---|
93 | cout << "Usage: treccyl act ppfname \n"
|
---|
94 | << " -act= X ou XY \n"
|
---|
95 | << " -ppfname= treccyl.ppf par defaut" << endl;
|
---|
96 | return 1;
|
---|
97 | }
|
---|
98 | if (strcmp(arg[1],"XY") == 0) { act = 2 ;}
|
---|
99 | if (narg > 2) ppfname = arg[2];
|
---|
100 |
|
---|
101 | int rc = 0;
|
---|
102 | cout << ">>>> treccyl : " << arg[1] << " PPFName=" << ppfname << endl;
|
---|
103 | try {
|
---|
104 | if (act == 2) rc = testmulticyl(ppfname);
|
---|
105 | else rc = test1cyl(ppfname);
|
---|
106 | }
|
---|
107 | catch (PThrowable& exc) {
|
---|
108 | cerr << " treccyl.cc catched Exception " << exc.Msg() << endl;
|
---|
109 | rc = 77;
|
---|
110 | }
|
---|
111 | catch (std::exception& sex) {
|
---|
112 | cerr << "\n treccyl.cc std::exception :"
|
---|
113 | << (string)typeid(sex).name() << "\n msg= "
|
---|
114 | << sex.what() << endl;
|
---|
115 | }
|
---|
116 | catch (...) {
|
---|
117 | cerr << " treccyl.cc catched unknown (...) exception " << endl;
|
---|
118 | rc = 78;
|
---|
119 | }
|
---|
120 |
|
---|
121 | cout << ">>>> treccyl ------- FIN ----------- Rc=" << rc << endl;
|
---|
122 | return rc;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | //-----------------------------------------------------------------------------
|
---|
127 | //--- Fonction de test : reconstruction plan AngX-Frequence (1 cylindre)
|
---|
128 | int test1cyl(string& ppfname)
|
---|
129 | {
|
---|
130 |
|
---|
131 | // BRSourceGen sg;
|
---|
132 | // int nsrc = 60;
|
---|
133 | BRSourceGen sg(nsrcmax, maxangX, 0.);
|
---|
134 | // sg.WritePPF(string("brsrc1.ppf"));
|
---|
135 |
|
---|
136 | cout << "=== test1cyl: BRSourceGen NbSrc= " << sg.NbSources()
|
---|
137 | << " NbRecep=" << MR << " NSamples=" << NE << endl;
|
---|
138 |
|
---|
139 | // BRSourceGen sg(string("brsrc1.ppf"));
|
---|
140 | if (prtlevel > 1) sg.Print(cout);
|
---|
141 |
|
---|
142 |
|
---|
143 | MultiBeamCyl mb(MR, NE);
|
---|
144 | mb.SetPrintLevel(prtlevel);
|
---|
145 | mb.SetBaseFreqDa(freq0, da);
|
---|
146 | mb.SetNoiseSigma(snoise);
|
---|
147 | mb.SetTimeJitter(tjit);
|
---|
148 | mb.SetTimeOffsetSigma(tos);
|
---|
149 | mb.SetGains(gmean, gsig, nantgz);
|
---|
150 |
|
---|
151 | mb.SetSources(sg);
|
---|
152 |
|
---|
153 | mb.ComputeTimeVectors();
|
---|
154 | mb.ComputeSignalVector(0, true);
|
---|
155 | cout << "treccy/test1cyl: signal vectors OK " << endl;
|
---|
156 | PrtTim("test1cyl:[1] ");
|
---|
157 |
|
---|
158 | cout << "--- treccy/test1cyl: Saving to PPF file " << ppfname << endl;
|
---|
159 |
|
---|
160 | POutPersist po(ppfname);
|
---|
161 | // direct access to variables members !!!!
|
---|
162 | po << PPFNameTag("signal") << mb.signal_;
|
---|
163 | po << PPFNameTag("sigjitt") << mb.sigjitt_;
|
---|
164 | po << PPFNameTag("f_sig") << mb.f_sig_;
|
---|
165 | po << PPFNameTag("f_sigjit") << mb.f_sigjit_;
|
---|
166 |
|
---|
167 | NTuple ntsrc = sg.Convert2Table(freq0);
|
---|
168 | po << PPFNameTag("ntsrc") << ntsrc;
|
---|
169 |
|
---|
170 | cout << "treccy/test1cyl: - sig/f_sig,ntsrc to OutPPF OK " << endl;
|
---|
171 | PrtTim("test1cyl[2] ");
|
---|
172 |
|
---|
173 | mb.ReconstructSourcePlane(true);
|
---|
174 | {
|
---|
175 | TMatrix<r_4> srcplane = module(mb.getRecSrcPlane() );
|
---|
176 | po << PPFNameTag("recsrcplane") << srcplane;
|
---|
177 | }
|
---|
178 | PrtTim("test1cyl[3] ");
|
---|
179 |
|
---|
180 | return 0;
|
---|
181 |
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | //-----------------------------------------------------------------------------
|
---|
186 | //--- Fonction de test : reconstruction cube AngX-AngY-Frequence (multi-cylindre)
|
---|
187 | int testmulticyl(string& ppfname)
|
---|
188 | {
|
---|
189 |
|
---|
190 | //............. sources
|
---|
191 | // BRSourceGen sg;
|
---|
192 | int nsf = 6;
|
---|
193 | vector<double> frq;
|
---|
194 | frq.push_back(0.1/tClock);
|
---|
195 | frq.push_back(0.27/tClock);
|
---|
196 | frq.push_back(0.38/tClock);
|
---|
197 |
|
---|
198 |
|
---|
199 | cout << "testmulticyl: BRSourceGen sg([frq=0.1,0.27,0.38], " << nsf
|
---|
200 | << "," << maxangX << "," << maxangY << ")" << endl;
|
---|
201 | BRSourceGen sg(frq, nsf, maxangX, maxangY);
|
---|
202 |
|
---|
203 | int is;
|
---|
204 | double fay[6] = {-0.7,-0.5,0.,0.,0.5,0.7};
|
---|
205 | // double fay[6] = {-0.2,0.5,-0.3,0.6,-0.1,0.7};
|
---|
206 | // double fax[6] = {0.6,-0.2,-0.5,0.4,-0.1,0.3};
|
---|
207 | for(is=0; is<3*nsf; is++) {
|
---|
208 | int ism = is%nsf;
|
---|
209 | sg.angX(is) = maxangX*(ism-2.5)/3.; // accessing data member
|
---|
210 | sg.angY(is) = maxangY*fay[ism]; // directly !!!
|
---|
211 | // sg.angX(is) = maxangX*fax[ism]; // accessing data member
|
---|
212 | }
|
---|
213 | // sg.WritePPF(string("brsrcm.ppf"));
|
---|
214 | // BRSourceGen sg(string("brsrcm.ppf"));
|
---|
215 | cout << "=== testmulticyl: NbSrc= " << sg.NbSources()
|
---|
216 | << " NbRecep=" << MR << " NSamples=" << NE << " NCyl=" << nCyl << endl;
|
---|
217 | if (prtlevel > 1) sg.Print(cout);
|
---|
218 |
|
---|
219 | //.......................... cylinders
|
---|
220 | MultiCylinders mcyl ("telescope.in");
|
---|
221 | // MultiCylinders mcyl (MR, NE);
|
---|
222 | // mcyl.SetPrintLevel(prtlevel);
|
---|
223 | // mcyl.SetBaseFreqDa(freq0, da);
|
---|
224 | // mcyl.SetNoiseSigma(snoise);
|
---|
225 | // mcyl.SetTimeJitter(tjit);
|
---|
226 | // mcyl.SetTimeOffsetSigma(tos);
|
---|
227 | // mcyl.SetGains(gmean, gsig, nantgz);
|
---|
228 |
|
---|
229 | // for (int iCyl=0; iCyl<nCyl; iCyl++)
|
---|
230 | // {
|
---|
231 | // mcyl.AddCylinder(xCyl[iCyl],yCyl[iCyl]);
|
---|
232 | // }
|
---|
233 |
|
---|
234 |
|
---|
235 | mcyl.SetSources(sg);
|
---|
236 |
|
---|
237 | PrtTim("testmulticyl[1] ");
|
---|
238 |
|
---|
239 | // mcyl.ReconstructCylinderPlaneS(true);
|
---|
240 | mcyl.ReconstructSourceBox(halfNY, maxangY/halfNY, NX, maxangX/NX);
|
---|
241 |
|
---|
242 | cout << "--- treccy/testmulticyl: Saving to PPF file " << ppfname << endl;
|
---|
243 | POutPersist po(ppfname);
|
---|
244 |
|
---|
245 | DVList dvl;
|
---|
246 | dvl("Da") = da;
|
---|
247 | po << PPFNameTag("dvl") <<dvl;
|
---|
248 |
|
---|
249 | NTuple ntsrc = sg.Convert2Table(freq0);
|
---|
250 | po << PPFNameTag("ntsrc") << ntsrc;
|
---|
251 |
|
---|
252 | // TMatrix<r_4> srcplane0 = module(mcyl.GetCylinder(0).getRecSrcPlane());
|
---|
253 | TMatrix< complex<r_4> > srcplane0 = mcyl.GetCylinder(0).getRecSrcPlane();
|
---|
254 | po << PPFNameTag("recsrcplane0") << srcplane0;
|
---|
255 | TMatrix< complex<r_4> > srcplane1 = mcyl.GetCylinder(1).getRecSrcPlane();
|
---|
256 | po << PPFNameTag("recsrcplane1") << srcplane1;
|
---|
257 | // TMatrix< complex<r_4> > srcplane3 = mcyl.GetCylinder(3).getRecSrcPlane();
|
---|
258 | // po << PPFNameTag("recsrcplane3") << srcplane3;
|
---|
259 | PrtTim("testmulticyl[2] ");
|
---|
260 |
|
---|
261 | po << PPFNameTag("recsrcbox") << mcyl.getRecSrcBox();
|
---|
262 |
|
---|
263 | // k= N T frq with N=2*SizeZ()
|
---|
264 | int kfmin = (int)(2.*frq[0]*tClock*(float)mcyl.getRecSrcBox().SizeZ() - 2.);
|
---|
265 | int kfmax = kfmin+2;
|
---|
266 | cout << "testmulticyl/Info: slice0 kfmin=" << kfmin << " kfmax=" << kfmax << endl;
|
---|
267 | TMatrix<r_4> slice0 = mcyl.getRecXYSlice(kfmin, kfmax);
|
---|
268 | po << PPFNameTag("recXYf0") << slice0;
|
---|
269 | kfmin = (int)(2*frq[1]*tClock*(float)mcyl.getRecSrcBox().SizeZ() - 2.);
|
---|
270 | kfmax = kfmin+2;
|
---|
271 | cout << "testmulticyl/Info: slice1 kfmin=" << kfmin << " kfmax=" << kfmax << endl;
|
---|
272 | TMatrix<r_4> slice1 = mcyl.getRecXYSlice(kfmin, kfmax);
|
---|
273 | po << PPFNameTag("recXYf1") << slice1;
|
---|
274 | kfmin = (int)(2*frq[2]*tClock*(float)mcyl.getRecSrcBox().SizeZ() - 2.);
|
---|
275 | kfmax = kfmin+2;
|
---|
276 | cout << "testmulticyl/Info: slice2 kfmin=" << kfmin << " kfmax=" << kfmax << endl;
|
---|
277 | TMatrix<r_4> slice2 = mcyl.getRecXYSlice(kfmin, kfmax);
|
---|
278 | po << PPFNameTag("recXYf2") << slice2;
|
---|
279 |
|
---|
280 | PrtTim("testmulticyl[3] ");
|
---|
281 |
|
---|
282 | return 0;
|
---|
283 |
|
---|
284 | }
|
---|
285 |
|
---|
286 | //---------------------------------------------------------------------
|
---|
287 | int ReadParam(const char* fileName)
|
---|
288 | {
|
---|
289 | DataCards dc;
|
---|
290 | dc.ReadFile(fileName);
|
---|
291 | // frequences are in units of 1/T = 0.5 GHz
|
---|
292 | // distance are in units of cT =3E8 * 2E-9=0.60 m
|
---|
293 | // double fUnit=0.5; // 0.5 GHz <=> T = 2 ns
|
---|
294 | // double dUnit=0.6; // distance unit in m.
|
---|
295 | double fUnit=1.; // 0.5 GHz <=> T = 2 ns
|
---|
296 | double dUnit=1.; // distance unit in m.
|
---|
297 |
|
---|
298 | NE=dc.IParam("nSample");
|
---|
299 | freq0=dc.DParam("freq0")/fUnit;
|
---|
300 | // tClock=dc.DParam("tClock");
|
---|
301 | nCyl=dc.IParam("nCyl");
|
---|
302 | for (int i=0; i<nCyl; i++){
|
---|
303 | xCyl[i]=dc.DParam("xCyl",i)/dUnit;
|
---|
304 | yCyl[i]=dc.DParam("yCyl",i)/dUnit;
|
---|
305 | }
|
---|
306 | MR=dc.IParam("nAntenna");
|
---|
307 | da=dc.DParam("dAntenna")/dUnit;
|
---|
308 | maxangX=dc.DParam("angMaxX");
|
---|
309 | double cylDiam=dc.DParam("cylinderDiam")/dUnit;
|
---|
310 | // thetaMax = lambda_M/d = c/freq_min/d; freq_min = freq0 + 1/2T
|
---|
311 | maxangY=cLight/(freq0+1./2./tClock)/cylDiam;
|
---|
312 | // cout << "*************** maxangY = " <<maxangY << endl;
|
---|
313 | // maxangY=dc.DParam("angMaxY");
|
---|
314 | snoise=dc.DParam("noiseSigma");
|
---|
315 | tjit=dc.DParam("sigmaTimeJitt");
|
---|
316 | tos=dc.DParam("sigmaClockJitt");
|
---|
317 | gmean=dc.DParam("meanGain");
|
---|
318 | gsig=dc.DParam("sigmaGain");
|
---|
319 | nantgz=dc.IParam("nDeadAntenna");
|
---|
320 | prtlevel=dc.IParam("printLevel");
|
---|
321 | halfNY=dc.IParam("halfNY");
|
---|
322 | NX=dc.IParam("NX");
|
---|
323 | return 1;
|
---|
324 | }
|
---|