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

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

suite des modifs importantes , cmv 12/10/2007

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