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

Last change on this file since 3584 was 3583, checked in by cmv, 17 years ago
  • ajout de l'option -O a,b,c,d,e pour selectionner l'ecriture sur disque du cube reel ou fourier.
  • Enleve option -D et -d (fgrzproc) de Reza, il faut maintenant utiliser le flag adequat avec l'option -O

cmv 26/02/2009

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