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

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

intro choix dabs calcul de beta pour les redshift-distorsions, cmv 10/12/2010

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