[3160] | 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"
|
---|
[3192] | 19 | #include "datacards.h"
|
---|
| 20 | #include <dvlist.h>
|
---|
[3160] | 21 |
|
---|
| 22 | #include "multicyl.h"
|
---|
| 23 | #include "mbeamcyl.h"
|
---|
[3192] | 24 | #define LENGTH 1024
|
---|
[3160] | 25 |
|
---|
[3165] | 26 | /*
|
---|
| 27 | Projet BAORadio / HSHS
|
---|
| 28 | Programme de simulation pour reconstruction de lobe radio.
|
---|
| 29 | programme principal de test
|
---|
[3160] | 30 |
|
---|
[3165] | 31 | R. Ansari - LAL Jan 2007
|
---|
| 32 |
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[3160] | 35 | // Declaration des fonctions de ce fichier
|
---|
| 36 | static int test1cyl(string& ppfname);
|
---|
[3192] | 37 | static int testmulticyl(string& ppfname);
|
---|
[3572] | 38 | int ReadParam(const char* fileName);
|
---|
[3160] | 39 |
|
---|
| 40 | //-----------------------------------------------------------
|
---|
| 41 | // -------------- Parametres de simulation -----------------
|
---|
| 42 | //-----------------------------------------------------------
|
---|
[3192] | 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 | //
|
---|
[3160] | 48 | static int MR = 256; // Nombre de recepteur
|
---|
[3192] | 49 | static int NE = 64; // Nombre d'echantillon en temps;
|
---|
[3160] | 50 | static double freq0 = 2.; // frequence de base
|
---|
| 51 | static double da = 0.25; // pas des antennes le long du cylindre
|
---|
[3165] | 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 ( +/- )
|
---|
[3192] | 55 | static int halfNY;
|
---|
| 56 | static int NX;
|
---|
[3165] | 57 | static int nsrcmax = 50; // Nb total de sources - en un plan
|
---|
| 58 |
|
---|
[3164] | 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
|
---|
[3160] | 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
|
---|
[3192] | 66 |
|
---|
| 67 | static int nCyl;
|
---|
| 68 | static double xCyl[1000];
|
---|
| 69 | static double yCyl[1000];
|
---|
[3160] | 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 |
|
---|
[3192] | 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;
|
---|
[3160] | 88 |
|
---|
[3192] | 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"
|
---|
[3165] | 95 | << " -ppfname= treccyl.ppf par defaut" << endl;
|
---|
[3192] | 96 | return 1;
|
---|
| 97 | }
|
---|
| 98 | if (strcmp(arg[1],"XY") == 0) { act = 2 ;}
|
---|
| 99 | if (narg > 2) ppfname = arg[2];
|
---|
[3160] | 100 |
|
---|
[3192] | 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 | }
|
---|
[3160] | 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 |
|
---|
[3192] | 121 | cout << ">>>> treccyl ------- FIN ----------- Rc=" << rc << endl;
|
---|
| 122 | return rc;
|
---|
[3160] | 123 | }
|
---|
| 124 |
|
---|
| 125 |
|
---|
[3192] | 126 | //-----------------------------------------------------------------------------
|
---|
[3160] | 127 | //--- Fonction de test : reconstruction plan AngX-Frequence (1 cylindre)
|
---|
| 128 | int test1cyl(string& ppfname)
|
---|
| 129 | {
|
---|
| 130 |
|
---|
| 131 | // BRSourceGen sg;
|
---|
[3192] | 132 | // int nsrc = 60;
|
---|
[3165] | 133 | BRSourceGen sg(nsrcmax, maxangX, 0.);
|
---|
[3160] | 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] ");
|
---|
[3165] | 157 |
|
---|
| 158 | cout << "--- treccy/test1cyl: Saving to PPF file " << ppfname << endl;
|
---|
[3160] | 159 |
|
---|
| 160 | POutPersist po(ppfname);
|
---|
[3192] | 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_;
|
---|
[3160] | 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 |
|
---|
[3192] | 185 | //-----------------------------------------------------------------------------
|
---|
[3160] | 186 | //--- Fonction de test : reconstruction cube AngX-AngY-Frequence (multi-cylindre)
|
---|
[3192] | 187 | int testmulticyl(string& ppfname)
|
---|
[3160] | 188 | {
|
---|
| 189 |
|
---|
[3192] | 190 | //............. sources
|
---|
[3160] | 191 | // BRSourceGen sg;
|
---|
[3164] | 192 | int nsf = 6;
|
---|
[3160] | 193 | vector<double> frq;
|
---|
[3192] | 194 | frq.push_back(0.1/tClock);
|
---|
| 195 | frq.push_back(0.27/tClock);
|
---|
| 196 | frq.push_back(0.38/tClock);
|
---|
[3160] | 197 |
|
---|
| 198 |
|
---|
[3165] | 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 |
|
---|
[3163] | 203 | int is;
|
---|
[3165] | 204 | double fay[6] = {-0.7,-0.5,0.,0.,0.5,0.7};
|
---|
[3192] | 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};
|
---|
[3165] | 207 | for(is=0; is<3*nsf; is++) {
|
---|
| 208 | int ism = is%nsf;
|
---|
[3192] | 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
|
---|
[3165] | 212 | }
|
---|
[3160] | 213 | // sg.WritePPF(string("brsrcm.ppf"));
|
---|
| 214 | // BRSourceGen sg(string("brsrcm.ppf"));
|
---|
[3165] | 215 | cout << "=== testmulticyl: NbSrc= " << sg.NbSources()
|
---|
[3192] | 216 | << " NbRecep=" << MR << " NSamples=" << NE << " NCyl=" << nCyl << endl;
|
---|
[3160] | 217 | if (prtlevel > 1) sg.Print(cout);
|
---|
| 218 |
|
---|
[3192] | 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);
|
---|
[3160] | 228 |
|
---|
[3192] | 229 | // for (int iCyl=0; iCyl<nCyl; iCyl++)
|
---|
| 230 | // {
|
---|
| 231 | // mcyl.AddCylinder(xCyl[iCyl],yCyl[iCyl]);
|
---|
| 232 | // }
|
---|
[3165] | 233 |
|
---|
[3192] | 234 |
|
---|
[3160] | 235 | mcyl.SetSources(sg);
|
---|
| 236 |
|
---|
| 237 | PrtTim("testmulticyl[1] ");
|
---|
| 238 |
|
---|
| 239 | // mcyl.ReconstructCylinderPlaneS(true);
|
---|
[3192] | 240 | mcyl.ReconstructSourceBox(halfNY, maxangY/halfNY, NX, maxangX/NX);
|
---|
[3160] | 241 |
|
---|
[3165] | 242 | cout << "--- treccy/testmulticyl: Saving to PPF file " << ppfname << endl;
|
---|
[3160] | 243 | POutPersist po(ppfname);
|
---|
| 244 |
|
---|
[3192] | 245 | DVList dvl;
|
---|
| 246 | dvl("Da") = da;
|
---|
| 247 | po << PPFNameTag("dvl") <<dvl;
|
---|
| 248 |
|
---|
[3160] | 249 | NTuple ntsrc = sg.Convert2Table(freq0);
|
---|
| 250 | po << PPFNameTag("ntsrc") << ntsrc;
|
---|
| 251 |
|
---|
[3163] | 252 | // TMatrix<r_4> srcplane0 = module(mcyl.GetCylinder(0).getRecSrcPlane());
|
---|
| 253 | TMatrix< complex<r_4> > srcplane0 = mcyl.GetCylinder(0).getRecSrcPlane();
|
---|
[3160] | 254 | po << PPFNameTag("recsrcplane0") << srcplane0;
|
---|
[3192] | 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;
|
---|
[3160] | 259 | PrtTim("testmulticyl[2] ");
|
---|
| 260 |
|
---|
| 261 | po << PPFNameTag("recsrcbox") << mcyl.getRecSrcBox();
|
---|
[3192] | 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;
|
---|
[3164] | 266 | cout << "testmulticyl/Info: slice0 kfmin=" << kfmin << " kfmax=" << kfmax << endl;
|
---|
[3160] | 267 | TMatrix<r_4> slice0 = mcyl.getRecXYSlice(kfmin, kfmax);
|
---|
| 268 | po << PPFNameTag("recXYf0") << slice0;
|
---|
[3192] | 269 | kfmin = (int)(2*frq[1]*tClock*(float)mcyl.getRecSrcBox().SizeZ() - 2.);
|
---|
| 270 | kfmax = kfmin+2;
|
---|
[3164] | 271 | cout << "testmulticyl/Info: slice1 kfmin=" << kfmin << " kfmax=" << kfmax << endl;
|
---|
[3160] | 272 | TMatrix<r_4> slice1 = mcyl.getRecXYSlice(kfmin, kfmax);
|
---|
| 273 | po << PPFNameTag("recXYf1") << slice1;
|
---|
[3192] | 274 | kfmin = (int)(2*frq[2]*tClock*(float)mcyl.getRecSrcBox().SizeZ() - 2.);
|
---|
| 275 | kfmax = kfmin+2;
|
---|
[3164] | 276 | cout << "testmulticyl/Info: slice2 kfmin=" << kfmin << " kfmax=" << kfmax << endl;
|
---|
[3160] | 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 | }
|
---|
[3192] | 285 |
|
---|
| 286 | //---------------------------------------------------------------------
|
---|
[3572] | 287 | int ReadParam(const char* fileName)
|
---|
[3192] | 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 | }
|
---|