[3115] | 1 | #include "machdefs.h"
|
---|
| 2 | #include <iostream>
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <stdio.h>
|
---|
| 5 | #include <string.h>
|
---|
| 6 | #include <math.h>
|
---|
| 7 | #include <unistd.h>
|
---|
| 8 |
|
---|
| 9 | #include "tarray.h"
|
---|
| 10 | #include "pexceptions.h"
|
---|
| 11 | #include "perandom.h"
|
---|
| 12 | #include "srandgen.h"
|
---|
| 13 |
|
---|
[3141] | 14 | #include "fabtcolread.h"
|
---|
| 15 | #include "fabtwriter.h"
|
---|
| 16 | #include "fioarr.h"
|
---|
| 17 |
|
---|
| 18 | #include "arrctcast.h"
|
---|
| 19 |
|
---|
[3115] | 20 | #include "constcosmo.h"
|
---|
| 21 | #include "geneutils.h"
|
---|
[3199] | 22 | #include "schechter.h"
|
---|
[3115] | 23 |
|
---|
| 24 | #include "genefluct3d.h"
|
---|
| 25 |
|
---|
[3349] | 26 | #define WITH_FFTW_THREAD
|
---|
[3115] | 27 |
|
---|
| 28 | #define MODULE2(_x_) ((double)((_x_).real()*(_x_).real() + (_x_).imag()*(_x_).imag()))
|
---|
| 29 |
|
---|
[3325] | 30 | namespace SOPHYA {
|
---|
| 31 |
|
---|
[3115] | 32 | //-------------------------------------------------------
|
---|
[3349] | 33 | GeneFluct3D::GeneFluct3D(long nx,long ny,long nz,double dx,double dy,double dz
|
---|
| 34 | ,unsigned short nthread,int lp)
|
---|
[3115] | 35 | {
|
---|
[3349] | 36 | init_default();
|
---|
[3115] | 37 |
|
---|
[3349] | 38 | lp_ = lp;
|
---|
| 39 | nthread_ = nthread;
|
---|
[3115] | 40 |
|
---|
[3349] | 41 | setsize(nx,ny,nz,dx,dy,dz);
|
---|
| 42 | setalloc();
|
---|
| 43 | setpointers(false);
|
---|
| 44 | init_fftw();
|
---|
[3141] | 45 | }
|
---|
| 46 |
|
---|
[3349] | 47 | GeneFluct3D::GeneFluct3D(unsigned short nthread)
|
---|
[3154] | 48 | {
|
---|
[3349] | 49 | init_default();
|
---|
| 50 | setsize(2,2,2,1.,1.,1.);
|
---|
| 51 | nthread_ = nthread;
|
---|
| 52 | setalloc();
|
---|
| 53 | setpointers(false);
|
---|
| 54 | init_fftw();
|
---|
[3154] | 55 | }
|
---|
| 56 |
|
---|
[3349] | 57 | GeneFluct3D::~GeneFluct3D(void)
|
---|
[3157] | 58 | {
|
---|
[3349] | 59 | delete_fftw();
|
---|
[3157] | 60 | }
|
---|
| 61 |
|
---|
[3349] | 62 | //-------------------------------------------------------
|
---|
| 63 | void GeneFluct3D::init_default(void)
|
---|
[3157] | 64 | {
|
---|
[3349] | 65 | Nx_ = Ny_ = Nz_ = 0;
|
---|
| 66 | is_set_fftw_plan = false;
|
---|
| 67 | nthread_ = 0;
|
---|
| 68 | lp_ = 0;
|
---|
| 69 | array_allocated_ = false;
|
---|
| 70 | cosmo_ = NULL;
|
---|
| 71 | growth_ = NULL;
|
---|
| 72 | redsh_ref_ = -999.;
|
---|
| 73 | kredsh_ref_ = 0.;
|
---|
| 74 | dred_ref_ = -999.;
|
---|
| 75 | loscom_ref_ = -999.;
|
---|
| 76 | dtrc_ref_ = dlum_ref_ = dang_ref_ = -999.;
|
---|
| 77 | nu_ref_ = dnu_ref_ = -999.;
|
---|
| 78 | loscom_min_ = loscom_max_ = -999.;
|
---|
| 79 | loscom2zred_min_ = loscom2zred_max_ = 0.;
|
---|
| 80 | xobs_[0] = xobs_[1] = xobs_[2] = 0.;
|
---|
| 81 | zred_.resize(0);
|
---|
| 82 | loscom_.resize(0);
|
---|
| 83 | loscom2zred_.resize(0);
|
---|
[3157] | 84 | }
|
---|
| 85 |
|
---|
[3141] | 86 | void GeneFluct3D::setsize(long nx,long ny,long nz,double dx,double dy,double dz)
|
---|
| 87 | {
|
---|
[3155] | 88 | if(lp_>1) cout<<"--- GeneFluct3D::setsize: N="<<nx<<","<<ny<<","<<nz
|
---|
| 89 | <<" D="<<dx<<","<<dy<<","<<dz<<endl;
|
---|
[3141] | 90 | if(nx<=0 || dx<=0.) {
|
---|
[3267] | 91 | char *bla = "GeneFluct3D::setsize_Error: bad value(s) for nn/dx";
|
---|
[3199] | 92 | cout<<bla<<endl; throw ParmError(bla);
|
---|
[3115] | 93 | }
|
---|
| 94 |
|
---|
[3141] | 95 | // Les tailles des tableaux
|
---|
[3115] | 96 | Nx_ = nx;
|
---|
| 97 | Ny_ = ny; if(Ny_ <= 0) Ny_ = Nx_;
|
---|
| 98 | Nz_ = nz; if(Nz_ <= 0) Nz_ = Nx_;
|
---|
[3141] | 99 | N_.resize(0); N_.push_back(Nx_); N_.push_back(Ny_); N_.push_back(Nz_);
|
---|
[3115] | 100 | NRtot_ = Nx_*Ny_*Nz_; // nombre de pixels dans le survey
|
---|
| 101 | NCz_ = Nz_/2 +1;
|
---|
| 102 | NTz_ = 2*NCz_;
|
---|
| 103 |
|
---|
| 104 | // le pas dans l'espace (Mpc)
|
---|
| 105 | Dx_ = dx;
|
---|
| 106 | Dy_ = dy; if(Dy_ <= 0.) Dy_ = Dx_;
|
---|
| 107 | Dz_ = dz; if(Dz_ <= 0.) Dz_ = Dx_;
|
---|
[3141] | 108 | D_.resize(0); D_.push_back(Dx_); D_.push_back(Dy_); D_.push_back(Dz_);
|
---|
[3115] | 109 | dVol_ = Dx_*Dy_*Dz_;
|
---|
| 110 | Vol_ = (Nx_*Dx_)*(Ny_*Dy_)*(Nz_*Dz_);
|
---|
| 111 |
|
---|
| 112 | // Le pas dans l'espace de Fourier (Mpc^-1)
|
---|
| 113 | Dkx_ = 2.*M_PI/(Nx_*Dx_);
|
---|
| 114 | Dky_ = 2.*M_PI/(Ny_*Dy_);
|
---|
| 115 | Dkz_ = 2.*M_PI/(Nz_*Dz_);
|
---|
[3141] | 116 | Dk_.resize(0); Dk_.push_back(Dkx_); Dk_.push_back(Dky_); Dk_.push_back(Dkz_);
|
---|
[3115] | 117 | Dk3_ = Dkx_*Dky_*Dkz_;
|
---|
| 118 |
|
---|
| 119 | // La frequence de Nyquist en k (Mpc^-1)
|
---|
| 120 | Knyqx_ = M_PI/Dx_;
|
---|
| 121 | Knyqy_ = M_PI/Dy_;
|
---|
| 122 | Knyqz_ = M_PI/Dz_;
|
---|
[3141] | 123 | Knyq_.resize(0); Knyq_.push_back(Knyqx_); Knyq_.push_back(Knyqy_); Knyq_.push_back(Knyqz_);
|
---|
| 124 | }
|
---|
[3115] | 125 |
|
---|
[3141] | 126 | void GeneFluct3D::setalloc(void)
|
---|
| 127 | {
|
---|
[3155] | 128 | if(lp_>1) cout<<"--- GeneFluct3D::setalloc ---"<<endl;
|
---|
[3141] | 129 | // Dimensionnement du tableau complex<r_8>
|
---|
| 130 | // ATTENTION: TArray adresse en memoire a l'envers du C
|
---|
| 131 | // Tarray(n1,n2,n3) == Carray[n3][n2][n1]
|
---|
| 132 | sa_size_t SzK_[3] = {NCz_,Ny_,Nx_}; // a l'envers
|
---|
| 133 | try {
|
---|
| 134 | T_.ReSize(3,SzK_);
|
---|
| 135 | array_allocated_ = true;
|
---|
[3255] | 136 | if(lp_>1) cout<<" allocating: "<<T_.Size()*sizeof(complex<r_8>)/1.e6<<" Mo"<<endl;
|
---|
[3141] | 137 | } catch (...) {
|
---|
[3155] | 138 | cout<<"GeneFluct3D::setalloc_Error: Problem allocating T_"<<endl;
|
---|
[3141] | 139 | }
|
---|
| 140 | T_.SetMemoryMapping(BaseArray::CMemoryMapping);
|
---|
[3115] | 141 | }
|
---|
| 142 |
|
---|
[3141] | 143 | void GeneFluct3D::setpointers(bool from_real)
|
---|
| 144 | {
|
---|
[3155] | 145 | if(lp_>1) cout<<"--- GeneFluct3D::setpointers ---"<<endl;
|
---|
[3141] | 146 | if(from_real) T_ = ArrCastR2C(R_);
|
---|
| 147 | else R_ = ArrCastC2R(T_);
|
---|
| 148 | // On remplit les pointeurs
|
---|
| 149 | fdata_ = (fftw_complex *) (&T_(0,0,0));
|
---|
| 150 | data_ = (double *) (&R_(0,0,0));
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[3349] | 153 | void GeneFluct3D::init_fftw(void)
|
---|
[3141] | 154 | {
|
---|
[3349] | 155 | if( is_set_fftw_plan ) delete_fftw();
|
---|
[3141] | 156 |
|
---|
[3154] | 157 | // --- Initialisation de fftw3 (attention data est sur-ecrit a l'init)
|
---|
[3155] | 158 | if(lp_>1) cout<<"--- GeneFluct3D::init_fftw ---"<<endl;
|
---|
[3349] | 159 | #ifdef WITH_FFTW_THREAD
|
---|
[3154] | 160 | if(nthread_>0) {
|
---|
[3155] | 161 | cout<<"...Computing with "<<nthread_<<" threads"<<endl;
|
---|
[3154] | 162 | fftw_init_threads();
|
---|
| 163 | fftw_plan_with_nthreads(nthread_);
|
---|
| 164 | }
|
---|
| 165 | #endif
|
---|
[3155] | 166 | if(lp_>1) cout<<"...forward plan"<<endl;
|
---|
[3154] | 167 | pf_ = fftw_plan_dft_r2c_3d(Nx_,Ny_,Nz_,data_,fdata_,FFTW_ESTIMATE);
|
---|
[3155] | 168 | if(lp_>1) cout<<"...backward plan"<<endl;
|
---|
[3154] | 169 | pb_ = fftw_plan_dft_c2r_3d(Nx_,Ny_,Nz_,fdata_,data_,FFTW_ESTIMATE);
|
---|
[3349] | 170 | is_set_fftw_plan = true;
|
---|
[3154] | 171 | }
|
---|
[3141] | 172 |
|
---|
[3349] | 173 | void GeneFluct3D::delete_fftw(void)
|
---|
| 174 | {
|
---|
| 175 | if( !is_set_fftw_plan ) return;
|
---|
| 176 | fftw_destroy_plan(pf_);
|
---|
| 177 | fftw_destroy_plan(pb_);
|
---|
| 178 | #ifdef WITH_FFTW_THREAD
|
---|
| 179 | if(nthread_>0) fftw_cleanup_threads();
|
---|
| 180 | #endif
|
---|
| 181 | is_set_fftw_plan = false;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | void GeneFluct3D::check_array_alloc(void)
|
---|
| 185 | // Pour tester si le tableau T_ est alloue
|
---|
| 186 | {
|
---|
| 187 | if(array_allocated_) return;
|
---|
| 188 | char bla[90];
|
---|
| 189 | sprintf(bla,"GeneFluct3D::check_array_alloc_Error: array is not allocated");
|
---|
| 190 | cout<<bla<<endl; throw ParmError(bla);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[3157] | 193 | //-------------------------------------------------------
|
---|
[3349] | 194 | void GeneFluct3D::SetObservator(double redshref,double kredshref)
|
---|
| 195 | // L'observateur est au redshift z=0
|
---|
| 196 | // est situe sur la "perpendiculaire" a la face x,y
|
---|
| 197 | // issue du centre de cette face
|
---|
| 198 | // Il faut positionner le cube sur l'axe des z cad des redshifts:
|
---|
| 199 | // redshref = redshift de reference
|
---|
| 200 | // Si redshref<0 alors redshref=0
|
---|
| 201 | // kredshref = indice (en double) correspondant a ce redshift
|
---|
| 202 | // Si kredshref<0 alors kredshref=nz/2 (milieu du cube)
|
---|
| 203 | // Exemple: redshref=1.5 kredshref=250.75
|
---|
| 204 | // -> Le pixel i=nx/2 j=ny/2 k=250.75 est au redshift 1.5
|
---|
| 205 | {
|
---|
| 206 | if(redshref<0.) redshref = 0.;
|
---|
| 207 | if(kredshref<0.) {
|
---|
| 208 | if(Nz_<=0) {
|
---|
| 209 | char *bla = "GeneFluct3D::SetObservator_Error: for kredsh_ref<0 define cube geometry first";
|
---|
| 210 | cout<<bla<<endl; throw ParmError(bla);
|
---|
| 211 | }
|
---|
| 212 | kredshref = Nz_/2.;
|
---|
| 213 | }
|
---|
| 214 | redsh_ref_ = redshref;
|
---|
| 215 | kredsh_ref_ = kredshref;
|
---|
| 216 | if(lp_>0)
|
---|
| 217 | cout<<"--- GeneFluct3D::SetObservator zref="<<redsh_ref_<<" kref="<<kredsh_ref_<<endl;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | void GeneFluct3D::SetCosmology(CosmoCalc& cosmo)
|
---|
| 221 | {
|
---|
| 222 | cosmo_ = &cosmo;
|
---|
| 223 | if(lp_>1) cosmo_->Print();
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | void GeneFluct3D::SetGrowthFactor(GrowthFactor& growth)
|
---|
| 227 | {
|
---|
| 228 | growth_ = &growth;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
[3199] | 231 | long GeneFluct3D::LosComRedshift(double zinc,long npoints)
|
---|
[3157] | 232 | // Given a position of the cube relative to the observer
|
---|
| 233 | // and a cosmology
|
---|
| 234 | // (SetObservator() and SetCosmology() should have been called !)
|
---|
| 235 | // This routine filled:
|
---|
| 236 | // the vector "zred_" of scanned redshift (by zinc increments)
|
---|
| 237 | // the vector "loscom_" of corresponding los comoving distance
|
---|
[3199] | 238 | // -- Input:
|
---|
| 239 | // zinc : redshift increment for computation
|
---|
| 240 | // npoints : number of points required for inverting loscom -> zred
|
---|
[3157] | 241 | //
|
---|
| 242 | {
|
---|
[3199] | 243 | if(lp_>0) cout<<"--- LosComRedshift: zinc="<<zinc<<" , npoints="<<npoints<<endl;
|
---|
[3154] | 244 |
|
---|
[3271] | 245 | if(cosmo_ == NULL || redsh_ref_<0.) {
|
---|
[3199] | 246 | char *bla = "GeneFluct3D::LosComRedshift_Error: set Observator and Cosmology first";
|
---|
| 247 | cout<<bla<<endl; throw ParmError(bla);
|
---|
[3157] | 248 | }
|
---|
| 249 |
|
---|
[3271] | 250 | // La distance angulaire/luminosite/Dnu au pixel de reference
|
---|
| 251 | dred_ref_ = Dz_/(cosmo_->Dhubble()/cosmo_->E(redsh_ref_));
|
---|
| 252 | loscom_ref_ = cosmo_->Dloscom(redsh_ref_);
|
---|
| 253 | dtrc_ref_ = cosmo_->Dtrcom(redsh_ref_);
|
---|
| 254 | dlum_ref_ = cosmo_->Dlum(redsh_ref_);
|
---|
| 255 | dang_ref_ = cosmo_->Dang(redsh_ref_);
|
---|
| 256 | nu_ref_ = Fr_HyperFin_Par/(1.+redsh_ref_); // GHz
|
---|
| 257 | dnu_ref_ = Fr_HyperFin_Par *dred_ref_/pow(1.+redsh_ref_,2.); // GHz
|
---|
| 258 | if(lp_>0) {
|
---|
| 259 | cout<<"...reference pixel redshref="<<redsh_ref_
|
---|
| 260 | <<", dredref="<<dred_ref_
|
---|
| 261 | <<", nuref="<<nu_ref_ <<" GHz"
|
---|
| 262 | <<", dnuref="<<dnu_ref_ <<" GHz"<<endl
|
---|
| 263 | <<" dlosc="<<loscom_ref_<<" Mpc com"
|
---|
| 264 | <<", dtrc="<<dtrc_ref_<<" Mpc com"
|
---|
| 265 | <<", dlum="<<dlum_ref_<<" Mpc"
|
---|
| 266 | <<", dang="<<dang_ref_<<" Mpc"<<endl;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[3199] | 269 | // On calcule les coordonnees de l'observateur dans le repere du cube
|
---|
| 270 | // cad dans le repere ou l'origine est au centre du pixel i=j=l=0.
|
---|
| 271 | // L'observateur est sur un axe centre sur le milieu de la face Oxy
|
---|
[3157] | 272 | xobs_[0] = Nx_/2.*Dx_;
|
---|
| 273 | xobs_[1] = Ny_/2.*Dy_;
|
---|
[3271] | 274 | xobs_[2] = kredsh_ref_*Dz_ - loscom_ref_;
|
---|
[3157] | 275 |
|
---|
| 276 | // L'observateur est-il dans le cube?
|
---|
| 277 | bool obs_in_cube = false;
|
---|
| 278 | if(xobs_[2]>=0. && xobs_[2]<=Nz_*Dz_) obs_in_cube = true;
|
---|
| 279 |
|
---|
| 280 | // Find MINIMUM los com distance to the observer:
|
---|
| 281 | // c'est le centre de la face a k=0
|
---|
| 282 | // (ou zero si l'observateur est dans le cube)
|
---|
| 283 | loscom_min_ = 0.;
|
---|
| 284 | if(!obs_in_cube) loscom_min_ = -xobs_[2];
|
---|
| 285 |
|
---|
[3271] | 286 | // TO BE FIXED TO BE FIXED TO BE FIXED TO BE FIXED TO BE FIXED TO BE FIXED
|
---|
| 287 | if(loscom_min_<=1.e-50)
|
---|
| 288 | for(int i=0;i<50;i++)
|
---|
| 289 | cout<<"ATTENTION TOUTES LES PARTIES DU CODE NE MARCHENT PAS POUR UN OBSERVATEUR DANS LE CUBE"<<endl;
|
---|
| 290 | // TO BE FIXED TO BE FIXED TO BE FIXED TO BE FIXED TO BE FIXED TO BE FIXED
|
---|
| 291 |
|
---|
| 292 |
|
---|
[3157] | 293 | // Find MAXIMUM los com distance to the observer:
|
---|
| 294 | // ou que soit positionne l'observateur, la distance
|
---|
| 295 | // maximal est sur un des coins du cube
|
---|
| 296 | loscom_max_ = 0.;
|
---|
| 297 | for(long i=0;i<=1;i++) {
|
---|
[3271] | 298 | double dx2 = DXcom(i*(Nx_-1)); dx2 *= dx2;
|
---|
[3157] | 299 | for(long j=0;j<=1;j++) {
|
---|
[3271] | 300 | double dy2 = DYcom(j*(Ny_-1)); dy2 *= dy2;
|
---|
[3157] | 301 | for(long k=0;k<=1;k++) {
|
---|
[3271] | 302 | double dz2 = DZcom(k*(Nz_-1)); dz2 *= dz2;
|
---|
[3157] | 303 | dz2 = sqrt(dx2+dy2+dz2);
|
---|
| 304 | if(dz2>loscom_max_) loscom_max_ = dz2;
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
| 308 | if(lp_>0) {
|
---|
[3271] | 309 | cout<<"...zref="<<redsh_ref_<<" kzref="<<kredsh_ref_<<" losref="<<loscom_ref_<<" Mpc\n"
|
---|
[3157] | 310 | <<" xobs="<<xobs_[0]<<" , "<<xobs_[1]<<" , "<<xobs_[2]<<" Mpc "
|
---|
| 311 | <<" in_cube="<<obs_in_cube
|
---|
[3271] | 312 | <<" loscom_min="<<loscom_min_<<" loscom_max="<<loscom_max_<<" Mpc (com)"<<endl;
|
---|
[3157] | 313 | }
|
---|
| 314 |
|
---|
[3199] | 315 | // Fill the corresponding vectors for loscom and zred
|
---|
[3267] | 316 | // Be shure to have one dlc <loscom_min and one >loscom_max
|
---|
[3199] | 317 | if(zinc<=0.) zinc = 0.01;
|
---|
[3157] | 318 | for(double z=0.; ; z+=zinc) {
|
---|
| 319 | double dlc = cosmo_->Dloscom(z);
|
---|
| 320 | if(dlc<loscom_min_) {zred_.resize(0); loscom_.resize(0);}
|
---|
| 321 | zred_.push_back(z);
|
---|
| 322 | loscom_.push_back(dlc);
|
---|
| 323 | z += zinc;
|
---|
[3199] | 324 | if(dlc>loscom_max_) break; // on sort apres avoir stoque un dlc>dlcmax
|
---|
[3157] | 325 | }
|
---|
| 326 |
|
---|
| 327 | if(lp_>0) {
|
---|
[3199] | 328 | long n = zred_.size();
|
---|
| 329 | cout<<"...zred/loscom tables[zinc="<<zinc<<"]: n="<<n;
|
---|
[3157] | 330 | if(n>0) cout<<" z="<<zred_[0]<<" -> d="<<loscom_[0];
|
---|
| 331 | if(n>1) cout<<" , z="<<zred_[n-1]<<" -> d="<<loscom_[n-1];
|
---|
| 332 | cout<<endl;
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[3199] | 335 | // Compute the parameters and tables needed for inversion loscom->zred
|
---|
| 336 | if(npoints<3) npoints = zred_.size();
|
---|
| 337 | InverseFunc invfun(zred_,loscom_);
|
---|
| 338 | invfun.ComputeParab(npoints,loscom2zred_);
|
---|
| 339 | loscom2zred_min_ = invfun.YMin();
|
---|
| 340 | loscom2zred_max_ = invfun.YMax();
|
---|
| 341 |
|
---|
| 342 | if(lp_>0) {
|
---|
| 343 | long n = loscom2zred_.size();
|
---|
| 344 | cout<<"...loscom -> zred[npoints="<<npoints<<"]: n="<<n
|
---|
| 345 | <<" los_min="<<loscom2zred_min_
|
---|
| 346 | <<" los_max="<<loscom2zred_max_
|
---|
| 347 | <<" -> zred=[";
|
---|
| 348 | if(n>0) cout<<loscom2zred_[0];
|
---|
| 349 | cout<<",";
|
---|
| 350 | if(n>1) cout<<loscom2zred_[n-1];
|
---|
| 351 | cout<<"]"<<endl;
|
---|
| 352 | if(lp_>1 && n>0)
|
---|
| 353 | for(int i=0;i<n;i++)
|
---|
[3330] | 354 | if(i<2 || abs(i-n/2)<2 || i>=n-2)
|
---|
| 355 | cout<<" i="<<i
|
---|
| 356 | <<" d="<<loscom2zred_min_+i*(loscom2zred_max_-loscom2zred_min_)/(n-1.)
|
---|
| 357 | <<" Mpc z="<<loscom2zred_[i]<<endl;
|
---|
[3199] | 358 | }
|
---|
| 359 |
|
---|
| 360 | return zred_.size();
|
---|
[3157] | 361 | }
|
---|
| 362 |
|
---|
[3115] | 363 | //-------------------------------------------------------
|
---|
[3141] | 364 | void GeneFluct3D::WriteFits(string cfname,int bitpix)
|
---|
| 365 | {
|
---|
[3155] | 366 | cout<<"--- GeneFluct3D::WriteFits: Writing Cube to "<<cfname<<endl;
|
---|
[3141] | 367 | try {
|
---|
| 368 | FitsImg3DWriter fwrt(cfname.c_str(),bitpix,5);
|
---|
| 369 | fwrt.WriteKey("NX",Nx_," axe transverse 1");
|
---|
| 370 | fwrt.WriteKey("NY",Ny_," axe transverse 2");
|
---|
| 371 | fwrt.WriteKey("NZ",Nz_," axe longitudinal (redshift)");
|
---|
| 372 | fwrt.WriteKey("DX",Dx_," Mpc");
|
---|
| 373 | fwrt.WriteKey("DY",Dy_," Mpc");
|
---|
| 374 | fwrt.WriteKey("DZ",Dz_," Mpc");
|
---|
| 375 | fwrt.WriteKey("DKX",Dkx_," Mpc^-1");
|
---|
| 376 | fwrt.WriteKey("DKY",Dky_," Mpc^-1");
|
---|
| 377 | fwrt.WriteKey("DKZ",Dkz_," Mpc^-1");
|
---|
[3271] | 378 | fwrt.WriteKey("ZREF",redsh_ref_," reference redshift");
|
---|
| 379 | fwrt.WriteKey("KZREF",kredsh_ref_," reference redshift on z axe");
|
---|
[3141] | 380 | fwrt.Write(R_);
|
---|
| 381 | } catch (PThrowable & exc) {
|
---|
| 382 | cout<<"Exception : "<<(string)typeid(exc).name()
|
---|
| 383 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 384 | return;
|
---|
| 385 | } catch (...) {
|
---|
| 386 | cout<<" some other exception was caught !"<<endl;
|
---|
| 387 | return;
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 | void GeneFluct3D::ReadFits(string cfname)
|
---|
| 392 | {
|
---|
[3155] | 393 | cout<<"--- GeneFluct3D::ReadFits: Reading Cube from "<<cfname<<endl;
|
---|
[3141] | 394 | try {
|
---|
| 395 | FitsImg3DRead fimg(cfname.c_str(),0,5);
|
---|
| 396 | fimg.Read(R_);
|
---|
| 397 | long nx = fimg.ReadKeyL("NX");
|
---|
| 398 | long ny = fimg.ReadKeyL("NY");
|
---|
| 399 | long nz = fimg.ReadKeyL("NZ");
|
---|
| 400 | double dx = fimg.ReadKey("DX");
|
---|
| 401 | double dy = fimg.ReadKey("DY");
|
---|
| 402 | double dz = fimg.ReadKey("DZ");
|
---|
[3154] | 403 | double zref = fimg.ReadKey("ZREF");
|
---|
| 404 | double kzref = fimg.ReadKey("KZREF");
|
---|
[3141] | 405 | setsize(nx,ny,nz,dx,dy,dz);
|
---|
| 406 | setpointers(true);
|
---|
[3154] | 407 | init_fftw();
|
---|
| 408 | SetObservator(zref,kzref);
|
---|
[3330] | 409 | array_allocated_ = true;
|
---|
[3141] | 410 | } catch (PThrowable & exc) {
|
---|
| 411 | cout<<"Exception : "<<(string)typeid(exc).name()
|
---|
| 412 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 413 | return;
|
---|
| 414 | } catch (...) {
|
---|
| 415 | cout<<" some other exception was caught !"<<endl;
|
---|
| 416 | return;
|
---|
| 417 | }
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | void GeneFluct3D::WritePPF(string cfname,bool write_real)
|
---|
| 421 | // On ecrit soit le TArray<r_8> ou le TArray<complex <r_8> >
|
---|
| 422 | {
|
---|
[3155] | 423 | cout<<"--- GeneFluct3D::WritePPF: Writing Cube (real="<<write_real<<") to "<<cfname<<endl;
|
---|
[3141] | 424 | try {
|
---|
| 425 | R_.Info()["NX"] = (int_8)Nx_;
|
---|
| 426 | R_.Info()["NY"] = (int_8)Ny_;
|
---|
| 427 | R_.Info()["NZ"] = (int_8)Nz_;
|
---|
| 428 | R_.Info()["DX"] = (r_8)Dx_;
|
---|
| 429 | R_.Info()["DY"] = (r_8)Dy_;
|
---|
| 430 | R_.Info()["DZ"] = (r_8)Dz_;
|
---|
[3271] | 431 | R_.Info()["ZREF"] = (r_8)redsh_ref_;
|
---|
| 432 | R_.Info()["KZREF"] = (r_8)kredsh_ref_;
|
---|
[3141] | 433 | POutPersist pos(cfname.c_str());
|
---|
| 434 | if(write_real) pos << PPFNameTag("rgen") << R_;
|
---|
| 435 | else pos << PPFNameTag("pkgen") << T_;
|
---|
| 436 | } catch (PThrowable & exc) {
|
---|
| 437 | cout<<"Exception : "<<(string)typeid(exc).name()
|
---|
| 438 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 439 | return;
|
---|
| 440 | } catch (...) {
|
---|
| 441 | cout<<" some other exception was caught !"<<endl;
|
---|
| 442 | return;
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | void GeneFluct3D::ReadPPF(string cfname)
|
---|
| 447 | {
|
---|
[3155] | 448 | cout<<"--- GeneFluct3D::ReadPPF: Reading Cube from "<<cfname<<endl;
|
---|
[3141] | 449 | try {
|
---|
| 450 | bool from_real = true;
|
---|
| 451 | PInPersist pis(cfname.c_str());
|
---|
| 452 | string name_tag_k = "pkgen";
|
---|
| 453 | bool found_tag_k = pis.GotoNameTag("pkgen");
|
---|
| 454 | if(found_tag_k) {
|
---|
[3262] | 455 | cout<<" ...reading spectrum into TArray<complex <r_8> >"<<endl;
|
---|
[3141] | 456 | pis >> PPFNameTag("pkgen") >> T_;
|
---|
| 457 | from_real = false;
|
---|
| 458 | } else {
|
---|
| 459 | cout<<" ...reading space into TArray<r_8>"<<endl;
|
---|
| 460 | pis >> PPFNameTag("rgen") >> R_;
|
---|
| 461 | }
|
---|
[3154] | 462 | setpointers(from_real); // a mettre ici pour relire les DVInfo
|
---|
[3141] | 463 | int_8 nx = R_.Info()["NX"];
|
---|
| 464 | int_8 ny = R_.Info()["NY"];
|
---|
| 465 | int_8 nz = R_.Info()["NZ"];
|
---|
| 466 | r_8 dx = R_.Info()["DX"];
|
---|
| 467 | r_8 dy = R_.Info()["DY"];
|
---|
| 468 | r_8 dz = R_.Info()["DZ"];
|
---|
[3154] | 469 | r_8 zref = R_.Info()["ZREF"];
|
---|
| 470 | r_8 kzref = R_.Info()["KZREF"];
|
---|
[3141] | 471 | setsize(nx,ny,nz,dx,dy,dz);
|
---|
[3154] | 472 | init_fftw();
|
---|
| 473 | SetObservator(zref,kzref);
|
---|
[3330] | 474 | array_allocated_ = true;
|
---|
[3141] | 475 | } catch (PThrowable & exc) {
|
---|
| 476 | cout<<"Exception : "<<(string)typeid(exc).name()
|
---|
| 477 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 478 | return;
|
---|
| 479 | } catch (...) {
|
---|
| 480 | cout<<" some other exception was caught !"<<endl;
|
---|
| 481 | return;
|
---|
| 482 | }
|
---|
| 483 | }
|
---|
| 484 |
|
---|
[3281] | 485 | void GeneFluct3D::WriteSlicePPF(string cfname)
|
---|
| 486 | // On ecrit 3 tranches du cube selon chaque axe
|
---|
| 487 | {
|
---|
[3283] | 488 | cout<<"--- GeneFluct3D::WriteSlicePPF: Writing Cube Slices "<<cfname<<endl;
|
---|
[3281] | 489 | try {
|
---|
| 490 |
|
---|
| 491 | POutPersist pos(cfname.c_str());
|
---|
| 492 | TMatrix<r_4> S;
|
---|
| 493 | char str[16];
|
---|
| 494 | long i,j,l;
|
---|
| 495 |
|
---|
| 496 | // Tranches en Z
|
---|
| 497 | for(int s=0;s<3;s++) {
|
---|
| 498 | S.ReSize(Nx_,Ny_);
|
---|
| 499 | if(s==0) l=0; else if(s==1) l=(Nz_+1)/2; else l=Nz_-1;
|
---|
[3289] | 500 | sprintf(str,"z%ld",l);
|
---|
[3281] | 501 | for(i=0;i<Nx_;i++) for(j=0;j<Ny_;j++) S(i,j)=data_[IndexR(i,j,l)];
|
---|
| 502 | pos<<PPFNameTag(str)<<S; S.RenewObjId();
|
---|
| 503 | }
|
---|
| 504 |
|
---|
| 505 | // Tranches en Y
|
---|
| 506 | for(int s=0;s<3;s++) {
|
---|
| 507 | S.ReSize(Nz_,Nx_);
|
---|
| 508 | if(s==0) j=0; else if(s==1) j=(Ny_+1)/2; else j=Ny_-1;
|
---|
[3289] | 509 | sprintf(str,"y%ld",j);
|
---|
[3281] | 510 | for(i=0;i<Nx_;i++) for(l=0;l<Nz_;l++) S(l,i)=data_[IndexR(i,j,l)];
|
---|
| 511 | pos<<PPFNameTag(str)<<S; S.RenewObjId();
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | // Tranches en X
|
---|
| 515 | for(int s=0;s<3;s++) {
|
---|
| 516 | S.ReSize(Nz_,Ny_);
|
---|
| 517 | if(s==0) i=0; else if(s==1) i=(Nx_+1)/2; else i=Nx_-1;
|
---|
[3289] | 518 | sprintf(str,"x%ld",i);
|
---|
[3281] | 519 | for(j=0;j<Ny_;j++) for(l=0;l<Nz_;l++) S(l,j)=data_[IndexR(i,j,l)];
|
---|
| 520 | pos<<PPFNameTag(str)<<S; S.RenewObjId();
|
---|
| 521 | }
|
---|
| 522 |
|
---|
| 523 | } catch (PThrowable & exc) {
|
---|
| 524 | cout<<"Exception : "<<(string)typeid(exc).name()
|
---|
| 525 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 526 | return;
|
---|
| 527 | } catch (...) {
|
---|
| 528 | cout<<" some other exception was caught !"<<endl;
|
---|
| 529 | return;
|
---|
| 530 | }
|
---|
| 531 | }
|
---|
| 532 |
|
---|
[3141] | 533 | //-------------------------------------------------------
|
---|
[3115] | 534 | void GeneFluct3D::Print(void)
|
---|
| 535 | {
|
---|
[3141] | 536 | cout<<"GeneFluct3D(T_alloc="<<array_allocated_<<"):"<<endl;
|
---|
[3115] | 537 | cout<<"Space Size : nx="<<Nx_<<" ny="<<Ny_<<" nz="<<Nz_<<" ("<<NTz_<<") size="
|
---|
| 538 | <<NRtot_<<endl;
|
---|
| 539 | cout<<" Resol: dx="<<Dx_<<" dy="<<Dy_<<" dz="<<Dz_<<" Mpc"
|
---|
| 540 | <<", dVol="<<dVol_<<", Vol="<<Vol_<<" Mpc^3"<<endl;
|
---|
| 541 | cout<<"Fourier Size : nx="<<Nx_<<" ny="<<Ny_<<" nz="<<NCz_<<endl;
|
---|
| 542 | cout<<" Resol: dkx="<<Dkx_<<" dky="<<Dky_<<" dkz="<<Dkz_<<" Mpc^-1"
|
---|
| 543 | <<", Dk3="<<Dk3_<<" Mpc^-3"<<endl;
|
---|
| 544 | cout<<" (2Pi/k: "<<2.*M_PI/Dkx_<<" "<<2.*M_PI/Dky_<<" "<<2.*M_PI/Dkz_<<" Mpc)"<<endl;
|
---|
| 545 | cout<<" Nyquist: kx="<<Knyqx_<<" ky="<<Knyqy_<<" kz="<<Knyqz_<<" Mpc^-1"
|
---|
| 546 | <<", Kmax="<<GetKmax()<<" Mpc^-1"<<endl;
|
---|
| 547 | cout<<" (2Pi/k: "<<2.*M_PI/Knyqx_<<" "<<2.*M_PI/Knyqy_<<" "<<2.*M_PI/Knyqz_<<" Mpc)"<<endl;
|
---|
[3271] | 548 | cout<<"Redshift "<<redsh_ref_<<" for z axe at k="<<kredsh_ref_<<endl;
|
---|
[3115] | 549 | }
|
---|
| 550 |
|
---|
| 551 | //-------------------------------------------------------
|
---|
[3141] | 552 | void GeneFluct3D::ComputeFourier0(GenericFunc& pk_at_z)
|
---|
[3115] | 553 | // cf ComputeFourier() mais avec autre methode de realisation du spectre
|
---|
| 554 | // (attention on fait une fft pour realiser le spectre)
|
---|
| 555 | {
|
---|
| 556 |
|
---|
| 557 | // --- realisation d'un tableau de tirage gaussiens
|
---|
[3155] | 558 | if(lp_>0) cout<<"--- ComputeFourier0: before gaussian filling ---"<<endl;
|
---|
[3115] | 559 | // On tient compte du pb de normalisation de FFTW3
|
---|
| 560 | double sntot = sqrt((double)NRtot_);
|
---|
[3129] | 561 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
[3141] | 562 | int_8 ip = IndexR(i,j,l);
|
---|
| 563 | data_[ip] = NorRand()/sntot;
|
---|
[3115] | 564 | }
|
---|
| 565 |
|
---|
| 566 | // --- realisation d'un tableau de tirage gaussiens
|
---|
[3155] | 567 | if(lp_>0) cout<<"...before fft real ---"<<endl;
|
---|
[3115] | 568 | fftw_execute(pf_);
|
---|
| 569 |
|
---|
| 570 | // --- On remplit avec une realisation
|
---|
[3157] | 571 | if(lp_>0) cout<<"...before Fourier realization filling"<<endl;
|
---|
[3115] | 572 | T_(0,0,0) = complex<r_8>(0.); // on coupe le continue et on l'initialise
|
---|
[3129] | 573 | long lmod = Nx_/10; if(lmod<1) lmod=1;
|
---|
| 574 | for(long i=0;i<Nx_;i++) {
|
---|
| 575 | long ii = (i>Nx_/2) ? Nx_-i : i;
|
---|
[3115] | 576 | double kx = ii*Dkx_; kx *= kx;
|
---|
[3155] | 577 | if(lp_>0 && i%lmod==0) cout<<"i="<<i<<" ii="<<ii<<endl;
|
---|
[3129] | 578 | for(long j=0;j<Ny_;j++) {
|
---|
| 579 | long jj = (j>Ny_/2) ? Ny_-j : j;
|
---|
[3115] | 580 | double ky = jj*Dky_; ky *= ky;
|
---|
[3129] | 581 | for(long l=0;l<NCz_;l++) {
|
---|
[3115] | 582 | double kz = l*Dkz_; kz *= kz;
|
---|
| 583 | if(i==0 && j==0 && l==0) continue; // Suppression du continu
|
---|
| 584 | double k = sqrt(kx+ky+kz);
|
---|
| 585 | // cf normalisation: Peacock, Cosmology, formule 16.38 p504
|
---|
[3141] | 586 | double pk = pk_at_z(k)/Vol_;
|
---|
[3115] | 587 | // ici pas de "/2" a cause de la remarque ci-dessus
|
---|
| 588 | T_(l,j,i) *= sqrt(pk);
|
---|
| 589 | }
|
---|
| 590 | }
|
---|
| 591 | }
|
---|
| 592 |
|
---|
[3155] | 593 | if(lp_>0) cout<<"...computing power"<<endl;
|
---|
[3115] | 594 | double p = compute_power_carte();
|
---|
[3155] | 595 | if(lp_>0) cout<<"Puissance dans la realisation: "<<p<<endl;
|
---|
[3115] | 596 |
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 | //-------------------------------------------------------
|
---|
[3141] | 600 | void GeneFluct3D::ComputeFourier(GenericFunc& pk_at_z)
|
---|
| 601 | // Calcule une realisation du spectre "pk_at_z"
|
---|
[3115] | 602 | // Attention: dans TArray le premier indice varie le + vite
|
---|
| 603 | // Explication normalisation: see Coles & Lucchin, Cosmology, p264-265
|
---|
| 604 | // FFTW3: on note N=Nx*Ny*Nz
|
---|
| 605 | // f --(FFT)--> F = TF(f) --(FFT^-1)--> fb = TF^-1(F) = TF^-1(TF(f))
|
---|
| 606 | // sum(f(x_i)^2) = S
|
---|
| 607 | // sum(F(nu_i)^2) = S*N
|
---|
| 608 | // sum(fb(x_i)^2) = S*N^2
|
---|
| 609 | {
|
---|
| 610 | // --- RaZ du tableau
|
---|
| 611 | T_ = complex<r_8>(0.);
|
---|
| 612 |
|
---|
| 613 | // --- On remplit avec une realisation
|
---|
[3155] | 614 | if(lp_>0) cout<<"--- ComputeFourier ---"<<endl;
|
---|
[3129] | 615 | long lmod = Nx_/10; if(lmod<1) lmod=1;
|
---|
| 616 | for(long i=0;i<Nx_;i++) {
|
---|
| 617 | long ii = (i>Nx_/2) ? Nx_-i : i;
|
---|
[3115] | 618 | double kx = ii*Dkx_; kx *= kx;
|
---|
[3155] | 619 | if(lp_>0 && i%lmod==0) cout<<"i="<<i<<" ii="<<ii<<endl;
|
---|
[3129] | 620 | for(long j=0;j<Ny_;j++) {
|
---|
| 621 | long jj = (j>Ny_/2) ? Ny_-j : j;
|
---|
[3115] | 622 | double ky = jj*Dky_; ky *= ky;
|
---|
[3129] | 623 | for(long l=0;l<NCz_;l++) {
|
---|
[3115] | 624 | double kz = l*Dkz_; kz *= kz;
|
---|
| 625 | if(i==0 && j==0 && l==0) continue; // Suppression du continu
|
---|
| 626 | double k = sqrt(kx+ky+kz);
|
---|
| 627 | // cf normalisation: Peacock, Cosmology, formule 16.38 p504
|
---|
[3141] | 628 | double pk = pk_at_z(k)/Vol_;
|
---|
[3115] | 629 | // Explication de la division par 2: voir perandom.cc
|
---|
| 630 | // ou egalement Coles & Lucchin, Cosmology formula 13.7.2 p279
|
---|
| 631 | T_(l,j,i) = ComplexGaussRan(sqrt(pk/2.));
|
---|
| 632 | }
|
---|
| 633 | }
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | manage_coefficients(); // gros effet pour les spectres que l'on utilise !
|
---|
| 637 |
|
---|
[3155] | 638 | if(lp_>0) cout<<"...computing power"<<endl;
|
---|
[3115] | 639 | double p = compute_power_carte();
|
---|
[3155] | 640 | if(lp_>0) cout<<"Puissance dans la realisation: "<<p<<endl;
|
---|
[3115] | 641 |
|
---|
| 642 | }
|
---|
| 643 |
|
---|
[3129] | 644 | long GeneFluct3D::manage_coefficients(void)
|
---|
[3115] | 645 | // Take into account the real and complexe conjugate coefficients
|
---|
| 646 | // because we want a realization of a real data in real space
|
---|
| 647 | {
|
---|
[3155] | 648 | if(lp_>1) cout<<"...managing coefficients"<<endl;
|
---|
[3141] | 649 | check_array_alloc();
|
---|
[3115] | 650 |
|
---|
| 651 | // 1./ Le Continu et Nyquist sont reels
|
---|
[3129] | 652 | long nreal = 0;
|
---|
| 653 | for(long kk=0;kk<2;kk++) {
|
---|
| 654 | long k=0; // continu
|
---|
[3115] | 655 | if(kk==1) {if(Nz_%2!=0) continue; else k = Nz_/2;} // Nyquist
|
---|
[3129] | 656 | for(long jj=0;jj<2;jj++) {
|
---|
| 657 | long j=0;
|
---|
[3115] | 658 | if(jj==1) {if( Ny_%2!=0) continue; else j = Ny_/2;}
|
---|
[3129] | 659 | for(long ii=0;ii<2;ii++) {
|
---|
| 660 | long i=0;
|
---|
[3115] | 661 | if(ii==1) {if( Nx_%2!=0) continue; else i = Nx_/2;}
|
---|
[3141] | 662 | int_8 ip = IndexC(i,j,k);
|
---|
| 663 | //cout<<"i="<<i<<" j="<<j<<" k="<<k<<" = ("<<fdata_[ip][0]<<","<<fdata_[ip][1]<<")"<<endl;
|
---|
| 664 | fdata_[ip][1] = 0.; fdata_[ip][0] *= M_SQRT2;
|
---|
[3115] | 665 | nreal++;
|
---|
| 666 | }
|
---|
| 667 | }
|
---|
| 668 | }
|
---|
[3155] | 669 | if(lp_>1) cout<<"Number of forced real number ="<<nreal<<endl;
|
---|
[3115] | 670 |
|
---|
| 671 | // 2./ Les elements complexe conjugues (tous dans le plan k=0,Nyquist)
|
---|
| 672 |
|
---|
| 673 | // a./ les lignes et colonnes du continu et de nyquist
|
---|
[3129] | 674 | long nconj1 = 0;
|
---|
| 675 | for(long kk=0;kk<2;kk++) {
|
---|
| 676 | long k=0; // continu
|
---|
[3115] | 677 | if(kk==1) {if(Nz_%2!=0) continue; else k = Nz_/2;} // Nyquist
|
---|
[3129] | 678 | for(long jj=0;jj<2;jj++) { // selon j
|
---|
| 679 | long j=0;
|
---|
[3115] | 680 | if(jj==1) {if( Ny_%2!=0) continue; else j = Ny_/2;}
|
---|
[3129] | 681 | for(long i=1;i<(Nx_+1)/2;i++) {
|
---|
[3141] | 682 | int_8 ip = IndexC(i,j,k);
|
---|
| 683 | int_8 ip1 = IndexC(Nx_-i,j,k);
|
---|
| 684 | fdata_[ip1][0] = fdata_[ip][0]; fdata_[ip1][1] = -fdata_[ip][1];
|
---|
[3115] | 685 | nconj1++;
|
---|
| 686 | }
|
---|
| 687 | }
|
---|
[3129] | 688 | for(long ii=0;ii<2;ii++) {
|
---|
| 689 | long i=0;
|
---|
[3115] | 690 | if(ii==1) {if( Nx_%2!=0) continue; else i = Nx_/2;}
|
---|
[3129] | 691 | for(long j=1;j<(Ny_+1)/2;j++) {
|
---|
[3141] | 692 | int_8 ip = IndexC(i,j,k);
|
---|
| 693 | int_8 ip1 = IndexC(i,Ny_-j,k);
|
---|
| 694 | fdata_[ip1][0] = fdata_[ip][0]; fdata_[ip1][1] = -fdata_[ip][1];
|
---|
[3115] | 695 | nconj1++;
|
---|
| 696 | }
|
---|
| 697 | }
|
---|
| 698 | }
|
---|
[3155] | 699 | if(lp_>1) cout<<"Number of forced conjugate on cont+nyq ="<<nconj1<<endl;
|
---|
[3115] | 700 |
|
---|
| 701 | // b./ les lignes et colonnes hors continu et de nyquist
|
---|
[3129] | 702 | long nconj2 = 0;
|
---|
| 703 | for(long kk=0;kk<2;kk++) {
|
---|
| 704 | long k=0; // continu
|
---|
[3115] | 705 | if(kk==1) {if(Nz_%2!=0) continue; else k = Nz_/2;} // Nyquist
|
---|
[3129] | 706 | for(long j=1;j<(Ny_+1)/2;j++) {
|
---|
[3115] | 707 | if(Ny_%2==0 && j==Ny_/2) continue; // on ne retraite pas nyquist en j
|
---|
[3129] | 708 | for(long i=1;i<Nx_;i++) {
|
---|
[3115] | 709 | if(Nx_%2==0 && i==Nx_/2) continue; // on ne retraite pas nyquist en i
|
---|
[3141] | 710 | int_8 ip = IndexC(i,j,k);
|
---|
| 711 | int_8 ip1 = IndexC(Nx_-i,Ny_-j,k);
|
---|
| 712 | fdata_[ip1][0] = fdata_[ip][0]; fdata_[ip1][1] = -fdata_[ip][1];
|
---|
[3115] | 713 | nconj2++;
|
---|
| 714 | }
|
---|
| 715 | }
|
---|
| 716 | }
|
---|
[3155] | 717 | if(lp_>1) cout<<"Number of forced conjugate hors cont+nyq ="<<nconj2<<endl;
|
---|
[3115] | 718 |
|
---|
[3155] | 719 | if(lp_>1) cout<<"Check: ddl= "<<NRtot_<<" =?= "<<2*(Nx_*Ny_*NCz_-nconj1-nconj2)-8<<endl;
|
---|
[3115] | 720 |
|
---|
| 721 | return nreal+nconj1+nconj2;
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 | double GeneFluct3D::compute_power_carte(void)
|
---|
| 725 | // Calcul la puissance de la realisation du spectre Pk
|
---|
| 726 | {
|
---|
[3141] | 727 | check_array_alloc();
|
---|
| 728 |
|
---|
[3115] | 729 | double s2 = 0.;
|
---|
[3129] | 730 | for(long l=0;l<NCz_;l++)
|
---|
| 731 | for(long j=0;j<Ny_;j++)
|
---|
| 732 | for(long i=0;i<Nx_;i++) s2 += MODULE2(T_(l,j,i));
|
---|
[3115] | 733 |
|
---|
| 734 | double s20 = 0.;
|
---|
[3129] | 735 | for(long j=0;j<Ny_;j++)
|
---|
| 736 | for(long i=0;i<Nx_;i++) s20 += MODULE2(T_(0,j,i));
|
---|
[3115] | 737 |
|
---|
| 738 | double s2n = 0.;
|
---|
| 739 | if(Nz_%2==0)
|
---|
[3129] | 740 | for(long j=0;j<Ny_;j++)
|
---|
| 741 | for(long i=0;i<Nx_;i++) s2n += MODULE2(T_(NCz_-1,j,i));
|
---|
[3115] | 742 |
|
---|
| 743 | return 2.*s2 -s20 -s2n;
|
---|
| 744 | }
|
---|
| 745 |
|
---|
| 746 | //-------------------------------------------------------------------
|
---|
| 747 | void GeneFluct3D::FilterByPixel(void)
|
---|
| 748 | // Filtrage par la fonction fenetre du pixel (parallelepipede)
|
---|
[3120] | 749 | // TF = 1/(dx*dy*dz)*Int[{-dx/2,dx/2},{-dy/2,dy/2},{-dz/2,dz/2}]
|
---|
[3115] | 750 | // e^(ik_x*x) e^(ik_y*y) e^(ik_z*z) dxdydz
|
---|
[3120] | 751 | // = 2/(k_x*dx) * sin(k_x*dx/2) * (idem y) * (idem z)
|
---|
| 752 | // Gestion divergence en 0: sin(y)/y = 1 - y^2/6*(1-y^2/20)
|
---|
| 753 | // avec y = k_x*dx/2
|
---|
[3115] | 754 | {
|
---|
[3155] | 755 | if(lp_>0) cout<<"--- FilterByPixel ---"<<endl;
|
---|
[3141] | 756 | check_array_alloc();
|
---|
| 757 |
|
---|
[3129] | 758 | for(long i=0;i<Nx_;i++) {
|
---|
| 759 | long ii = (i>Nx_/2) ? Nx_-i : i;
|
---|
[3120] | 760 | double kx = ii*Dkx_ *Dx_/2;
|
---|
[3330] | 761 | double pk_x = pixelfilter(kx);
|
---|
[3129] | 762 | for(long j=0;j<Ny_;j++) {
|
---|
| 763 | long jj = (j>Ny_/2) ? Ny_-j : j;
|
---|
[3120] | 764 | double ky = jj*Dky_ *Dy_/2;
|
---|
[3330] | 765 | double pk_y = pixelfilter(ky);
|
---|
[3129] | 766 | for(long l=0;l<NCz_;l++) {
|
---|
[3120] | 767 | double kz = l*Dkz_ *Dz_/2;
|
---|
[3141] | 768 | double pk_z = pixelfilter(kz);
|
---|
| 769 | T_(l,j,i) *= pk_x*pk_y*pk_z;
|
---|
[3115] | 770 | }
|
---|
| 771 | }
|
---|
| 772 | }
|
---|
| 773 |
|
---|
| 774 | }
|
---|
| 775 |
|
---|
| 776 | //-------------------------------------------------------------------
|
---|
[3331] | 777 | void GeneFluct3D::ApplyGrowthFactor(int type_evol)
|
---|
[3157] | 778 | // Apply Growth to real space
|
---|
| 779 | // Using the correspondance between redshift and los comoving distance
|
---|
| 780 | // describe in vector "zred_" "loscom_"
|
---|
[3331] | 781 | // type_evol = 1 : evolution de la puissance du bruit avec la distance a l'observateur
|
---|
| 782 | // 2 : evolution de la puissance du bruit avec la distance du plan Z
|
---|
| 783 | // (tous les pixels d'un plan Z sont mis au meme redshift z que celui du milieu)
|
---|
[3157] | 784 | {
|
---|
[3331] | 785 | if(lp_>0) cout<<"--- ApplyGrowthFactor: evol="<<type_evol<<endl;
|
---|
[3157] | 786 | check_array_alloc();
|
---|
| 787 |
|
---|
| 788 | if(growth_ == NULL) {
|
---|
[3199] | 789 | char *bla = "GeneFluct3D::ApplyGrowthFactor_Error: set GrowthFactor first";
|
---|
| 790 | cout<<bla<<endl; throw ParmError(bla);
|
---|
[3157] | 791 | }
|
---|
[3331] | 792 | if(type_evol<1 || type_evol>2) {
|
---|
| 793 | char *bla = "GeneFluct3D::ApplyGrowthFactor_Error: bad type_evol value";
|
---|
| 794 | cout<<bla<<endl; throw ParmError(bla);
|
---|
| 795 | }
|
---|
[3157] | 796 |
|
---|
[3199] | 797 | InterpFunc interpinv(loscom2zred_min_,loscom2zred_max_,loscom2zred_);
|
---|
[3157] | 798 | unsigned short ok;
|
---|
| 799 |
|
---|
| 800 | //CHECK: Histo hgr(0.9*zred_[0],1.1*zred_[n-1],1000);
|
---|
| 801 | for(long i=0;i<Nx_;i++) {
|
---|
[3331] | 802 | double dx2 = DXcom(i); dx2 *= dx2;
|
---|
[3157] | 803 | for(long j=0;j<Ny_;j++) {
|
---|
[3331] | 804 | double dy2 = DYcom(j); dy2 *= dy2;
|
---|
[3157] | 805 | for(long l=0;l<Nz_;l++) {
|
---|
[3331] | 806 | double dz = DZcom(l);
|
---|
| 807 | if(type_evol==1) dz = sqrt(dx2+dy2+dz*dz);
|
---|
| 808 | else dz = fabs(dz); // tous les plans Z au meme redshift
|
---|
| 809 | double z = interpinv(dz);
|
---|
[3157] | 810 | //CHECK: hgr.Add(z);
|
---|
| 811 | double dzgr = (*growth_)(z); // interpolation par morceau
|
---|
| 812 | //double dzgr = growth_->Linear(z,ok); // interpolation lineaire
|
---|
| 813 | //double dzgr = growth_->Parab(z,ok); // interpolation parabolique
|
---|
| 814 | int_8 ip = IndexR(i,j,l);
|
---|
| 815 | data_[ip] *= dzgr;
|
---|
| 816 | }
|
---|
| 817 | }
|
---|
| 818 | }
|
---|
| 819 |
|
---|
| 820 | //CHECK: {POutPersist pos("applygrowth.ppf"); string tag="hgr"; pos.PutObject(hgr,tag);}
|
---|
| 821 |
|
---|
| 822 | }
|
---|
| 823 |
|
---|
| 824 | //-------------------------------------------------------------------
|
---|
[3115] | 825 | void GeneFluct3D::ComputeReal(void)
|
---|
| 826 | // Calcule une realisation dans l'espace reel
|
---|
| 827 | {
|
---|
[3155] | 828 | if(lp_>0) cout<<"--- ComputeReal ---"<<endl;
|
---|
[3141] | 829 | check_array_alloc();
|
---|
[3115] | 830 |
|
---|
| 831 | // On fait la FFT
|
---|
| 832 | fftw_execute(pb_);
|
---|
| 833 | }
|
---|
| 834 |
|
---|
| 835 | //-------------------------------------------------------------------
|
---|
| 836 | void GeneFluct3D::ReComputeFourier(void)
|
---|
| 837 | {
|
---|
[3155] | 838 | if(lp_>0) cout<<"--- ReComputeFourier ---"<<endl;
|
---|
[3141] | 839 | check_array_alloc();
|
---|
[3115] | 840 |
|
---|
| 841 | // On fait la FFT
|
---|
| 842 | fftw_execute(pf_);
|
---|
| 843 | // On corrige du pb de la normalisation de FFTW3
|
---|
| 844 | double v = (double)NRtot_;
|
---|
[3129] | 845 | for(long i=0;i<Nx_;i++)
|
---|
| 846 | for(long j=0;j<Ny_;j++)
|
---|
| 847 | for(long l=0;l<NCz_;l++) T_(l,j,i) /= complex<r_8>(v);
|
---|
[3115] | 848 |
|
---|
| 849 | }
|
---|
| 850 |
|
---|
| 851 | //-------------------------------------------------------------------
|
---|
[3141] | 852 | int GeneFluct3D::ComputeSpectrum(HistoErr& herr)
|
---|
| 853 | // Compute spectrum from "T" and fill HistoErr "herr"
|
---|
[3115] | 854 | // T : dans le format standard de GeneFuct3D: T(nz,ny,nx)
|
---|
| 855 | // cad T(kz,ky,kx) avec 0<kz<kz_nyq -ky_nyq<ky<ky_nyq -kx_nyq<kx<kx_nyq
|
---|
| 856 | {
|
---|
[3155] | 857 | if(lp_>0) cout<<"--- ComputeSpectrum ---"<<endl;
|
---|
[3141] | 858 | check_array_alloc();
|
---|
[3115] | 859 |
|
---|
[3141] | 860 | if(herr.NBins()<0) return -1;
|
---|
| 861 | herr.Zero();
|
---|
[3115] | 862 |
|
---|
| 863 | // Attention a l'ordre
|
---|
[3129] | 864 | for(long i=0;i<Nx_;i++) {
|
---|
| 865 | long ii = (i>Nx_/2) ? Nx_-i : i;
|
---|
[3115] | 866 | double kx = ii*Dkx_; kx *= kx;
|
---|
[3129] | 867 | for(long j=0;j<Ny_;j++) {
|
---|
| 868 | long jj = (j>Ny_/2) ? Ny_-j : j;
|
---|
[3115] | 869 | double ky = jj*Dky_; ky *= ky;
|
---|
[3129] | 870 | for(long l=0;l<NCz_;l++) {
|
---|
[3330] | 871 | double kz = l*Dkz_;
|
---|
| 872 | double k = sqrt(kx+ky+kz*kz);
|
---|
[3115] | 873 | double pk = MODULE2(T_(l,j,i));
|
---|
[3141] | 874 | herr.Add(k,pk);
|
---|
[3115] | 875 | }
|
---|
| 876 | }
|
---|
| 877 | }
|
---|
[3150] | 878 | herr.ToVariance();
|
---|
[3115] | 879 |
|
---|
| 880 | // renormalize to directly compare to original spectrum
|
---|
| 881 | double norm = Vol_;
|
---|
[3141] | 882 | herr *= norm;
|
---|
[3115] | 883 |
|
---|
| 884 | return 0;
|
---|
| 885 | }
|
---|
| 886 |
|
---|
[3141] | 887 | int GeneFluct3D::ComputeSpectrum2D(Histo2DErr& herr)
|
---|
| 888 | {
|
---|
[3155] | 889 | if(lp_>0) cout<<"--- ComputeSpectrum2D ---"<<endl;
|
---|
[3141] | 890 | check_array_alloc();
|
---|
| 891 |
|
---|
| 892 | if(herr.NBinX()<0 || herr.NBinY()<0) return -1;
|
---|
| 893 | herr.Zero();
|
---|
| 894 |
|
---|
| 895 | // Attention a l'ordre
|
---|
| 896 | for(long i=0;i<Nx_;i++) {
|
---|
| 897 | long ii = (i>Nx_/2) ? Nx_-i : i;
|
---|
| 898 | double kx = ii*Dkx_; kx *= kx;
|
---|
| 899 | for(long j=0;j<Ny_;j++) {
|
---|
| 900 | long jj = (j>Ny_/2) ? Ny_-j : j;
|
---|
| 901 | double ky = jj*Dky_; ky *= ky;
|
---|
| 902 | double kt = sqrt(kx+ky);
|
---|
| 903 | for(long l=0;l<NCz_;l++) {
|
---|
| 904 | double kz = l*Dkz_;
|
---|
| 905 | double pk = MODULE2(T_(l,j,i));
|
---|
| 906 | herr.Add(kt,kz,pk);
|
---|
| 907 | }
|
---|
| 908 | }
|
---|
| 909 | }
|
---|
[3150] | 910 | herr.ToVariance();
|
---|
[3141] | 911 |
|
---|
| 912 | // renormalize to directly compare to original spectrum
|
---|
| 913 | double norm = Vol_;
|
---|
| 914 | herr *= norm;
|
---|
| 915 |
|
---|
| 916 | return 0;
|
---|
| 917 | }
|
---|
| 918 |
|
---|
[3330] | 919 | //-------------------------------------------------------------------
|
---|
| 920 | int GeneFluct3D::ComputeSpectrum(HistoErr& herr,double sigma,bool pixcor)
|
---|
| 921 | // Compute spectrum from "T" and fill HistoErr "herr"
|
---|
| 922 | // AVEC la soustraction du niveau de bruit et la correction par filterpixel()
|
---|
| 923 | // Si on ne fait pas ca, alors on obtient un spectre non-isotrope!
|
---|
| 924 | //
|
---|
| 925 | // T : dans le format standard de GeneFuct3D: T(nz,ny,nx)
|
---|
| 926 | // cad T(kz,ky,kx) avec 0<kz<kz_nyq -ky_nyq<ky<ky_nyq -kx_nyq<kx<kx_nyq
|
---|
| 927 | {
|
---|
| 928 | if(lp_>0) cout<<"--- ComputeSpectrum: sigma="<<sigma<<endl;
|
---|
| 929 | check_array_alloc();
|
---|
| 930 |
|
---|
| 931 | if(sigma<=0.) sigma = 0.;
|
---|
| 932 | double sigma2 = sigma*sigma / (double)NRtot_;
|
---|
| 933 |
|
---|
| 934 | if(herr.NBins()<0) return -1;
|
---|
| 935 | herr.Zero();
|
---|
| 936 |
|
---|
| 937 | TVector<r_8> vfz(NCz_);
|
---|
| 938 | if(pixcor) // kz = l*Dkz_
|
---|
| 939 | for(long l=0;l<NCz_;l++) {vfz(l)=pixelfilter(l*Dkz_ *Dz_/2); vfz(l)*=vfz(l);}
|
---|
| 940 |
|
---|
| 941 | // Attention a l'ordre
|
---|
| 942 | for(long i=0;i<Nx_;i++) {
|
---|
| 943 | long ii = (i>Nx_/2) ? Nx_-i : i;
|
---|
| 944 | double kx = ii*Dkx_;
|
---|
| 945 | double fx = (pixcor) ? pixelfilter(kx*Dx_/2): 1.;
|
---|
| 946 | kx *= kx; fx *= fx;
|
---|
| 947 | for(long j=0;j<Ny_;j++) {
|
---|
| 948 | long jj = (j>Ny_/2) ? Ny_-j : j;
|
---|
| 949 | double ky = jj*Dky_;
|
---|
| 950 | double fy = (pixcor) ? pixelfilter(ky*Dy_/2): 1.;
|
---|
| 951 | ky *= ky; fy *= fy;
|
---|
| 952 | for(long l=0;l<NCz_;l++) {
|
---|
| 953 | double kz = l*Dkz_;
|
---|
| 954 | double k = sqrt(kx+ky+kz*kz);
|
---|
| 955 | double pk = MODULE2(T_(l,j,i)) - sigma2;
|
---|
| 956 | double fz = (pixcor) ? vfz(l): 1.;
|
---|
| 957 | double f = fx*fy*fz;
|
---|
| 958 | if(f>0.) herr.Add(k,pk/f);
|
---|
| 959 | }
|
---|
| 960 | }
|
---|
| 961 | }
|
---|
| 962 | herr.ToVariance();
|
---|
[3351] | 963 | for(int i=0;i<herr.NBins();i++) herr(i) += sigma2;
|
---|
[3330] | 964 |
|
---|
| 965 | // renormalize to directly compare to original spectrum
|
---|
| 966 | double norm = Vol_;
|
---|
| 967 | herr *= norm;
|
---|
| 968 |
|
---|
| 969 | return 0;
|
---|
| 970 | }
|
---|
| 971 |
|
---|
| 972 | int GeneFluct3D::ComputeSpectrum2D(Histo2DErr& herr,double sigma,bool pixcor)
|
---|
| 973 | // AVEC la soustraction du niveau de bruit et la correction par filterpixel()
|
---|
| 974 | {
|
---|
| 975 | if(lp_>0) cout<<"--- ComputeSpectrum2D: sigma="<<sigma<<endl;
|
---|
| 976 | check_array_alloc();
|
---|
| 977 |
|
---|
| 978 | if(sigma<=0.) sigma = 0.;
|
---|
| 979 | double sigma2 = sigma*sigma / (double)NRtot_;
|
---|
| 980 |
|
---|
| 981 | if(herr.NBinX()<0 || herr.NBinY()<0) return -1;
|
---|
| 982 | herr.Zero();
|
---|
| 983 |
|
---|
| 984 | TVector<r_8> vfz(NCz_);
|
---|
| 985 | if(pixcor) // kz = l*Dkz_
|
---|
| 986 | for(long l=0;l<NCz_;l++) {vfz(l)=pixelfilter(l*Dkz_ *Dz_/2); vfz(l)*=vfz(l);}
|
---|
| 987 |
|
---|
| 988 | // Attention a l'ordre
|
---|
| 989 | for(long i=0;i<Nx_;i++) {
|
---|
| 990 | long ii = (i>Nx_/2) ? Nx_-i : i;
|
---|
| 991 | double kx = ii*Dkx_;
|
---|
| 992 | double fx = (pixcor) ? pixelfilter(kx*Dx_/2) : 1.;
|
---|
| 993 | kx *= kx; fx *= fx;
|
---|
| 994 | for(long j=0;j<Ny_;j++) {
|
---|
| 995 | long jj = (j>Ny_/2) ? Ny_-j : j;
|
---|
| 996 | double ky = jj*Dky_;
|
---|
| 997 | double fy = (pixcor) ? pixelfilter(ky*Dy_/2) : 1.;
|
---|
| 998 | ky *= ky; fy *= fy;
|
---|
| 999 | double kt = sqrt(kx+ky);
|
---|
| 1000 | for(long l=0;l<NCz_;l++) {
|
---|
| 1001 | double kz = l*Dkz_;
|
---|
| 1002 | double pk = MODULE2(T_(l,j,i)) - sigma2;
|
---|
| 1003 | double fz = (pixcor) ? vfz(l): 1.;
|
---|
| 1004 | double f = fx*fy*fz;
|
---|
| 1005 | if(f>0.) herr.Add(kt,kz,pk/f);
|
---|
| 1006 | }
|
---|
| 1007 | }
|
---|
| 1008 | }
|
---|
| 1009 | herr.ToVariance();
|
---|
[3351] | 1010 | for(int i=0;i<herr.NBinX();i++)
|
---|
| 1011 | for(int j=0;j<herr.NBinY();j++) herr(i,j) += sigma2;
|
---|
[3330] | 1012 |
|
---|
| 1013 | // renormalize to directly compare to original spectrum
|
---|
| 1014 | double norm = Vol_;
|
---|
| 1015 | herr *= norm;
|
---|
| 1016 |
|
---|
| 1017 | return 0;
|
---|
| 1018 | }
|
---|
| 1019 |
|
---|
[3115] | 1020 | //-------------------------------------------------------
|
---|
[3134] | 1021 | int_8 GeneFluct3D::VarianceFrReal(double R,double& var)
|
---|
[3115] | 1022 | // Recompute MASS variance in spherical top-hat (rayon=R)
|
---|
[3353] | 1023 | // Par definition: SigmaR^2 = <(M-<M>)^2>/<M>^2
|
---|
| 1024 | // ou M = masse dans sphere de rayon R
|
---|
[3354] | 1025 | // --- ATTENTION: la variance calculee a une tres grande dispersion
|
---|
| 1026 | // (surtout si le volume du cube est petit). Pour verifier
|
---|
| 1027 | // que le sigmaR calcule par cette methode est en accord avec
|
---|
| 1028 | // le sigmaR en input, il faut faire plusieurs simulations (~100)
|
---|
| 1029 | // et regarder la moyenne des sigmaR reconstruits
|
---|
[3115] | 1030 | {
|
---|
[3262] | 1031 | if(lp_>0) cout<<"--- VarianceFrReal R="<<R<<endl;
|
---|
[3141] | 1032 | check_array_alloc();
|
---|
| 1033 |
|
---|
[3353] | 1034 | long dnx = long(R/Dx_)+1; if(dnx<=0) dnx = 1;
|
---|
| 1035 | long dny = long(R/Dy_)+1; if(dny<=0) dny = 1;
|
---|
| 1036 | long dnz = long(R/Dz_)+1; if(dnz<=0) dnz = 1;
|
---|
[3155] | 1037 | if(lp_>0) cout<<"dnx="<<dnx<<" dny="<<dny<<" dnz="<<dnz<<endl;
|
---|
[3115] | 1038 |
|
---|
[3353] | 1039 | double sum=0., sum2=0., sn=0., r2 = R*R;
|
---|
| 1040 | int_8 nsum=0;
|
---|
[3115] | 1041 |
|
---|
[3353] | 1042 | for(long i=dnx;i<Nx_-dnx;i+=2*dnx) {
|
---|
| 1043 | for(long j=dny;j<Ny_-dny;j+=2*dny) {
|
---|
| 1044 | for(long l=dnz;l<Nz_-dnz;l+=2*dnz) {
|
---|
| 1045 | double m=0.; int_8 n=0;
|
---|
[3129] | 1046 | for(long ii=i-dnx;ii<=i+dnx;ii++) {
|
---|
[3115] | 1047 | double x = (ii-i)*Dx_; x *= x;
|
---|
[3129] | 1048 | for(long jj=j-dny;jj<=j+dny;jj++) {
|
---|
[3115] | 1049 | double y = (jj-j)*Dy_; y *= y;
|
---|
[3129] | 1050 | for(long ll=l-dnz;ll<=l+dnz;ll++) {
|
---|
[3115] | 1051 | double z = (ll-l)*Dz_; z *= z;
|
---|
| 1052 | if(x+y+z>r2) continue;
|
---|
[3141] | 1053 | int_8 ip = IndexR(ii,jj,ll);
|
---|
[3353] | 1054 | m += 1.+data_[ip]; // 1+drho/rho
|
---|
[3115] | 1055 | n++;
|
---|
| 1056 | }
|
---|
| 1057 | }
|
---|
| 1058 | }
|
---|
[3353] | 1059 | if(n>0) {sum += m; sum2 += m*m; nsum++; sn += n;}
|
---|
| 1060 | //cout<<i<<","<<j<<","<<l<<" n="<<n<<" m="<<m<<" sum="<<sum<<" sum2="<<sum2<<endl;
|
---|
[3115] | 1061 | }
|
---|
| 1062 | }
|
---|
| 1063 | }
|
---|
| 1064 |
|
---|
| 1065 | if(nsum<=1) {var=0.; return nsum;}
|
---|
| 1066 | sum /= nsum;
|
---|
| 1067 | sum2 = sum2/nsum - sum*sum;
|
---|
[3353] | 1068 | sn /= nsum;
|
---|
| 1069 | if(lp_>0) cout<<"...<n>="<<sn<<", nsum="<<nsum<<" <M>="<<sum<<" <(M-<M>)^2>="<<sum2<<endl;
|
---|
| 1070 | var = sum2/(sum*sum); // <dM^2>/<M>^2
|
---|
| 1071 | if(lp_>0) cout<<"...sigmaR^2 = <(M-<M>)^2>/<M>^2 = "<<var
|
---|
| 1072 | <<" -> sigmaR = "<<sqrt(var)<<endl;
|
---|
[3115] | 1073 |
|
---|
| 1074 | return nsum;
|
---|
| 1075 | }
|
---|
| 1076 |
|
---|
| 1077 | //-------------------------------------------------------
|
---|
[3134] | 1078 | int_8 GeneFluct3D::NumberOfBad(double vmin,double vmax)
|
---|
[3115] | 1079 | // number of pixels outside of ]vmin,vmax[ extremites exclues
|
---|
| 1080 | // -> vmin and vmax are considered as bad
|
---|
| 1081 | {
|
---|
[3141] | 1082 | check_array_alloc();
|
---|
[3115] | 1083 |
|
---|
[3134] | 1084 | int_8 nbad = 0;
|
---|
[3129] | 1085 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
[3141] | 1086 | int_8 ip = IndexR(i,j,l);
|
---|
| 1087 | double v = data_[ip];
|
---|
[3115] | 1088 | if(v<=vmin || v>=vmax) nbad++;
|
---|
| 1089 | }
|
---|
| 1090 |
|
---|
[3358] | 1091 | if(lp_>0) cout<<"--- NumberOfBad "<<nbad<<" px out of ]"<<vmin<<","<<vmax
|
---|
| 1092 | <<"[ i.e. frac="<<nbad/(double)NRtot_<<endl;
|
---|
[3115] | 1093 | return nbad;
|
---|
| 1094 | }
|
---|
| 1095 |
|
---|
[3320] | 1096 | int_8 GeneFluct3D::MinMax(double& xmin,double& xmax,double vmin,double vmax)
|
---|
| 1097 | // Calcul des valeurs xmin et xmax dans le cube reel avec valeurs ]vmin,vmax[ extremites exclues
|
---|
| 1098 | {
|
---|
| 1099 | bool tstval = (vmax>vmin)? true: false;
|
---|
| 1100 | if(lp_>0) {
|
---|
| 1101 | cout<<"--- MinMax";
|
---|
| 1102 | if(tstval) cout<<" range=]"<<vmin<<","<<vmax<<"[";
|
---|
| 1103 | cout<<endl;
|
---|
| 1104 | }
|
---|
| 1105 | check_array_alloc();
|
---|
| 1106 |
|
---|
| 1107 | int_8 n = 0;
|
---|
| 1108 | xmin = xmax = data_[0];
|
---|
| 1109 |
|
---|
| 1110 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
| 1111 | int_8 ip = IndexR(i,j,l);
|
---|
| 1112 | double x = data_[ip];
|
---|
| 1113 | if(tstval && (x<=vmin || x>=vmax)) continue;
|
---|
| 1114 | if(x<xmin) xmin = x;
|
---|
| 1115 | if(x>xmax) xmax = x;
|
---|
| 1116 | n++;
|
---|
| 1117 | }
|
---|
| 1118 |
|
---|
| 1119 | if(lp_>0) cout<<" n="<<n<<" min="<<xmin<<" max="<<xmax<<endl;
|
---|
| 1120 |
|
---|
| 1121 | return n;
|
---|
| 1122 | }
|
---|
| 1123 |
|
---|
[3261] | 1124 | int_8 GeneFluct3D::MeanSigma2(double& rm,double& rs2,double vmin,double vmax
|
---|
| 1125 | ,bool useout,double vout)
|
---|
| 1126 | // Calcul de mean,sigma2 dans le cube reel avec valeurs ]vmin,vmax[ extremites exclues
|
---|
| 1127 | // useout = false: ne pas utiliser les pixels hors limites pour calculer mean,sigma2
|
---|
| 1128 | // true : utiliser les pixels hors limites pour calculer mean,sigma2
|
---|
| 1129 | // en remplacant leurs valeurs par "vout"
|
---|
[3115] | 1130 | {
|
---|
[3261] | 1131 | bool tstval = (vmax>vmin)? true: false;
|
---|
| 1132 | if(lp_>0) {
|
---|
[3262] | 1133 | cout<<"--- MeanSigma2";
|
---|
| 1134 | if(tstval) cout<<" range=]"<<vmin<<","<<vmax<<"[";
|
---|
[3261] | 1135 | if(useout) cout<<", useout="<<useout<<" vout="<<vout;
|
---|
| 1136 | cout<<endl;
|
---|
| 1137 | }
|
---|
[3141] | 1138 | check_array_alloc();
|
---|
[3115] | 1139 |
|
---|
[3134] | 1140 | int_8 n = 0;
|
---|
[3115] | 1141 | rm = rs2 = 0.;
|
---|
| 1142 |
|
---|
[3129] | 1143 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
[3141] | 1144 | int_8 ip = IndexR(i,j,l);
|
---|
| 1145 | double v = data_[ip];
|
---|
[3261] | 1146 | if(tstval) {
|
---|
| 1147 | if(v<=vmin || v>=vmax) {if(useout) v=vout; else continue;}
|
---|
| 1148 | }
|
---|
[3115] | 1149 | rm += v;
|
---|
| 1150 | rs2 += v*v;
|
---|
| 1151 | n++;
|
---|
| 1152 | }
|
---|
| 1153 |
|
---|
| 1154 | if(n>1) {
|
---|
| 1155 | rm /= (double)n;
|
---|
| 1156 | rs2 = rs2/(double)n - rm*rm;
|
---|
| 1157 | }
|
---|
| 1158 |
|
---|
[3261] | 1159 | if(lp_>0) cout<<" n="<<n<<" m="<<rm<<" s2="<<rs2<<" s="<<sqrt(fabs(rs2))<<endl;
|
---|
| 1160 |
|
---|
[3115] | 1161 | return n;
|
---|
| 1162 | }
|
---|
| 1163 |
|
---|
[3134] | 1164 | int_8 GeneFluct3D::SetToVal(double vmin, double vmax,double val0)
|
---|
[3115] | 1165 | // set to "val0" if out of range ]vmin,vmax[ extremites exclues
|
---|
[3261] | 1166 | // cad set to "val0" if in [vmin,vmax] -> vmin and vmax are set to val0
|
---|
[3115] | 1167 | {
|
---|
[3141] | 1168 | check_array_alloc();
|
---|
[3115] | 1169 |
|
---|
[3134] | 1170 | int_8 nbad = 0;
|
---|
[3129] | 1171 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
[3141] | 1172 | int_8 ip = IndexR(i,j,l);
|
---|
| 1173 | double v = data_[ip];
|
---|
| 1174 | if(v<=vmin || v>=vmax) {data_[ip] = val0; nbad++;}
|
---|
[3115] | 1175 | }
|
---|
| 1176 |
|
---|
[3262] | 1177 | if(lp_>0) cout<<"--- SetToVal "<<nbad<<" px set to="<<val0
|
---|
| 1178 | <<" because out of range=]"<<vmin<<","<<vmax<<"["<<endl;
|
---|
[3115] | 1179 | return nbad;
|
---|
| 1180 | }
|
---|
| 1181 |
|
---|
[3283] | 1182 | void GeneFluct3D::ScaleOffset(double scalecube,double offsetcube)
|
---|
| 1183 | // Replace "V" by "scalecube * ( V + offsetcube )"
|
---|
| 1184 | {
|
---|
[3284] | 1185 | if(lp_>0) cout<<"--- ScaleCube scale="<<scalecube<<" offset="<<offsetcube<<endl;
|
---|
[3283] | 1186 |
|
---|
| 1187 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
| 1188 | int_8 ip = IndexR(i,j,l);
|
---|
| 1189 | data_[ip] = scalecube * ( data_[ip] + offsetcube );
|
---|
| 1190 | }
|
---|
| 1191 |
|
---|
| 1192 | return;
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
[3115] | 1195 | //-------------------------------------------------------
|
---|
| 1196 | void GeneFluct3D::TurnFluct2Mass(void)
|
---|
| 1197 | // d_rho/rho -> Mass (add one!)
|
---|
| 1198 | {
|
---|
[3155] | 1199 | if(lp_>0) cout<<"--- TurnFluct2Mass ---"<<endl;
|
---|
[3141] | 1200 | check_array_alloc();
|
---|
| 1201 |
|
---|
[3115] | 1202 |
|
---|
[3129] | 1203 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
[3141] | 1204 | int_8 ip = IndexR(i,j,l);
|
---|
| 1205 | data_[ip] += 1.;
|
---|
[3115] | 1206 | }
|
---|
| 1207 | }
|
---|
| 1208 |
|
---|
[3358] | 1209 | double GeneFluct3D::TurnFluct2MeanNumber(double val_by_mpc3)
|
---|
[3365] | 1210 | // ATTENTION: la gestion des pixels<0 proposee ici induit une perte de variance
|
---|
| 1211 | // sur la carte, le spectre Pk reconstruit sera plus faible!
|
---|
| 1212 | // L'effet sera d'autant plus grand que le nombre de pixels<0 sera grand.
|
---|
[3329] | 1213 | {
|
---|
[3358] | 1214 | if(lp_>0) cout<<"--- TurnFluct2MeanNumber : "<<val_by_mpc3<<" quantity (gal or mass)/Mpc^3"<<endl;
|
---|
[3329] | 1215 |
|
---|
[3358] | 1216 | // First convert dRho/Rho into 1+dRho/Rho
|
---|
| 1217 | int_8 nball = 0; double sumall = 0., sumall2 = 0.;
|
---|
[3329] | 1218 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
| 1219 | int_8 ip = IndexR(i,j,l);
|
---|
[3358] | 1220 | data_[ip] += 1.;
|
---|
| 1221 | nball++; sumall += data_[ip]; sumall2 += data_[ip]*data_[ip];
|
---|
[3329] | 1222 | }
|
---|
[3358] | 1223 | if(nball>2) {
|
---|
| 1224 | sumall /= (double)nball;
|
---|
| 1225 | sumall2 = sumall2/(double)nball - sumall*sumall;
|
---|
| 1226 | if(lp_>0) cout<<"1+dRho/Rho: mean="<<sumall<<" variance="<<sumall2
|
---|
| 1227 | <<" -> "<<sqrt(fabs(sumall2))<<endl;
|
---|
[3329] | 1228 | }
|
---|
| 1229 |
|
---|
[3358] | 1230 | // Find contribution for positive pixels
|
---|
| 1231 | int_8 nbpos = 0; double sumpos = 0. , sumpos2 = 0.;
|
---|
| 1232 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
| 1233 | int_8 ip = IndexR(i,j,l);
|
---|
| 1234 | double v = data_[ip];
|
---|
| 1235 | if(data_[ip]>0.) {nbpos++; sumpos += v; sumpos2 += v*v;}
|
---|
| 1236 | }
|
---|
| 1237 | if(nbpos<1) {
|
---|
| 1238 | cout<<"TurnFluct2MeanNumber_Error: nbpos<1"<<endl;
|
---|
| 1239 | throw RangeCheckError("TurnFluct2MeanNumber_Error: nbpos<1");
|
---|
| 1240 | }
|
---|
| 1241 | sumpos2 = sumpos2/nball - sumpos*sumpos/(nball*nball);
|
---|
| 1242 | if(lp_>0)
|
---|
| 1243 | cout<<"1+dRho/Rho with v<0 set to zero: mean="<<sumpos/nball
|
---|
| 1244 | <<" variance="<<sumpos2<<" -> "<<sqrt(fabs(sumpos2))<<endl;
|
---|
| 1245 | cout<<"Sum of positive values: sumpos="<<sumpos
|
---|
| 1246 | <<" (n(v>0) = "<<nbpos<<" frac(v>0)="<<nbpos/(double)NRtot_<<")"<<endl;
|
---|
[3329] | 1247 |
|
---|
[3358] | 1248 | // - Mettre exactement val_by_mpc3*Vol galaxies (ou Msol) dans notre survey
|
---|
| 1249 | // - Uniquement dans les pixels de masse >0.
|
---|
| 1250 | // - Mise a zero des pixels <0
|
---|
| 1251 | double dn = val_by_mpc3 * Vol_ / sumpos;
|
---|
| 1252 | if(lp_>0) cout<<"...density move from "
|
---|
| 1253 | <<val_by_mpc3*dVol_<<" to "<<dn<<" / pixel"<<endl;
|
---|
| 1254 |
|
---|
[3329] | 1255 | double sum = 0.;
|
---|
| 1256 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
| 1257 | int_8 ip = IndexR(i,j,l);
|
---|
| 1258 | if(data_[ip]<=0.) data_[ip] = 0.;
|
---|
| 1259 | else {
|
---|
[3349] | 1260 | data_[ip] *= dn;
|
---|
| 1261 | sum += data_[ip];
|
---|
[3329] | 1262 | }
|
---|
| 1263 | }
|
---|
| 1264 |
|
---|
[3358] | 1265 | if(lp_>0) cout<<"...quantity put into survey "<<sum<<" / "<<val_by_mpc3*Vol_<<endl;
|
---|
[3329] | 1266 |
|
---|
| 1267 | return sum;
|
---|
| 1268 | }
|
---|
| 1269 |
|
---|
[3115] | 1270 | double GeneFluct3D::ApplyPoisson(void)
|
---|
| 1271 | // do NOT treate negative or nul mass -> let it as it is
|
---|
| 1272 | {
|
---|
[3155] | 1273 | if(lp_>0) cout<<"--- ApplyPoisson ---"<<endl;
|
---|
[3141] | 1274 | check_array_alloc();
|
---|
| 1275 |
|
---|
[3115] | 1276 | double sum = 0.;
|
---|
[3129] | 1277 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
[3141] | 1278 | int_8 ip = IndexR(i,j,l);
|
---|
| 1279 | double v = data_[ip];
|
---|
[3115] | 1280 | if(v>0.) {
|
---|
| 1281 | unsigned long dn = PoissRandLimit(v,10.);
|
---|
[3141] | 1282 | data_[ip] = (double)dn;
|
---|
[3115] | 1283 | sum += (double)dn;
|
---|
| 1284 | }
|
---|
| 1285 | }
|
---|
[3155] | 1286 | if(lp_>0) cout<<sum<<" galaxies put into survey"<<endl;
|
---|
[3115] | 1287 |
|
---|
| 1288 | return sum;
|
---|
| 1289 | }
|
---|
| 1290 |
|
---|
| 1291 | double GeneFluct3D::TurnNGal2Mass(FunRan& massdist,bool axeslog)
|
---|
| 1292 | // do NOT treate negative or nul mass -> let it as it is
|
---|
| 1293 | // INPUT:
|
---|
| 1294 | // massdist : distribution de masse (m*dn/dm)
|
---|
| 1295 | // axeslog = false : retourne la masse
|
---|
| 1296 | // = true : retourne le log10(mass)
|
---|
| 1297 | // RETURN la masse totale
|
---|
| 1298 | {
|
---|
[3155] | 1299 | if(lp_>0) cout<<"--- TurnNGal2Mass ---"<<endl;
|
---|
[3141] | 1300 | check_array_alloc();
|
---|
| 1301 |
|
---|
[3115] | 1302 | double sum = 0.;
|
---|
[3129] | 1303 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
[3141] | 1304 | int_8 ip = IndexR(i,j,l);
|
---|
| 1305 | double v = data_[ip];
|
---|
[3115] | 1306 | if(v>0.) {
|
---|
[3129] | 1307 | long ngal = long(v+0.1);
|
---|
[3141] | 1308 | data_[ip] = 0.;
|
---|
[3129] | 1309 | for(long i=0;i<ngal;i++) {
|
---|
[3115] | 1310 | double m = massdist.RandomInterp(); // massdist.Random();
|
---|
| 1311 | if(axeslog) m = pow(10.,m);
|
---|
[3141] | 1312 | data_[ip] += m;
|
---|
[3115] | 1313 | }
|
---|
[3141] | 1314 | sum += data_[ip];
|
---|
[3115] | 1315 | }
|
---|
| 1316 | }
|
---|
[3155] | 1317 | if(lp_>0) cout<<sum<<" MSol HI mass put into survey"<<endl;
|
---|
[3115] | 1318 |
|
---|
| 1319 | return sum;
|
---|
| 1320 | }
|
---|
| 1321 |
|
---|
[3320] | 1322 | double GeneFluct3D::TurnNGal2MassQuick(SchechterMassDist& schmdist)
|
---|
| 1323 | // idem TurnNGal2Mass mais beaucoup plus rapide
|
---|
| 1324 | {
|
---|
| 1325 | if(lp_>0) cout<<"--- TurnNGal2MassQuick ---"<<endl;
|
---|
| 1326 | check_array_alloc();
|
---|
| 1327 |
|
---|
| 1328 | double sum = 0.;
|
---|
| 1329 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) for(long l=0;l<Nz_;l++) {
|
---|
| 1330 | int_8 ip = IndexR(i,j,l);
|
---|
| 1331 | double v = data_[ip];
|
---|
| 1332 | if(v>0.) {
|
---|
| 1333 | long ngal = long(v+0.1);
|
---|
| 1334 | data_[ip] = schmdist.TirMass(ngal);
|
---|
| 1335 | sum += data_[ip];
|
---|
| 1336 | }
|
---|
| 1337 | }
|
---|
| 1338 | if(lp_>0) cout<<sum<<" MSol HI mass put into survey"<<endl;
|
---|
| 1339 |
|
---|
| 1340 | return sum;
|
---|
| 1341 | }
|
---|
| 1342 |
|
---|
[3349] | 1343 | void GeneFluct3D::AddNoise2Real(double snoise,int type_evol)
|
---|
| 1344 | // add noise to every pixels (meme les <=0 !)
|
---|
| 1345 | // type_evol = 0 : pas d'evolution de la puissance du bruit
|
---|
| 1346 | // 1 : evolution de la puissance du bruit avec la distance a l'observateur
|
---|
| 1347 | // 2 : evolution de la puissance du bruit avec la distance du plan Z
|
---|
| 1348 | // (tous les plans Z sont mis au meme redshift z de leur milieu)
|
---|
| 1349 | {
|
---|
| 1350 | if(lp_>0) cout<<"--- AddNoise2Real: snoise = "<<snoise<<" evol="<<type_evol<<endl;
|
---|
| 1351 | check_array_alloc();
|
---|
| 1352 |
|
---|
| 1353 | if(type_evol<0) type_evol = 0;
|
---|
| 1354 | if(type_evol>2) {
|
---|
| 1355 | char *bla = "GeneFluct3D::AddNoise2Real_Error: bad type_evol value";
|
---|
| 1356 | cout<<bla<<endl; throw ParmError(bla);
|
---|
| 1357 | }
|
---|
| 1358 |
|
---|
| 1359 | vector<double> correction;
|
---|
| 1360 | InterpFunc *intercor = NULL;
|
---|
| 1361 |
|
---|
| 1362 | if(type_evol>0) {
|
---|
| 1363 | // Sigma_Noise(en mass) :
|
---|
| 1364 | // Slim ~ 1/sqrt(DNu) * sqrt(nlobe) en W/m^2Hz
|
---|
| 1365 | // Flim ~ sqrt(DNu) * sqrt(nlobe) en W/m^2
|
---|
| 1366 | // Mlim ~ sqrt(DNu) * (Dlum)^2 * sqrt(nlobe) en Msol
|
---|
| 1367 | // nlobe ~ 1/Dtrcom^2
|
---|
| 1368 | // Mlim ~ sqrt(DNu) * (Dlum)^2 / Dtrcom
|
---|
| 1369 | if(cosmo_ == NULL || redsh_ref_<0.| loscom2zred_.size()<1) {
|
---|
| 1370 | char *bla = "GeneFluct3D::AddNoise2Real_Error: set Observator and Cosmology first";
|
---|
| 1371 | cout<<bla<<endl; throw ParmError(bla);
|
---|
| 1372 | }
|
---|
| 1373 | InterpFunc interpinv(loscom2zred_min_,loscom2zred_max_,loscom2zred_);
|
---|
| 1374 | long nsz = loscom2zred_.size(), nszmod=((nsz>10)? nsz/10: 1);
|
---|
| 1375 | for(long i=0;i<nsz;i++) {
|
---|
| 1376 | double d = interpinv.X(i);
|
---|
| 1377 | double zred = interpinv(d);
|
---|
| 1378 | double dtrc = cosmo_->Dtrcom(zred); // pour variation angle solide
|
---|
| 1379 | double dlum = cosmo_->Dlum(zred); // pour variation conversion mass HI
|
---|
| 1380 | double dred = Dz_/(cosmo_->Dhubble()/cosmo_->E(zred));
|
---|
| 1381 | double dnu = Fr_HyperFin_Par *dred/pow(1.+zred,2.); // pour variation dNu
|
---|
| 1382 | double corr = sqrt(dnu/dnu_ref_) * pow(dlum/dlum_ref_,2.) * dtrc_ref_/dtrc;
|
---|
| 1383 | if(lp_>0 && (i==0 || i==nsz-1 || i%nszmod==0))
|
---|
| 1384 | cout<<"i="<<i<<" d="<<d<<" red="<<zred<<" dred="<<dred<<" dnu="<<dnu
|
---|
| 1385 | <<" dtrc="<<dtrc<<" dlum="<<dlum<<" -> cor="<<corr<<endl;
|
---|
| 1386 | correction.push_back(corr);
|
---|
| 1387 | }
|
---|
| 1388 | intercor = new InterpFunc(loscom2zred_min_,loscom2zred_max_,correction);
|
---|
| 1389 | }
|
---|
| 1390 |
|
---|
| 1391 | double corrlim[2] = {1.,1.};
|
---|
| 1392 | for(long i=0;i<Nx_;i++) {
|
---|
| 1393 | double dx2 = DXcom(i); dx2 *= dx2;
|
---|
| 1394 | for(long j=0;j<Ny_;j++) {
|
---|
| 1395 | double dy2 = DYcom(j); dy2 *= dy2;
|
---|
| 1396 | for(long l=0;l<Nz_;l++) {
|
---|
| 1397 | double corr = 1.;
|
---|
| 1398 | if(type_evol>0) {
|
---|
| 1399 | double dz = DZcom(l);
|
---|
| 1400 | if(type_evol==1) dz = sqrt(dx2+dy2+dz*dz);
|
---|
| 1401 | else dz = fabs(dz); // tous les plans Z au meme redshift
|
---|
| 1402 | corr = (*intercor)(dz);
|
---|
| 1403 | if(corr<corrlim[0]) corrlim[0]=corr; else if(corr>corrlim[1]) corrlim[1]=corr;
|
---|
| 1404 | }
|
---|
| 1405 | int_8 ip = IndexR(i,j,l);
|
---|
| 1406 | data_[ip] += snoise*corr*NorRand();
|
---|
| 1407 | }
|
---|
| 1408 | }
|
---|
| 1409 | }
|
---|
| 1410 | if(type_evol>0)
|
---|
| 1411 | cout<<"correction factor range: ["<<corrlim[0]<<","<<corrlim[1]<<"]"<<endl;
|
---|
| 1412 |
|
---|
| 1413 | if(intercor!=NULL) delete intercor;
|
---|
| 1414 | }
|
---|
| 1415 |
|
---|
| 1416 | } // Fin namespace SOPHYA
|
---|
| 1417 |
|
---|
| 1418 |
|
---|
| 1419 |
|
---|
| 1420 |
|
---|
| 1421 | /*********************************************************************
|
---|
[3199] | 1422 | void GeneFluct3D::AddAGN(double lfjy,double lsigma,double powlaw)
|
---|
[3196] | 1423 | // Add AGN flux into simulation:
|
---|
| 1424 | // --- Procedure:
|
---|
| 1425 | // 1. lancer "cmvdefsurv" avec les parametres du survey
|
---|
[3199] | 1426 | // (au redshift de reference du survey)
|
---|
[3196] | 1427 | // et recuperer l'angle solide "angsol sr" du pixel elementaire
|
---|
| 1428 | // au centre du cube.
|
---|
| 1429 | // 2. lancer "cmvtstagn" pour cet angle solide -> cmvtstagn.ppf
|
---|
| 1430 | // 3. regarder l'histo "hlfang" et en deduire un equivalent gaussienne
|
---|
| 1431 | // cad une moyenne <log10(S)> et un sigma "sig"
|
---|
[3199] | 1432 | // Attention: la distribution n'est pas gaussienne les "mean,sigma"
|
---|
| 1433 | // de l'histo ne sont pas vraiment ce que l'on veut
|
---|
[3196] | 1434 | // --- Limitations actuelle du code:
|
---|
[3271] | 1435 | // . les AGN sont supposes evoluer avec la meme loi de puissance pour tout theta,phi
|
---|
[3199] | 1436 | // . le flux des AGN est mis dans une colonne Oz (indice k) et pas sur la ligne de visee
|
---|
| 1437 | // . la distribution est approximee a une gaussienne
|
---|
| 1438 | // ... C'est une approximation pour un observateur loin du centre du cube
|
---|
| 1439 | // et pour un cube peu epais / distance observateur
|
---|
[3196] | 1440 | // --- Parametres de la routine:
|
---|
[3271] | 1441 | // llfy : c'est le <log10(S)> du flux depose par les AGN
|
---|
| 1442 | // dans l'angle solide du pixel elementaire de reference du cube
|
---|
| 1443 | // lsigma : c'est le sigma de la distribution des log10(S)
|
---|
| 1444 | // powlaw : c'est la pente de la distribution cad que le flux "lmsol"
|
---|
[3199] | 1445 | // et considere comme le flux a 1.4GHz et qu'on suppose une loi
|
---|
| 1446 | // F(nu) = (1.4GHz/nu)^powlaw * F(1.4GHz)
|
---|
[3196] | 1447 | // - Comme on est en echelle log10():
|
---|
| 1448 | // on tire log10(Msol) + X
|
---|
| 1449 | // ou X est une realisation sur une gaussienne de variance "sig^2"
|
---|
| 1450 | // La masse realisee est donc: Msol*10^X
|
---|
| 1451 | // - Pas de probleme de pixel negatif car on a une multiplication!
|
---|
| 1452 | {
|
---|
[3199] | 1453 | if(lp_>0) cout<<"--- AddAGN: <log10(S Jy)> = "<<lfjy<<" , sigma = "<<lsigma<<endl;
|
---|
[3196] | 1454 | check_array_alloc();
|
---|
| 1455 |
|
---|
[3271] | 1456 | if(cosmo_ == NULL || redsh_ref_<0.| loscom2zred_.size()<1) {
|
---|
[3199] | 1457 | char *bla = "GeneFluct3D::AddAGN_Error: set Observator and Cosmology first";
|
---|
| 1458 | cout<<bla<<endl; throw ParmError(bla);
|
---|
| 1459 | }
|
---|
[3196] | 1460 |
|
---|
[3271] | 1461 | // Le flux des AGN en Jy et en mass solaire
|
---|
| 1462 | double fagnref = pow(10.,lfjy)*(dnu_ref_*1.e9); // Jy.Hz = W/m^2
|
---|
| 1463 | double magnref = FluxHI2Msol(fagnref*Jansky2Watt_cst,dlum_ref_); // Msol
|
---|
| 1464 | if(lp_>0)
|
---|
| 1465 | cout<<"Au pixel de ref: fagnref="<<fagnref
|
---|
| 1466 | <<" Jy.Hz (a 1.4GHz), magnref="<<magnref<<" Msol"<<endl;
|
---|
[3196] | 1467 |
|
---|
[3199] | 1468 | if(powlaw!=0.) {
|
---|
[3271] | 1469 | // F(nu) = F(1.4GHz)*(nu GHz/1.4 Ghz)^p = F(1.4GHz)*(1/(1+z))^p , car nu = 1.4 GHz/(1+z)
|
---|
| 1470 | magnref *= pow(1/(1.+redsh_ref_),powlaw);
|
---|
[3199] | 1471 | if(lp_>0) cout<<" powlaw="<<powlaw<<" -> change magnref to "<<magnref<<" Msol"<<endl;
|
---|
| 1472 | }
|
---|
| 1473 |
|
---|
| 1474 | // Les infos en fonction de l'indice "l" selon Oz
|
---|
| 1475 | vector<double> correction;
|
---|
| 1476 | InterpFunc interpinv(loscom2zred_min_,loscom2zred_max_,loscom2zred_);
|
---|
[3271] | 1477 | long nzmod = ((Nz_>10)?Nz_/10:1);
|
---|
[3199] | 1478 | for(long l=0;l<Nz_;l++) {
|
---|
[3271] | 1479 | double z = fabs(DZcom(l));
|
---|
[3199] | 1480 | double zred = interpinv(z);
|
---|
[3271] | 1481 | double dtrc = cosmo_->Dtrcom(zred); // pour variation angle solide
|
---|
[3199] | 1482 | double dlum = cosmo_->Dlum(zred); // pour variation conversion mass HI
|
---|
| 1483 | double dred = Dz_/(cosmo_->Dhubble()/cosmo_->E(zred));
|
---|
| 1484 | double dnu = Fr_HyperFin_Par *dred/pow(1.+zred,2.); // pour variation dNu
|
---|
[3271] | 1485 | // on a: Mass ~ DNu * Dlum^2 / Dtrcom^2
|
---|
| 1486 | double corr = dnu/dnu_ref_*pow(dtrc_ref_/dtrc*dlum/dlum_ref_,2.);
|
---|
| 1487 | // F(nu) = F(1.4GHz)*(nu GHz/1.4 Ghz)^p = F(1.4GHz)*(1/(1+z))^p , car nu = 1.4 GHz/(1+z)
|
---|
| 1488 | if(powlaw!=0.) corr *= pow((1.+redsh_ref_)/(1.+zred),powlaw);
|
---|
[3199] | 1489 | correction.push_back(corr);
|
---|
[3271] | 1490 | if(lp_>0 && (l==0 || l==Nz_-1 || l%nzmod==0)) {
|
---|
| 1491 | cout<<"l="<<l<<" z="<<z<<" red="<<zred<<" dred="<<dred<<" dnu="<<dnu
|
---|
| 1492 | <<" dtrc="<<dtrc<<" dlum="<<dlum
|
---|
| 1493 | <<" -> cor="<<corr<<endl;
|
---|
[3199] | 1494 | }
|
---|
| 1495 | }
|
---|
| 1496 |
|
---|
| 1497 | double sum=0., sum2=0., nsum=0.;
|
---|
| 1498 | for(long i=0;i<Nx_;i++) for(long j=0;j<Ny_;j++) {
|
---|
| 1499 | double a = lsigma*NorRand();
|
---|
| 1500 | a = magnref*pow(10.,a);
|
---|
| 1501 | // On met le meme tirage le long de Oz (indice k)
|
---|
| 1502 | for(long l=0;l<Nz_;l++) {
|
---|
| 1503 | int_8 ip = IndexR(i,j,l);
|
---|
| 1504 | data_[ip] += a*correction[l];
|
---|
| 1505 | }
|
---|
| 1506 | sum += a; sum2 += a*a; nsum += 1.;
|
---|
| 1507 | }
|
---|
| 1508 |
|
---|
| 1509 | if(lp_>0 && nsum>1.) {
|
---|
[3196] | 1510 | sum /= nsum;
|
---|
| 1511 | sum2 = sum2/nsum - sum*sum;
|
---|
| 1512 | cout<<"...Mean mass="<<sum<<" Msol , s^2="<<sum2<<" s="<<sqrt(fabs(sum2))<<endl;
|
---|
| 1513 | }
|
---|
| 1514 |
|
---|
| 1515 | }
|
---|
[3349] | 1516 | *********************************************************************/
|
---|