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

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

Intro SchechterMassDist + lecture sur fichier cmv 05/09/2007

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