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

Last change on this file since 3524 was 3524, checked in by cmv, 17 years ago

intro du remplissage du NTuple de debug cmv 22/09/2008

File size: 25.2 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 <<" (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 =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 <<endl;
59 ////<<" -A <log10(S_agn in Jy at 1.4 GHz)>,sigma,powlaw :"<<endl
60 ////<<" AGN mean and sigma gaussian equiv. distrib. for solid angle of centeral pixel"<<endl
61 ////<<" powlaw: apply S_agn evolution as (Nu/1.4)^powlaw"<<endl
62}
63
64int main(int narg,char *arg[])
65{
66 InitTim();
67
68 //-----------------------------------------------------------------
69 // *** Survey definition
70 long nx=360, ny=-1, nz=64; double dx=1., dy=-1., dz=-1.;
71 //long nx=1000, ny=-1, nz=128; double dx=3., dy=-1., dz=6.;
72 //long nx=1200, ny=-1, nz=128; double dx=1., dy=-1., dz=3;
73
74 // *** Cosmography definition (WMAP)
75 unsigned short flat = 0;
76 double ob0 = 0.0444356;
77 double h100=0.71, om0=0.267804, or0=7.9e-05, ol0=0.73,w0=-1.;
78 double zref = 0.5;
79 double perc=0.01,dzinc=-1.,dzmax=-1.; unsigned short glorder=4;
80
81 // *** Spectrum and variance definition
82 double ns = 1., as = 1.;
83 double R=8./h100, Rg=R/sqrt(5.);
84 double sigmaR = 1.;
85
86 double kmin=1e-5,kmax=1000.;
87 int npt = 10000;
88 double lkmin=log10(kmin), lkmax=log10(kmax);
89 double eps=1.e-3;
90
91 // *** Schechter mass function definition
92 double h75 = h100 / 0.75;
93 double nstar = 0.006*pow(h75,3.);
94 double mstar = pow(10.,9.8); // MSol
95 double alpha = -1.37;
96
97 double schmin=1.e7, schmax=1.e13;
98 int schnpt = -100;
99 bool use_schmassdist = false;
100 long naleagal = 100000;
101 bool recompute_schmassdist = true;
102 string schmassdistfile = "";
103 int no_poisson_type = 0;
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 unsigned long ntnent = 10000; // 0 = do not fill NTuple
129
130 // --- Decodage arguments
131 if(narg>0) {
132 cout<<"\n--- Arguments: "<<endl;
133 for(int i=0;i<narg;i++) cout<<arg[i]<<" ";
134 cout<<endl;
135 }
136
137 char c;
138 while((c = getopt(narg,arg,"ha0PWSV2U:G:F:x:y:z:s:Z:M:A:T:N:Q:R:8:")) != -1) {
139 int nth = 0;
140 switch (c) {
141 case 'a' :
142 Auto_Ini_Ranf(5);
143 break;
144 case '0' :
145 computefourier0 = true;
146 break;
147 case 'G' :
148 sscanf(optarg,"%d",&use_growth_factor);
149 break;
150 case 'U' :
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_type!=0) 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<GEN3D_TYPE> >& pkgen = fluct3d.GetComplexArray();
382 TArray<GEN3D_TYPE>& 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 fluct3d.NTupleCheck(posobs,string("ntpkgen"),ntnent);
422 PrtTim(">>>> End Computing a realization in Fourier space");
423
424 cout<<"\n--- Checking realization spectra"<<endl;
425 HistoErr hpkgen(0.,knyqmax,nherr);
426 hpkgen.ReCenterBin(); hpkgen.Zero();
427 hpkgen.Show();
428 fluct3d.ComputeSpectrum(hpkgen);
429 {
430 tagobs = "hpkgen"; posobs.PutObject(hpkgen,tagobs);
431 }
432 PrtTim(">>>> End Checking realization spectra");
433
434 if(comp2dspec) {
435 cout<<"\n--- Checking realization 2D spectra"<<endl;
436 Histo2DErr hpkgen2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
437 hpkgen2.ReCenterBin(); hpkgen2.Zero();
438 hpkgen2.Show();
439 fluct3d.ComputeSpectrum2D(hpkgen2);
440 {
441 tagobs = "hpkgen2"; posobs.PutObject(hpkgen2,tagobs);
442 }
443 PrtTim(">>>> End Checking realization 2D spectra");
444 }
445
446 if(filter_by_pixel!=0) {
447 cout<<"\n--- Computing convolution by pixel shape"<<endl;
448 fluct3d.FilterByPixel();
449 fluct3d.NTupleCheck(posobs,string("ntpkgenf"),ntnent);
450 PrtTim(">>>> End Computing convolution by pixel shape");
451
452 cout<<"\n--- Checking realization spectra after pixel shape convol."<<endl;
453 HistoErr hpkgenfb(0.,knyqmax,nherr);
454 hpkgenfb.ReCenterBin(); hpkgenfb.Zero();
455 hpkgenfb.Show();
456 fluct3d.ComputeSpectrum(hpkgenfb);
457 {
458 tagobs = "hpkgenfb"; posobs.PutObject(hpkgenfb,tagobs);
459 }
460 PrtTim(">>>> End Checking realization spectra");
461
462 cout<<"\n--- Checking realization spectra after pixel shape convol. with pixel correc."<<endl;
463 HistoErr hpkgenf(hpkgenfb); hpkgenf.Zero();
464 fluct3d.ComputeSpectrum(hpkgenf,0.,filter_by_pixel);
465 {
466 tagobs = "hpkgenf"; posobs.PutObject(hpkgenf,tagobs);
467 }
468 PrtTim(">>>> End Checking realization spectra with pixel correc.");
469
470 if(comp2dspec) {
471 cout<<"\n--- Checking realization 2D spectra after pixel shape convol."<<endl;
472 Histo2DErr hpkgenfb2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
473 hpkgenfb2.ReCenterBin(); hpkgenfb2.Zero();
474 hpkgenfb2.Show();
475 fluct3d.ComputeSpectrum2D(hpkgenfb2);
476 {
477 tagobs = "hpkgenfb2"; posobs.PutObject(hpkgenfb2,tagobs);
478 }
479 PrtTim(">>>> End Checking realization 2D spectra");
480
481 cout<<"\n--- Checking realization 2D spectra after pixel shape convol. with pixel correc."<<endl;
482 Histo2DErr hpkgenf2(hpkgenfb2); hpkgenf2.Zero();
483 fluct3d.ComputeSpectrum2D(hpkgenf2,0.,filter_by_pixel);
484 {
485 tagobs = "hpkgenf2"; posobs.PutObject(hpkgenf2,tagobs);
486 }
487 PrtTim(">>>> End Checking realization 2D spectra with pixel correc.");
488 }
489 }
490
491 if(wfits) {
492 fluct3d.WriteFits("!cmvobserv3d_k0.fits");
493 PrtTim(">>>> End WriteFits");
494 }
495 if(wppf) {
496 fluct3d.WritePPF("cmvobserv3d_k0.ppf",false);
497 PrtTim(">>>> End WritePPF");
498 }
499
500 //-----------------------------------------------------------------
501 cout<<"\n--- Computing a realization in real space"<<endl;
502 fluct3d.ComputeReal();
503 double rmin,rmax; fluct3d.MinMax(rmin,rmax);
504 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
505 fluct3d.NTupleCheck(posobs,string("ntreal"),ntnent);
506 PrtTim(">>>> End Computing a realization in real space");
507
508 if(use_growth_factor>0) {
509 cout<<"\n--- Apply Growth factor"<<endl;
510 cout<<"...D(z=0)="<<growth(0.)<<" D(z="<<zref<<")="<<growth(zref)<<endl;
511 fluct3d.ApplyGrowthFactor(use_growth_factor);
512 fluct3d.MinMax(rmin,rmax);
513 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
514 fluct3d.NTupleCheck(posobs,string("ntgrow"),ntnent);
515 PrtTim(">>>> End Applying growth factor");
516 }
517
518 int_8 nm;
519 double rmref,rs2ref;
520 cout<<"\n--- Computing reference variance in real space"<<endl;
521 nm = fluct3d.MeanSigma2(rmref,rs2ref);
522 cout<<" rs2ref= "<<rs2ref<<" , rmref="<<rmref<<" ("<<nm<<")"<<endl;
523 PrtTim(">>>> End Computing reference variance in real space");
524
525 if(wfits) {
526 fluct3d.WriteFits("!cmvobserv3d_r0.fits");
527 PrtTim(">>>> End WriteFits");
528 }
529 if(wppf) {
530 fluct3d.WritePPF("cmvobserv3d_r0.ppf",true);
531 PrtTim(">>>> End WritePPF");
532 }
533 if(wslice) {
534 fluct3d.WriteSlicePPF("cmvobserv3d_s_r0.ppf");
535 PrtTim(">>>> End WriteSlicePPF");
536 }
537
538 cout<<"\n--- Check mean and variance in real space"<<endl;
539 fluct3d.NumberOfBad(-1.,1e+200);
540 double rm,rs2;
541 nm = fluct3d.MeanSigma2(rm,rs2);
542 PrtTim(">>>> End Check mean and variance in real space");
543
544 if(compvarreal) {
545 cout<<"\n--- Check variance sigmaR in real space"<<endl;
546 double varr;
547 fluct3d.VarianceFrReal(R,varr);
548 cout<<"...Computed variance = "<<varr
549 <<" , Theorical variance at (z=0) = "<<pow(sigmaR,2.)
550 <<" , at (z="<<zref<<") = "<<pow(sigmaR*growth_at_z,2.)<<endl;
551 PrtTim(">>>> End Check variance sigmaR in real space");
552 }
553
554 //-----------------------------------------------------------------
555 if(no_poisson_type!=0) {
556 cout<<"\n--- Converting !!!DIRECTLY!!! mass into HI mass: mass per pixel ="
557 <<mass_by_pixel<<endl;
558 if(no_poisson_type<0) {
559 cout<<"!!!WARNING!!! dRho/Rho is just multiplied by "<<mass_by_pixel<<endl;
560 fluct3d.ScaleOffset(mass_by_pixel);
561 } else {
562 rm = fluct3d.TurnFluct2MeanNumber(mass_by_mpc3); // ici on doit donner Msol/Mpc^3
563 }
564 fluct3d.NTupleCheck(posobs,string("ntmhi"),ntnent);
565 } else {
566 cout<<"\n--- Converting mass into galaxy number: gal per pixel ="
567 <<ngal_by_mpc3*fluct3d.GetDVol()<<endl;
568 rm = fluct3d.TurnFluct2MeanNumber(ngal_by_mpc3); // ici on doit donner Ngal/Mpc^3
569 fluct3d.NTupleCheck(posobs,string("ntmeang"),ntnent);
570 }
571 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
572 nm = fluct3d.MeanSigma2(rm,rs2);
573 if(rm>0.) cout<<"normalised sigma(dM/M) is "<<sqrt(rs2)/rm<<endl;
574 PrtTim(">>>> End Converting mass into galaxy number or mass");
575
576 if( no_poisson_type==0 ) {
577
578 cout<<"\n--- Apply poisson on galaxy number"<<endl;
579 fluct3d.ApplyPoisson();
580 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
581 nm = fluct3d.MeanSigma2(rm,rs2);
582 double xgalmin,xgalmax; fluct3d.MinMax(xgalmin,xgalmax,0.1,1.e50);
583 fluct3d.NTupleCheck(posobs,string("ntpois"),ntnent);
584 PrtTim(">>>> End Apply poisson on galaxy number");
585 if(wslice) {
586 fluct3d.WriteSlicePPF("cmvobserv3d_s_rn.ppf");
587 PrtTim(">>>> End WriteSlicePPF");
588 }
589
590 cout<<"\n--- Convert Galaxy number to HI mass"<<endl;
591 double mhi = 0.;
592 if(use_schmassdist) {
593 if(recompute_schmassdist) {
594 int ngalmax = int(xgalmax+0.5);
595 schmdist.SetNgalLim(ngalmax,1,naleagal);
596 PrtTim(">>>> End creating tabulated histograms for trials");
597 }
598 mhi = fluct3d.TurnNGal2MassQuick(schmdist);
599 schmdist.PrintStatus();
600 } else {
601 mhi = fluct3d.TurnNGal2Mass(tirhmdndm,true);
602 }
603 cout<<mhi<<" MSol in survey / "<<mass_by_mpc3*fluct3d.GetVol()<<endl;
604 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
605 cout<<"Equivalent: "<<rm*nm/fluct3d.NPix()<<" Msol / pixels"<<endl;
606 nm = fluct3d.MeanSigma2(rm,rs2);
607 fluct3d.NTupleCheck(posobs,string("ntmhi"),ntnent);
608 PrtTim(">>>> End Convert Galaxy number to HI mass");
609
610 }
611
612 //-----------------------------------------------------------------
613 if(wfits) {
614 fluct3d.WriteFits("!cmvobserv3d_r.fits");
615 PrtTim(">>>> End WriteFits");
616 }
617 if(wppf) {
618 fluct3d.WritePPF("cmvobserv3d_r.ppf",true);
619 PrtTim(">>>> End WritePPF");
620 }
621 if(wslice) {
622 fluct3d.WriteSlicePPF("cmvobserv3d_s_r.ppf");
623 PrtTim(">>>> End WriteSlicePPF");
624 }
625
626 //-----------------------------------------------------------------
627 ////if(do_agn) {
628 //// cout<<"\n--- Add AGN: <log10(S Jy)>="<<lfjy_agn<<" , sigma="<<lsigma_agn
629 //// <<" , powlaw="<<powlaw_agn<<endl;
630 //// fluct3d.AddAGN(lfjy_agn,lsigma_agn,powlaw_agn);
631 //// nm = fluct3d.MeanSigma2(rm,rs2);
632 //// fluct3d.NTupleCheck(posobs,string("ntagn"),ntnent);
633 //// PrtTim(">>>> End Add AGN");
634 ////}
635
636 //-----------------------------------------------------------------
637 double snoisesave = 0.;
638 if(snoise>0.) {
639 cout<<"\n--- Add noise to HI Flux snoise="<<snoise<<", evolution="<<noise_evol<<endl;
640 fluct3d.AddNoise2Real(snoise,noise_evol);
641 snoisesave = snoise;
642 nm = fluct3d.MeanSigma2(rm,rs2);
643 fluct3d.NTupleCheck(posobs,string("ntnois"),ntnent);
644 PrtTim(">>>> End Add noise");
645 }
646
647 //-----------------------------------------------------------------
648 if(scalemass!=0. && scalemass!=1.) { // Si scalemass==0 pas de normalisation
649 if(scalemass<0.) scalemass = 1. / (-scalemass * mass_by_pixel);
650 cout<<"\n--- Scale cube scale="<<scalemass<<endl;
651 fluct3d.ScaleOffset(scalemass);
652 snoisesave *= scalemass;
653 nm = fluct3d.MeanSigma2(rm,rs2);
654 PrtTim(">>>> End Scale cube");
655 }
656 fluct3d.NTupleCheck(posobs,string("ntfin"),ntnent);
657
658 //-----------------------------------------------------------------
659 if(wfits) {
660 fluct3d.WriteFits("!cmvobserv3d_rf.fits");
661 PrtTim(">>>> End WriteFits");
662 }
663 if(wppf) {
664 fluct3d.WritePPF("cmvobserv3d_rf.ppf",true);
665 PrtTim(">>>> End WritePPF");
666 }
667 if(wslice) {
668 fluct3d.WriteSlicePPF("cmvobserv3d_s_rf.ppf");
669 PrtTim(">>>> End WriteSlicePPF");
670 }
671
672 //-----------------------------------------------------------------
673 // -- NE PAS FAIRE CA SI ON VEUT CONTINUER LA SIMULATION -> d_rho/rho ecrase
674
675 cout<<endl<<"\n--- ReComputing spectrum from real space"<<endl;
676 fluct3d.ReComputeFourier();
677 fluct3d.NTupleCheck(posobs,string("ntpkrec"),ntnent);
678 PrtTim(">>>> End ReComputing spectrum");
679
680 if(wfits) {
681 fluct3d.WriteFits("!cmvobserv3d_k.fits");
682 PrtTim(">>>> End WriteFits");
683 }
684 if(wppf) {
685 fluct3d.WritePPF("cmvobserv3d_k.ppf",false);
686 PrtTim(">>>> End WritePPF");
687 }
688
689 cout<<endl<<"\n--- Computing final spectrum"<<endl;
690 HistoErr hpkrecb(0.,knyqmax,nherr); hpkrecb.Zero();
691 hpkrecb.ReCenterBin();
692 hpkrecb.Show();
693 fluct3d.ComputeSpectrum(hpkrecb);
694 {
695 tagobs = "hpkrecb"; posobs.PutObject(hpkrecb,tagobs);
696 }
697 PrtTim(">>>> End Computing final spectrum");
698
699 cout<<endl<<"\n--- Computing final spectrum with pixel deconv."<<endl;
700 HistoErr hpkrec(hpkrecb); hpkrec.Zero();
701 fluct3d.ComputeSpectrum(hpkrec,snoisesave,filter_by_pixel);
702 {
703 tagobs = "hpkrec"; posobs.PutObject(hpkrec,tagobs);
704 }
705 PrtTim(">>>> End Computing final spectrum with pixel deconv.");
706
707 if(comp2dspec) {
708 cout<<"\n--- Computing final 2D spectrum"<<endl;
709 Histo2DErr hpkrecb2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
710 hpkrecb2.ReCenterBin(); hpkrecb2.Zero();
711 hpkrecb2.Show();
712 fluct3d.ComputeSpectrum2D(hpkrecb2);
713 {
714 tagobs = "hpkrecb2"; posobs.PutObject(hpkrecb2,tagobs);
715 }
716 PrtTim(">>>> End Computing final 2D spectrum");
717
718 cout<<"\n--- Computing final 2D spectrum with pixel deconv."<<endl;
719 Histo2DErr hpkrec2(hpkrecb2); hpkrec2.Zero();
720 fluct3d.ComputeSpectrum2D(hpkrec2,snoisesave,filter_by_pixel);
721 {
722 tagobs = "hpkrec2"; posobs.PutObject(hpkrec2,tagobs);
723 }
724 PrtTim(">>>> End Computing final 2D spectrum with pixel deconv.");
725
726 }
727
728 PrtTim(">>>> End Of Job");
729 return 0;
730}
731
Note: See TracBrowser for help on using the repository browser.