source: Sophya/trunk/Cosmo/SimLSS/cmvobserv3d.cc@ 3154

Last change on this file since 3154 was 3154, checked in by cmv, 19 years ago

modifs d'options de cmvobserv3d.cc
creation de init_fftw() et deplacement a l'initialisation
creation de SetObservator pour positionner l'observateur + ecriture FITS et PPF

(mais le codage des distance/redshift reste a coder)

cmv 19/01/2007

File size: 14.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#include "timing.h"
10#include "ntuple.h"
11#include "matharr.h"
12
13#include "constcosmo.h"
14#include "schechter.h"
15#include "geneutils.h"
16#include "integfunc.h"
17#include "genefluct3d.h"
18
19void usage(void);
20void usage(void)
21{
22 cout<<"cmvobserv3d [-a] [-0]"<<endl
23 <<" -a : init auto de l aleatoire"<<endl
24 <<" -0 : use methode ComputeFourier0"<<endl
25 <<" -x nx,dx : taille en x (npix,Mpc)"<<endl
26 <<" -y ny,dy : taille en y (npix,Mpc)"<<endl
27 <<" -z nz,dz : taille en z (npix,Mpc)"<<endl
28 <<" -Z zref : redshift median"<<endl
29 <<" -s snoise : sigma du bruit en Msol"<<endl
30 <<" -2 : compute 2D spectrum"<<endl
31 <<" -F : write cube in FITS format"<<endl
32 <<" -P : write cube in PPF format"<<endl
33 <<" -V : compute variance from real space"<<endl
34 <<endl;
35}
36
37int main(int narg,char *arg[])
38{
39 InitTim();
40
41 //-----------------------------------------------------------------
42 // *** Survey definition
43 long nx=360, ny=-1, nz=64; double dx=1., dy=-1., dz=-1.;
44 //long nx=1000, ny=-1, nz=128; double dx=3., dy=-1., dz=6.;
45 //long nx=1200, ny=-1, nz=128; double dx=1., dy=-1., dz=3;
46
47 // *** Cosmography definition (WMAP)
48 double ob0 = 0.0444356;
49 double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73,w0=-1.;
50 double zref = 0.5;
51
52 // *** Spectrum and variance definition
53 double ns = 1., as = 1.;
54 double R=8./h100, Rg=R/sqrt(5.);
55 double sigmaR = 1.;
56
57 double kmin=1e-5,kmax=1000.;
58 int npt = 10000;
59 double lkmin=log10(kmin), lkmax=log10(kmax);
60 double eps=1.e-3;
61
62 // *** Schechter mass function definition
63 double h75 = 0.71 / 0.75;
64 double nstar = 0.006*pow(h75,3.);
65 double mstar = pow(10.,9.8/(h75*h75)); // MSol
66 double alpha = -1.37;
67
68 double schmin=1e8, schmax=1e12;
69 int schnpt = 1000;
70 double lschmin=log10(schmin), lschmax=log10(schmax), dlsch=(lschmax-lschmin)/schnpt;
71
72 // *** Niveau de bruit
73 double snoise= 0.; // en equivalent MSol
74
75 // *** type de generation
76 bool computefourier0=false;
77 unsigned short nthread=4;
78
79 // *** What to do
80 bool comp2dspec = false;
81 bool wfits = false;
82 bool wppf = false;
83 bool compvarreal = false;
84
85 // --- Decodage arguments
86
87 char c;
88 while((c = getopt(narg,arg,"ha0PWV2x:y:z:s:Z:")) != -1) {
89 switch (c) {
90 case 'a' :
91 Auto_Ini_Ranf(5);
92 break;
93 case '0' :
94 computefourier0 = true;
95 break;
96 case 'x' :
97 sscanf(optarg,"%ld,%lf",&nx,&dx);
98 break;
99 case 'y' :
100 sscanf(optarg,"%ld,%lf",&ny,&dy);
101 break;
102 case 'z' :
103 sscanf(optarg,"%ld,%lf",&nz,&dz);
104 break;
105 case 's' :
106 sscanf(optarg,"%lf",&snoise);
107 break;
108 case 'Z' :
109 sscanf(optarg,"%lf",&zref);
110 break;
111 case '2' :
112 comp2dspec = true;
113 break;
114 case 'V' :
115 compvarreal = true;
116 break;
117 case 'W' :
118 wfits = true;
119 break;
120 case 'P' :
121 wppf = true;
122 break;
123 case 'h' :
124 default :
125 usage(); return -1;
126 }
127 }
128
129 string tagobs = "cmvobserv3d.ppf";
130 POutPersist posobs(tagobs);
131
132 cout<<"zref="<<zref<<endl;
133 cout<<"nx="<<nx<<" dx="<<dx<<" ny="<<ny<<" dy="<<dy<<" nz="<<nz<<" dz="<<dz<<endl;
134 cout<<"kmin="<<kmin<<" ("<<lkmin<<"), kmax="<<kmax<<" ("<<lkmax<<") Mpc^-1"
135 <<", npt="<<npt<<endl;
136 cout<<"R="<<R<<" Rg="<<Rg<<" Mpc, sigmaR="<<sigmaR<<endl;
137 cout<<"nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
138 cout<<"schmin="<<schmin<<" ("<<lschmin
139 <<"), schmax="<<schmax<<" ("<<lschmax<<") Msol"
140 <<", schnpt="<<schnpt<<endl;
141 cout<<"snoise="<<snoise<<" equivalent Msol"<<endl;
142
143 //-----------------------------------------------------------------
144 cout<<endl<<"\n--- Create Spectrum and mass function"<<endl;
145
146 InitialSpectrum pkini(ns,as);
147
148 TransfertEisenstein tf(h100,om0-ob0,ob0,T_CMB_Par,false);
149 //tf.SetNoOscEnv(2);
150
151 GrowthFactor d1(om0,ol0);
152
153 PkSpectrum0 pk0(pkini,tf);
154
155 PkSpectrumZ pkz(pk0,d1,zref);
156
157 Schechter sch(nstar,mstar,alpha);
158
159 //-----------------------------------------------------------------
160 pkz.SetZ(0.);
161 cout<<endl<<"\n--- Compute variance for top-hat R="<<R
162 <<" at z="<<pkz.GetZ()<<endl;
163 VarianceSpectrum varpk_th(pkz,0);
164 double kfind_th = varpk_th.FindMaximum(R,kmin,kmax,eps);
165 double pkmax_th = varpk_th(kfind_th);
166 cout<<"kfind_th = "<<kfind_th<<" ("<<log10(kfind_th)<<"), integrand="<<pkmax_th<<endl;
167 double k1=kmin, k2=kmax;
168 int rc = varpk_th.FindLimits(R,pkmax_th/1.e4,k1,k2,eps);
169 cout<<"limit_th: rc="<<rc<<" : "<<k1<<" ("<<log10(k1)<<") , "
170 <<k2<<" ("<<log10(k2)<<")"<<endl;
171
172 double ldlk = (log10(k2)-log10(k1))/npt;
173 varpk_th.SetInteg(0.01,ldlk,-1.,4);
174 double sr2 = varpk_th.Variance(R,k1,k2);
175 cout<<"varpk_th="<<sr2<<" -> sigma="<<sqrt(sr2)<<endl;
176
177 double normpkz = sigmaR*sigmaR/sr2;
178 pkz.SetScale(normpkz);
179 cout<<"Spectrum normalisation = "<<pkz.GetScale()<<endl;
180
181 pkz.SetZ(zref);
182
183 Histo hpkz(lkmin,lkmax,npt); hpkz.ReCenterBin();
184 FuncToHisto(pkz,hpkz,true);
185 {
186 tagobs = "hpkz"; posobs.PutObject(hpkz,tagobs);
187 }
188
189 //-----------------------------------------------------------------
190 cout<<endl<<"\n--- Compute variance for Pk at z="<<pkz.GetZ()<<endl;
191 VarianceSpectrum varpk_int(pkz,2);
192
193 double kfind_int = varpk_int.FindMaximum(R,kmin,kmax,eps);
194 double pkmax_int = varpk_int(kfind_int);
195 cout<<"kfind_int = "<<kfind_int<<" ("<<log10(kfind_int)<<"), integrand="<<pkmax_int<<endl;
196 double k1int=kmin, k2int=kmax;
197 int rcint = varpk_int.FindLimits(R,pkmax_int/1.e4,k1int,k2int,eps);
198 cout<<"limit_int: rc="<<rcint<<" : "<<k1int<<" ("<<log10(k1int)<<") , "
199 <<k2int<<" ("<<log10(k2int)<<")"<<endl;
200
201 double ldlkint = (log10(k2int)-log10(k1int))/npt;
202 varpk_int.SetInteg(0.01,ldlkint,-1.,4);
203 double sr2int = varpk_int.Variance(R,k1int,k2int);
204 cout<<"varpk_int="<<sr2int<<" -> sigma="<<sqrt(sr2int)<<endl;
205
206 PrtTim("End of definition");
207
208 //-----------------------------------------------------------------
209 cout<<endl<<"\n--- Compute galaxy density number"<<endl;
210
211 sch.SetOutValue(0);
212 cout<<"sch(mstar) = "<<sch(mstar)<<" /Mpc^3/Msol"<<endl;
213 double ngal_by_mpc3 = IntegrateFuncLog(sch,lschmin,lschmax,0.01,dlsch,10.*dlsch,4);
214 cout<<"Galaxy density number = "<<ngal_by_mpc3<<" /Mpc^3 between limits"<<endl;
215
216 sch.SetOutValue(1);
217 cout<<"mstar*sch(mstar) = "<<sch(mstar)<<" Msol/Mpc^3/Msol"<<endl;
218 double mass_by_mpc3 = IntegrateFuncLog(sch,lschmin,lschmax,0.01,dlsch,10.*dlsch,4);
219 cout<<"Galaxy mass density= "<<mass_by_mpc3<<" Msol/Mpc^3 between limits"<<endl;
220
221 //-----------------------------------------------------------------
222 // FFTW3 (p26): faster if sizes 2^a 3^b 5^c 7^d 11^e 13^f with e+f=0 ou 1
223 cout<<endl<<"\n--- Compute Spectrum Realization"<<endl;
224
225 pkz.SetZ(zref);
226 TArray< complex<r_8> > pkgen;
227 GeneFluct3D fluct3d(pkgen);
228 fluct3d.SetPrtLevel(3);
229 fluct3d.SetNThread(nthread);
230 fluct3d.SetSize(nx,ny,nz,dx,dy,dz);
231 TArray<r_8>& rgen = fluct3d.GetRealArray();
232 fluct3d.Print();
233
234 double dkmin = fluct3d.GetKincMin();
235 double knyqmax = fluct3d.GetKmax();
236 long nherr = long(knyqmax/dkmin+0.5);
237 cout<<"For HistoErr: d="<<dkmin<<" max="<<knyqmax<<" n="<<nherr<<endl;
238
239 double dktmin = fluct3d.GetKTincMin();
240 double ktnyqmax = fluct3d.GetKTmax();
241 long nherrt = long(ktnyqmax/dktmin+0.5);
242 double dkzmin = fluct3d.GetKinc()[2];
243 double kznyqmax = fluct3d.GetKnyq()[2];
244 long nherrz = long(kznyqmax/dkzmin+0.5);
245 cout<<"For Histo2DErr: d="<<dktmin<<","<<dkzmin
246 <<" max="<<ktnyqmax<<","<<kznyqmax<<" n="<<nherrt<<","<<nherrz<<endl;
247
248 cout<<"\n--- Computing spectra variance up to Kmax at z="<<pkz.GetZ()<<endl;
249 // En fait on travaille sur un cube inscrit dans la sphere de rayon kmax:
250 // sphere: Vs = 4Pi/3 k^3 , cube inscrit (cote k*sqrt(2)): Vc = (k*sqrt(2))^3
251 // Vc/Vs = 0.675 -> keff = kmax * (0.675)^(1/3) = kmax * 0.877
252 double knyqmax_mod = 0.877*knyqmax;
253 ldlkint = (log10(knyqmax_mod)-log10(k1int))/npt;
254 varpk_int.SetInteg(0.01,ldlkint,-1.,4);
255 double sr2int_kmax = varpk_int.Variance(R,k1int,knyqmax_mod);
256 cout<<"varpk_int(<"<<knyqmax_mod<<")="<<sr2int_kmax<<" -> sigma="<<sqrt(sr2int_kmax)<<endl;
257
258 cout<<"\n--- Computing a realization in Fourier space"<<endl;
259 if(computefourier0) fluct3d.ComputeFourier0(pkz);
260 else fluct3d.ComputeFourier(pkz);
261
262 if(1) {
263 cout<<"\n--- Checking realization spectra"<<endl;
264 HistoErr hpkgen(0.,knyqmax,nherr);
265 hpkgen.ReCenterBin(); hpkgen.Zero();
266 hpkgen.Show();
267 fluct3d.ComputeSpectrum(hpkgen);
268 {
269 tagobs = "hpkgen"; posobs.PutObject(hpkgen,tagobs);
270 }
271 }
272
273 if(comp2dspec) {
274 cout<<"\n--- Checking realization 2D spectra"<<endl;
275 Histo2DErr hpkgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
276 hpkgen2.ReCenterBin(); hpkgen2.Zero();
277 hpkgen2.Show();
278 fluct3d.ComputeSpectrum2D(hpkgen2);
279 {
280 tagobs = "hpkgen2"; posobs.PutObject(hpkgen2,tagobs);
281 }
282 }
283
284 if(1) {
285 cout<<"\n--- Computing convolution by pixel shape"<<endl;
286 fluct3d.FilterByPixel();
287 }
288
289 if(wfits) fluct3d.WriteFits("!cmvobserv3d_k0.fits");
290 if(wppf) fluct3d.WritePPF("cmvobserv3d_k0.ppf",false);
291
292 if(1) {
293 cout<<"\n--- Checking realization spectra after pixel shape convol."<<endl;
294 HistoErr hpkgenf(0.,knyqmax,nherr);
295 hpkgenf.ReCenterBin(); hpkgenf.Zero();
296 hpkgenf.Show();
297 fluct3d.ComputeSpectrum(hpkgenf);
298 {
299 tagobs = "hpkgenf"; posobs.PutObject(hpkgenf,tagobs);
300 }
301 }
302
303 if(comp2dspec) {
304 cout<<"\n--- Checking realization 2D spectra after pixel shape convol."<<endl;
305 Histo2DErr hpkgenf2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
306 hpkgenf2.ReCenterBin(); hpkgenf2.Zero();
307 hpkgenf2.Show();
308 fluct3d.ComputeSpectrum2D(hpkgenf2);
309 {
310 tagobs = "hpkgenf2"; posobs.PutObject(hpkgenf2,tagobs);
311 }
312 }
313
314 cout<<"\n--- Computing a realization in real space"<<endl;
315 fluct3d.ComputeReal();
316 double rmin,rmax; rgen.MinMax(rmin,rmax);
317 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
318
319 if(wfits) fluct3d.WriteFits("!cmvobserv3d_r0.fits");
320 if(wppf) fluct3d.WritePPF("cmvobserv3d_r0.ppf",true);
321
322 int_8 nm;
323 double rm,rs2;
324 if(1) {
325 cout<<"\n--- Check mean and variance in real space"<<endl;
326 int_8 nlowone = fluct3d.NumberOfBad(-1.,1e+200);
327 nm = fluct3d.MeanSigma2(rm,rs2);
328 cout<<"rgen:("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
329 <<rs2<<" -> "<<sqrt(rs2)<<", n(<-1)="<<nlowone<<endl;
330 }
331
332 if(compvarreal) {
333 cout<<"\n--- Check variance sigmaR in real space"<<endl;
334 double varr;
335 int_8 nvarr = fluct3d.VarianceFrReal(R,varr);
336 cout<<"R="<<R<<" : sigmaR^2="<<varr<<" -> "<<sqrt(varr)<<", n="<<nvarr<<endl;
337 }
338
339 //-----------------------------------------------------------------
340 cout<<endl<<"\n--- Converting fluctuations into mass"<<endl;
341 fluct3d.TurnFluct2Mass();
342 nm = fluct3d.MeanSigma2(rm,rs2);
343 cout<<"1+rgen: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
344 <<rs2<<" -> "<<sqrt(rs2)<<endl;
345
346 cout<<"\n--- Converting mass into galaxy number"<<endl;
347 rm = fluct3d.TurnMass2MeanNumber(ngal_by_mpc3);
348 cout<<rm<<" galaxies put into survey"<<endl;
349 nm = fluct3d.MeanSigma2(rm,rs2,0.);
350 cout<<"galaxy: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
351 <<rs2<<" -> "<<sqrt(rs2)<<endl;
352
353 cout<<"\n--- Set negative pixels to BAD"<<endl;
354 nm = fluct3d.SetToVal(0.,1e+200,-999.);
355 cout<<nm<<" negative in survey set to BAD"<<endl;
356 nm = fluct3d.MeanSigma2(rm,rs2,-998.);
357 cout<<"galaxy: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
358 <<rs2<<" -> "<<sqrt(rs2)<<endl;
359
360 cout<<"\n--- Apply poisson on galaxy number"<<endl;
361 nm = fluct3d.ApplyPoisson();
362 cout<<nm<<" galaxies into survey after poisson"<<endl;
363 nm = fluct3d.MeanSigma2(rm,rs2,-998.);
364 cout<<"galaxy: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
365 <<rs2<<" -> "<<sqrt(rs2)<<endl;
366
367 cout<<"\n--- Convert Galaxy number to HI mass"<<endl;
368 long nhmdndm = long( (lschmax-lschmin+1.)*100. + 0.5);
369 Histo hmdndm(lschmin,lschmax,nhmdndm);
370 sch.SetOutValue(1);
371 FuncToHisto(sch,hmdndm,true);
372 FunRan tirhmdndm(hmdndm,true);
373 {
374 tagobs = "hmdndm"; posobs.PutObject(hmdndm,tagobs);
375 Histo hdum1(tirhmdndm);
376 tagobs = "tirhmdndm"; posobs.PutObject(hdum1,tagobs);
377 }
378 double mhi = fluct3d.TurnNGal2Mass(tirhmdndm,true);
379 cout<<mhi<<" MSol in survey / "<<mass_by_mpc3*fluct3d.GetVol()<<endl;
380 nm = fluct3d.MeanSigma2(rm,rs2,0.);
381 cout<<"HI mass: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
382 <<rs2<<" -> "<<sqrt(rs2)<<endl;
383 cout<<"Equivalent: "<<rm*nm/fluct3d.NPix()<<" Msol / pixels"<<endl;
384
385 cout<<"\n--- Set BAD pixels to Zero"<<endl;
386 nm = fluct3d.SetToVal(-998.,1e+200,0.);
387 cout<<nm<<" BAD in survey set to zero"<<endl;
388 nm = fluct3d.MeanSigma2(rm,rs2);
389 cout<<"galaxy: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
390 <<rs2<<" -> "<<sqrt(rs2)<<endl;
391
392 if(wfits) fluct3d.WriteFits("!cmvobserv3d_r.fits");
393 if(wppf) fluct3d.WritePPF("cmvobserv3d_r.ppf",true);
394
395 cout<<"\n--- Add noise to HI Flux snoise="<<snoise<<endl;
396 fluct3d.AddNoise2Real(snoise);
397 nm = fluct3d.MeanSigma2(rm,rs2);
398 cout<<"HI mass with noise: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
399 <<rs2<<" -> "<<sqrt(rs2)<<endl;
400
401 //-----------------------------------------------------------------
402 // -- NE PAS FAIRE CA SI ON VEUT CONTINUER LA SIMULATION -> d_rho/rho ecrase
403
404 if(1) {
405 cout<<endl<<"\n--- ReComputing spectrum from real space"<<endl;
406 fluct3d.ReComputeFourier();
407 }
408
409 if(wfits) fluct3d.WriteFits("!cmvobserv3d_k.fits");
410 if(wppf) fluct3d.WritePPF("cmvobserv3d_k.ppf",false);
411
412 if(1) {
413 cout<<endl<<"\n--- Computing final spectrum"<<endl;
414 HistoErr hpkrec(0.,knyqmax,nherr);
415 hpkrec.ReCenterBin();
416 hpkrec.Show();
417 fluct3d.ComputeSpectrum(hpkrec);
418 tagobs = "hpkrec"; posobs.PutObject(hpkrec,tagobs);
419 }
420
421 if(comp2dspec) {
422 cout<<"\n--- Computing final 2D spectrum"<<endl;
423 Histo2DErr hpkrec2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
424 hpkrec2.ReCenterBin(); hpkrec2.Zero();
425 hpkrec2.Show();
426 fluct3d.ComputeSpectrum2D(hpkrec2);
427 {
428 tagobs = "hpkrec2"; posobs.PutObject(hpkrec2,tagobs);
429 }
430 }
431
432 return 0;
433}
434
435/*
436######################################################
437readfits cmvobserv3d_k0.fits
438readfits cmvobserv3d_k.fits
439readfits cmvobserv3d_r0.fits
440readfits cmvobserv3d_r.fits
441
442openppf cmvobserv3d_k0.ppf
443openppf cmvobserv3d_k.ppf
444openppf cmvobserv3d_r0.ppf
445openppf cmvobserv3d_r.ppf
446
447# pour le plot 2D d'une slice en Z du 3D: to2d nom_obj3D num_slice
448defscript to2d
449 objaoper $1 sliceyz $2
450 mv sliceyz_${2} ${1}_$2
451 disp ${1}_$2
452 echo display slice $2 of $1
453endscript
454
455to2d $cobj 0
456
457######################################################
458openppf cmvobserv3d.ppf
459
460zone
461set k pow(10.,x)
462n/plot hpkz.val*$k*$k/(2*M_PI*M_PI)%x ! "connectpoints"
463
464zone
465n/plot hpkz.val%x ! ! "nsta connectpoints"
466n/plot hpkgen.val%log10(x) x>0 ! "nsta same red connectpoints"
467n/plot hpkgenf.val%log10(x) x>0 ! "nsta same orange connectpoints"
468n/plot hpkrec.val%log10(x) x>0 ! "nsta same blue connectpoints"
469
470disp hpkgen "hbincont err"
471disp hpkgenf "hbincont err"
472disp hpkrec "hbincont err"
473
474zone 2 2
475imag hpkgen2
476imag hpkgenf2
477imag hpkrec2
478
479zone 2 1
480disp hmdndm "nsta"
481disp tirhmdndm "nsta"
482addline 0 1 20 1 "red"
483
484 */
Note: See TracBrowser for help on using the repository browser.