[3768] | 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 |
|
---|
[3806] | 23 | string decodecambarg(string arg,double& h, double& z);
|
---|
| 24 |
|
---|
[3768] | 25 | void usage(void);
|
---|
| 26 | void usage(void)
|
---|
| 27 | {
|
---|
[3782] | 28 | cout<<"cmvginit3d [...options...]"<<endl
|
---|
[3768] | 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
|
---|
[3806] | 40 | <<" -f cambspec.dat,h100tab,ztab : use CAMB file (def: Eisenstein spectrum)"<<endl
|
---|
[3768] | 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
|
---|
[3782] | 49 | <<" -O a,b : tell what you want to write"<<endl
|
---|
[3768] | 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
|
---|
[3782] | 54 | <<" -o out_base_name : base string for output file name (def: cmvginit3d)"<<endl
|
---|
[3768] | 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;
|
---|
[3806] | 74 | double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73, w0=-1.;
|
---|
[3768] | 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 |
|
---|
[3806] | 83 | double kmin=1e-4,kmax=100.;
|
---|
| 84 | int npt = 1000;
|
---|
[3768] | 85 | double eps=1.e-3;
|
---|
| 86 |
|
---|
[3806] | 87 | // *** Spectrum read from CAMB file
|
---|
| 88 | string cambfread = "";
|
---|
| 89 |
|
---|
[3768] | 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;
|
---|
[3806] | 122 | while((c = getopt(narg,arg,"haG:F:x:y:z:Z:128:v:n:CO:So:VT:f:")) != -1) {
|
---|
[3768] | 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;
|
---|
[3806] | 182 | case 'f' :
|
---|
| 183 | cambfread = optarg;
|
---|
| 184 | break;
|
---|
[3768] | 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;
|
---|
[3806] | 199 | cout<<"kmin="<<kmin<<" ("<<log10(kmin)<<"), kmax="<<kmax<<" ("<<log10(kmax)<<") Mpc^-1"<<", npt="<<npt<<endl;
|
---|
[3768] | 200 | cout<<"Filter by pixel = "<<filter_by_pixel<<endl;
|
---|
| 201 | if(comptransveloc) cout<<"Tansverse velocity generation requested"<<endl;
|
---|
[3806] | 202 | if(cambfread.size()>0) cout<<"use CAMB file: cambfread="<<cambfread<<endl;
|
---|
[3768] | 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 | //-----------------------------------------------------------------
|
---|
[3806] | 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 | //-----------------------------------------------------------------
|
---|
[3768] | 235 | cout<<endl<<"\n--- Create Spectrum"<<endl;
|
---|
| 236 |
|
---|
[3805] | 237 | InitialPowerLaw pkini(ns,as);
|
---|
[3768] | 238 |
|
---|
[3782] | 239 | TransfertEisenstein tfnos(h100,om0-ob0,ob0,T_CMB_Par,false);
|
---|
| 240 | tfnos.SetNoOscEnv(2);
|
---|
[3806] | 241 | TransfertEisenstein tf(h100,om0-ob0,ob0,T_CMB_Par,false);
|
---|
[3768] | 242 |
|
---|
[3805] | 243 | PkSpecCalc pkznos(pkini,tfnos,growth,zref);
|
---|
[3806] | 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);
|
---|
[3821] | 252 | pkzt->SetInterpTyp(2);
|
---|
[3806] | 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 | }
|
---|
[3768] | 263 |
|
---|
| 264 | //-----------------------------------------------------------------
|
---|
[3806] | 265 | cout<<endl<<"\n--- Normalize Spectrum"<<endl;
|
---|
| 266 |
|
---|
| 267 | pkz->SetZ(0.);
|
---|
[3782] | 268 | pkznos.SetZ(0.);
|
---|
[3768] | 269 |
|
---|
[3806] | 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;
|
---|
[3768] | 290 |
|
---|
[3806] | 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 |
|
---|
[3768] | 301 | {
|
---|
[3806] | 302 | Histo hpkz0(log10(kmin),log10(kmax),npt); hpkz0.ReCenterBin();
|
---|
| 303 | FuncToHisto(*pkz,hpkz0,true);
|
---|
[3768] | 304 | posobs.PutObject(hpkz0,"hpkz0");
|
---|
[3782] | 305 | Histo hpkz0nos(hpkz0);
|
---|
| 306 | FuncToHisto(pkznos,hpkz0nos,true);
|
---|
| 307 | posobs.PutObject(hpkz0nos,"hpkz0nos");
|
---|
[3768] | 308 | }
|
---|
| 309 |
|
---|
[3806] | 310 | pkz->SetZ(zref);
|
---|
[3782] | 311 | pkznos.SetZ(zref);
|
---|
[3806] | 312 |
|
---|
[3768] | 313 | {
|
---|
[3806] | 314 | Histo hpkz(log10(kmin),log10(kmax),npt); hpkz.ReCenterBin();
|
---|
| 315 | FuncToHisto(*pkz,hpkz,true);
|
---|
[3768] | 316 | posobs.PutObject(hpkz,"hpkz");
|
---|
[3782] | 317 | Histo hpkznos(hpkz);
|
---|
| 318 | FuncToHisto(pkznos,hpkznos,true);
|
---|
| 319 | posobs.PutObject(hpkznos,"hpkznos");
|
---|
[3768] | 320 | }
|
---|
| 321 |
|
---|
| 322 | //-----------------------------------------------------------------
|
---|
[3806] | 323 | cout<<endl<<"\n--- Compute variance for Pk at z="<<pkz->GetZ()<<endl;
|
---|
| 324 | VarianceSpectrum varpk_int(*pkz,R,VarianceSpectrum::NOFILTER);
|
---|
[3768] | 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 |
|
---|
| 372 | //-----------------------------------------------------------------
|
---|
[3806] | 373 | cout<<"\n--- Computing spectra variance up to Kmax at z="<<pkz->GetZ()<<endl;
|
---|
[3768] | 374 | // En fait on travaille sur un cube inscrit dans la sphere de rayon kmax:
|
---|
| 375 | // sphere: Vs = 4Pi/3 k^3 , cube inscrit (cote k*sqrt(2)): Vc = (k*sqrt(2))^3
|
---|
| 376 | // Vc/Vs = 0.675 -> keff = kmax * (0.675)^(1/3) = kmax * 0.877
|
---|
| 377 | double knyqmax_mod = 0.877*knyqmax;
|
---|
| 378 | ldlkint = (log10(knyqmax_mod)-log10(k1int))/npt;
|
---|
| 379 | varpk_int.SetInteg(0.01,ldlkint,-1.,4);
|
---|
| 380 | double sr2int_kmax = varpk_int.Variance(k1int,knyqmax_mod);
|
---|
| 381 | cout<<"varpk_int(<"<<knyqmax_mod<<")="<<sr2int_kmax<<" -> sigma="<<sqrt(sr2int_kmax)<<endl;
|
---|
| 382 |
|
---|
| 383 | PrtTim(">>>> End Initialisation of GeneFluct3D");
|
---|
| 384 |
|
---|
| 385 | //-----------------------------------------------------------------
|
---|
| 386 | cout<<"\n--- Computing a realization in Fourier space"<<endl;
|
---|
[3806] | 387 | if(use_growth_factor>0) pkz->SetZ(0.); else pkz->SetZ(zref);
|
---|
| 388 | cout<<"Power spectrum set at redshift: "<<pkz->GetZ()<<endl;
|
---|
| 389 | fluct3d.ComputeFourier(*pkz);
|
---|
[3768] | 390 | fluct3d.NTupleCheck(posobs,string("ntpkgen"),ntnent);
|
---|
| 391 | PrtTim(">>>> End Computing a realization in Fourier space");
|
---|
| 392 |
|
---|
| 393 | HistoErr hpkgen(0.,knyqmax,nherr);
|
---|
| 394 | if(compdspec&1) {
|
---|
| 395 | cout<<"\n--- Checking realization spectra"<<endl;
|
---|
| 396 | hpkgen.ReCenterBin(); hpkgen.Zero(); hpkgen.Show();
|
---|
| 397 | fluct3d.ComputeSpectrum(hpkgen);
|
---|
| 398 | posobs.PutObject(hpkgen,"hpkgen");
|
---|
| 399 | PrtTim(">>>> End Checking realization 1D spectra");
|
---|
| 400 | }
|
---|
| 401 | Histo2DErr hpkgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
|
---|
| 402 | if(compdspec&2) {
|
---|
| 403 | cout<<"\n--- Checking realization 2D spectra"<<endl;
|
---|
| 404 | hpkgen2.ReCenterBin(); hpkgen2.Zero(); hpkgen2.Show();
|
---|
| 405 | fluct3d.ComputeSpectrum2D(hpkgen2);
|
---|
| 406 | posobs.PutObject(hpkgen2,"hpkgen2");
|
---|
| 407 | PrtTim(">>>> End Checking realization 2D spectra");
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | //-----------------------------------------------------------------
|
---|
| 411 | if(filter_by_pixel!=0) {
|
---|
| 412 | cout<<"\n--- Computing convolution by pixel shape"<<endl;
|
---|
| 413 | fluct3d.FilterByPixel();
|
---|
| 414 | fluct3d.NTupleCheck(posobs,string("ntpkgenf"),ntnent);
|
---|
| 415 | PrtTim(">>>> End Computing convolution by pixel shape");
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | if(compdspec&1) {
|
---|
| 419 | HistoErr hpkgenf(hpkgen);
|
---|
| 420 | if(filter_by_pixel!=0) {
|
---|
| 421 | cout<<"\n--- Checking realization spectra"<<endl;
|
---|
| 422 | hpkgenf.Zero(); hpkgenf.Show();
|
---|
| 423 | fluct3d.ComputeSpectrum(hpkgenf);
|
---|
| 424 | PrtTim(">>>> End Checking realization 1D spectra");
|
---|
| 425 | }
|
---|
| 426 | posobs.PutObject(hpkgenf,"hpkgenf");
|
---|
| 427 | }
|
---|
| 428 | if(compdspec&2) {
|
---|
| 429 | Histo2DErr hpkgenf2(hpkgen2);
|
---|
| 430 | if(filter_by_pixel!=0) {
|
---|
| 431 | cout<<"\n--- Checking realization 2D spectra"<<endl;
|
---|
| 432 | hpkgenf2.Zero(); hpkgenf2.Show();
|
---|
| 433 | fluct3d.ComputeSpectrum2D(hpkgenf2);
|
---|
| 434 | PrtTim(">>>> End Checking realization 2D spectra");
|
---|
| 435 | }
|
---|
| 436 | posobs.PutObject(hpkgenf2,"hpkgenf2");
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | //-----------------------------------------------------------------
|
---|
| 440 | if(whattowrt[0]&1) {
|
---|
| 441 | tagobs = rootnameout + "_k.ppf";
|
---|
| 442 | fluct3d.WritePPF(tagobs,false);
|
---|
| 443 | PrtTim(">>>> End WritePPF");
|
---|
| 444 | temporay_file = tagobs;
|
---|
| 445 | }
|
---|
| 446 | if(whattowrt[0]&2) {
|
---|
| 447 | tagobs = "!" + rootnameout + "_k.fits";
|
---|
| 448 | fluct3d.WriteFits(tagobs);
|
---|
| 449 | PrtTim(">>>> End WriteFits");
|
---|
| 450 | }
|
---|
| 451 | if(comptransveloc && !(whattowrt[0]&1)) {
|
---|
| 452 | cout<<">>> Writing FT cube (for transv veloc.) in "<<temporay_file<<endl;
|
---|
| 453 | fluct3d.WritePPF(temporay_file,false);
|
---|
| 454 | PrtTim(">>>> End Writing FT cube");
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | //-----------------------------------------------------------------
|
---|
| 458 | cout<<"\n--- Computing a realization in real space"<<endl;
|
---|
[3806] | 459 | double vdum1,vdum2;
|
---|
[3768] | 460 | fluct3d.ComputeReal();
|
---|
[3806] | 461 | fluct3d.MinMax(vdum1,vdum2);
|
---|
| 462 | fluct3d.MeanSigma2(vdum1,vdum2);
|
---|
[3768] | 463 | fluct3d.NTupleCheck(posobs,string("ntreal"),ntnent);
|
---|
| 464 | PrtTim(">>>> End Computing a realization in real space");
|
---|
| 465 |
|
---|
| 466 | if(use_growth_factor>0) {
|
---|
| 467 | cout<<"\n--- Apply Growth factor"<<endl;
|
---|
| 468 | cout<<"...D(z=0)="<<growth(0.)<<" D(z="<<zref<<")="<<growth(zref)<<endl;
|
---|
| 469 | fluct3d.ApplyGrowthFactor(use_growth_factor);
|
---|
[3806] | 470 | fluct3d.MinMax(vdum1,vdum2);
|
---|
| 471 | fluct3d.MeanSigma2(vdum1,vdum2);
|
---|
[3768] | 472 | fluct3d.NTupleCheck(posobs,string("ntgrow"),ntnent);
|
---|
| 473 | PrtTim(">>>> End Applying growth factor");
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | if(whattowrt[1]&1) {
|
---|
| 477 | tagobs = rootnameout + "_r.ppf";
|
---|
| 478 | fluct3d.WritePPF(tagobs,true);
|
---|
| 479 | PrtTim(">>>> End WritePPF");
|
---|
| 480 | }
|
---|
| 481 | if(whattowrt[1]&2) {
|
---|
| 482 | tagobs = "!" + rootnameout + "_r.fits";
|
---|
| 483 | fluct3d.WriteFits(tagobs);
|
---|
| 484 | PrtTim(">>>> End WriteFits");
|
---|
| 485 | }
|
---|
| 486 | if(wslice) {
|
---|
| 487 | tagobs = rootnameout + "_s_r.ppf";
|
---|
| 488 | fluct3d.WriteSlicePPF(tagobs);
|
---|
| 489 | PrtTim(">>>> End WriteSlicePPF");
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | //-----------------------------------------------------------------
|
---|
| 493 | if(compvarreal) {
|
---|
| 494 | cout<<"\n--- Check variance sigmaR in real space"<<endl;
|
---|
| 495 | double varr;
|
---|
| 496 | fluct3d.VarianceFrReal(R,varr);
|
---|
| 497 | cout<<"...Computed variance = "<<varr
|
---|
| 498 | <<" , Theorical variance at (z=0) = "<<pow(sigmaR,2.)
|
---|
| 499 | <<" , at (z="<<zref<<") = "<<pow(sigmaR*growth_at_z,2.)<<endl;
|
---|
| 500 | PrtTim(">>>> End Check variance sigmaR in real space");
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | //-----------------------------------------------------------------
|
---|
| 504 | if(compdspec&4) { // ATTENTION: d_rho/rho ecrase
|
---|
| 505 | cout<<endl<<"\n--- ReComputing spectrum from real space"
|
---|
| 506 | <<"\n Warning: REAL SPACE CUBE OVERWRITTEN"<<endl;
|
---|
| 507 | fluct3d.ReComputeFourier();
|
---|
| 508 | fluct3d.NTupleCheck(posobs,string("ntpkrec"),ntnent);
|
---|
| 509 | PrtTim(">>>> End ReComputing spectrum");
|
---|
| 510 |
|
---|
| 511 | cout<<endl<<"\n--- Computing final spectrum"<<endl;
|
---|
| 512 | HistoErr hpkrecb(0.,knyqmax,nherr); hpkrecb.Zero();
|
---|
| 513 | hpkrecb.ReCenterBin(); hpkrecb.Show();
|
---|
| 514 | fluct3d.ComputeSpectrum(hpkrecb);
|
---|
| 515 | posobs.PutObject(hpkrecb,"hpkrecb");
|
---|
| 516 | PrtTim(">>>> End Computing final spectrum");
|
---|
| 517 |
|
---|
| 518 | HistoErr hpkrec(hpkrecb);
|
---|
| 519 | if(filter_by_pixel!=0) {
|
---|
| 520 | cout<<endl<<"\n--- Computing final spectrum with pixel deconv."<<endl;
|
---|
| 521 | hpkrec.Zero();
|
---|
| 522 | fluct3d.ComputeSpectrum(hpkrec,0.,filter_by_pixel);
|
---|
| 523 | PrtTim(">>>> End Computing final spectrum with pixel deconv.");
|
---|
| 524 | }
|
---|
| 525 | posobs.PutObject(hpkrec,"hpkrec");
|
---|
| 526 |
|
---|
| 527 | cout<<"\n--- Computing final 2D spectrum"<<endl;
|
---|
| 528 | Histo2DErr hpkrecb2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
|
---|
| 529 | hpkrecb2.ReCenterBin(); hpkrecb2.Zero(); hpkrecb2.Show();
|
---|
| 530 | fluct3d.ComputeSpectrum2D(hpkrecb2);
|
---|
| 531 | posobs.PutObject(hpkrecb2,"hpkrecb2");
|
---|
| 532 | PrtTim(">>>> End Computing final 2D spectrum");
|
---|
| 533 |
|
---|
| 534 | Histo2DErr hpkrec2(hpkrecb2);
|
---|
| 535 | if(filter_by_pixel!=0) {
|
---|
| 536 | cout<<"\n--- Computing final 2D spectrum with pixel deconv."<<endl;
|
---|
| 537 | hpkrec2.Zero();
|
---|
| 538 | fluct3d.ComputeSpectrum2D(hpkrec2,0.,filter_by_pixel);
|
---|
| 539 | PrtTim(">>>> End Computing final 2D spectrum with pixel deconv.");
|
---|
| 540 | }
|
---|
| 541 | posobs.PutObject(hpkrec2,"hpkrec2");
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | //-----------------------------------------------------------------
|
---|
| 545 | //-----------------------------------------------------------------
|
---|
| 546 | //-----------------------------------------------------------------
|
---|
| 547 |
|
---|
| 548 | if(comptransveloc) {
|
---|
| 549 | cout<<"\n\n\n"<<"---------------------------------------------\n"
|
---|
| 550 | <<"--- Transverse velocity space computation ---\n"
|
---|
| 551 | <<"---------------------------------------------\n"<<endl;
|
---|
| 552 |
|
---|
| 553 | //-----------------------------------------------------------------
|
---|
| 554 | cout<<"\n--- Reading back the Pk(vec(k)) cube from "<<temporay_file<<endl;
|
---|
| 555 | fluct3d.ReadPPF(temporay_file);
|
---|
| 556 | PrtTim(">>>> End Reading the Pk(vec(k)) cube");
|
---|
| 557 |
|
---|
[3781] | 558 | if(compdspec&1) {
|
---|
| 559 | cout<<"\n--- Check realization spectra that has been re-read"<<endl;
|
---|
| 560 | HistoErr hpkgenf_rr(hpkgen); hpkgenf_rr.Zero();
|
---|
| 561 | fluct3d.ComputeSpectrum(hpkgenf_rr);
|
---|
| 562 | PrtTim(">>>> End Checking re-read realization 1D spectra");
|
---|
| 563 | posobs.PutObject(hpkgenf_rr,"hpkgenf_rr");
|
---|
| 564 | }
|
---|
| 565 |
|
---|
[3768] | 566 | //-----------------------------------------------------------------
|
---|
| 567 | cout<<"\n--- Modifying cube for Transverse velocity"<<endl;
|
---|
[3770] | 568 | fluct3d.ToVelLoS();
|
---|
[3768] | 569 | fluct3d.NTupleCheck(posobs,string("ntpvgenf"),ntnent);
|
---|
| 570 | PrtTim(">>>> End Modifying cube for Transverse velocity");
|
---|
| 571 |
|
---|
| 572 | if(compdspec&1) {
|
---|
| 573 | cout<<"\n--- Checking realization spectra"<<endl;
|
---|
| 574 | HistoErr hpvgen(0.,knyqmax,nherr);
|
---|
| 575 | hpvgen.ReCenterBin(); hpvgen.Zero(); hpvgen.Show();
|
---|
| 576 | fluct3d.ComputeSpectrum(hpvgen);
|
---|
| 577 | posobs.PutObject(hpvgen,"hpvgen");
|
---|
| 578 | PrtTim(">>>> End Checking realization 1D spectra");
|
---|
| 579 | }
|
---|
| 580 | if(compdspec&2) {
|
---|
| 581 | cout<<"\n--- Checking realization 2D spectra"<<endl;
|
---|
| 582 | Histo2DErr hpvgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
|
---|
| 583 | hpvgen2.ReCenterBin(); hpvgen2.Zero(); hpvgen2.Show();
|
---|
| 584 | fluct3d.ComputeSpectrum2D(hpvgen2);
|
---|
| 585 | posobs.PutObject(hpvgen2,"hpvgen2");
|
---|
| 586 | PrtTim(">>>> End Checking realization 2D spectra");
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | if(whattowrt[0]&1) {
|
---|
| 590 | tagobs = rootnameout + "_kv.ppf";
|
---|
| 591 | fluct3d.WritePPF(tagobs,false);
|
---|
| 592 | PrtTim(">>>> End WritePPF");
|
---|
| 593 | }
|
---|
| 594 | if(whattowrt[0]&2) {
|
---|
| 595 | tagobs = "!" + rootnameout + "_kv.fits";
|
---|
| 596 | fluct3d.WriteFits(tagobs);
|
---|
| 597 | PrtTim(">>>> End WriteFits");
|
---|
| 598 | }
|
---|
| 599 |
|
---|
| 600 | //-----------------------------------------------------------------
|
---|
| 601 | cout<<"\n--- Computing a realization in real space for Transverse velocity"<<endl;
|
---|
| 602 | fluct3d.ComputeReal();
|
---|
[3806] | 603 | fluct3d.MinMax(vdum1,vdum2);
|
---|
| 604 | fluct3d.MeanSigma2(vdum1,vdum2);
|
---|
[3768] | 605 | fluct3d.NTupleCheck(posobs,string("nvreal"),ntnent);
|
---|
| 606 | PrtTim(">>>> End Computing a realization in real space");
|
---|
| 607 |
|
---|
| 608 | if(use_growth_factor>0) {
|
---|
[3806] | 609 | cout<<"\n--- Apply Growth factor for transverse velocity"<<endl;
|
---|
[3768] | 610 | cout<<"...D(z=0)="<<growth(0.)<<" D(z="<<zref<<")="<<growth(zref)<<endl;
|
---|
[3800] | 611 | fluct3d.ApplyVelLosGrowthFactor(use_growth_factor);
|
---|
[3806] | 612 | fluct3d.MinMax(vdum1,vdum2);
|
---|
| 613 | fluct3d.MeanSigma2(vdum1,vdum2);
|
---|
[3768] | 614 | fluct3d.NTupleCheck(posobs,string("nvgrow"),ntnent);
|
---|
| 615 | PrtTim(">>>> End Applying growth factor");
|
---|
| 616 | }
|
---|
| 617 |
|
---|
| 618 | if(whattowrt[1]&1) {
|
---|
| 619 | tagobs = rootnameout + "_rv.ppf";
|
---|
| 620 | fluct3d.WritePPF(tagobs,true);
|
---|
| 621 | PrtTim(">>>> End WritePPF");
|
---|
| 622 | }
|
---|
| 623 | if(whattowrt[1]&2) {
|
---|
| 624 | tagobs = "!" + rootnameout + "_rv.fits";
|
---|
| 625 | fluct3d.WriteFits(tagobs);
|
---|
| 626 | PrtTim(">>>> End WriteFits");
|
---|
| 627 | }
|
---|
| 628 | if(wslice) {
|
---|
| 629 | tagobs = rootnameout + "_s_rv.ppf";
|
---|
| 630 | fluct3d.WriteSlicePPF(tagobs);
|
---|
| 631 | PrtTim(">>>> End WriteSlicePPF");
|
---|
| 632 | }
|
---|
| 633 |
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | //-----------------------------------------------------------------
|
---|
| 637 | {
|
---|
| 638 | DVList dvl;
|
---|
| 639 | dvl("Nx") = (int_4)fluct3d.Nx(); dvl("Ny") = (int_4)fluct3d.Ny(); dvl("Nz") = (int_4)fluct3d.Nz();
|
---|
| 640 | dvl("Dx") = fluct3d.Dx(); dvl("Dy") = fluct3d.Dy(); dvl("Dz") = fluct3d.Dz();
|
---|
| 641 | dvl("Z") = fluct3d.Zref(); dvl("Zpk") = fluct3d.ZrefPk();
|
---|
| 642 | dvl("D") = fluct3d.Dref(); dvl("Dpk") = fluct3d.DrefPk();
|
---|
| 643 | dvl("s8") = sigmaR;
|
---|
| 644 | dvl("Dtype") = (int_4)use_growth_factor; dvl("Pxfilt") = (int_4)filter_by_pixel;
|
---|
[3806] | 645 | if(cambfread.size()>0) dvl("fCAMB") = cambfread;
|
---|
[3768] | 646 | posobs.PutObject(dvl,"siminfo");
|
---|
| 647 | }
|
---|
| 648 |
|
---|
| 649 | delete RandGen;
|
---|
[3806] | 650 | if(pkz != NULL) delete pkz;
|
---|
[3768] | 651 | PrtTim(">>>> End Of Job");
|
---|
| 652 |
|
---|
| 653 | //----TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH
|
---|
| 654 | } catch (PException& exc) {
|
---|
[3770] | 655 | cerr<<"cmvginit3d.cc catched PException"<<exc.Msg()<<endl;
|
---|
[3768] | 656 | return 77;
|
---|
| 657 | } catch (std::exception& sex) {
|
---|
[3770] | 658 | cerr << "cmvginit3d.cc std::exception :"
|
---|
[3768] | 659 | << (string)typeid(sex).name() << "\n msg= "
|
---|
| 660 | << sex.what() << endl;
|
---|
| 661 | return 78;
|
---|
| 662 | } catch (...) {
|
---|
[3770] | 663 | cerr << "cmvginit3d.cc catched unknown (...) exception " << endl;
|
---|
[3768] | 664 | return 79;
|
---|
| 665 | }
|
---|
| 666 | //----TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH
|
---|
| 667 |
|
---|
| 668 | return 0;
|
---|
| 669 | }
|
---|
| 670 |
|
---|
[3806] | 671 | #include "strutilxx.h"
|
---|
| 672 | string decodecambarg(string arg,double& h, double& z)
|
---|
| 673 | // - decode argument for CAMB generation:
|
---|
| 674 | // input: arg = "cambfilename,h100tab,ztab"
|
---|
| 675 | // output: h = h100 use to generate CAMB file
|
---|
| 676 | // z = redshift use to generate CAMB file
|
---|
| 677 | // return: CAMB file name
|
---|
| 678 | {
|
---|
| 679 | h = -1.;
|
---|
| 680 | z = 0.;
|
---|
| 681 | vector<string> vs;
|
---|
| 682 | FillVStringFrString(arg,vs,',');
|
---|
| 683 | if(vs.size()>1) h = atof(vs[1].c_str());
|
---|
| 684 | if(vs.size()>2) z = atof(vs[2].c_str());
|
---|
| 685 | cout<<"decodecambarg: "<<arg<<" fn=\""<<vs[0]<<"\" h="<<h<<" z="<<z<<endl;
|
---|
| 686 | return vs[0];
|
---|
| 687 | }
|
---|