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

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

add possibility to just multiply dRho.Rho , cmv 23/10/2007

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