| 1 | #include "sopnamsp.h" | 
|---|
| 2 | #include "machdefs.h" | 
|---|
| 3 | #include <iostream> | 
|---|
| 4 | #include <stdlib.h> | 
|---|
| 5 | #include <stdio.h> | 
|---|
| 6 | #include <string.h> | 
|---|
| 7 | #include <math.h> | 
|---|
| 8 | #include <unistd.h> | 
|---|
| 9 |  | 
|---|
| 10 | #include "sophyainit.h" | 
|---|
| 11 | #include "timing.h" | 
|---|
| 12 | #include "dvlist.h" | 
|---|
| 13 | #include "ntuple.h" | 
|---|
| 14 | #include "matharr.h" | 
|---|
| 15 | #include "randfmt.h" | 
|---|
| 16 | //#include "randr48.h" | 
|---|
| 17 | #include "srandgen.h" | 
|---|
| 18 |  | 
|---|
| 19 | #include "constcosmo.h" | 
|---|
| 20 | #include "geneutils.h" | 
|---|
| 21 | #include "genefluct3d.h" | 
|---|
| 22 |  | 
|---|
| 23 | string decodecambarg(string arg,double& h, double& z); | 
|---|
| 24 |  | 
|---|
| 25 | void usage(void); | 
|---|
| 26 | void usage(void) | 
|---|
| 27 | { | 
|---|
| 28 | cout<<"cmvginit3d [...options...]"<<endl | 
|---|
| 29 | <<" -a : auto init random seed (needed for multiple simul)"<<endl | 
|---|
| 30 | <<" -G typevol: compute Pk(z=0) and apply growth factor in real space"<<endl | 
|---|
| 31 | <<"       typevol=1 evolved with distance / observateur (def)"<<endl | 
|---|
| 32 | <<"       typevol=2 evolved with distance to middle of Z planes"<<endl | 
|---|
| 33 | <<"       else : no evol, spectrum Pk(z=z_median) for all cube (def)"<<endl | 
|---|
| 34 | <<" -F : filter spectrum by pixel shape (0=no 1=yes(default)"<<endl | 
|---|
| 35 | <<" -x nx,dx : size along x axis (npix,Mpc)"<<endl | 
|---|
| 36 | <<" -y ny,dy : size along y axis (npix,Mpc)"<<endl | 
|---|
| 37 | <<"            if ny or dy <=0 take same value as for x"<<endl | 
|---|
| 38 | <<" -z nz,dz : size along z axis (redshift axis, npix,Mpc)"<<endl | 
|---|
| 39 | <<" -Z zref : redshift for the center of the simulation cube"<<endl | 
|---|
| 40 | <<" -f cambspec.dat,h100tab,ztab : use CAMB file (def: Eisenstein spectrum)"<<endl | 
|---|
| 41 | <<" -1 : compute 1D spectrum (default: no)"<<endl | 
|---|
| 42 | <<" -2 : compute 2D spectrum (default: no)"<<endl | 
|---|
| 43 | <<" -C : go back to cube in FT space and compute P(k) for check (def: do nothing)"<<endl | 
|---|
| 44 | <<" -8 sigmaR,R : normalisation du spectre de puissance, R en Mpc"<<endl | 
|---|
| 45 | <<"               (default sigmaR=1, R=8/h100 Mpc)"<<endl | 
|---|
| 46 | <<" -v temp_file.ppf: generate los velocity cube"<<endl | 
|---|
| 47 | <<"                   temporary save cube in temp_file.ppf"<<endl | 
|---|
| 48 | <<" -n nent : fill control ntuple with nent entries (def: do not fill)"<<endl | 
|---|
| 49 | <<" -O a,b : tell what you want to write"<<endl | 
|---|
| 50 | <<"      a : write generated fourier cube (_k0)"<<endl | 
|---|
| 51 | <<"      b : write real space cube dRho/Rho at z (_r0)"<<endl | 
|---|
| 52 | <<"      a,b= 0 no write, 1 ppf write, 2 fits write, 3 ppf+fits write"<<endl | 
|---|
| 53 | <<" -S : write cube slices in PPF format"<<endl | 
|---|
| 54 | <<" -o out_base_name : base string for output file name (def: cmvginit3d)"<<endl | 
|---|
| 55 | <<" -V : compute variance from real space (for check, default: no)"<<endl | 
|---|
| 56 | <<" -T nth : nombre de threads (si compil multi-thread, default: 0)"<<endl | 
|---|
| 57 | <<endl; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | int main(int narg,char *arg[]) | 
|---|
| 61 | { | 
|---|
| 62 | SophyaInit(); | 
|---|
| 63 | InitTim(); | 
|---|
| 64 |  | 
|---|
| 65 | //----------------------------------------------------------------- | 
|---|
| 66 | // *** Survey definition | 
|---|
| 67 | long nx=360, ny=-1, nz=64; double dx=1., dy=-1., dz=-1.; | 
|---|
| 68 | //long nx=1000, ny=-1, nz=128; double dx=3., dy=-1., dz=6.; | 
|---|
| 69 | //long nx=1200, ny=-1, nz=128; double dx=1., dy=-1., dz=3; | 
|---|
| 70 |  | 
|---|
| 71 | // *** Cosmography definition   (WMAP) | 
|---|
| 72 | unsigned short flat = 0; | 
|---|
| 73 | double ob0 = 0.0444356; | 
|---|
| 74 | double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73, w0=-1.; | 
|---|
| 75 | double zref = 0.5; | 
|---|
| 76 | double perc=0.01,dzinc=-1.,dzmax=-1.; unsigned short glorder=4; | 
|---|
| 77 |  | 
|---|
| 78 | // *** Spectrum and variance definition | 
|---|
| 79 | double ns = 1., as = 1.; | 
|---|
| 80 | double R=8./h100, Rg=R/sqrt(5.); | 
|---|
| 81 | double sigmaR = 1.; | 
|---|
| 82 |  | 
|---|
| 83 | double kmin=1e-4,kmax=100.; | 
|---|
| 84 | int npt = 1000; | 
|---|
| 85 | double eps=1.e-3; | 
|---|
| 86 |  | 
|---|
| 87 | // *** Spectrum read from CAMB file | 
|---|
| 88 | string cambfread = ""; | 
|---|
| 89 |  | 
|---|
| 90 | // *** type de generation | 
|---|
| 91 | int use_growth_factor = 0; | 
|---|
| 92 | unsigned short nthread=0; | 
|---|
| 93 | int filter_by_pixel = 1; | 
|---|
| 94 |  | 
|---|
| 95 | // *** What to do | 
|---|
| 96 | bool comptransveloc = false; | 
|---|
| 97 | string temporay_file = "cmvginit3d_tmp.ppf"; | 
|---|
| 98 | // compute: 1=1D spectra,  2=2D spectra, | 
|---|
| 99 | //          4=recompute spectra after real space generation | 
|---|
| 100 | unsigned short compdspec = 0; | 
|---|
| 101 | long ntnent = 0;  // fill control NTuple | 
|---|
| 102 | bool wslice = false; | 
|---|
| 103 | bool compvarreal = false; | 
|---|
| 104 | unsigned short whattowrt[2] = {1,1}; | 
|---|
| 105 | string rootnameout = "cmvobserv3d"; | 
|---|
| 106 |  | 
|---|
| 107 | // --- Decodage arguments | 
|---|
| 108 | if(narg>0) { | 
|---|
| 109 | cout<<"\n--- Arguments: "<<endl; | 
|---|
| 110 | for(int i=0;i<narg;i++) cout<<arg[i]<<" "; | 
|---|
| 111 | cout<<endl; | 
|---|
| 112 | } | 
|---|
| 113 | system("date -u"); | 
|---|
| 114 |  | 
|---|
| 115 | // --- Choix du generateur aleatoire (a faire ICI imperativement avant AutoInitRand) | 
|---|
| 116 | FMTRandGen *RandGen = new FMTRandGen; | 
|---|
| 117 | RandGen->SelectGaussianAlgo(C_Gaussian_RandLibSNorm); | 
|---|
| 118 | RandomGeneratorInterface::SetGlobalRandGenP(RandGen); | 
|---|
| 119 |  | 
|---|
| 120 | // --- Decodage des arguments | 
|---|
| 121 | char c; | 
|---|
| 122 | while((c = getopt(narg,arg,"haG:F:x:y:z:Z:128:v:n:CO:So:VT:f:")) != -1) { | 
|---|
| 123 | int nth = 0; | 
|---|
| 124 | switch (c) { | 
|---|
| 125 | case 'a' : | 
|---|
| 126 | AutoInitRand(5); | 
|---|
| 127 | break; | 
|---|
| 128 | case 'G' : | 
|---|
| 129 | use_growth_factor = atoi(optarg); | 
|---|
| 130 | break; | 
|---|
| 131 | case 'F' : | 
|---|
| 132 | filter_by_pixel = atoi(optarg); | 
|---|
| 133 | break; | 
|---|
| 134 | case 'x' : | 
|---|
| 135 | sscanf(optarg,"%ld,%lf",&nx,&dx); | 
|---|
| 136 | break; | 
|---|
| 137 | case 'y' : | 
|---|
| 138 | sscanf(optarg,"%ld,%lf",&ny,&dy); | 
|---|
| 139 | break; | 
|---|
| 140 | case 'z' : | 
|---|
| 141 | sscanf(optarg,"%ld,%lf",&nz,&dz); | 
|---|
| 142 | break; | 
|---|
| 143 | case 'Z' : | 
|---|
| 144 | zref = atof(optarg); | 
|---|
| 145 | break; | 
|---|
| 146 | case 'v' : | 
|---|
| 147 | comptransveloc = true; | 
|---|
| 148 | temporay_file = optarg; | 
|---|
| 149 | break; | 
|---|
| 150 | case '1' : | 
|---|
| 151 | compdspec |= 1; | 
|---|
| 152 | break; | 
|---|
| 153 | case '2' : | 
|---|
| 154 | compdspec |= 2; | 
|---|
| 155 | break; | 
|---|
| 156 | case 'C' : | 
|---|
| 157 | compdspec |= 4; | 
|---|
| 158 | break; | 
|---|
| 159 | case '8' : | 
|---|
| 160 | sscanf(optarg,"%lf,%lf",&sigmaR,&R); | 
|---|
| 161 | break; | 
|---|
| 162 | case 'V' : | 
|---|
| 163 | compvarreal = true; | 
|---|
| 164 | break; | 
|---|
| 165 | case 'n': | 
|---|
| 166 | ntnent = atol(optarg); | 
|---|
| 167 | if(ntnent<0) ntnent = 0; | 
|---|
| 168 | break; | 
|---|
| 169 | case 'O' : | 
|---|
| 170 | sscanf(optarg,"%hu,%hu",&whattowrt[0],&whattowrt[1]); | 
|---|
| 171 | break; | 
|---|
| 172 | case 'S' : | 
|---|
| 173 | wslice = true; | 
|---|
| 174 | break; | 
|---|
| 175 | case 'o' : | 
|---|
| 176 | rootnameout = optarg; | 
|---|
| 177 | break; | 
|---|
| 178 | case 'T' : | 
|---|
| 179 | nth = atoi(optarg); | 
|---|
| 180 | nthread = (nth<1)? 0: nth; | 
|---|
| 181 | break; | 
|---|
| 182 | case 'f' : | 
|---|
| 183 | cambfread = optarg; | 
|---|
| 184 | break; | 
|---|
| 185 | case 'h' : | 
|---|
| 186 | default : | 
|---|
| 187 | usage(); return -1; | 
|---|
| 188 | } | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|
| 191 | //----TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH | 
|---|
| 192 | try { | 
|---|
| 193 | //----TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH | 
|---|
| 194 |  | 
|---|
| 195 | //----------------------------------------------------------------- | 
|---|
| 196 | cout<<endl<<"\n--- Initialisation and parameters"<<endl; | 
|---|
| 197 | cout<<"zref="<<zref<<endl; | 
|---|
| 198 | cout<<"nx="<<nx<<" dx="<<dx<<" ny="<<ny<<" dy="<<dy<<" nz="<<nz<<" dz="<<dz<<endl; | 
|---|
| 199 | cout<<"kmin="<<kmin<<" ("<<log10(kmin)<<"), kmax="<<kmax<<" ("<<log10(kmax)<<") Mpc^-1"<<", npt="<<npt<<endl; | 
|---|
| 200 | cout<<"Filter by pixel = "<<filter_by_pixel<<endl; | 
|---|
| 201 | if(comptransveloc) cout<<"Tansverse velocity generation requested"<<endl; | 
|---|
| 202 | if(cambfread.size()>0) cout<<"use CAMB file: cambfread="<<cambfread<<endl; | 
|---|
| 203 | cout<<"R="<<R<<" Rg="<<Rg<<" Mpc, sigmaR="<<sigmaR<<endl; | 
|---|
| 204 | cout<<"Use_growth_factor = "<<use_growth_factor<<endl; | 
|---|
| 205 | cout<<"wslice="<<wslice<<" what?="<<whattowrt[0]<<","<<whattowrt[1]<<endl; | 
|---|
| 206 | cout<<"rootnameout="<<rootnameout<<endl; | 
|---|
| 207 | ShowRandom(); | 
|---|
| 208 | cout<<"   First random is: "<<drand01()<<endl; | 
|---|
| 209 |  | 
|---|
| 210 | string tagobs = rootnameout + ".ppf"; | 
|---|
| 211 | cout<<"Writing result in "<<tagobs<<endl; | 
|---|
| 212 | POutPersist posobs(tagobs); | 
|---|
| 213 |  | 
|---|
| 214 | //----------------------------------------------------------------- | 
|---|
| 215 | cout<<endl<<"\n--- Create Cosmology"<<endl; | 
|---|
| 216 |  | 
|---|
| 217 | CosmoCalc univ(flat,true,zref+1.); | 
|---|
| 218 | univ.SetInteg(perc,dzinc,dzmax,glorder); | 
|---|
| 219 | univ.SetDynParam(h100,om0,or0,ol0,w0); | 
|---|
| 220 | univ.PrtInteg(); | 
|---|
| 221 | univ.Print(); | 
|---|
| 222 | double loscomref = univ.Dloscom(zref); | 
|---|
| 223 | cout<<"\nzref = "<<zref<<" -> dloscom = "<<loscomref<<" Mpc"<<endl; | 
|---|
| 224 | univ.Print(zref); | 
|---|
| 225 |  | 
|---|
| 226 | //----------------------------------------------------------------- | 
|---|
| 227 | cout<<endl<<"\n--- Create GrowthFactor"<<endl; | 
|---|
| 228 |  | 
|---|
| 229 | GrowthEisenstein growth(om0,ol0); | 
|---|
| 230 | // GrowthEisenstein growth(1.,0.); // D(z) = 1/(1+z) | 
|---|
| 231 | double growth_at_z = growth(zref); | 
|---|
| 232 | cout<<"...Growth factor at z="<<zref<<" = "<<growth_at_z<<endl; | 
|---|
| 233 |  | 
|---|
| 234 | //----------------------------------------------------------------- | 
|---|
| 235 | cout<<endl<<"\n--- Create Spectrum"<<endl; | 
|---|
| 236 |  | 
|---|
| 237 | InitialPowerLaw pkini(ns,as); | 
|---|
| 238 |  | 
|---|
| 239 | TransfertEisenstein tfnos(h100,om0-ob0,ob0,T_CMB_Par,false); | 
|---|
| 240 | tfnos.SetNoOscEnv(2); | 
|---|
| 241 | TransfertEisenstein tf(h100,om0-ob0,ob0,T_CMB_Par,false); | 
|---|
| 242 |  | 
|---|
| 243 | PkSpecCalc pkznos(pkini,tfnos,growth,zref); | 
|---|
| 244 | PkSpectrum* pkz = NULL; | 
|---|
| 245 | if(cambfread.size()>0) {  // read pk in CAMB file | 
|---|
| 246 | double h100tab, ztab; | 
|---|
| 247 | string fn = decodecambarg(cambfread,h100tab,ztab); | 
|---|
| 248 | if(h100tab<=0.) h100tab = h100; | 
|---|
| 249 | PkTabulate* pkzt = new PkTabulate; | 
|---|
| 250 | pkzt->ReadCAMB(fn,h100tab,ztab); | 
|---|
| 251 | pkzt->SetGrowthFactor(&growth); | 
|---|
| 252 | pkzt->SetInterpTyp(2); | 
|---|
| 253 | pkzt->SetZ(zref); | 
|---|
| 254 | pkz = pkzt; | 
|---|
| 255 | // change k limits | 
|---|
| 256 | kmin = pkzt->KMin(); | 
|---|
| 257 | kmax = pkzt->KMax(); | 
|---|
| 258 | cout<<"Change k limits to kmin="<<kmin<<" kmax="<<kmax<<endl; | 
|---|
| 259 | } else {   // use Eisenstein pk | 
|---|
| 260 | PkSpecCalc* pkze = new PkSpecCalc(pkini,tf,growth,zref); | 
|---|
| 261 | pkz = pkze; | 
|---|
| 262 | } | 
|---|
| 263 |  | 
|---|
| 264 | //----------------------------------------------------------------- | 
|---|
| 265 | cout<<endl<<"\n--- Normalize Spectrum"<<endl; | 
|---|
| 266 |  | 
|---|
| 267 | pkz->SetZ(0.); | 
|---|
| 268 | pkznos.SetZ(0.); | 
|---|
| 269 |  | 
|---|
| 270 | double normpkz[2] = {0.,0.}; | 
|---|
| 271 | for(int i=0;i<2;i++) { | 
|---|
| 272 | PkSpectrum* pkvar = NULL; string nam = ""; | 
|---|
| 273 | if(i==0) pkvar = pkz; else {pkvar = &pkznos; nam = "NoOsc";} | 
|---|
| 274 | cout<<endl<<"\n--- Compute variance for Pk "<<nam<<" with top-hat R="<<R<<" at z="<<pkvar->GetZ()<<endl; | 
|---|
| 275 | VarianceSpectrum varpk_th(*pkvar,R,VarianceSpectrum::TOPHAT); | 
|---|
| 276 | double kfind_th = varpk_th.FindMaximum(kmin,kmax,eps); | 
|---|
| 277 | double pkmax_th = varpk_th(kfind_th); | 
|---|
| 278 | cout<<"kfind_th = "<<kfind_th<<" ("<<log10(kfind_th)<<"), integrand="<<pkmax_th<<endl; | 
|---|
| 279 | double k1=kmin, k2=kmax; | 
|---|
| 280 | int rc = varpk_th.FindLimits(pkmax_th/1.e4,k1,k2,eps); | 
|---|
| 281 | cout<<"limit_th: rc="<<rc<<" : "<<k1<<" ("<<log10(k1)<<") , " | 
|---|
| 282 | <<k2<<" ("<<log10(k2)<<")"<<endl; | 
|---|
| 283 | double ldlk = (log10(k2)-log10(k1))/npt; | 
|---|
| 284 | varpk_th.SetInteg(0.01,ldlk,-1.,4); | 
|---|
| 285 | double sr2 = varpk_th.Variance(k1,k2); | 
|---|
| 286 | normpkz[i] = sigmaR*sigmaR/sr2; | 
|---|
| 287 | cout<<"varpk_th="<<sr2<<"  ->  sigma="<<sqrt(sr2)<<" normpkz="<<normpkz[i]<<endl; | 
|---|
| 288 | } | 
|---|
| 289 | cout<<endl; | 
|---|
| 290 |  | 
|---|
| 291 | if(cambfread.size()>0) { | 
|---|
| 292 | pkz->SetScale(1.); | 
|---|
| 293 | pkznos.SetScale(normpkz[1]); | 
|---|
| 294 | cout<<"Warning: CAMB spectrum, no normalisation applied, scale="<<pkz->GetScale()<<endl; | 
|---|
| 295 | } else { | 
|---|
| 296 | pkz->SetScale(normpkz[0]); | 
|---|
| 297 | pkznos.SetScale(normpkz[0]); | 
|---|
| 298 | cout<<"Spectrum normalisation (osc+noosc), scale = "<<pkz->GetScale()<<endl; | 
|---|
| 299 | } | 
|---|
| 300 |  | 
|---|
| 301 | { | 
|---|
| 302 | Histo hpkz0(log10(kmin),log10(kmax),npt); hpkz0.ReCenterBin(); | 
|---|
| 303 | FuncToHisto(*pkz,hpkz0,true); | 
|---|
| 304 | posobs.PutObject(hpkz0,"hpkz0"); | 
|---|
| 305 | Histo hpkz0nos(hpkz0); | 
|---|
| 306 | FuncToHisto(pkznos,hpkz0nos,true); | 
|---|
| 307 | posobs.PutObject(hpkz0nos,"hpkz0nos"); | 
|---|
| 308 | } | 
|---|
| 309 |  | 
|---|
| 310 | pkz->SetZ(zref); | 
|---|
| 311 | pkznos.SetZ(zref); | 
|---|
| 312 |  | 
|---|
| 313 | { | 
|---|
| 314 | Histo hpkz(log10(kmin),log10(kmax),npt); hpkz.ReCenterBin(); | 
|---|
| 315 | FuncToHisto(*pkz,hpkz,true); | 
|---|
| 316 | posobs.PutObject(hpkz,"hpkz"); | 
|---|
| 317 | Histo hpkznos(hpkz); | 
|---|
| 318 | FuncToHisto(pkznos,hpkznos,true); | 
|---|
| 319 | posobs.PutObject(hpkznos,"hpkznos"); | 
|---|
| 320 | } | 
|---|
| 321 |  | 
|---|
| 322 | //----------------------------------------------------------------- | 
|---|
| 323 | cout<<endl<<"\n--- Compute variance for Pk at z="<<pkz->GetZ()<<endl; | 
|---|
| 324 | VarianceSpectrum varpk_int(*pkz,R,VarianceSpectrum::NOFILTER); | 
|---|
| 325 | double kfind_int = varpk_int.FindMaximum(kmin,kmax,eps); | 
|---|
| 326 | double pkmax_int = varpk_int(kfind_int); | 
|---|
| 327 | cout<<"kfind_int = "<<kfind_int<<" ("<<log10(kfind_int)<<"), integrand="<<pkmax_int<<endl; | 
|---|
| 328 | double k1int=kmin, k2int=kmax; | 
|---|
| 329 | int rcint = varpk_int.FindLimits(pkmax_int/1.e4,k1int,k2int,eps); | 
|---|
| 330 | cout<<"limit_int: rc="<<rcint<<" : "<<k1int<<" ("<<log10(k1int)<<") , " | 
|---|
| 331 | <<k2int<<" ("<<log10(k2int)<<")"<<endl; | 
|---|
| 332 |  | 
|---|
| 333 | double ldlkint = (log10(k2int)-log10(k1int))/npt; | 
|---|
| 334 | varpk_int.SetInteg(0.01,ldlkint,-1.,4); | 
|---|
| 335 | double sr2int = varpk_int.Variance(k1int,k2int); | 
|---|
| 336 | cout<<"varpk_int="<<sr2int<<"  ->  sigma="<<sqrt(sr2int)<<endl; | 
|---|
| 337 |  | 
|---|
| 338 | //----------------------------------------------------------------- | 
|---|
| 339 |  | 
|---|
| 340 | PrtTim(">>>> End of definition"); | 
|---|
| 341 |  | 
|---|
| 342 | //----------------------------------------------------------------- | 
|---|
| 343 | // Le cube et sa cosmlogie | 
|---|
| 344 | // FFTW3 (p26): faster if sizes 2^a 3^b 5^c 7^d 11^e 13^f  with e+f=0 ou 1 | 
|---|
| 345 | cout<<endl<<"\n--- Initialisation de GeneFluct3D"<<endl; | 
|---|
| 346 |  | 
|---|
| 347 | GeneFluct3D fluct3d(nx,ny,nz,dx,dy,dz,nthread,2); | 
|---|
| 348 | fluct3d.SetCosmology(univ); | 
|---|
| 349 | fluct3d.SetGrowthFactor(growth); | 
|---|
| 350 | fluct3d.SetObservator(zref,-nz/2.); | 
|---|
| 351 | fluct3d.LosComRedshift(0.001,-1); | 
|---|
| 352 | //TArray< complex<GEN3D_TYPE> >& pkgen = fluct3d.GetComplexArray(); | 
|---|
| 353 | //TArray<GEN3D_TYPE>& rgen = fluct3d.GetRealArray(); | 
|---|
| 354 | cout<<endl; fluct3d.Print(); | 
|---|
| 355 |  | 
|---|
| 356 | //----------------------------------------------------------------- | 
|---|
| 357 | // Les bins et ranges en k pour les histos 1D et 2D | 
|---|
| 358 | double dkmin = fluct3d.GetKincMin(); | 
|---|
| 359 | double knyqmax = fluct3d.GetKmax(); | 
|---|
| 360 | long nherr = long(knyqmax/dkmin+0.5); | 
|---|
| 361 | cout<<"\nFor HistoErr: d="<<dkmin<<" max="<<knyqmax<<" n="<<nherr<<endl; | 
|---|
| 362 |  | 
|---|
| 363 | double dktmin = fluct3d.GetKTincMin(); | 
|---|
| 364 | double ktnyqmax = fluct3d.GetKTmax(); | 
|---|
| 365 | long nherrt = long(ktnyqmax/dktmin+0.5); | 
|---|
| 366 | double dkzmin = fluct3d.GetKinc()[2]; | 
|---|
| 367 | double kznyqmax = fluct3d.GetKnyq()[2]; | 
|---|
| 368 | long nherrz = long(kznyqmax/dkzmin+0.5); | 
|---|
| 369 | cout<<"For Histo2DErr: d="<<dktmin<<","<<dkzmin | 
|---|
| 370 | <<" max="<<ktnyqmax<<","<<kznyqmax<<" n="<<nherrt<<","<<nherrz<<endl; | 
|---|
| 371 | PrtTim(">>>> End Initialisation of GeneFluct3D"); | 
|---|
| 372 |  | 
|---|
| 373 | //----------------------------------------------------------------- | 
|---|
| 374 | cout<<"\n--- Computing a realization in Fourier space"<<endl; | 
|---|
| 375 | if(use_growth_factor>0) pkz->SetZ(0.); else pkz->SetZ(zref); | 
|---|
| 376 | cout<<"Power spectrum set at redshift: "<<pkz->GetZ()<<endl; | 
|---|
| 377 | fluct3d.ComputeFourier(*pkz); | 
|---|
| 378 | fluct3d.NTupleCheck(posobs,string("ntpkgen"),ntnent); | 
|---|
| 379 | PrtTim(">>>> End Computing a realization in Fourier space"); | 
|---|
| 380 |  | 
|---|
| 381 | HistoErr hpkgen(0.,knyqmax,nherr); | 
|---|
| 382 | if(compdspec&1) { | 
|---|
| 383 | cout<<"\n--- Checking realization spectra"<<endl; | 
|---|
| 384 | hpkgen.ReCenterBin(); hpkgen.Zero(); hpkgen.Show(); | 
|---|
| 385 | fluct3d.ComputeSpectrum(hpkgen); | 
|---|
| 386 | posobs.PutObject(hpkgen,"hpkgen"); | 
|---|
| 387 | PrtTim(">>>> End Checking realization 1D spectra"); | 
|---|
| 388 | } | 
|---|
| 389 | Histo2DErr hpkgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz); | 
|---|
| 390 | if(compdspec&2) { | 
|---|
| 391 | cout<<"\n--- Checking realization 2D spectra"<<endl; | 
|---|
| 392 | hpkgen2.ReCenterBin(); hpkgen2.Zero(); hpkgen2.Show(); | 
|---|
| 393 | fluct3d.ComputeSpectrum2D(hpkgen2); | 
|---|
| 394 | posobs.PutObject(hpkgen2,"hpkgen2"); | 
|---|
| 395 | PrtTim(">>>> End Checking realization 2D spectra"); | 
|---|
| 396 | } | 
|---|
| 397 |  | 
|---|
| 398 | //----------------------------------------------------------------- | 
|---|
| 399 | if(filter_by_pixel!=0) { | 
|---|
| 400 | cout<<"\n--- Computing convolution by pixel shape"<<endl; | 
|---|
| 401 | fluct3d.FilterByPixel(); | 
|---|
| 402 | fluct3d.NTupleCheck(posobs,string("ntpkgenf"),ntnent); | 
|---|
| 403 | PrtTim(">>>> End Computing convolution by pixel shape"); | 
|---|
| 404 | } | 
|---|
| 405 |  | 
|---|
| 406 | if(compdspec&1) { | 
|---|
| 407 | HistoErr hpkgenf(hpkgen); | 
|---|
| 408 | if(filter_by_pixel!=0) { | 
|---|
| 409 | cout<<"\n--- Checking realization spectra"<<endl; | 
|---|
| 410 | hpkgenf.Zero(); hpkgenf.Show(); | 
|---|
| 411 | fluct3d.ComputeSpectrum(hpkgenf); | 
|---|
| 412 | PrtTim(">>>> End Checking realization 1D spectra"); | 
|---|
| 413 | } | 
|---|
| 414 | posobs.PutObject(hpkgenf,"hpkgenf"); | 
|---|
| 415 | } | 
|---|
| 416 | if(compdspec&2) { | 
|---|
| 417 | Histo2DErr hpkgenf2(hpkgen2); | 
|---|
| 418 | if(filter_by_pixel!=0) { | 
|---|
| 419 | cout<<"\n--- Checking realization 2D spectra"<<endl; | 
|---|
| 420 | hpkgenf2.Zero(); hpkgenf2.Show(); | 
|---|
| 421 | fluct3d.ComputeSpectrum2D(hpkgenf2); | 
|---|
| 422 | PrtTim(">>>> End Checking realization 2D spectra"); | 
|---|
| 423 | } | 
|---|
| 424 | posobs.PutObject(hpkgenf2,"hpkgenf2"); | 
|---|
| 425 | } | 
|---|
| 426 |  | 
|---|
| 427 | //----------------------------------------------------------------- | 
|---|
| 428 | if(whattowrt[0]&1) { | 
|---|
| 429 | tagobs = rootnameout + "_k.ppf"; | 
|---|
| 430 | fluct3d.WritePPF(tagobs,false); | 
|---|
| 431 | PrtTim(">>>> End WritePPF"); | 
|---|
| 432 | temporay_file = tagobs; | 
|---|
| 433 | } | 
|---|
| 434 | if(whattowrt[0]&2) { | 
|---|
| 435 | tagobs = "!" + rootnameout + "_k.fits"; | 
|---|
| 436 | fluct3d.WriteFits(tagobs); | 
|---|
| 437 | PrtTim(">>>> End WriteFits"); | 
|---|
| 438 | } | 
|---|
| 439 | if(comptransveloc && !(whattowrt[0]&1)) { | 
|---|
| 440 | cout<<">>> Writing FT cube (for transv veloc.) in "<<temporay_file<<endl; | 
|---|
| 441 | fluct3d.WritePPF(temporay_file,false); | 
|---|
| 442 | PrtTim(">>>> End Writing FT cube"); | 
|---|
| 443 | } | 
|---|
| 444 |  | 
|---|
| 445 | //----------------------------------------------------------------- | 
|---|
| 446 | cout<<"\n--- Computing a realization in real space"<<endl; | 
|---|
| 447 | double vdum1,vdum2; | 
|---|
| 448 | fluct3d.ComputeReal(); | 
|---|
| 449 | fluct3d.MinMax(vdum1,vdum2); | 
|---|
| 450 | fluct3d.MeanSigma2(vdum1,vdum2); | 
|---|
| 451 | fluct3d.NTupleCheck(posobs,string("ntreal"),ntnent); | 
|---|
| 452 | PrtTim(">>>> End Computing a realization in real space"); | 
|---|
| 453 |  | 
|---|
| 454 | if(use_growth_factor>0) { | 
|---|
| 455 | cout<<"\n--- Apply Growth factor"<<endl; | 
|---|
| 456 | cout<<"...D(z=0)="<<growth(0.)<<"  D(z="<<zref<<")="<<growth(zref)<<endl; | 
|---|
| 457 | fluct3d.ApplyGrowthFactor(use_growth_factor); | 
|---|
| 458 | fluct3d.MinMax(vdum1,vdum2); | 
|---|
| 459 | fluct3d.MeanSigma2(vdum1,vdum2); | 
|---|
| 460 | fluct3d.NTupleCheck(posobs,string("ntgrow"),ntnent); | 
|---|
| 461 | PrtTim(">>>> End Applying growth factor"); | 
|---|
| 462 | } | 
|---|
| 463 |  | 
|---|
| 464 | if(whattowrt[1]&1) { | 
|---|
| 465 | tagobs = rootnameout + "_r.ppf"; | 
|---|
| 466 | fluct3d.WritePPF(tagobs,true); | 
|---|
| 467 | PrtTim(">>>> End WritePPF"); | 
|---|
| 468 | } | 
|---|
| 469 | if(whattowrt[1]&2) { | 
|---|
| 470 | tagobs = "!" + rootnameout + "_r.fits"; | 
|---|
| 471 | fluct3d.WriteFits(tagobs); | 
|---|
| 472 | PrtTim(">>>> End WriteFits"); | 
|---|
| 473 | } | 
|---|
| 474 | if(wslice) { | 
|---|
| 475 | tagobs = rootnameout + "_s_r.ppf"; | 
|---|
| 476 | fluct3d.WriteSlicePPF(tagobs); | 
|---|
| 477 | PrtTim(">>>> End WriteSlicePPF"); | 
|---|
| 478 | } | 
|---|
| 479 |  | 
|---|
| 480 | //----------------------------------------------------------------- | 
|---|
| 481 | if(compvarreal) { | 
|---|
| 482 | cout<<"\n--- Check variance sigmaR in real space"<<endl; | 
|---|
| 483 | double varr; | 
|---|
| 484 | fluct3d.VarianceFrReal(R,varr); | 
|---|
| 485 | cout<<"...Computed variance = "<<varr | 
|---|
| 486 | <<" , Theorical variance at (z=0) = "<<pow(sigmaR,2.) | 
|---|
| 487 | <<" , at (z="<<zref<<") = "<<pow(sigmaR*growth_at_z,2.)<<endl; | 
|---|
| 488 | PrtTim(">>>> End Check variance sigmaR in real space"); | 
|---|
| 489 | } | 
|---|
| 490 |  | 
|---|
| 491 | //----------------------------------------------------------------- | 
|---|
| 492 | if(compdspec&4) { // ATTENTION:  d_rho/rho ecrase | 
|---|
| 493 | cout<<endl<<"\n--- ReComputing spectrum from real space" | 
|---|
| 494 | <<"\n    Warning: REAL SPACE CUBE OVERWRITTEN"<<endl; | 
|---|
| 495 | fluct3d.ReComputeFourier(); | 
|---|
| 496 | fluct3d.NTupleCheck(posobs,string("ntpkrec"),ntnent); | 
|---|
| 497 | PrtTim(">>>> End ReComputing spectrum"); | 
|---|
| 498 |  | 
|---|
| 499 | cout<<endl<<"\n--- Computing final spectrum"<<endl; | 
|---|
| 500 | HistoErr hpkrecb(0.,knyqmax,nherr); hpkrecb.Zero(); | 
|---|
| 501 | hpkrecb.ReCenterBin(); hpkrecb.Show(); | 
|---|
| 502 | fluct3d.ComputeSpectrum(hpkrecb); | 
|---|
| 503 | posobs.PutObject(hpkrecb,"hpkrecb"); | 
|---|
| 504 | PrtTim(">>>> End Computing final spectrum"); | 
|---|
| 505 |  | 
|---|
| 506 | HistoErr hpkrec(hpkrecb); | 
|---|
| 507 | if(filter_by_pixel!=0) { | 
|---|
| 508 | cout<<endl<<"\n--- Computing final spectrum with pixel deconv."<<endl; | 
|---|
| 509 | hpkrec.Zero(); | 
|---|
| 510 | fluct3d.ComputeSpectrum(hpkrec,0.,filter_by_pixel); | 
|---|
| 511 | PrtTim(">>>> End Computing final spectrum with pixel deconv."); | 
|---|
| 512 | } | 
|---|
| 513 | posobs.PutObject(hpkrec,"hpkrec"); | 
|---|
| 514 |  | 
|---|
| 515 | cout<<"\n--- Computing final 2D spectrum"<<endl; | 
|---|
| 516 | Histo2DErr hpkrecb2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz); | 
|---|
| 517 | hpkrecb2.ReCenterBin(); hpkrecb2.Zero(); hpkrecb2.Show(); | 
|---|
| 518 | fluct3d.ComputeSpectrum2D(hpkrecb2); | 
|---|
| 519 | posobs.PutObject(hpkrecb2,"hpkrecb2"); | 
|---|
| 520 | PrtTim(">>>> End Computing final 2D spectrum"); | 
|---|
| 521 |  | 
|---|
| 522 | Histo2DErr hpkrec2(hpkrecb2); | 
|---|
| 523 | if(filter_by_pixel!=0) { | 
|---|
| 524 | cout<<"\n--- Computing final 2D spectrum with pixel deconv."<<endl; | 
|---|
| 525 | hpkrec2.Zero(); | 
|---|
| 526 | fluct3d.ComputeSpectrum2D(hpkrec2,0.,filter_by_pixel); | 
|---|
| 527 | PrtTim(">>>> End Computing final 2D spectrum with pixel deconv."); | 
|---|
| 528 | } | 
|---|
| 529 | posobs.PutObject(hpkrec2,"hpkrec2"); | 
|---|
| 530 | } | 
|---|
| 531 |  | 
|---|
| 532 | //----------------------------------------------------------------- | 
|---|
| 533 | //----------------------------------------------------------------- | 
|---|
| 534 | //----------------------------------------------------------------- | 
|---|
| 535 |  | 
|---|
| 536 | if(comptransveloc) { | 
|---|
| 537 | cout<<"\n\n\n"<<"---------------------------------------------\n" | 
|---|
| 538 | <<"--- Transverse velocity space computation ---\n" | 
|---|
| 539 | <<"---------------------------------------------\n"<<endl; | 
|---|
| 540 |  | 
|---|
| 541 | //----------------------------------------------------------------- | 
|---|
| 542 | cout<<"\n--- Reading back the Pk(vec(k)) cube from "<<temporay_file<<endl; | 
|---|
| 543 | fluct3d.ReadPPF(temporay_file); | 
|---|
| 544 | PrtTim(">>>> End Reading the Pk(vec(k)) cube"); | 
|---|
| 545 |  | 
|---|
| 546 | if(compdspec&1) { | 
|---|
| 547 | cout<<"\n--- Check realization spectra that has been re-read"<<endl; | 
|---|
| 548 | HistoErr hpkgenf_rr(hpkgen); hpkgenf_rr.Zero(); | 
|---|
| 549 | fluct3d.ComputeSpectrum(hpkgenf_rr); | 
|---|
| 550 | PrtTim(">>>> End Checking re-read realization 1D spectra"); | 
|---|
| 551 | posobs.PutObject(hpkgenf_rr,"hpkgenf_rr"); | 
|---|
| 552 | } | 
|---|
| 553 |  | 
|---|
| 554 | //----------------------------------------------------------------- | 
|---|
| 555 | cout<<"\n--- Modifying cube for Transverse velocity"<<endl; | 
|---|
| 556 | fluct3d.ToVelLoS(); | 
|---|
| 557 | fluct3d.NTupleCheck(posobs,string("ntpvgenf"),ntnent); | 
|---|
| 558 | PrtTim(">>>> End Modifying cube for Transverse velocity"); | 
|---|
| 559 |  | 
|---|
| 560 | if(compdspec&1) { | 
|---|
| 561 | cout<<"\n--- Checking realization spectra"<<endl; | 
|---|
| 562 | HistoErr hpvgen(0.,knyqmax,nherr); | 
|---|
| 563 | hpvgen.ReCenterBin(); hpvgen.Zero(); hpvgen.Show(); | 
|---|
| 564 | fluct3d.ComputeSpectrum(hpvgen); | 
|---|
| 565 | posobs.PutObject(hpvgen,"hpvgen"); | 
|---|
| 566 | PrtTim(">>>> End Checking realization 1D spectra"); | 
|---|
| 567 | } | 
|---|
| 568 | if(compdspec&2) { | 
|---|
| 569 | cout<<"\n--- Checking realization 2D spectra"<<endl; | 
|---|
| 570 | Histo2DErr hpvgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz); | 
|---|
| 571 | hpvgen2.ReCenterBin(); hpvgen2.Zero(); hpvgen2.Show(); | 
|---|
| 572 | fluct3d.ComputeSpectrum2D(hpvgen2); | 
|---|
| 573 | posobs.PutObject(hpvgen2,"hpvgen2"); | 
|---|
| 574 | PrtTim(">>>> End Checking realization 2D spectra"); | 
|---|
| 575 | } | 
|---|
| 576 |  | 
|---|
| 577 | if(whattowrt[0]&1) { | 
|---|
| 578 | tagobs = rootnameout + "_kv.ppf"; | 
|---|
| 579 | fluct3d.WritePPF(tagobs,false); | 
|---|
| 580 | PrtTim(">>>> End WritePPF"); | 
|---|
| 581 | } | 
|---|
| 582 | if(whattowrt[0]&2) { | 
|---|
| 583 | tagobs = "!" + rootnameout + "_kv.fits"; | 
|---|
| 584 | fluct3d.WriteFits(tagobs); | 
|---|
| 585 | PrtTim(">>>> End WriteFits"); | 
|---|
| 586 | } | 
|---|
| 587 |  | 
|---|
| 588 | //----------------------------------------------------------------- | 
|---|
| 589 | cout<<"\n--- Computing a realization in real space for Transverse velocity"<<endl; | 
|---|
| 590 | fluct3d.ComputeReal(); | 
|---|
| 591 | fluct3d.MinMax(vdum1,vdum2); | 
|---|
| 592 | fluct3d.MeanSigma2(vdum1,vdum2); | 
|---|
| 593 | fluct3d.NTupleCheck(posobs,string("nvreal"),ntnent); | 
|---|
| 594 | PrtTim(">>>> End Computing a realization in real space"); | 
|---|
| 595 |  | 
|---|
| 596 | if(use_growth_factor>0) { | 
|---|
| 597 | cout<<"\n--- Apply Growth factor for transverse velocity"<<endl; | 
|---|
| 598 | cout<<"...D(z=0)="<<growth(0.)<<"  D(z="<<zref<<")="<<growth(zref)<<endl; | 
|---|
| 599 | fluct3d.ApplyVelLosGrowthFactor(use_growth_factor); | 
|---|
| 600 | fluct3d.MinMax(vdum1,vdum2); | 
|---|
| 601 | fluct3d.MeanSigma2(vdum1,vdum2); | 
|---|
| 602 | fluct3d.NTupleCheck(posobs,string("nvgrow"),ntnent); | 
|---|
| 603 | PrtTim(">>>> End Applying growth factor"); | 
|---|
| 604 | } | 
|---|
| 605 |  | 
|---|
| 606 | if(whattowrt[1]&1) { | 
|---|
| 607 | tagobs = rootnameout + "_rv.ppf"; | 
|---|
| 608 | fluct3d.WritePPF(tagobs,true); | 
|---|
| 609 | PrtTim(">>>> End WritePPF"); | 
|---|
| 610 | } | 
|---|
| 611 | if(whattowrt[1]&2) { | 
|---|
| 612 | tagobs = "!" + rootnameout + "_rv.fits"; | 
|---|
| 613 | fluct3d.WriteFits(tagobs); | 
|---|
| 614 | PrtTim(">>>> End WriteFits"); | 
|---|
| 615 | } | 
|---|
| 616 | if(wslice) { | 
|---|
| 617 | tagobs = rootnameout + "_s_rv.ppf"; | 
|---|
| 618 | fluct3d.WriteSlicePPF(tagobs); | 
|---|
| 619 | PrtTim(">>>> End WriteSlicePPF"); | 
|---|
| 620 | } | 
|---|
| 621 |  | 
|---|
| 622 | } | 
|---|
| 623 |  | 
|---|
| 624 | //----------------------------------------------------------------- | 
|---|
| 625 | { | 
|---|
| 626 | DVList dvl; | 
|---|
| 627 | dvl("Nx") = (int_4)fluct3d.Nx(); dvl("Ny") = (int_4)fluct3d.Ny(); dvl("Nz") = (int_4)fluct3d.Nz(); | 
|---|
| 628 | dvl("Dx") = fluct3d.Dx(); dvl("Dy") = fluct3d.Dy(); dvl("Dz") = fluct3d.Dz(); | 
|---|
| 629 | dvl("Z") = fluct3d.Zref(); dvl("Zpk") = fluct3d.ZrefPk(); | 
|---|
| 630 | dvl("D") = fluct3d.Dref(); dvl("Dpk") = fluct3d.DrefPk(); | 
|---|
| 631 | dvl("s8") = sigmaR; | 
|---|
| 632 | dvl("Dtype") = (int_4)use_growth_factor; dvl("Pxfilt") = (int_4)filter_by_pixel; | 
|---|
| 633 | if(cambfread.size()>0) dvl("fCAMB") = cambfread; | 
|---|
| 634 | posobs.PutObject(dvl,"siminfo"); | 
|---|
| 635 | } | 
|---|
| 636 |  | 
|---|
| 637 | delete RandGen; | 
|---|
| 638 | if(pkz != NULL) delete pkz; | 
|---|
| 639 | PrtTim(">>>> End Of Job"); | 
|---|
| 640 |  | 
|---|
| 641 | //----TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH | 
|---|
| 642 | } catch (PException& exc) { | 
|---|
| 643 | cerr<<"cmvginit3d.cc catched PException"<<exc.Msg()<<endl; | 
|---|
| 644 | return 77; | 
|---|
| 645 | } catch (std::exception& sex) { | 
|---|
| 646 | cerr << "cmvginit3d.cc std::exception :" | 
|---|
| 647 | << (string)typeid(sex).name() << "\n msg= " | 
|---|
| 648 | << sex.what() << endl; | 
|---|
| 649 | return 78; | 
|---|
| 650 | } catch (...) { | 
|---|
| 651 | cerr << "cmvginit3d.cc catched unknown (...) exception  " << endl; | 
|---|
| 652 | return 79; | 
|---|
| 653 | } | 
|---|
| 654 | //----TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH | 
|---|
| 655 |  | 
|---|
| 656 | return 0; | 
|---|
| 657 | } | 
|---|
| 658 |  | 
|---|
| 659 | #include "strutilxx.h" | 
|---|
| 660 | string decodecambarg(string arg,double& h, double& z) | 
|---|
| 661 | // - decode argument for CAMB generation: | 
|---|
| 662 | // input: arg = "cambfilename,h100tab,ztab" | 
|---|
| 663 | // output: h = h100 use to generate CAMB file | 
|---|
| 664 | //         z = redshift use to generate CAMB file | 
|---|
| 665 | // return: CAMB file name | 
|---|
| 666 | { | 
|---|
| 667 | h = -1.; | 
|---|
| 668 | z = 0.; | 
|---|
| 669 | vector<string> vs; | 
|---|
| 670 | FillVStringFrString(arg,vs,','); | 
|---|
| 671 | if(vs.size()>1) h = atof(vs[1].c_str()); | 
|---|
| 672 | if(vs.size()>2) z = atof(vs[2].c_str()); | 
|---|
| 673 | cout<<"decodecambarg: "<<arg<<" fn=\""<<vs[0]<<"\" h="<<h<<" z="<<z<<endl; | 
|---|
| 674 | return vs[0]; | 
|---|
| 675 | } | 
|---|