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

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

pb lecture file et recompute FunRan 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 recompute_schmassdist = false;
322 }
323 schmdist.Print();
324 Histo hmdndm = schmdist.GetHmDnDm();
325 FunRan tirhmdndm = schmdist.GetTmDnDm();
326 {
327 tagobs = "hmdndm"; posobs.PutObject(hmdndm,tagobs);
328 Histo hdum1(tirhmdndm);
329 tagobs = "tirhmdndm"; posobs.PutObject(hdum1,tagobs);
330 }
331
332 PrtTim(">>>> End of definition");
333
334 //-----------------------------------------------------------------
335 // FFTW3 (p26): faster if sizes 2^a 3^b 5^c 7^d 11^e 13^f with e+f=0 ou 1
336 cout<<endl<<"\n--- Initialisation de GeneFluct3D"<<endl;
337
338 TArray< complex<r_8> > pkgen;
339 GeneFluct3D fluct3d(pkgen);
340 fluct3d.SetPrtLevel(2);
341 fluct3d.SetNThread(nthread);
342 fluct3d.SetSize(nx,ny,nz,dx,dy,dz);
343 fluct3d.SetObservator(zref,-nz/2.);
344 fluct3d.SetCosmology(univ);
345 fluct3d.SetGrowthFactor(growth);
346 fluct3d.LosComRedshift(0.001,-1);
347 //TArray<r_8>& rgen = fluct3d.GetRealArray();
348 cout<<endl; fluct3d.Print();
349 cout<<"\nMean number of galaxies per pixel = "<<ngal_by_mpc3*fluct3d.GetDVol()<<endl;
350 cout<<"Mean mass per pixel = "<<mass_by_mpc3*fluct3d.GetDVol()<<endl;
351
352 double dkmin = fluct3d.GetKincMin();
353 double knyqmax = fluct3d.GetKmax();
354 long nherr = long(knyqmax/dkmin+0.5);
355 cout<<"\nFor HistoErr: d="<<dkmin<<" max="<<knyqmax<<" n="<<nherr<<endl;
356
357 double dktmin = fluct3d.GetKTincMin();
358 double ktnyqmax = fluct3d.GetKTmax();
359 long nherrt = long(ktnyqmax/dktmin+0.5);
360 double dkzmin = fluct3d.GetKinc()[2];
361 double kznyqmax = fluct3d.GetKnyq()[2];
362 long nherrz = long(kznyqmax/dkzmin+0.5);
363 cout<<"For Histo2DErr: d="<<dktmin<<","<<dkzmin
364 <<" max="<<ktnyqmax<<","<<kznyqmax<<" n="<<nherrt<<","<<nherrz<<endl;
365
366 //-----------------------------------------------------------------
367 cout<<"\n--- Computing spectra variance up to Kmax at z="<<pkz.GetZ()<<endl;
368 // En fait on travaille sur un cube inscrit dans la sphere de rayon kmax:
369 // sphere: Vs = 4Pi/3 k^3 , cube inscrit (cote k*sqrt(2)): Vc = (k*sqrt(2))^3
370 // Vc/Vs = 0.675 -> keff = kmax * (0.675)^(1/3) = kmax * 0.877
371 double knyqmax_mod = 0.877*knyqmax;
372 ldlkint = (log10(knyqmax_mod)-log10(k1int))/npt;
373 varpk_int.SetInteg(0.01,ldlkint,-1.,4);
374 double sr2int_kmax = varpk_int.Variance(R,k1int,knyqmax_mod);
375 cout<<"varpk_int(<"<<knyqmax_mod<<")="<<sr2int_kmax<<" -> sigma="<<sqrt(sr2int_kmax)<<endl;
376
377 PrtTim(">>>> End Initialisation de GeneFluct3D");
378
379 //-----------------------------------------------------------------
380 cout<<"\n--- Computing a realization in Fourier space"<<endl;
381 if(use_growth_factor) pkz.SetZ(0.); else pkz.SetZ(zref);
382 cout<<"Power spectrum set at redshift: "<<pkz.GetZ()<<endl;
383 if(computefourier0) fluct3d.ComputeFourier0(pkz);
384 else fluct3d.ComputeFourier(pkz);
385 PrtTim(">>>> End Computing a realization in Fourier space");
386
387 /*
388 // CMVTEST
389 for(int l=0;l<pkgen.SizeX();l++)
390 for(int j=0;j<pkgen.SizeY();j++)
391 for(int i=0;i<pkgen.SizeZ();i++) {
392 double k2 = fluct3d.Kx(i)*fluct3d.Kx(i)
393 +fluct3d.Ky(j)*fluct3d.Ky(j)
394 +fluct3d.Kz(l)*fluct3d.Kz(l);
395 double pk = (k2>0.)? 1./k2: 0.;
396 //pkgen(l,j,i) = ComplexGaussRan(sqrt(pk/2.));
397 //pkgen(l,j,i) = sqrt(pk/2.);
398 pkgen(l,j,i) = 1.;
399 }
400 // CMVTEST
401 */
402
403 cout<<"\n--- Checking realization spectra"<<endl;
404 HistoErr hpkgen(0.,knyqmax,nherr);
405 hpkgen.ReCenterBin(); hpkgen.Zero();
406 hpkgen.Show();
407 fluct3d.ComputeSpectrum(hpkgen);
408 {
409 tagobs = "hpkgen"; posobs.PutObject(hpkgen,tagobs);
410 }
411 PrtTim(">>>> End Checking realization spectra");
412
413 if(comp2dspec) {
414 cout<<"\n--- Checking realization 2D spectra"<<endl;
415 Histo2DErr hpkgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
416 hpkgen2.ReCenterBin(); hpkgen2.Zero();
417 hpkgen2.Show();
418 fluct3d.ComputeSpectrum2D(hpkgen2);
419 {
420 tagobs = "hpkgen2"; posobs.PutObject(hpkgen2,tagobs);
421 }
422 PrtTim(">>>> End Checking realization 2D spectra");
423 }
424
425 if(filter_by_pixel!=0) {
426 cout<<"\n--- Computing convolution by pixel shape"<<endl;
427 fluct3d.FilterByPixel();
428 PrtTim(">>>> End Computing convolution by pixel shape");
429
430 cout<<"\n--- Checking realization spectra after pixel shape convol."<<endl;
431 HistoErr hpkgenf(0.,knyqmax,nherr);
432 hpkgenf.ReCenterBin(); hpkgenf.Zero();
433 hpkgenf.Show();
434 fluct3d.ComputeSpectrum(hpkgenf);
435 {
436 tagobs = "hpkgenf"; posobs.PutObject(hpkgenf,tagobs);
437 }
438 PrtTim(">>>> End Checking realization spectra");
439
440 if(comp2dspec) {
441 cout<<"\n--- Checking realization 2D spectra after pixel shape convol."<<endl;
442 Histo2DErr hpkgenf2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
443 hpkgenf2.ReCenterBin(); hpkgenf2.Zero();
444 hpkgenf2.Show();
445 fluct3d.ComputeSpectrum2D(hpkgenf2);
446 {
447 tagobs = "hpkgenf2"; posobs.PutObject(hpkgenf2,tagobs);
448 }
449 PrtTim(">>>> End Checking realization 2D spectra");
450 }
451 }
452
453 if(wfits) {
454 fluct3d.WriteFits("!cmvobserv3d_k0.fits");
455 PrtTim(">>>> End WriteFits");
456 }
457 if(wppf) {
458 fluct3d.WritePPF("cmvobserv3d_k0.ppf",false);
459 PrtTim(">>>> End WritePPF");
460 }
461
462 //-----------------------------------------------------------------
463 cout<<"\n--- Computing a realization in real space"<<endl;
464 fluct3d.ComputeReal();
465 double rmin,rmax; fluct3d.MinMax(rmin,rmax);
466 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
467 PrtTim(">>>> End Computing a realization in real space");
468
469 if(use_growth_factor) {
470 cout<<"\n--- Apply Growth factor"<<endl;
471 cout<<"...D(z=0)="<<growth(0.)<<" D(z="<<zref<<")="<<growth(zref)<<endl;
472 fluct3d.ApplyGrowthFactor();
473 fluct3d.MinMax(rmin,rmax);
474 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
475 PrtTim(">>>> End Applying growth factor");
476 }
477
478 int_8 nm;
479 double rmref,rs2ref;
480 cout<<"\n--- Computing reference variance in real space"<<endl;
481 nm = fluct3d.MeanSigma2(rmref,rs2ref);
482 cout<<" rs2ref= "<<rs2ref<<" , rmref="<<rmref<<" ("<<nm<<")"<<endl;
483 PrtTim(">>>> End Computing reference variance in real space");
484
485 if(wfits) {
486 fluct3d.WriteFits("!cmvobserv3d_r0.fits");
487 PrtTim(">>>> End WriteFits");
488 }
489 if(wppf) {
490 fluct3d.WritePPF("cmvobserv3d_r0.ppf",true);
491 PrtTim(">>>> End WritePPF");
492 }
493 if(wslice) {
494 fluct3d.WriteSlicePPF("cmvobserv3d_s_r0.ppf");
495 PrtTim(">>>> End WriteSlicePPF");
496 }
497
498 cout<<"\n--- Check mean and variance in real space"<<endl;
499 fluct3d.NumberOfBad(-1.,1e+200);
500 double rm,rs2;
501 nm = fluct3d.MeanSigma2(rm,rs2);
502 PrtTim(">>>> End Check mean and variance in real space");
503
504 if(compvarreal) {
505 cout<<"\n--- Check variance sigmaR in real space"<<endl;
506 double varr;
507 fluct3d.VarianceFrReal(R,varr);
508 cout<<"...Computed variance = "<<varr
509 <<" , Theorical variance at (z=0) = "<<pow(sigmaR,1.)
510 <<" , at (z="<<zref<<") = "<<pow(sigmaR*growth_at_z,1.)<<endl;
511 PrtTim(">>>> End Check variance sigmaR in real space");
512 }
513
514 //STOP_HERE_FOR QUICK_DEBUG
515 // return -41;
516
517 //-----------------------------------------------------------------
518 cout<<endl<<"\n--- Converting fluctuations into mass"<<endl;
519 fluct3d.TurnFluct2Mass();
520 nm = fluct3d.MeanSigma2(rm,rs2);
521 PrtTim(">>>> End Converting fluctuations into mass");
522
523 cout<<"\n--- Converting mass into galaxy number: gal per pixel ="
524 <<ngal_by_mpc3*fluct3d.GetDVol()<<endl;
525 rm = fluct3d.TurnMass2MeanNumber(ngal_by_mpc3);
526 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
527 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200,true,0.);
528 PrtTim(">>>> End Converting mass into galaxy number");
529
530 cout<<"\n--- Set negative and null pixels to BAD"<<endl;
531 nm = fluct3d.SetToVal(0.,1e+200,-999.);
532 PrtTim(">>>> End Set negative pixels to BAD etc...");
533
534 cout<<"\n--- Apply poisson on galaxy number"<<endl;
535 fluct3d.ApplyPoisson();
536 nm = fluct3d.MeanSigma2(rm,rs2,-998.,1e200);
537 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200,true,0.);
538 double xgalmin,xgalmax; fluct3d.MinMax(xgalmin,xgalmax,0.1,1.e50);
539 PrtTim(">>>> End Apply poisson on galaxy number");
540 if(wslice) {
541 fluct3d.WriteSlicePPF("cmvobserv3d_s_rn.ppf");
542 PrtTim(">>>> End WriteSlicePPF");
543 }
544
545 cout<<"\n--- Convert Galaxy number to HI mass"<<endl;
546 double mhi = 0.;
547 if(use_schmassdist) {
548 if(recompute_schmassdist) {
549 int ngalmax = int(xgalmax+0.5);
550 schmdist.SetNgalLim(ngalmax,1,naleagal);
551 PrtTim(">>>> End creating tabulated histograms for trials");
552 }
553 mhi = fluct3d.TurnNGal2MassQuick(schmdist);
554 schmdist.PrintStatus();
555 } else {
556 mhi = fluct3d.TurnNGal2Mass(tirhmdndm,true);
557 }
558 cout<<mhi<<" MSol in survey / "<<mass_by_mpc3*fluct3d.GetVol()<<endl;
559 nm = fluct3d.MeanSigma2(rm,rs2,-998.,1e200);
560 cout<<"Equivalent: "<<rm*nm/fluct3d.NPix()<<" Msol / pixels"<<endl;
561 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200,true,0.);
562 PrtTim(">>>> End Convert Galaxy number to HI mass");
563
564 cout<<"\n--- Set BAD pixels to Zero"<<endl;
565 nm = fluct3d.SetToVal(-998.,1e+200,0.);
566 PrtTim(">>>> End Set BAD pixels to Zero etc...");
567
568 if(wfits) {
569 fluct3d.WriteFits("!cmvobserv3d_r.fits");
570 PrtTim(">>>> End WriteFits");
571 }
572 if(wppf) {
573 fluct3d.WritePPF("cmvobserv3d_r.ppf",true);
574 PrtTim(">>>> End WritePPF");
575 }
576 if(wslice) {
577 fluct3d.WriteSlicePPF("cmvobserv3d_s_r.ppf");
578 PrtTim(">>>> End WriteSlicePPF");
579 }
580
581 if(do_agn) {
582 cout<<"\n--- Add AGN: <log10(S Jy)>="<<lfjy_agn<<" , sigma="<<lsigma_agn
583 <<" , powlaw="<<powlaw_agn<<endl;
584 fluct3d.AddAGN(lfjy_agn,lsigma_agn,powlaw_agn);
585 nm = fluct3d.MeanSigma2(rm,rs2);
586 PrtTim(">>>> End Add AGN");
587 }
588
589 if(snoise>0.) {
590 cout<<"\n--- Add noise to HI Flux snoise="<<snoise<<", evolution="<<isnoise_evol<<endl;
591 fluct3d.AddNoise2Real(snoise,(isnoise_evol>0? true:false));
592 nm = fluct3d.MeanSigma2(rm,rs2);
593 PrtTim(">>>> End Add noise");
594 }
595
596 if(scalecube!=0.) { // Si scalecube==0 pas de normalisation
597 cout<<"\n--- Scale cube rs2ref="<<rs2ref<<endl;
598 if(scalecube<0. && rs2ref>0.) { // si negatif on scale automatiquement
599 nm = fluct3d.MeanSigma2(rm,rs2);
600 if(rs2>0.) {scalecube=sqrt(rs2ref)/sqrt(rs2); offsetcube=-rm;}
601 }
602 cout<<"...scale="<<scalecube<<" offset="<<offsetcube<<endl;
603 if(scalecube>0.) fluct3d.ScaleOffset(scalecube,offsetcube);
604 PrtTim(">>>> End Scale cube");
605 }
606
607 if(wfits) {
608 fluct3d.WriteFits("!cmvobserv3d_rf.fits");
609 PrtTim(">>>> End WriteFits");
610 }
611 if(wppf) {
612 fluct3d.WritePPF("cmvobserv3d_rf.ppf",true);
613 PrtTim(">>>> End WritePPF");
614 }
615 if(wslice) {
616 fluct3d.WriteSlicePPF("cmvobserv3d_s_rf.ppf");
617 PrtTim(">>>> End WriteSlicePPF");
618 }
619
620 //-----------------------------------------------------------------
621 // -- NE PAS FAIRE CA SI ON VEUT CONTINUER LA SIMULATION -> d_rho/rho ecrase
622
623 cout<<endl<<"\n--- ReComputing spectrum from real space"<<endl;
624 fluct3d.ReComputeFourier();
625 PrtTim(">>>> End ReComputing spectrum");
626
627 if(wfits) {
628 fluct3d.WriteFits("!cmvobserv3d_k.fits");
629 PrtTim(">>>> End WriteFits");
630 }
631 if(wppf) {
632 fluct3d.WritePPF("cmvobserv3d_k.ppf",false);
633 PrtTim(">>>> End WritePPF");
634 }
635
636 cout<<endl<<"\n--- Computing final spectrum"<<endl;
637 HistoErr hpkrec(0.,knyqmax,nherr);
638 hpkrec.ReCenterBin();
639 hpkrec.Show();
640 fluct3d.ComputeSpectrum(hpkrec);
641 tagobs = "hpkrec"; posobs.PutObject(hpkrec,tagobs);
642 PrtTim(">>>> End Computing final spectrum");
643
644 if(comp2dspec) {
645 cout<<"\n--- Computing final 2D spectrum"<<endl;
646 Histo2DErr hpkrec2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
647 hpkrec2.ReCenterBin(); hpkrec2.Zero();
648 hpkrec2.Show();
649 fluct3d.ComputeSpectrum2D(hpkrec2);
650 {
651 tagobs = "hpkrec2"; posobs.PutObject(hpkrec2,tagobs);
652 }
653 PrtTim(">>>> End Computing final 2D spectrum");
654 }
655
656 PrtTim(">>>> End Of Job");
657 return 0;
658}
659
Note: See TracBrowser for help on using the repository browser.