source: Sophya/trunk/Cosmo/SimLSS/cmvginit3d.cc@ 3908

Last change on this file since 3908 was 3908, checked in by cmv, 15 years ago

Kaiser spectrum modif for redshift distortions cmvginit3d.cc interface, cmv 15/11/2010

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