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

Last change on this file since 3115 was 3115, checked in by ansari, 19 years ago

Creation initiale du groupe Cosmo avec le repertoire SimLSS de
simulation de distribution de masse 3D des galaxies par CMV+Rz
18/12/2006

File size: 11.8 KB
RevLine 
[3115]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#include "srandgen.h"
13#include "perandom.h"
14
15#include "arrctcast.h"
16
17#include "constcosmo.h"
18#include "schechter.h"
19#include "geneutils.h"
20#include "integfunc.h"
21#include "genefluct3d.h"
22
23void usage(void);
24void usage(void)
25{
26 cout<<"cmvobserv3d [-a] [-0]"<<endl
27 <<" -a : init auto de l aleatoire"<<endl
28 <<" -0 : use methode ComputeFourier0"<<endl
29 <<" -x nx,dx : taille en x (npix,Mpc)"<<endl
30 <<" -y ny,dy : taille en y (npix,Mpc)"<<endl
31 <<" -z nz,dz : taille en z (npix,Mpc)"<<endl
32 <<" -Z zref : redshift median"<<endl
33 <<" -s scale : sigma du bruit en Msol"<<endl
34 <<endl;
35}
36
37int main(int narg,char *arg[])
38{
39 InitTim();
40
41 //-----------------------------------------------------------------
42 // *** Survey definition
43 int nx=360, ny=-1, nz=64; double dx=1., dy=-1., dz=-1.;
44 //int nx=1000, ny=-1, nz=128; double dx=3., dy=-1., dz=6.;
45 //int 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 // --- Decodage arguments
80
81 char c;
82 while((c = getopt(narg,arg,"ha0x:y:z:s:Z:")) != -1) {
83 switch (c) {
84 case 'a' :
85 Auto_Ini_Ranf(5);
86 break;
87 case '0' :
88 computefourier0 = true;
89 break;
90 case 'x' :
91 sscanf(optarg,"%d,%lf",&nx,&dx);
92 break;
93 case 'y' :
94 sscanf(optarg,"%d,%lf",&ny,&dy);
95 break;
96 case 'z' :
97 sscanf(optarg,"%d,%lf",&nz,&dz);
98 break;
99 case 's' :
100 sscanf(optarg,"%lf",&snoise);
101 break;
102 case 'Z' :
103 sscanf(optarg,"%lf",&zref);
104 break;
105 case 'h' :
106 default :
107 usage(); return -1;
108 }
109 }
110
111 string tagobs = "cmvobserv3d.ppf";
112 POutPersist posobs(tagobs);
113
114 cout<<"zref="<<zref<<endl;
115 cout<<"nx="<<nx<<" dx="<<dx<<" ny="<<ny<<" dy="<<dy<<" nz="<<nz<<" dz="<<dz<<endl;
116 cout<<"kmin="<<kmin<<" ("<<lkmin<<"), kmax="<<kmax<<" ("<<lkmax<<") Mpc^-1"
117 <<", npt="<<npt<<endl;
118 cout<<"R="<<R<<" Rg="<<Rg<<" Mpc, sigmaR="<<sigmaR<<endl;
119 cout<<"nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
120 cout<<"schmin="<<schmin<<" ("<<lschmin
121 <<"), schmax="<<schmax<<" ("<<lschmax<<") Msol"
122 <<", schnpt="<<schnpt<<endl;
123 cout<<"snoise="<<snoise<<" equivalent Msol"<<endl;
124
125 //-----------------------------------------------------------------
126 cout<<endl<<"\n--- Create Spectrum and mass function"<<endl;
127
128 InitialSpectrum pkini(ns,as);
129
130 TransfertEisenstein tf(h100,om0-ob0,ob0,T_CMB_Par,false);
131 //tf.SetNoOscEnv(2);
132
133 GrowthFactor d1(om0,ol0);
134
135 PkSpectrum0 pk0(pkini,tf);
136
137 PkSpectrumZ pkz(pk0,d1,zref);
138
139 Schechter sch(nstar,mstar,alpha);
140
141 //-----------------------------------------------------------------
142 pkz.SetZ(0.);
143 cout<<endl<<"\n--- Compute variance for top-hat R="<<R
144 <<" at z="<<pkz.GetZ()<<endl;
145 VarianceSpectrum varpk_th(pkz,0);
146 double kfind_th = varpk_th.FindMaximum(R,kmin,kmax,eps);
147 double pkmax_th = varpk_th(kfind_th);
148 cout<<"kfind_th = "<<kfind_th<<" ("<<log10(kfind_th)<<"), integrand="<<pkmax_th<<endl;
149 double k1=kmin, k2=kmax;
150 int rc = varpk_th.FindLimits(R,pkmax_th/1.e4,k1,k2,eps);
151 cout<<"limit_th: rc="<<rc<<" : "<<k1<<" ("<<log10(k1)<<") , "
152 <<k2<<" ("<<log10(k2)<<")"<<endl;
153
154 double ldlk = (log10(k2)-log10(k1))/npt;
155 varpk_th.SetInteg(0.01,ldlk,-1.,4);
156 double sr2 = varpk_th.Variance(R,k1,k2);
157 cout<<"varpk_th="<<sr2<<" -> sigma="<<sqrt(sr2)<<endl;
158
159 double normpkz = sigmaR*sigmaR/sr2;
160 pkz.SetScale(normpkz);
161 cout<<"Spectrum normalisation = "<<pkz.GetScale()<<endl;
162
163 pkz.SetZ(zref);
164
165 Histo hpkz (lkmin,lkmax,npt); hpkz.ReCenterBin();
166 FuncToHisto(pkz,hpkz,true);
167 {
168 tagobs = "hpkz"; posobs.PutObject(hpkz,tagobs);
169 }
170
171 //-----------------------------------------------------------------
172 cout<<endl<<"\n--- Compute variance for Pk at z="<<pkz.GetZ()<<endl;
173 VarianceSpectrum varpk_int(pkz,2);
174
175 double kfind_int = varpk_int.FindMaximum(R,kmin,kmax,eps);
176 double pkmax_int = varpk_int(kfind_int);
177 cout<<"kfind_int = "<<kfind_int<<" ("<<log10(kfind_int)<<"), integrand="<<pkmax_int<<endl;
178 double k1int=kmin, k2int=kmax;
179 int rcint = varpk_int.FindLimits(R,pkmax_int/1.e4,k1int,k2int,eps);
180 cout<<"limit_int: rc="<<rcint<<" : "<<k1int<<" ("<<log10(k1int)<<") , "
181 <<k2int<<" ("<<log10(k2int)<<")"<<endl;
182
183 double ldlkint = (log10(k2int)-log10(k1int))/npt;
184 varpk_int.SetInteg(0.01,ldlkint,-1.,4);
185 double sr2int = varpk_int.Variance(R,k1int,k2int);
186 cout<<"varpk_int="<<sr2int<<" -> sigma="<<sqrt(sr2int)<<endl;
187
188 PrtTim("End of definition");
189
190 //-----------------------------------------------------------------
191 cout<<endl<<"\n--- Compute galaxies density number"<<endl;
192
193 sch.SetOutValue(0);
194 cout<<"sch(mstar) = "<<sch(mstar)<<" /Mpc^3/Msol"<<endl;
195 double ngal_by_mpc3 = IntegrateFuncLog(sch,lschmin,lschmax,0.01,dlsch,10.*dlsch,4);
196 cout<<"Galaxy density number = "<<ngal_by_mpc3<<" /Mpc^3 between limits"<<endl;
197
198 sch.SetOutValue(1);
199 cout<<"mstar*sch(mstar) = "<<sch(mstar)<<" Msol/Mpc^3/Msol"<<endl;
200 double mass_by_mpc3 = IntegrateFuncLog(sch,lschmin,lschmax,0.01,dlsch,10.*dlsch,4);
201 cout<<"Galaxy mass density= "<<mass_by_mpc3<<" Msol/Mpc^3 between limits"<<endl;
202
203 //-----------------------------------------------------------------
204 // FFTW3 (p26): faster if sizes 2^a 3^b 5^c 7^d 11^e 13^f with e+f=0 ou 1
205 cout<<endl<<"\n--- Compute Spectrum Realization"<<endl;
206
207 pkz.SetZ(zref);
208 TArray< complex<r_8> > pkgen;
209 GeneFluct3D fluct3d(pkgen,pkz);
210 fluct3d.SetNThread(nthread);
211 fluct3d.SetSize(nx,ny,nz,dx,dy,dz);
212 fluct3d.Print();
213 double knyqmax = fluct3d.GetKmax();
214 double dkmin = fluct3d.GetKinc()[0];
215
216 cout<<"\n--- Computing spectra variance up to Kmax at z="<<pkz.GetZ()<<endl;
217 // En fait on travaille sur un cube inscrit dans la sphere de rayon kmax:
218 // sphere: Vs = 4Pi/3 k^3 , cube inscrit (cote k*sqrt(2)): Vc = (k*sqrt(2))^3
219 // Vc/Vs = 0.675 -> keff = kmax * (0.675)^(1/3) = kmax * 0.877
220 knyqmax *= 0.877;
221 ldlkint = (log10(knyqmax)-log10(k1int))/npt;
222 varpk_int.SetInteg(0.01,ldlkint,-1.,4);
223 double sr2int_kmax = varpk_int.Variance(R,k1int,knyqmax);
224 cout<<"varpk_int(<"<<knyqmax<<")="<<sr2int_kmax<<" -> sigma="<<sqrt(sr2int_kmax)<<endl;
225
226 cout<<"\n--- Computing a realization in Fourier space"<<endl;
227 if(computefourier0) fluct3d.ComputeFourier0();
228 else fluct3d.ComputeFourier();
229
230 cout<<"\n--- Checking realization spectra"<<endl;
231 int nhprof = int(fluct3d.GetKmax()/dkmin+0.5);
232 HProf hpkgen(0.,fluct3d.GetKmax(),nhprof);
233 hpkgen.ReCenterBin();
234 fluct3d.ComputeSpectrum(hpkgen);
235 {
236 tagobs = "hpkgen"; posobs.PutObject(hpkgen,tagobs);
237 }
238
239 if(1) {
240 cout<<"\n--- Computing convolution by pixel shape"<<endl;
241 fluct3d.FilterByPixel();
242
243 cout<<"\n--- Checking realization spectra after pixel shape convol."<<endl;
244 HProf hpkgenf(hpkgen); hpkgenf.Zero();
245 fluct3d.ComputeSpectrum(hpkgenf);
246 {
247 tagobs = "hpkgenf"; posobs.PutObject(hpkgenf,tagobs);
248 }
249 }
250
251 if(0) {
252 cout<<"\n--- Writing cmvobserv3dk.ppf"<<endl;
253 string tag = "cmvobserv3dk.ppf";
254 POutPersist pos(tag);
255 tag = "pkgen"; pos.PutObject(pkgen,tag);
256 }
257
258 cout<<"\n--- Computing a realization in real space"<<endl;
259 fluct3d.ComputeReal();
260 r_8 undouble=0.;
261 TArray<r_8> rgen = ArrayCast(pkgen,undouble);
262 double rmin,rmax; rgen.MinMax(rmin,rmax);
263 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
264
265 cout<<"\n--- Check mean and variance in real space"<<endl;
266 size_t nlowone = fluct3d.NumberOfBad(-1.,1e+200);
267 double rm,rs2; size_t nm;
268 nm = fluct3d.MeanSigma2(rm,rs2);
269 cout<<"rgen:("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
270 <<rs2<<" -> "<<sqrt(rs2)<<", n(<-1)="<<nlowone<<endl;
271
272 if(1) {
273 cout<<"\n--- Check variance sigmaR in real space"<<endl;
274 double varr;
275 size_t nvarr = fluct3d.VarianceFrReal(R,varr);
276 cout<<"R="<<R<<" : sigmaR^2="<<varr<<" -> "<<sqrt(varr)<<", n="<<nvarr<<endl;
277 }
278
279 //-----------------------------------------------------------------
280 cout<<endl<<"\n--- Converting fluctuations into mass"<<endl;
281 fluct3d.TurnFluct2Mass();
282 nm = fluct3d.MeanSigma2(rm,rs2);
283 cout<<"1+rgen: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
284 <<rs2<<" -> "<<sqrt(rs2)<<endl;
285
286 cout<<"\n--- Converting mass into galaxy number"<<endl;
287 rm = fluct3d.TurnMass2MeanNumber(ngal_by_mpc3);
288 cout<<rm<<" galaxies put into survey"<<endl;
289 nm = fluct3d.MeanSigma2(rm,rs2,0.);
290 cout<<"galaxy: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
291 <<rs2<<" -> "<<sqrt(rs2)<<endl;
292
293 cout<<"\n--- Set negative pixels to BAD"<<endl;
294 nm = fluct3d.SetToVal(0.,1e+200,-999.);
295 cout<<nm<<" negative in survey set to BAD"<<endl;
296 nm = fluct3d.MeanSigma2(rm,rs2,-998.);
297 cout<<"galaxy: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
298 <<rs2<<" -> "<<sqrt(rs2)<<endl;
299
300 cout<<"\n--- Apply poisson on galaxie number"<<endl;
301 nm = fluct3d.ApplyPoisson();
302 cout<<nm<<" galaxies into survey after poisson"<<endl;
303 nm = fluct3d.MeanSigma2(rm,rs2,-998.);
304 cout<<"galaxy: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
305 <<rs2<<" -> "<<sqrt(rs2)<<endl;
306
307 cout<<"\n--- Convert Galaxies number to HI mass"<<endl;
308 int nhmdndm = int( (lschmax-lschmin+1.)*100. + 0.5);
309 Histo hmdndm(lschmin,lschmax,nhmdndm);
310 sch.SetOutValue(1);
311 FuncToHisto(sch,hmdndm,true);
312 FunRan tirhmdndm(hmdndm,true);
313 {
314 tagobs = "hmdndm"; posobs.PutObject(hmdndm,tagobs);
315 Histo hdum1(tirhmdndm);
316 tagobs = "tirhmdndm"; posobs.PutObject(hdum1,tagobs);
317 }
318 double mhi = fluct3d.TurnNGal2Mass(tirhmdndm,true);
319 cout<<mhi<<" MSol in survey / "<<mass_by_mpc3*fluct3d.GetVol()<<endl;
320 nm = fluct3d.MeanSigma2(rm,rs2,0.);
321 cout<<"HI mass: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
322 <<rs2<<" -> "<<sqrt(rs2)<<endl;
323 cout<<"Equivalent: "<<rm*nm/fluct3d.NPix()<<" Msol / pixels"<<endl;
324
325 cout<<"\n--- Set BAD pixels to Zero"<<endl;
326 nm = fluct3d.SetToVal(-998.,1e+200,0.);
327 cout<<nm<<" BAD in survey set to zero"<<endl;
328 nm = fluct3d.MeanSigma2(rm,rs2);
329 cout<<"galaxy: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
330 <<rs2<<" -> "<<sqrt(rs2)<<endl;
331
332 cout<<"\n--- Add noise to HI Flux snoise="<<snoise<<endl;
333 fluct3d.AddNoise2Real(snoise);
334 nm = fluct3d.MeanSigma2(rm,rs2);
335 cout<<"HI mass with noise: ("<<nm<<") Mean = "<<rm<<", Sigma^2 = "
336 <<rs2<<" -> "<<sqrt(rs2)<<endl;
337
338 if(0) {
339 cout<<"\n--- Writing cmvobserv3dr.ppf"<<endl;
340 string tag = "cmvobserv3dr.ppf";
341 POutPersist pos(tag);
342 tag = "rgen"; pos.PutObject(rgen,tag);
343 }
344
345 //-----------------------------------------------------------------
346 // -- NE PAS FAIRE CA SI ON VEUT CONTINUER LA SIMULATION -> d_rho/rho ecrase
347 if(1) {
348 cout<<endl<<"\n--- ReComputing spectrum from real space"<<endl;
349 fluct3d.ReComputeFourier();
350 HProf hpkrec(0.,fluct3d.GetKmax(),nhprof);
351 hpkrec.ReCenterBin();
352 fluct3d.ComputeSpectrum(hpkrec);
353 tagobs = "hpkrec"; posobs.PutObject(hpkrec,tagobs);
354 }
355
356 return 0;
357}
358
359/*
360openppf cmvobserv3dk.ppf
361openppf cmvobserv3dr.ppf
362openppf cmvobserv3d.ppf
363
364objaoper pkgen sliceyz 0
365
366n/plot hpkz.val%x x>0 ! "connectpoints"
367n/plot hpkgen.val%log10(x) x>0 ! "same red connectpoints"
368n/plot hpkgenf.val%log10(x) x>0 ! "same pink connectpoints"
369n/plot hpkrec.val%log10(x) x>0 ! "same blue connectpoints"
370
371set k pow(10.,x)
372n/plot hpkz.val*$k*$k/(2*M_PI*M_PI)%x ! "connectpoints"
373
374defscript rgensl
375 objaoper rgen sliceyz $1
376 disp sliceyz_$1
377endscript
378
379rgensl 0
380
381 */
Note: See TracBrowser for help on using the repository browser.