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

Last change on this file since 3358 was 3358, checked in by cmv, 18 years ago

suppression et rename de TurnMass2MeanNumber , cmv 23/10/2007

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