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

Last change on this file since 4075 was 3971, checked in by cmv, 14 years ago

intro possibilite de generer sans les BAO, cmv 01/04/2011

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