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

Last change on this file since 3565 was 3565, checked in by ansari, 17 years ago

Ajout options -d/-D pour ecriture d_rho/rho en PPF/fits et sortie du programme apres - Reza 30/01/2009

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