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

Last change on this file since 3594 was 3594, checked in by cmv, 16 years ago

options pour ecrire les cubes a divers endroits du main, cmv 10/04/2009

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