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

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

suite de la mise au point pour lecture fichiers CAMB, cmv 24/07/2010

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