[3930] | 1 | /* ------------------------ Projet BAORadio --------------------
|
---|
| 2 | Programme de calcul du spectre de puissance de bruit pour
|
---|
| 3 | un interferometre (spectre moyenne sur 3D -> P_noise(k) )
|
---|
| 4 |
|
---|
| 5 | R. Ansari , C. Magneville - Juin 2010
|
---|
| 6 |
|
---|
[3931] | 7 | Usage: pknoise pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName
|
---|
[4027] | 8 | -parname : -noise , -renmax, -scut, -ngen, -z, -bsize, -cszmpc, -nbin -prt
|
---|
[3930] | 9 | --------------------------------------------------------------- */
|
---|
| 10 |
|
---|
[3756] | 11 | #include "machdefs.h"
|
---|
| 12 | #include "sopnamsp.h"
|
---|
| 13 | #include <iostream>
|
---|
| 14 | #include <string>
|
---|
| 15 | #include <math.h>
|
---|
| 16 |
|
---|
| 17 | #include <typeinfo>
|
---|
| 18 |
|
---|
| 19 | #include "mdish.h"
|
---|
| 20 | #include "specpk.h"
|
---|
[3792] | 21 | #include "interfconfigs.h"
|
---|
[3930] | 22 | #include "radutil.h"
|
---|
[3792] | 23 |
|
---|
[3756] | 24 | #include "histinit.h"
|
---|
| 25 | // #include "fiosinit.h"
|
---|
| 26 | // #include "fitsioserver.h"
|
---|
| 27 |
|
---|
| 28 | #include "randr48.h"
|
---|
| 29 |
|
---|
| 30 | #include "timing.h"
|
---|
| 31 | #include "ctimer.h"
|
---|
[4027] | 32 | #include "slininterp.h"
|
---|
[3756] | 33 |
|
---|
| 34 | typedef DR48RandGen RandomGenerator ;
|
---|
| 35 |
|
---|
| 36 | // ---------------------------------------------------------------------
|
---|
[3930] | 37 | // Test main
|
---|
| 38 | // R. Ansari - Avril-Dec 2010
|
---|
[3756] | 39 | // ---------------------------------------------------------------------
|
---|
| 40 |
|
---|
[3931] | 41 | void Usage()
|
---|
| 42 | {
|
---|
| 43 | cout << " Usage: pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName \n"
|
---|
| 44 | << " -noise NoiseLevel (default=1.) \n"
|
---|
| 45 | << " -renmax MaxValue (default : Do NOT renormalize 2D response value \n"
|
---|
[3947] | 46 | << " -ngen NGen (default=0) number of noise fourier amp generations \n"
|
---|
| 47 | << " NGen=0 -> Call ComputeNoisePk(), else generate Fourier Amplitudes (random) \n"
|
---|
[4026] | 48 | << " NGen=-1 -> Call ComputeNoisePk(), dont change Four3DPk cell size \n"
|
---|
| 49 | << " -bsize sx,sy,sz : 3D real space box size (default=512x512x256) \n"
|
---|
[4027] | 50 | << " -cszmpc sx,sy,sz : 3D real space box cell size in Mpc (default=3x3x1.5) \n"
|
---|
| 51 | << " -z redshift : redshift (default=1.0) \n"
|
---|
[3948] | 52 | << " -scut SCutValue (default= -100.) \n"
|
---|
| 53 | << " if SCutValue<0. ==> SCut=MinNoisePower*(-SCutValue) \n"
|
---|
[4027] | 54 | << " -prt PrtLev,PrtModulo (default=0,10) \n"
|
---|
| 55 | << " -nbin PkNBin : nomber of histogram bins for Pnoise(k) (default= 256) \n"
|
---|
| 56 | << " NOTE : this program needs redshift_da.txt andredshift_Hz.txt files" << endl;
|
---|
[3931] | 57 | return;
|
---|
| 58 | }
|
---|
[3756] | 59 |
|
---|
[3769] | 60 | //-------------------------------------------------------------------------
|
---|
| 61 | // ------------------ MAIN PROGRAM ------------------------------
|
---|
| 62 | //-------------------------------------------------------------------------
|
---|
[3756] | 63 | int main(int narg, const char* arg[])
|
---|
| 64 | {
|
---|
[3930] | 65 | if ( (narg<3)||((narg>1)&&(strcmp(arg[1],"-h")==0)) ) {
|
---|
[3931] | 66 | Usage();
|
---|
[3756] | 67 | return 1;
|
---|
| 68 | }
|
---|
[3930] | 69 | cout << " ==== pknoise.cc : interferometer noise power spectrum computation ==== " << endl;
|
---|
[3756] | 70 | // make sure SOPHYA modules are initialized
|
---|
| 71 | SophyaInit();
|
---|
| 72 | // FitsIOServerInit();
|
---|
| 73 | InitTim();
|
---|
| 74 | //--- decoding command line arguments
|
---|
[3930] | 75 | string tits="pknoise";
|
---|
| 76 | char cbuff[64];
|
---|
| 77 | bool fgresptbl=false;
|
---|
| 78 | double DIAMETRE=100.;
|
---|
| 79 | string resptblname;
|
---|
[3931] | 80 | double NoiseLevel=1.;
|
---|
| 81 |
|
---|
| 82 | bool fgrenorm=false;
|
---|
| 83 | double rmax=1.;
|
---|
[3947] | 84 | int NMAX = 0;
|
---|
[3948] | 85 | double SCut=-100.;
|
---|
| 86 | bool fgautoscut=true;
|
---|
| 87 | double FacSCut=-SCut;
|
---|
[4026] | 88 | double z_Redshift=1.0 ; // z=0.7 : 21 cm at z=0.7 -> 0.357 m
|
---|
| 89 | double comov_dA_z=3330.; // Comoving radial distance = (1+z)dA
|
---|
| 90 | double H_z=120.5; // Hubble_param(z)
|
---|
| 91 | int box3dsz[3]={512,512,256};
|
---|
[4027] | 92 | double cellsz[3]={3.,3.,1.5};
|
---|
| 93 | int NBINPK=256;
|
---|
[3931] | 94 | int prtlev=0;
|
---|
| 95 | int prtmod=10;
|
---|
| 96 |
|
---|
| 97 | int ka=1;
|
---|
| 98 | while (ka<(narg-1)) {
|
---|
| 99 | if (strcmp(arg[ka],"-noise")==0) {
|
---|
| 100 | NoiseLevel=atof(arg[ka+1]);
|
---|
| 101 | ka+=2;
|
---|
| 102 | }
|
---|
| 103 | else if (strcmp(arg[ka],"-renmax")==0) {
|
---|
| 104 | rmax=atof(arg[ka+1]); fgrenorm=true; ka+=2;
|
---|
| 105 | }
|
---|
| 106 | else if (strcmp(arg[ka],"-scut")==0) {
|
---|
| 107 | SCut=atof(arg[ka+1]); ka+=2;
|
---|
[3948] | 108 | if (SCut<0.) { FacSCut=-SCut; fgautoscut=true; }
|
---|
[3931] | 109 | }
|
---|
| 110 | else if (strcmp(arg[ka],"-ngen")==0) {
|
---|
| 111 | NMAX=atoi(arg[ka+1]); ka+=2;
|
---|
| 112 | }
|
---|
| 113 | else if (strcmp(arg[ka],"-z")==0) {
|
---|
[4027] | 114 | z_Redshift=atof(arg[ka+1]); ka+=2;
|
---|
[3931] | 115 | }
|
---|
[4026] | 116 | else if (strcmp(arg[ka],"-bsize")==0) {
|
---|
| 117 | sscanf(arg[ka+1],"%d,%d,%d",box3dsz,box3dsz+1,box3dsz+2); ka+=2;
|
---|
| 118 | }
|
---|
| 119 | else if (strcmp(arg[ka],"-cszmpc")==0) {
|
---|
| 120 | sscanf(arg[ka+1],"%lg,%lg,%lg",cellsz,cellsz+1,cellsz+2); ka+=2;
|
---|
| 121 | }
|
---|
[4027] | 122 | else if (strcmp(arg[ka],"-nbin")==0) {
|
---|
| 123 | NBINPK=atoi(arg[ka+1]); ka+=2;
|
---|
| 124 | }
|
---|
[3931] | 125 | else if (strcmp(arg[ka],"-prt")==0) {
|
---|
| 126 | sscanf(arg[ka+1],"%d,%d",&prtlev,&prtmod); ka+=2;
|
---|
| 127 | }
|
---|
| 128 | else break;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | if ((ka+1)>=narg) {
|
---|
| 132 | cout << " pknoise / Argument error " << endl;
|
---|
| 133 | Usage();
|
---|
| 134 | return 2;
|
---|
| 135 | }
|
---|
| 136 | if (isdigit(*arg[ka])) {
|
---|
[3930] | 137 | fgresptbl=false;
|
---|
[3931] | 138 | DIAMETRE=atof(arg[ka]);
|
---|
[3930] | 139 | sprintf(cbuff,"pknoise_Dish(%g m)", DIAMETRE);
|
---|
| 140 | }
|
---|
| 141 | else {
|
---|
[3931] | 142 | resptblname=arg[ka];
|
---|
[3930] | 143 | fgresptbl=true;
|
---|
[3931] | 144 | sprintf(cbuff,"pknoise_RespTblName=%s", arg[ka]);
|
---|
[3930] | 145 | }
|
---|
| 146 | tits=cbuff;
|
---|
[3931] | 147 | string outfile = arg[ka+1];
|
---|
[3756] | 148 | if (outfile==".") outfile = "pknoise.ppf";
|
---|
[3931] | 149 | //-- end command line arguments
|
---|
[3756] | 150 |
|
---|
| 151 | int rc = 1;
|
---|
| 152 | try { // exception handling try bloc at top level
|
---|
[3930] | 153 | cout << " pknoise[0] : Executing, output file= " << outfile << endl;
|
---|
[3756] | 154 | POutPersist po(outfile);
|
---|
[4027] | 155 |
|
---|
| 156 | cout << " pknoise[0.b] : Creating interpolating objects from redshift_da.txt and redshift_Hz.txt " << endl;
|
---|
| 157 | SLinInterp1D redshift2da;
|
---|
| 158 | string interpfilename="redshift_da.txt";
|
---|
| 159 | redshift2da.ReadXYFromFile(interpfilename);
|
---|
| 160 | SLinInterp1D redshift2hz;
|
---|
| 161 | interpfilename="redshift_hz.txt";
|
---|
| 162 | redshift2hz.ReadXYFromFile(interpfilename);
|
---|
| 163 | comov_dA_z=redshift2da(z_Redshift);
|
---|
| 164 | H_z=redshift2hz(z_Redshift);
|
---|
| 165 | cout << " Redshift= " << z_Redshift << " -> ComovdA= " << comov_dA_z
|
---|
| 166 | << " Mpc H(z)= " << H_z << " km/s/Mpc " << endl;
|
---|
[3756] | 167 |
|
---|
[3930] | 168 | H21Conversions conv;
|
---|
| 169 | conv.setRedshift(z_Redshift);
|
---|
| 170 | double lambda = conv.getLambda();
|
---|
[3756] | 171 |
|
---|
[3930] | 172 | double Dol = DIAMETRE/lambda;
|
---|
[3756] | 173 |
|
---|
[3930] | 174 | Four2DResponse arep(2, DIAMETRE/lambda, DIAMETRE/lambda, lambda);
|
---|
| 175 | Four2DResponse* arep_p=&arep;
|
---|
| 176 | Four2DRespTable resptbl;
|
---|
| 177 | if (fgresptbl) {
|
---|
| 178 | cout << "pknoise[1]: initializing Four2DRespTable from file" << resptblname << endl;
|
---|
| 179 | resptbl.readFromPPF(resptblname);
|
---|
[3947] | 180 | cout << "pknoise[1.b] Four2DRespTable.LambdaRef=" << resptbl.getLambdaRef() << " setLambda("
|
---|
| 181 | << lambda << ")" << endl;
|
---|
| 182 | resptbl.setLambda(lambda);
|
---|
[3930] | 183 | arep_p=&resptbl;
|
---|
| 184 | if (fgrenorm) {
|
---|
[3947] | 185 | cout << "pknoise[1.c] call to resptbl.renormalize(" << rmax << ")";
|
---|
[3930] | 186 | double omax=resptbl.renormalize(rmax);
|
---|
| 187 | cout << " ... Old Max=" << omax << endl;
|
---|
| 188 | }
|
---|
[3769] | 189 | }
|
---|
[3930] | 190 | else cout << " pknoise[1]: Four2DResponse ( Diameter=" << DIAMETRE << " Lambda= " << lambda
|
---|
| 191 | << " DoL=" << DIAMETRE/lambda << " ) " << endl;
|
---|
[3948] | 192 | Histo2D h2drep = arep_p->GetResponse();
|
---|
| 193 | double repmax= h2drep.VMax();
|
---|
| 194 | if (fgautoscut) {
|
---|
| 195 | SCut = FacSCut/repmax;
|
---|
| 196 | cout << " pknoise[1.b]: Four2DResponse.RepMax=" << repmax << " --> SCut=" << FacSCut << "/repmax="
|
---|
| 197 | << SCut << endl;
|
---|
| 198 | }
|
---|
| 199 | else cout << " pknoise[1.b]: Four2DResponse.RepMax=" << repmax << " , SCut=" << SCut << endl;
|
---|
[3756] | 200 |
|
---|
[3930] | 201 | cout << " pknoise[2]: Instanciating object type Four3DPk " << endl;
|
---|
[3756] | 202 | RandomGenerator rg;
|
---|
[4026] | 203 |
|
---|
[4027] | 204 | double dfreq=H_z*cellsz[2]/(1+z_Redshift)/lambda/1000.;
|
---|
| 205 | double freq0=conv.getFrequency()-dfreq*box3dsz[2]/2;
|
---|
| 206 |
|
---|
[4026] | 207 | double dkxmpc=2.*DeuxPI;
|
---|
| 208 | double dkympc=2.*DeuxPI;
|
---|
| 209 | double dkzmpc=2.*DeuxPI;
|
---|
| 210 | double angscale=1.;
|
---|
[4027] | 211 | Vector angscales(box3dsz[2]);
|
---|
| 212 | angscales=angscale;
|
---|
[4026] | 213 | if (NMAX<0) { box3dsz[0]=256; box3dsz[1]=256; box3dsz[3]=128; }
|
---|
| 214 | else {
|
---|
| 215 | angscale=comov_dA_z;
|
---|
[4027] | 216 | for(int kz=0; kz<box3dsz[2]; kz++) angscales(kz)=redshift2da(1420.4/(freq0+(double)kz*dfreq)-1.);
|
---|
[4026] | 217 | dkxmpc = DeuxPI/(double)box3dsz[0]/cellsz[0];
|
---|
| 218 | dkympc = DeuxPI/(double)box3dsz[1]/cellsz[1];
|
---|
| 219 | dkzmpc = DeuxPI/(double)box3dsz[2]/cellsz[2];
|
---|
| 220 | }
|
---|
[4027] | 221 | cout << " pknoise[2.b]: ComovDist=" << comov_dA_z << " Mpc H(z)=" << H_z << " Mpc/km/s -> angscale=" << angscale << endl;
|
---|
| 222 | cout << " pknoise[2.c]: Freq0=" << freq0 << " dFreq=" << dfreq << " freq(z=" << z_Redshift << ")="
|
---|
| 223 | << conv.getFrequency() << " zmin=" << 1420.4/freq0-1. << " zmax=" << 1420.4/(freq0+box3dsz[2]*dfreq)-1. << endl;
|
---|
| 224 | cout << " pknoise[2.d]: Four3DPk m3d(rg," << box3dsz[0]/2 << "," << box3dsz[1] << ","
|
---|
[4026] | 225 | << box3dsz[2] << ")" << endl;
|
---|
| 226 | Four3DPk m3d(rg,box3dsz[0]/2,box3dsz[1],box3dsz[2]);
|
---|
| 227 | cout << " pknoise[2.d]: m3d.SetCellSize(" << dkxmpc << "," << dkympc << "," << dkzmpc << endl;
|
---|
| 228 | m3d.SetCellSize(dkxmpc, dkympc, dkzmpc);
|
---|
[3930] | 229 | m3d.SetPrtLevel(prtlev,prtmod);
|
---|
[3756] | 230 |
|
---|
[3947] | 231 | if (NMAX>0) {
|
---|
[4027] | 232 | cout << " pknoise[3]: Computing Noise P(k) using PkNoiseCalculator ..." << endl;
|
---|
[3947] | 233 | PkNoiseCalculator pkn(m3d, *(arep_p), SCut, NMAX, tits.c_str());
|
---|
[4026] | 234 | pkn.SetFreqRange(freq0, dfreq);
|
---|
[4027] | 235 | pkn.SetAngScaleConversion(angscales);
|
---|
[3947] | 236 | pkn.SetPrtLevel(prtlev,prtmod);
|
---|
[4027] | 237 | HProf hpn = pkn.Compute(NBINPK);
|
---|
[3947] | 238 | }
|
---|
| 239 | else {
|
---|
[4027] | 240 | cout << " pknoise[3]: Computing Noise P(k) m3d.ComputeNoisePk(...) " << endl;
|
---|
| 241 | HProf hpn = m3d.ComputeNoisePk(*(arep_p),angscale,SCut,NBINPK);
|
---|
[3947] | 242 | }
|
---|
[4027] | 243 |
|
---|
| 244 | HProf hpnoise=m3d.GetPk();
|
---|
| 245 | DataTable dtnoise;
|
---|
| 246 | Histo fracmodok=m3d.FillPkDataTable(dtnoise);
|
---|
| 247 | HProf h1dnoise=arep_p->GetProjNoiseLevel();
|
---|
| 248 | HProf h1drep=arep_p->GetProjResponse();
|
---|
| 249 | cout << " pknoise[3.b]: writing dtnoise,hpn,h2rep... with tags to " << outfile << endl;
|
---|
| 250 | po << PPFNameTag("dtnoise") << dtnoise;
|
---|
| 251 | po << PPFNameTag("hpnoise") << hpnoise;
|
---|
| 252 | po << PPFNameTag("fracmodok") << fracmodok;
|
---|
| 253 | po << PPFNameTag("h1dnoise") << h1dnoise;
|
---|
| 254 | po << PPFNameTag("h1drep") << h1drep;
|
---|
| 255 | po << PPFNameTag("h2drep") << h2drep;
|
---|
| 256 |
|
---|
[3756] | 257 | rc = 0;
|
---|
| 258 | } // End of try bloc
|
---|
| 259 | catch (PThrowable & exc) { // catching SOPHYA exceptions
|
---|
| 260 | cerr << " pknoise.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
| 261 | << "\n...exc.Msg= " << exc.Msg() << endl;
|
---|
| 262 | rc = 99;
|
---|
| 263 | }
|
---|
| 264 | catch (std::exception & e) { // catching standard C++ exceptions
|
---|
| 265 | cerr << " pknoise.cc: Catched std::exception " << " - what()= " << e.what() << endl;
|
---|
| 266 | rc = 98;
|
---|
| 267 | }
|
---|
| 268 | catch (...) { // catching other exceptions
|
---|
| 269 | cerr << " pknoise.cc: some other exception (...) was caught ! " << endl;
|
---|
| 270 | rc = 97;
|
---|
| 271 | }
|
---|
| 272 | PrtTim("End-pknoise");
|
---|
| 273 | cout << " ==== End of pknoise.cc program Rc= " << rc << endl;
|
---|
| 274 | return rc;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 |
|
---|