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

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

ajout de l'impressionde la date et l'heure dans le job de simulation, cmv 06/03/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 system("date -u");
145
146 char c;
147 while((c = getopt(narg,arg,"ha0PWSV2U:G:F:x:y:z:s:Z:M:A:T:N:Q:R:8:O:")) != -1) {
148 int nth = 0;
149 switch (c) {
150 case 'a' :
151 Auto_Ini_Ranf(5);
152 break;
153 case '0' :
154 computefourier0 = true;
155 break;
156 case 'G' :
157 sscanf(optarg,"%d",&use_growth_factor);
158 break;
159 case 'U' :
160 sscanf(optarg,"%d",&no_poisson_type);
161 break;
162 case 'F' :
163 sscanf(optarg,"%d",&filter_by_pixel);
164 break;
165 case 'x' :
166 sscanf(optarg,"%ld,%lf",&nx,&dx);
167 break;
168 case 'y' :
169 sscanf(optarg,"%ld,%lf",&ny,&dy);
170 break;
171 case 'z' :
172 sscanf(optarg,"%ld,%lf",&nz,&dz);
173 break;
174 case 's' :
175 sscanf(optarg,"%lf,%d",&snoise,&noise_evol);
176 break;
177 case 'Z' :
178 sscanf(optarg,"%lf",&zref);
179 break;
180 case '2' :
181 comp2dspec = true;
182 break;
183 case 'N' :
184 sscanf(optarg,"%lf",&scalemass);
185 if(scalemass==0.) scalemass = 1.;
186 break;
187 case 'M' :
188 sscanf(optarg,"%lf,%lf,%d",&schmin,&schmax,&schnpt);
189 break;
190 case 'Q' :
191 use_schmassdist = true;
192 sscanf(optarg,"%ld",&naleagal);
193 break;
194 case 'R' :
195 schmassdistfile = optarg;
196 break;
197 //// case 'A' :
198 ////do_agn = true;
199 ////sscanf(optarg,"%lf,%lf,%lf",&lfjy_agn,&lsigma_agn,&powlaw_agn);
200 ////break;
201 case '8' :
202 sscanf(optarg,"%lf,%lf",&sigmaR,&R);
203 break;
204 case 'V' :
205 compvarreal = true;
206 break;
207 case 'W' :
208 wfits = true;
209 break;
210 case 'P' :
211 wppf = true;
212 break;
213 case 'O' :
214 sscanf(optarg,"%hu,%hu,%hu,%hu,%hu"
215 ,&whattowrt[0],&whattowrt[1],&whattowrt[2],&whattowrt[3],&whattowrt[4]);
216 break;
217 case 'S' :
218 wslice = true;
219 break;
220 case 'T' :
221 sscanf(optarg,"%d",&nth);
222 nthread = (nth<1)? 0: nth;
223 break;
224 case 'h' :
225 default :
226 usage(); return -1;
227 }
228 }
229
230 double lschmin=log10(schmin), lschmax=log10(schmax);
231 if(schnpt<=0) { // alors c'est un nombre de points par decade
232 schnpt = long( (-schnpt)*(lschmax-lschmin+1.) + 0.5 );
233 if(schnpt<=2) schnpt = 1000;
234 }
235 if(naleagal<=2) naleagal = 100000;
236
237 cout<<"zref="<<zref<<endl;
238 cout<<"nx="<<nx<<" dx="<<dx<<" ny="<<ny<<" dy="<<dy<<" nz="<<nz<<" dz="<<dz<<endl;
239 cout<<"kmin="<<kmin<<" ("<<lkmin<<"), kmax="<<kmax<<" ("<<lkmax<<") Mpc^-1"
240 <<", npt="<<npt<<endl;
241 cout<<"Filter by pixel = "<<filter_by_pixel<<endl;
242 cout<<"R="<<R<<" Rg="<<Rg<<" Mpc, sigmaR="<<sigmaR<<endl;
243 cout<<"Use_growth_factor = "<<use_growth_factor<<endl;
244 cout<<"nstar= "<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
245 cout<<"schmin="<<schmin<<" ("<<lschmin
246 <<"), schmax="<<schmax<<" ("<<lschmax<<") Msol"
247 <<", schnpt="<<schnpt<<endl;
248 if(no_poisson_type!=0) cout<<"No poisson fluctuation, direct conversion to HI mass, typ="
249 <<no_poisson_type<<endl;
250 cout<<"snoise="<<snoise<<" equivalent Msol, evolution="<<noise_evol<<endl;
251 cout<<"scalemass="<<scalemass<<endl;
252 ////if(do_agn)
253 //// cout<<"AGN: <log10(Jy)>="<<lfjy_agn<<" , sigma="<<lsigma_agn
254 //// <<" , powlaw="<<powlaw_agn<<endl;
255 cout<<"wfits="<<wfits<<" wppf="<<wppf<<" wslice="<<wslice<<" what?="
256 <<whattowrt[0]<<","<<whattowrt[1]<<","<<whattowrt[2]<<","<<whattowrt[3]<<","
257 <<whattowrt[4]<<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(whattowrt[0]==1) {
508 if(wfits) {
509 fluct3d.WriteFits("!cmvobserv3d_k0.fits");
510 PrtTim(">>>> End WriteFits");
511 }
512 if(wppf) {
513 fluct3d.WritePPF("cmvobserv3d_k0.ppf",false);
514 PrtTim(">>>> End WritePPF");
515 }
516 }
517
518 //-----------------------------------------------------------------
519 cout<<"\n--- Computing a realization in real space"<<endl;
520 fluct3d.ComputeReal();
521 double rmin,rmax; fluct3d.MinMax(rmin,rmax);
522 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
523 fluct3d.NTupleCheck(posobs,string("ntreal"),ntnent);
524 PrtTim(">>>> End Computing a realization in real space");
525
526 if(use_growth_factor>0) {
527 cout<<"\n--- Apply Growth factor"<<endl;
528 cout<<"...D(z=0)="<<growth(0.)<<" D(z="<<zref<<")="<<growth(zref)<<endl;
529 fluct3d.ApplyGrowthFactor(use_growth_factor);
530 fluct3d.MinMax(rmin,rmax);
531 cout<<"rgen.Min = "<<rmin<<" , Max="<<rmax<<endl;
532 fluct3d.NTupleCheck(posobs,string("ntgrow"),ntnent);
533 PrtTim(">>>> End Applying growth factor");
534 }
535
536 int_8 nm;
537 double rmref,rs2ref;
538 cout<<"\n--- Computing reference variance in real space"<<endl;
539 nm = fluct3d.MeanSigma2(rmref,rs2ref);
540 cout<<" rs2ref= "<<rs2ref<<" , rmref="<<rmref<<" ("<<nm<<")"<<endl;
541 PrtTim(">>>> End Computing reference variance in real space");
542
543 if(whattowrt[1]==1) {
544 if(wfits) {
545 fluct3d.WriteFits("!cmvobserv3d_r0.fits");
546 PrtTim(">>>> End WriteFits");
547 }
548 if(wppf) {
549 fluct3d.WritePPF("cmvobserv3d_r0.ppf",true);
550 PrtTim(">>>> End WritePPF");
551 }
552 if(wslice) {
553 fluct3d.WriteSlicePPF("cmvobserv3d_s_r0.ppf");
554 PrtTim(">>>> End WriteSlicePPF");
555 }
556 }
557
558 cout<<"\n--- Check mean and variance in real space"<<endl;
559 fluct3d.NumberOfBad(-1.,1e+200);
560 double rm,rs2;
561 nm = fluct3d.MeanSigma2(rm,rs2);
562 PrtTim(">>>> End Check mean and variance in real space");
563
564 if(compvarreal) {
565 cout<<"\n--- Check variance sigmaR in real space"<<endl;
566 double varr;
567 fluct3d.VarianceFrReal(R,varr);
568 cout<<"...Computed variance = "<<varr
569 <<" , Theorical variance at (z=0) = "<<pow(sigmaR,2.)
570 <<" , at (z="<<zref<<") = "<<pow(sigmaR*growth_at_z,2.)<<endl;
571 PrtTim(">>>> End Check variance sigmaR in real space");
572 }
573
574 //-----------------------------------------------------------------
575 if(no_poisson_type!=0) {
576 cout<<"\n--- Converting !!!DIRECTLY!!! mass into HI mass: mass per pixel ="
577 <<mass_by_pixel<<endl;
578 if(no_poisson_type<0) {
579 cout<<"!!!WARNING!!! dRho/Rho is just multiplied by "<<mass_by_pixel<<endl;
580 fluct3d.ScaleOffset(mass_by_pixel);
581 } else {
582 rm = fluct3d.TurnFluct2MeanNumber(mass_by_mpc3); // ici on doit donner Msol/Mpc^3
583 }
584 fluct3d.NTupleCheck(posobs,string("ntmhi"),ntnent);
585 } else {
586 cout<<"\n--- Converting mass into galaxy number: gal per pixel ="
587 <<ngal_by_mpc3*fluct3d.GetDVol()<<endl;
588 rm = fluct3d.TurnFluct2MeanNumber(ngal_by_mpc3); // ici on doit donner Ngal/Mpc^3
589 fluct3d.NTupleCheck(posobs,string("ntmeang"),ntnent);
590 }
591 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
592 nm = fluct3d.MeanSigma2(rm,rs2);
593 if(rm>0.) cout<<"normalised sigma(dM/M) is "<<sqrt(rs2)/rm<<endl;
594 PrtTim(">>>> End Converting mass into galaxy number or mass");
595
596 if( no_poisson_type==0 ) {
597
598 cout<<"\n--- Apply poisson on galaxy number"<<endl;
599 fluct3d.ApplyPoisson();
600 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
601 nm = fluct3d.MeanSigma2(rm,rs2);
602 double xgalmin,xgalmax; fluct3d.MinMax(xgalmin,xgalmax,0.1,1.e50);
603 fluct3d.NTupleCheck(posobs,string("ntpois"),ntnent);
604 PrtTim(">>>> End Apply poisson on galaxy number");
605 if(wslice) {
606 fluct3d.WriteSlicePPF("cmvobserv3d_s_rn.ppf");
607 PrtTim(">>>> End WriteSlicePPF");
608 }
609
610 cout<<"\n--- Convert Galaxy number to HI mass"<<endl;
611 double mhi = 0.;
612 if(use_schmassdist) {
613 if(recompute_schmassdist) {
614 int ngalmax = int(xgalmax+0.5);
615 schmdist.SetNgalLim(ngalmax,1,naleagal);
616 PrtTim(">>>> End creating tabulated histograms for trials");
617 }
618 mhi = fluct3d.TurnNGal2MassQuick(schmdist);
619 schmdist.PrintStatus();
620 } else {
621 mhi = fluct3d.TurnNGal2Mass(tirhmdndm,true);
622 }
623 cout<<mhi<<" MSol in survey / "<<mass_by_mpc3*fluct3d.GetVol()<<endl;
624 nm = fluct3d.MeanSigma2(rm,rs2,0.,1e200);
625 cout<<"Equivalent: "<<rm*nm/fluct3d.NPix()<<" Msol / pixels"<<endl;
626 nm = fluct3d.MeanSigma2(rm,rs2);
627 fluct3d.NTupleCheck(posobs,string("ntmhi"),ntnent);
628 PrtTim(">>>> End Convert Galaxy number to HI mass");
629
630 }
631
632 //-----------------------------------------------------------------
633 if(whattowrt[2]==1) {
634 if(wfits) {
635 fluct3d.WriteFits("!cmvobserv3d_r.fits");
636 PrtTim(">>>> End WriteFits");
637 }
638 if(wppf) {
639 fluct3d.WritePPF("cmvobserv3d_r.ppf",true);
640 PrtTim(">>>> End WritePPF");
641 }
642 if(wslice) {
643 fluct3d.WriteSlicePPF("cmvobserv3d_s_r.ppf");
644 PrtTim(">>>> End WriteSlicePPF");
645 }
646 }
647
648 //-----------------------------------------------------------------
649 ////if(do_agn) {
650 //// cout<<"\n--- Add AGN: <log10(S Jy)>="<<lfjy_agn<<" , sigma="<<lsigma_agn
651 //// <<" , powlaw="<<powlaw_agn<<endl;
652 //// fluct3d.AddAGN(lfjy_agn,lsigma_agn,powlaw_agn);
653 //// nm = fluct3d.MeanSigma2(rm,rs2);
654 //// fluct3d.NTupleCheck(posobs,string("ntagn"),ntnent);
655 //// PrtTim(">>>> End Add AGN");
656 ////}
657
658 //-----------------------------------------------------------------
659 double snoisesave = 0.;
660 if(snoise>0.) {
661 cout<<"\n--- Add noise to HI Flux snoise="<<snoise<<", evolution="<<noise_evol<<endl;
662 fluct3d.AddNoise2Real(snoise,noise_evol);
663 snoisesave = snoise;
664 nm = fluct3d.MeanSigma2(rm,rs2);
665 fluct3d.NTupleCheck(posobs,string("ntnois"),ntnent);
666 PrtTim(">>>> End Add noise");
667 }
668
669 //-----------------------------------------------------------------
670 if(scalemass!=0. && scalemass!=1.) { // Si scalemass==0 pas de normalisation
671 if(scalemass<0.) scalemass = 1. / (-scalemass * mass_by_pixel);
672 cout<<"\n--- Scale cube scale="<<scalemass<<endl;
673 fluct3d.ScaleOffset(scalemass);
674 snoisesave *= scalemass;
675 nm = fluct3d.MeanSigma2(rm,rs2);
676 PrtTim(">>>> End Scale cube");
677 }
678 fluct3d.NTupleCheck(posobs,string("ntfin"),ntnent);
679
680 //-----------------------------------------------------------------
681 if(whattowrt[3]==1) {
682 if(wfits) {
683 fluct3d.WriteFits("!cmvobserv3d_rf.fits");
684 PrtTim(">>>> End WriteFits");
685 }
686 if(wppf) {
687 fluct3d.WritePPF("cmvobserv3d_rf.ppf",true);
688 PrtTim(">>>> End WritePPF");
689 }
690 if(wslice) {
691 fluct3d.WriteSlicePPF("cmvobserv3d_s_rf.ppf");
692 PrtTim(">>>> End WriteSlicePPF");
693 }
694 }
695
696 //-----------------------------------------------------------------
697 // -- NE PAS FAIRE CA SI ON VEUT CONTINUER LA SIMULATION -> d_rho/rho ecrase
698
699 cout<<endl<<"\n--- ReComputing spectrum from real space"<<endl;
700 fluct3d.ReComputeFourier();
701 fluct3d.NTupleCheck(posobs,string("ntpkrec"),ntnent);
702 PrtTim(">>>> End ReComputing spectrum");
703
704 if(whattowrt[4]==1) {
705 if(wfits) {
706 fluct3d.WriteFits("!cmvobserv3d_k.fits");
707 PrtTim(">>>> End WriteFits");
708 }
709 if(wppf) {
710 fluct3d.WritePPF("cmvobserv3d_k.ppf",false);
711 PrtTim(">>>> End WritePPF");
712 }
713 }
714
715 cout<<endl<<"\n--- Computing final spectrum"<<endl;
716 HistoErr hpkrecb(0.,knyqmax,nherr); hpkrecb.Zero();
717 hpkrecb.ReCenterBin();
718 hpkrecb.Show();
719 fluct3d.ComputeSpectrum(hpkrecb);
720 {
721 tagobs = "hpkrecb"; posobs.PutObject(hpkrecb,tagobs);
722 }
723 PrtTim(">>>> End Computing final spectrum");
724
725 cout<<endl<<"\n--- Computing final spectrum with pixel deconv."<<endl;
726 HistoErr hpkrec(hpkrecb); hpkrec.Zero();
727 fluct3d.ComputeSpectrum(hpkrec,snoisesave,filter_by_pixel);
728 {
729 tagobs = "hpkrec"; posobs.PutObject(hpkrec,tagobs);
730 }
731 PrtTim(">>>> End Computing final spectrum with pixel deconv.");
732
733 if(comp2dspec) {
734 cout<<"\n--- Computing final 2D spectrum"<<endl;
735 Histo2DErr hpkrecb2(0.,ktnyqmax,nherrt,0.,kznyqmax,nherrz);
736 hpkrecb2.ReCenterBin(); hpkrecb2.Zero();
737 hpkrecb2.Show();
738 fluct3d.ComputeSpectrum2D(hpkrecb2);
739 {
740 tagobs = "hpkrecb2"; posobs.PutObject(hpkrecb2,tagobs);
741 }
742 PrtTim(">>>> End Computing final 2D spectrum");
743
744 cout<<"\n--- Computing final 2D spectrum with pixel deconv."<<endl;
745 Histo2DErr hpkrec2(hpkrecb2); hpkrec2.Zero();
746 fluct3d.ComputeSpectrum2D(hpkrec2,snoisesave,filter_by_pixel);
747 {
748 tagobs = "hpkrec2"; posobs.PutObject(hpkrec2,tagobs);
749 }
750 PrtTim(">>>> End Computing final 2D spectrum with pixel deconv.");
751
752 }
753
754 PrtTim(">>>> End Of Job");
755 return 0;
756}
757
Note: See TracBrowser for help on using the repository browser.