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

Last change on this file since 3354 was 3354, checked in by cmv, 18 years ago

ajout options -8 sigmar,R , cmv 22/10/2007

File size: 24.0 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 "cosmocalc.h"
15#include "schechter.h"
16#include "geneutils.h"
17#include "genefluct3d.h"
18
19void usage(void);
20void usage(void)
21{
22 cout<<"cmvobserv3d [...options...]"<<endl
23 <<" -a : auto init random seed (needed for multiple simul)"<<endl
24 <<" -0 : use ComputeFourier0 method (defaut: no, use normal way)"<<endl
25 <<" -G typevol: compute Pk(z=0) and apply growth factor in real space"<<endl
26 <<" typevol=1 noise evolved with distance / observateur (def)"<<endl
27 <<" typevol=2 noise evolved with distance to middle of Z planes"<<endl
28 <<" (default: no, spectrum Pk(z=z_median) for all cube)"<<endl
29 <<" -F : filter spectrum by pixel shape (0=no 1=yes(default)"<<endl
30 <<" -U : do not poisson fluctuate with Ngal, convert directly to HI mass"<<endl
31 <<" -x nx,dx : size along x axis (npix,Mpc)"<<endl
32 <<" -y ny,dy : size along y axis (npix,Mpc)"<<endl
33 <<" if ny or dy <=0 take same value as for x"<<endl
34 <<" -z nz,dz : size along z axis (redshift axis, npix,Mpc)"<<endl
35 <<" -Z zref : redshift for the center of the simulation cube"<<endl
36 <<" -s snoise,typevol : gaussian noise sigma in equivalent Msol"<<endl
37 <<" typevol=0 no evolution (def)"<<endl
38 <<" typevol=1 noise evolved with distance / observateur"<<endl
39 <<" typevol=2 noise evolved with distance to middle of Z planes"<<endl
40 <<" -2 : compute also 2D spectrum (default: no)"<<endl
41 <<" -N scalemass: facteur d\'unite pour la masse (default: -1)"<<endl
42 <<" ex: si on veut unites 10^8 Msol -> scalemass=1.e-8"<<endl
43 <<" si <0 alors facteur=-scalemass*Mpix"<<endl
44 <<" -M schmin,schmax,nsch : min,max mass and nb points for schechter HI"<<endl
45 <<" If nsch<0 alors no,bre de points par decade"<<endl
46 <<" -Q naleagal : use quick method for turning ngal to mass"<<endl
47 <<" -R schmassdist.ppf : read mass distribution for trials from file"<<endl
48 <<" instead of computing it (ONLY if \"-Q\" option is activated)"<<endl
49 <<" -8 sigmaR,R : normalisation du spectre de puissance, R en Mpc"<<endl
50 <<" (default sigmaR=1, R=8/h100 Mpc)"<<endl
51 <<" -W : write cube in FITS format (complex cube is coded as real cube)"<<endl
52 <<" -P : write cube in PPF format"<<endl
53 <<" -S : write cube slices in PPF format"<<endl
54 <<" -V : compute variance from real space (for check, default: no)"<<endl
55 <<" -T nth : nombre de threads (si compil multi-thread, default: 0)"<<endl
56 <<endl;
57 ////<<" -A <log10(S_agn in Jy at 1.4 GHz)>,sigma,powlaw :"<<endl
58 ////<<" AGN mean and sigma gaussian equiv. distrib. for solid angle of centeral pixel"<<endl
59 ////<<" powlaw: apply S_agn evolution as (Nu/1.4)^powlaw"<<endl
60}
61
62int main(int narg,char *arg[])
63{
64 InitTim();
65
66 //-----------------------------------------------------------------
67 // *** Survey definition
68 long nx=360, ny=-1, nz=64; double dx=1., dy=-1., dz=-1.;
69 //long nx=1000, ny=-1, nz=128; double dx=3., dy=-1., dz=6.;
70 //long nx=1200, ny=-1, nz=128; double dx=1., dy=-1., dz=3;
71
72 // *** Cosmography definition (WMAP)
73 unsigned short flat = 0;
74 double ob0 = 0.0444356;
75 double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73,w0=-1.;
76 double zref = 0.5;
77 double perc=0.01,dzinc=-1.,dzmax=-1.; unsigned short glorder=4;
78
79 // *** Spectrum and variance definition
80 double ns = 1., as = 1.;
81 double R=8./h100, Rg=R/sqrt(5.);
82 double sigmaR = 1.;
83
84 double kmin=1e-5,kmax=1000.;
85 int npt = 10000;
86 double lkmin=log10(kmin), lkmax=log10(kmax);
87 double eps=1.e-3;
88
89 // *** Schechter mass function definition
90 double h75 = h100 / 0.75;
91 double nstar = 0.006*pow(h75,3.);
92 double mstar = pow(10.,9.8); // MSol
93 double alpha = -1.37;
94
95 double schmin=1.e7, schmax=1.e13;
96 int schnpt = -100;
97 bool use_schmassdist = false;
98 long naleagal = 100000;
99 bool recompute_schmassdist = true;
100 string schmassdistfile = "";
101 bool no_poisson = false;
102
103 double scalemass = -1.;
104
105 // *** Niveau de bruit
106 double snoise= 0.; // en equivalent MSol
107 int noise_evol = 0;
108
109 //// *** AGN
110 ////bool do_agn = false;
111 ////double lfjy_agn=-99., lsigma_agn=0.; // en Jy
112 ////double powlaw_agn = 0.;
113
114 // *** type de generation
115 bool computefourier0=false;
116 int use_growth_factor = 0;
117 unsigned short nthread=0;
118 int filter_by_pixel = 1;
119
120 // *** What to do
121 bool comp2dspec = false;
122 bool wfits = false;
123 bool wppf = false;
124 bool wslice = false;
125 bool compvarreal = false;
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
134 char c;
135 while((c = getopt(narg,arg,"ha0PWSV2UG:F:x:y:z:s:Z:M:A:T:N:Q:R:8:")) != -1) {
136 int nth = 0;
137 switch (c) {
138 case 'a' :
139 Auto_Ini_Ranf(5);
140 break;
141 case '0' :
142 computefourier0 = true;
143 break;
144 case 'G' :
145 sscanf(optarg,"%d",&use_growth_factor);
146 break;
147 case 'U' :
148 no_poisson = true;
149 break;
150 case 'F' :
151 sscanf(optarg,"%d",&filter_by_pixel);
152 break;
153 case 'x' :
154 sscanf(optarg,"%ld,%lf",&nx,&dx);
155 break;
156 case 'y' :
157 sscanf(optarg,"%ld,%lf",&ny,&dy);
158 break;
159 case 'z' :
160 sscanf(optarg,"%ld,%lf",&nz,&dz);
161 break;
162 case 's' :
163 sscanf(optarg,"%lf,%d",&snoise,&noise_evol);
164 break;
165 case 'Z' :
166 sscanf(optarg,"%lf",&zref);
167 break;
168 case '2' :
169 comp2dspec = true;
170 break;
171 case 'N' :
172 sscanf(optarg,"%lf",&scalemass);
173 if(scalemass==0.) scalemass = 1.;
174 break;
175 case 'M' :
176 sscanf(optarg,"%lf,%lf,%d",&schmin,&schmax,&schnpt);
177 break;
178 case 'Q' :
179 use_schmassdist = true;
180 sscanf(optarg,"%ld",&naleagal);
181 break;
182 case 'R' :
183 schmassdistfile = optarg;
184 break;
185 //// case 'A' :
186 ////do_agn = true;
187 ////sscanf(optarg,"%lf,%lf,%lf",&lfjy_agn,&lsigma_agn,&powlaw_agn);
188 ////break;
189 case '8' :
190 sscanf(optarg,"%lf,%lf",&sigmaR,&R);
191 break;
192 case 'V' :
193 compvarreal = true;
194 break;
195 case 'W' :
196 wfits = true;
197 break;
198 case 'P' :
199 wppf = true;
200 break;
201 case 'S' :
202 wslice = true;
203 break;
204 case 'T' :
205 sscanf(optarg,"%d",&nth);
206 nthread = (nth<1)? 0: nth;
207 break;
208 case 'h' :
209 default :
210 usage(); return -1;
211 }
212 }
213
214 double lschmin=log10(schmin), lschmax=log10(schmax);
215 if(schnpt<=0) { // alors c'est un nombre de points par decade
216 schnpt = long( (-schnpt)*(lschmax-lschmin+1.) + 0.5 );
217 if(schnpt<=2) schnpt = 1000;
218 }
219 if(naleagal<=2) naleagal = 100000;
220
221 cout<<"zref="<<zref<<endl;
222 cout<<"nx="<<nx<<" dx="<<dx<<" ny="<<ny<<" dy="<<dy<<" nz="<<nz<<" dz="<<dz<<endl;
223 cout<<"kmin="<<kmin<<" ("<<lkmin<<"), kmax="<<kmax<<" ("<<lkmax<<") Mpc^-1"
224 <<", npt="<<npt<<endl;
225 cout<<"Filter by pixel = "<<filter_by_pixel<<endl;
226 cout<<"R="<<R<<" Rg="<<Rg<<" Mpc, sigmaR="<<sigmaR<<endl;
227 cout<<"Use_growth_factor = "<<use_growth_factor<<endl;
228 cout<<"nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
229 cout<<"schmin="<<schmin<<" ("<<lschmin
230 <<"), schmax="<<schmax<<" ("<<lschmax<<") Msol"
231 <<", schnpt="<<schnpt<<endl;
232 if(no_poisson) cout<<"No poisson fluctuation, direct conversion to HI mass"<<endl;
233 cout<<"snoise="<<snoise<<" equivalent Msol, evolution="<<noise_evol<<endl;
234 cout<<"scalemass="<<scalemass<<endl;
235 ////if(do_agn)
236 //// cout<<"AGN: <log10(Jy)>="<<lfjy_agn<<" , sigma="<<lsigma_agn
237 //// <<" , powlaw="<<powlaw_agn<<endl;
238
239 string tagobs = "cmvobserv3d.ppf";
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 Spectrum"<<endl;
256
257 InitialSpectrum pkini(ns,as);
258
259 TransfertEisenstein tf(h100,om0-ob0,ob0,T_CMB_Par,false);
260 //tf.SetNoOscEnv(2);
261
262 GrowthFactor growth(om0,ol0);
263 // GrowthFactor growth(1.,0.); // D(z) = 1/(1+z)
264 double growth_at_z = growth(zref);
265 cout<<"...Growth factor at z="<<zref<<" = "<<growth_at_z<<endl;
266
267 PkSpectrum0 pk0(pkini,tf);
268
269 PkSpectrumZ pkz(pk0,growth,zref);
270
271 //-----------------------------------------------------------------
272 pkz.SetZ(0.);
273 cout<<endl<<"\n--- Compute variance for top-hat R="<<R
274 <<" at z="<<pkz.GetZ()<<endl;
275 VarianceSpectrum varpk_th(pkz,R,VarianceSpectrum::TOPHAT);
276 double kfind_th = varpk_th.FindMaximum(kmin,kmax,eps);
277 double pkmax_th = varpk_th(kfind_th);
278 cout<<"kfind_th = "<<kfind_th<<" ("<<log10(kfind_th)<<"), integrand="<<pkmax_th<<endl;
279 double k1=kmin, k2=kmax;
280 int rc = varpk_th.FindLimits(pkmax_th/1.e4,k1,k2,eps);
281 cout<<"limit_th: rc="<<rc<<" : "<<k1<<" ("<<log10(k1)<<") , "
282 <<k2<<" ("<<log10(k2)<<")"<<endl;
283
284 double ldlk = (log10(k2)-log10(k1))/npt;
285 varpk_th.SetInteg(0.01,ldlk,-1.,4);
286 double sr2 = varpk_th.Variance(k1,k2);
287 cout<<"varpk_th="<<sr2<<" -> sigma="<<sqrt(sr2)<<endl;
288
289 double normpkz = sigmaR*sigmaR/sr2;
290 pkz.SetScale(normpkz);
291 cout<<"Spectrum normalisation = "<<pkz.GetScale()<<endl;
292
293 pkz.SetZ(zref);
294
295 Histo hpkz(lkmin,lkmax,npt); hpkz.ReCenterBin();
296 FuncToHisto(pkz,hpkz,true);
297 {
298 tagobs = "hpkz"; posobs.PutObject(hpkz,tagobs);
299 }
300
301 //-----------------------------------------------------------------
302 cout<<endl<<"\n--- Compute variance for Pk at z="<<pkz.GetZ()<<endl;
303 VarianceSpectrum varpk_int(pkz,R,VarianceSpectrum::NOFILTER);
304
305 double kfind_int = varpk_int.FindMaximum(kmin,kmax,eps);
306 double pkmax_int = varpk_int(kfind_int);
307 cout<<"kfind_int = "<<kfind_int<<" ("<<log10(kfind_int)<<"), integrand="<<pkmax_int<<endl;
308 double k1int=kmin, k2int=kmax;
309 int rcint = varpk_int.FindLimits(pkmax_int/1.e4,k1int,k2int,eps);
310 cout<<"limit_int: rc="<<rcint<<" : "<<k1int<<" ("<<log10(k1int)<<") , "
311 <<k2int<<" ("<<log10(k2int)<<")"<<endl;
312
313 double ldlkint = (log10(k2int)-log10(k1int))/npt;
314 varpk_int.SetInteg(0.01,ldlkint,-1.,4);
315 double sr2int = varpk_int.Variance(k1int,k2int);
316 cout<<"varpk_int="<<sr2int<<" -> sigma="<<sqrt(sr2int)<<endl;
317
318 //-----------------------------------------------------------------
319 cout<<endl<<"\n--- Create mass function, compute number/mass density, init mass trials"<<endl;
320
321 Schechter sch(nstar,mstar,alpha);
322 sch.Print();
323
324 sch.SetOutValue(0);
325 cout<<"sch(mstar) = "<<sch(mstar)<<" /Mpc^3/Msol"<<endl;
326 double ngal_by_mpc3 = sch.Integrate(schmin,schmax,schnpt);
327 cout<<"Galaxy density number = "<<ngal_by_mpc3<<" /Mpc^3 between limits"<<endl;
328
329 sch.SetOutValue(1);
330 cout<<"mstar*sch(mstar) = "<<sch(mstar)<<" Msol/Mpc^3/Msol"<<endl;
331 double mass_by_mpc3 = sch.Integrate(schmin,schmax,schnpt);
332 cout<<"Galaxy mass density= "<<mass_by_mpc3<<" Msol/Mpc^3 between limits"<<endl;
333 cout<<"Omega_HI at z=0 is "<<mass_by_mpc3/(univ.Rhoc(0.)*GCm3toMsolMpc3_Cst)<<endl
334 <<" at z="<<zref<<" is "<<mass_by_mpc3/(univ.Rhoc(zref)*GCm3toMsolMpc3_Cst)<<endl;
335
336 SchechterMassDist schmdist(sch,schmin,schmax,schnpt);
337 if(use_schmassdist && schmassdistfile.size()>0) {
338 cout<<"\nSchechterMassDist read from "<<schmassdistfile<<endl;
339 schmdist.ReadPPF(schmassdistfile);
340 bool compsch = IsCompatible(sch,schmdist.GetSchechter());
341 double m1,m2; schmdist.GetMassLim(m1,m2);
342 if( !compsch || fabs(m1-schmin)>1e-4*schmin || fabs(m2-schmax)>1e-4*schmax) {
343 cout<<"FATAL_ERROR: INCONSISTENT SchechterMassDist file / Schechter or limits"<<endl;
344 cout<<"Schechter:"<<endl; sch.Print();
345 cout<<"schmin="<<schmin<<" schmax="<<schmax<<endl;
346 cout<<"SchechterMassDist:"<<endl; schmdist.Print();
347 return -10;
348 }
349 recompute_schmassdist = false;
350 }
351 schmdist.Print();
352 Histo hmdndm = schmdist.GetHmDnDm();
353 FunRan tirhmdndm = schmdist.GetTmDnDm();
354 {
355 tagobs = "hmdndm"; posobs.PutObject(hmdndm,tagobs);
356 Histo hdum1(tirhmdndm);
357 tagobs = "tirhmdndm"; posobs.PutObject(hdum1,tagobs);
358 }
359
360 PrtTim(">>>> End of definition");
361
362 //-----------------------------------------------------------------
363 // FFTW3 (p26): faster if sizes 2^a 3^b 5^c 7^d 11^e 13^f with e+f=0 ou 1
364 cout<<endl<<"\n--- Initialisation de GeneFluct3D"<<endl;
365
366 GeneFluct3D fluct3d(nx,ny,nz,dx,dy,dz,nthread,2);
367 fluct3d.SetObservator(zref,-nz/2.);
368 fluct3d.SetCosmology(univ);
369 fluct3d.SetGrowthFactor(growth);
370 fluct3d.LosComRedshift(0.001,-1);
371 TArray< complex<r_8> >& pkgen = fluct3d.GetComplexArray();
372 TArray<r_8>& rgen = fluct3d.GetRealArray();
373 cout<<endl; fluct3d.Print();
374 cout<<"\nMean number of galaxies per pixel = "<<ngal_by_mpc3*fluct3d.GetDVol()<<endl;
375 double mass_by_pixel = mass_by_mpc3 * fluct3d.GetDVol();
376 cout<<"Mean mass per pixel = "<<mass_by_pixel<<endl;
377
378 double dkmin = fluct3d.GetKincMin();
379 double knyqmax = fluct3d.GetKmax();
380 long nherr = long(knyqmax/dkmin+0.5);
381 cout<<"\nFor HistoErr: d="<<dkmin<<" max="<<knyqmax<<" n="<<nherr<<endl;
382
383 double dktmin = fluct3d.GetKTincMin();
384 double ktnyqmax = fluct3d.GetKTmax();
385 long nherrt = long(ktnyqmax/dktmin+0.5);
386 double dkzmin = fluct3d.GetKinc()[2];
387 double kznyqmax = fluct3d.GetKnyq()[2];
388 long nherrz = long(kznyqmax/dkzmin+0.5);
389 cout<<"For Histo2DErr: d="<<dktmin<<","<<dkzmin
390 <<" max="<<ktnyqmax<<","<<kznyqmax<<" n="<<nherrt<<","<<nherrz<<endl;
391
392 //-----------------------------------------------------------------
393 cout<<"\n--- Computing spectra variance up to Kmax at z="<<pkz.GetZ()<<endl;
394 // En fait on travaille sur un cube inscrit dans la sphere de rayon kmax:
395 // sphere: Vs = 4Pi/3 k^3 , cube inscrit (cote k*sqrt(2)): Vc = (k*sqrt(2))^3
396 // Vc/Vs = 0.675 -> keff = kmax * (0.675)^(1/3) = kmax * 0.877
397 double knyqmax_mod = 0.877*knyqmax;
398 ldlkint = (log10(knyqmax_mod)-log10(k1int))/npt;
399 varpk_int.SetInteg(0.01,ldlkint,-1.,4);
400 double sr2int_kmax = varpk_int.Variance(k1int,knyqmax_mod);
401 cout<<"varpk_int(<"<<knyqmax_mod<<")="<<sr2int_kmax<<" -> sigma="<<sqrt(sr2int_kmax)<<endl;
402
403 PrtTim(">>>> End Initialisation de GeneFluct3D");
404
405 //-----------------------------------------------------------------
406 cout<<"\n--- Computing a realization in Fourier space"<<endl;
407 if(use_growth_factor>0) pkz.SetZ(0.); else pkz.SetZ(zref);
408 cout<<"Power spectrum set at redshift: "<<pkz.GetZ()<<endl;
409 if(computefourier0) fluct3d.ComputeFourier0(pkz);
410 else fluct3d.ComputeFourier(pkz);
411 PrtTim(">>>> End Computing a realization in Fourier space");
412
413 cout<<"\n--- Checking realization spectra"<<endl;
414 HistoErr hpkgen(0.,knyqmax,nherr);
415 hpkgen.ReCenterBin(); hpkgen.Zero();
416 hpkgen.Show();
417 fluct3d.ComputeSpectrum(hpkgen);
418 {
419 tagobs = "hpkgen"; posobs.PutObject(hpkgen,tagobs);
420 }
421 PrtTim(">>>> End Checking realization spectra");
422
423 if(comp2dspec) {
424 cout<<"\n--- Checking realization 2D spectra"<<endl;
425 Histo2DErr hpkgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
426 hpkgen2.ReCenterBin(); hpkgen2.Zero();
427 hpkgen2.Show();
428 fluct3d.ComputeSpectrum2D(hpkgen2);
429 {
430 tagobs = "hpkgen2"; posobs.PutObject(hpkgen2,tagobs);
431 }
432 PrtTim(">>>> End Checking realization 2D spectra");
433 }
434
435 if(filter_by_pixel!=0) {
436 cout<<"\n--- Computing convolution by pixel shape"<<endl;
437 fluct3d.FilterByPixel();
438 PrtTim(">>>> End Computing convolution by pixel shape");
439
440 cout<<"\n--- Checking realization spectra after pixel shape convol."<<endl;
441 HistoErr hpkgenfb(0.,knyqmax,nherr);
442 hpkgenfb.ReCenterBin(); hpkgenfb.Zero();
443 hpkgenfb.Show();
444 fluct3d.ComputeSpectrum(hpkgenfb);
445 {
446 tagobs = "hpkgenfb"; posobs.PutObject(hpkgenfb,tagobs);
447 }
448 PrtTim(">>>> End Checking realization spectra");
449
450 cout<<"\n--- Checking realization spectra after pixel shape convol. with pixel correc."<<endl;
451 HistoErr hpkgenf(hpkgenfb); hpkgenf.Zero();
452 fluct3d.ComputeSpectrum(hpkgenf,0.,filter_by_pixel);
453 {
454 tagobs = "hpkgenf"; posobs.PutObject(hpkgenf,tagobs);
455 }
456 PrtTim(">>>> End Checking realization spectra with pixel correc.");
457
458 if(comp2dspec) {
459 cout<<"\n--- Checking realization 2D spectra after pixel shape convol."<<endl;
460 Histo2DErr hpkgenfb2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
461 hpkgenfb2.ReCenterBin(); hpkgenfb2.Zero();
462 hpkgenfb2.Show();
463 fluct3d.ComputeSpectrum2D(hpkgenfb2);
464 {
465 tagobs = "hpkgenfb2"; posobs.PutObject(hpkgenfb2,tagobs);
466 }
467 PrtTim(">>>> End Checking realization 2D spectra");
468
469 cout<<"\n--- Checking realization 2D spectra after pixel shape convol. with pixel correc."<<endl;
470 Histo2DErr hpkgenf2(hpkgenfb2); hpkgenf2.Zero();
471 fluct3d.ComputeSpectrum2D(hpkgenf2,0.,filter_by_pixel);
472 {
473 tagobs = "hpkgenf2"; posobs.PutObject(hpkgenf2,tagobs);
474 }
475 PrtTim(">>>> End Checking realization 2D spectra with pixel correc.");
476 }
477 }
478
479 if(wfits) {
480 fluct3d.WriteFits("!cmvobserv3d_k0.fits");
481 PrtTim(">>>> End WriteFits");
482 }
483 if(wppf) {
484 fluct3d.WritePPF("cmvobserv3d_k0.ppf",false);
485 PrtTim(">>>> End WritePPF");
486 }
487
488 //-----------------------------------------------------------------
489 cout<<"\n--- Computing a realization in real space"<<endl;
490 fluct3d.ComputeReal();
491 double rmin,rmax; fluct3d.MinMax(rmin,rmax);
492 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
493 PrtTim(">>>> End Computing a realization in real space");
494
495 if(use_growth_factor>0) {
496 cout<<"\n--- Apply Growth factor"<<endl;
497 cout<<"...D(z=0)="<<growth(0.)<<" D(z="<<zref<<")="<<growth(zref)<<endl;
498 fluct3d.ApplyGrowthFactor(use_growth_factor);
499 fluct3d.MinMax(rmin,rmax);
500 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
501 PrtTim(">>>> End Applying growth factor");
502 }
503
504 int_8 nm;
505 double rmref,rs2ref;
506 cout<<"\n--- Computing reference variance in real space"<<endl;
507 nm = fluct3d.MeanSigma2(rmref,rs2ref);
508 cout<<" rs2ref= "<<rs2ref<<" , rmref="<<rmref<<" ("<<nm<<")"<<endl;
509 PrtTim(">>>> End Computing reference variance in real space");
510
511 if(wfits) {
512 fluct3d.WriteFits("!cmvobserv3d_r0.fits");
513 PrtTim(">>>> End WriteFits");
514 }
515 if(wppf) {
516 fluct3d.WritePPF("cmvobserv3d_r0.ppf",true);
517 PrtTim(">>>> End WritePPF");
518 }
519 if(wslice) {
520 fluct3d.WriteSlicePPF("cmvobserv3d_s_r0.ppf");
521 PrtTim(">>>> End WriteSlicePPF");
522 }
523
524 cout<<"\n--- Check mean and variance in real space"<<endl;
525 fluct3d.NumberOfBad(-1.,1e+200);
526 double rm,rs2;
527 nm = fluct3d.MeanSigma2(rm,rs2);
528 PrtTim(">>>> End Check mean and variance in real space");
529
530 if(compvarreal) {
531 cout<<"\n--- Check variance sigmaR in real space"<<endl;
532 double varr;
533 fluct3d.VarianceFrReal(R,varr);
534 cout<<"...Computed variance = "<<varr
535 <<" , Theorical variance at (z=0) = "<<pow(sigmaR,2.)
536 <<" , at (z="<<zref<<") = "<<pow(sigmaR*growth_at_z,2.)<<endl;
537 PrtTim(">>>> End Check variance sigmaR in real space");
538 }
539
540 //-----------------------------------------------------------------
541 cout<<endl<<"\n--- Converting fluctuations into mass"<<endl;
542 fluct3d.TurnFluct2Mass();
543 nm = fluct3d.MeanSigma2(rm,rs2);
544 PrtTim(">>>> End Converting fluctuations into mass");
545
546 if(no_poisson) {
547 cout<<"\n--- Converting !!!DIRECTLY!!! mass into HI mass: mass per pixel ="
548 <<mass_by_pixel<<endl;
549 rm = fluct3d.TurnMass2MeanNumber(mass_by_mpc3); // ici on doit donner Msol/Mpc^3
550 } else {
551 cout<<"\n--- Converting mass into galaxy number: gal per pixel ="
552 <<ngal_by_mpc3*fluct3d.GetDVol()<<endl;
553 rm = fluct3d.TurnMass2MeanNumber(ngal_by_mpc3);
554 }
555 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
556 nm = fluct3d.MeanSigma2(rm,rs2);
557 PrtTim(">>>> End Converting mass into galaxy number or mass");
558
559 if( !no_poisson ) {
560
561 cout<<"\n--- Apply poisson on galaxy number"<<endl;
562 fluct3d.ApplyPoisson();
563 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
564 nm = fluct3d.MeanSigma2(rm,rs2);
565 double xgalmin,xgalmax; fluct3d.MinMax(xgalmin,xgalmax,0.1,1.e50);
566 PrtTim(">>>> End Apply poisson on galaxy number");
567 if(wslice) {
568 fluct3d.WriteSlicePPF("cmvobserv3d_s_rn.ppf");
569 PrtTim(">>>> End WriteSlicePPF");
570 }
571
572 cout<<"\n--- Convert Galaxy number to HI mass"<<endl;
573 double mhi = 0.;
574 if(use_schmassdist) {
575 if(recompute_schmassdist) {
576 int ngalmax = int(xgalmax+0.5);
577 schmdist.SetNgalLim(ngalmax,1,naleagal);
578 PrtTim(">>>> End creating tabulated histograms for trials");
579 }
580 mhi = fluct3d.TurnNGal2MassQuick(schmdist);
581 schmdist.PrintStatus();
582 } else {
583 mhi = fluct3d.TurnNGal2Mass(tirhmdndm,true);
584 }
585 cout<<mhi<<" MSol in survey / "<<mass_by_mpc3*fluct3d.GetVol()<<endl;
586 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
587 cout<<"Equivalent: "<<rm*nm/fluct3d.NPix()<<" Msol / pixels"<<endl;
588 nm = fluct3d.MeanSigma2(rm,rs2);
589 PrtTim(">>>> End Convert Galaxy number to HI mass");
590
591 }
592
593 //-----------------------------------------------------------------
594 if(wfits) {
595 fluct3d.WriteFits("!cmvobserv3d_r.fits");
596 PrtTim(">>>> End WriteFits");
597 }
598 if(wppf) {
599 fluct3d.WritePPF("cmvobserv3d_r.ppf",true);
600 PrtTim(">>>> End WritePPF");
601 }
602 if(wslice) {
603 fluct3d.WriteSlicePPF("cmvobserv3d_s_r.ppf");
604 PrtTim(">>>> End WriteSlicePPF");
605 }
606
607 //-----------------------------------------------------------------
608 ////if(do_agn) {
609 //// cout<<"\n--- Add AGN: <log10(S Jy)>="<<lfjy_agn<<" , sigma="<<lsigma_agn
610 //// <<" , powlaw="<<powlaw_agn<<endl;
611 //// fluct3d.AddAGN(lfjy_agn,lsigma_agn,powlaw_agn);
612 //// nm = fluct3d.MeanSigma2(rm,rs2);
613 //// PrtTim(">>>> End Add AGN");
614 ////}
615
616 //-----------------------------------------------------------------
617 double snoisesave = 0.;
618 if(snoise>0.) {
619 cout<<"\n--- Add noise to HI Flux snoise="<<snoise<<", evolution="<<noise_evol<<endl;
620 fluct3d.AddNoise2Real(snoise,noise_evol);
621 snoisesave = snoise;
622 nm = fluct3d.MeanSigma2(rm,rs2);
623 PrtTim(">>>> End Add noise");
624 }
625
626 //-----------------------------------------------------------------
627 if(scalemass!=0. && scalemass!=1.) { // Si scalemass==0 pas de normalisation
628 if(scalemass<0.) scalemass = 1. / (-scalemass * mass_by_pixel);
629 cout<<"\n--- Scale cube scale="<<scalemass<<endl;
630 fluct3d.ScaleOffset(scalemass);
631 snoisesave *= scalemass;
632 nm = fluct3d.MeanSigma2(rm,rs2);
633 PrtTim(">>>> End Scale cube");
634 }
635
636 //-----------------------------------------------------------------
637 if(wfits) {
638 fluct3d.WriteFits("!cmvobserv3d_rf.fits");
639 PrtTim(">>>> End WriteFits");
640 }
641 if(wppf) {
642 fluct3d.WritePPF("cmvobserv3d_rf.ppf",true);
643 PrtTim(">>>> End WritePPF");
644 }
645 if(wslice) {
646 fluct3d.WriteSlicePPF("cmvobserv3d_s_rf.ppf");
647 PrtTim(">>>> End WriteSlicePPF");
648 }
649
650 //-----------------------------------------------------------------
651 // -- NE PAS FAIRE CA SI ON VEUT CONTINUER LA SIMULATION -> d_rho/rho ecrase
652
653 cout<<endl<<"\n--- ReComputing spectrum from real space"<<endl;
654 fluct3d.ReComputeFourier();
655 PrtTim(">>>> End ReComputing spectrum");
656
657 if(wfits) {
658 fluct3d.WriteFits("!cmvobserv3d_k.fits");
659 PrtTim(">>>> End WriteFits");
660 }
661 if(wppf) {
662 fluct3d.WritePPF("cmvobserv3d_k.ppf",false);
663 PrtTim(">>>> End WritePPF");
664 }
665
666 cout<<endl<<"\n--- Computing final spectrum"<<endl;
667 HistoErr hpkrecb(0.,knyqmax,nherr); hpkrecb.Zero();
668 hpkrecb.ReCenterBin();
669 hpkrecb.Show();
670 fluct3d.ComputeSpectrum(hpkrecb);
671 {
672 tagobs = "hpkrecb"; posobs.PutObject(hpkrecb,tagobs);
673 }
674 PrtTim(">>>> End Computing final spectrum");
675
676 cout<<endl<<"\n--- Computing final spectrum with pixel deconv."<<endl;
677 HistoErr hpkrec(hpkrecb); hpkrec.Zero();
678 fluct3d.ComputeSpectrum(hpkrec,snoisesave,filter_by_pixel);
679 {
680 tagobs = "hpkrec"; posobs.PutObject(hpkrec,tagobs);
681 }
682 PrtTim(">>>> End Computing final spectrum with pixel deconv.");
683
684 if(comp2dspec) {
685 cout<<"\n--- Computing final 2D spectrum"<<endl;
686 Histo2DErr hpkrecb2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
687 hpkrecb2.ReCenterBin(); hpkrecb2.Zero();
688 hpkrecb2.Show();
689 fluct3d.ComputeSpectrum2D(hpkrecb2);
690 {
691 tagobs = "hpkrecb2"; posobs.PutObject(hpkrecb2,tagobs);
692 }
693 PrtTim(">>>> End Computing final 2D spectrum");
694
695 cout<<"\n--- Computing final 2D spectrum with pixel deconv."<<endl;
696 Histo2DErr hpkrec2(hpkrecb2); hpkrec2.Zero();
697 fluct3d.ComputeSpectrum2D(hpkrec2,snoisesave,filter_by_pixel);
698 {
699 tagobs = "hpkrec2"; posobs.PutObject(hpkrec2,tagobs);
700 }
701 PrtTim(">>>> End Computing final 2D spectrum with pixel deconv.");
702
703 }
704
705 PrtTim(">>>> End Of Job");
706 return 0;
707}
708
Note: See TracBrowser for help on using the repository browser.