Changeset 3821 in Sophya for trunk/Cosmo/SimLSS


Ignore:
Timestamp:
Jul 30, 2010, 12:35:57 PM (15 years ago)
Author:
cmv
Message:

type d'interpolation pour les spectres tabules, amelioration de cmvrvloscor.cc, cmv 30/07/2010

Location:
trunk/Cosmo/SimLSS
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/SimLSS/cmvginit3d.cc

    r3806 r3821  
    250250   pkzt->ReadCAMB(fn,h100tab,ztab);
    251251   pkzt->SetGrowthFactor(&growth);
     252   pkzt->SetInterpTyp(2);
    252253   pkzt->SetZ(zref);
    253254   pkz = pkzt;
  • trunk/Cosmo/SimLSS/cmvrvloscor.cc

    r3802 r3821  
    1919#include "genefluct3d.h"
    2020// set simul = 6_0p0_780
    21 // cmvrvloscorf -o rvlos_${simul}.ppf -K 75 -S ginit3d_${simul}_r.fits ginit3d_${simul}_rv.fits
    22 // cmvrvloscorf -o rvlos_${simul}.ppf -n 1,30 -K 75 -S -2 ginit3d_${simul}_r.fits ginit3d_${simul}_rv.fits
    23 // cmvrvloscorf -o rvlos_${simul}.ppf -n 1,30 -2 ginit3d_${simul}_r.fits ginit3d_${simul}_rv.fits
     21// cmvrvloscorf -o rvlos_${simul}.ppf -n 1,1 -z -1,0 -H 50 -2 -S 10000 -s 1. ginit3d_${simul}_r.fits ginit3d_${simul}_rv.fits
    2422
    2523void usage(void);
     
    2826cout
    2927<<"cmvrvloscor [options] rho.fits vlos.fits"<<endl
    30 <<"-n nplany,nhfill: process one Y plane every \"nplany\" (def:1(all))"<<endl
    31 <<"                  fill histos with \"nhfill\" los (def:25)"<<endl
    32 <<"-K npix: compute correlation R*V at +/- npix pixels (def: no)"<<endl
    33 <<"         (very time consuming!!!)"<<endl
    34 <<"-S: compute cross-power spectrum of V*conj(R) (def: no)"<<endl
     28<<"-n nplany,nplanx: process one Y (X) plane every \"nplany\" (\"nplanx\") (def:1,1(all))"<<endl
     29<<"-z nplanz,iplanz0: process only \"nplanz\" Z plane beginnig at plane \"iplanz0\" (def:all Z planes)"<<endl
     30<<"-H nhfill: fill displacement histo with \"nhfill\" los (def:25)"<<endl
     31<<"-s scaldis: scale the displacement by factor \"scaldis\" (def: 1.)"<<endl
     32<<"-p: do not distribute dRho/Rho in pixel, just take the nearest (def: no, distribute rho)"<<endl
     33<<"-S npkmax: compute cross-power spectrum of V*conj(R) with \"npkmax\" los (def: no)"<<endl
     34<<"-2: compute 2D projection for dRho and dRho(corrected) for 3 Y-Z plans (def=no)"<<endl
    3535<<"-N: do not create 3D cube and recompute 1D and 2D spectra (def: no do-it !)"<<endl
    36 <<"-p: do not distribute dRho/Rho in pixel, just take the nearest (def: no, distribute rho)"<<endl
    37 <<"-2: compute 2D projection fpr dRho and dRho(corrected) (def=no)"<<endl
    38 <<"-o: output ppf file name (def=\"cmvrvloscor.ppf\")"<<endl
     36<<"-o ppfout.ppf: output ppf file name (def=\"cmvrvloscor.ppf\")"<<endl
    3937<<endl;
    4038}
     
    4240int main(int narg,char *arg[])
    4341{
    44  int nthread = 1, nplany=1, nhfilllos = 25, npixcor = 0;
    45  bool docube=true, dopk = false, do2d = false, dodistrib=true;
     42 int nthread = 1, nplany=1, nplanx=1, nplanz=-1, iplanz0=0, nhfilllos = 25, npkmax = 0;
     43 double scaldis = 1.;
     44 bool docube=true, do2d = false, dodistrib=true;
    4645 string fnppf = "cmvrvloscor.ppf";
    4746 
    4847 // --- Decodage des arguments
    4948 char c;
    50  while((c = getopt(narg,arg,"hn:K:SNp2o:")) != -1) {
     49 while((c = getopt(narg,arg,"hn:H:S:Np2o:s:z:")) != -1) {
    5150  switch (c) {
    5251  case 'n' :
    53     sscanf(optarg,"%d,%d",&nplany,&nhfilllos);
     52    sscanf(optarg,"%d,%d",&nplany,&nplanx);
    5453    if(nplany<=0) nplany = 1;
     54    if(nplanx<=0) nplanx = 1;
     55    break;
     56  case 'z' :
     57    sscanf(optarg,"%d,%d",&nplanz,&iplanz0);
     58    break;
     59  case 'H' :
     60    nhfilllos = atoi(optarg);
    5561    if(nhfilllos<=0) nhfilllos = 0;
    5662    break;
    57   case 'K' :
    58     npixcor = atoi(optarg);
    59     break;
    6063  case 'S' :
    61     dopk = true;
     64    npkmax = atoi(optarg);
    6265    break;
    6366  case 'N' :
    6467    docube = false;
    6568    break;
     69  case 'p' :
     70    dodistrib = false;
     71    break;
    6672  case '2' :
    6773    do2d = true;
    6874    break;
    69   case 'p' :
    70     dodistrib = false;
    71     break;
    7275  case 'o' :
    7376    fnppf = optarg;
     77    break;
     78  case 's' :
     79    scaldis = atof(optarg);
    7480    break;
    7581  case 'h' :
     
    104110 cout<<"Zref="<<Zref<<" Href="<<Href<<endl;
    105111
    106  double dmin = min(Dx,min(Dy,Dz));
    107  long nmax = max(Nx,max(Ny,Nz));
    108  cout<<"dmin="<<dmin<<" nmax="<<nmax<<endl;
    109  Histo hmpc(-dmin*nmax/10.,dmin*nmax/10.,nmax);
    110 
    111112 POutPersist pos(fnppf.c_str());
    112  DVList dvlcor;
     113 DVList dvllos;
     114
     115 // --- Read and process data
     116 if(nplany>Ny || nplany<=0) nplany = Ny;
     117 if(nplanx>Nx || nplanx<=0) nplanx = Nx;
     118 cout<<"...Will read one Y plane every "<<nplany<<endl;
     119 cout<<"             one X plane every "<<nplanx<<endl;
     120 int nlospred = Nx*Ny/nplany/nplanx;
     121 cout<<"   predicted number of los to be read "<<nlospred<<endl;
     122 if(nplanz>Nz || nplanz<=0) nplanz = Nz;
     123 if(iplanz0<0)iplanz0 = 0;
     124 if(iplanz0>=Nz) {cout<<"Error: iplanz0="<<iplanz0<<" out of range"<<endl; return -2;}
     125 if(iplanz0+nplanz>Nz) nplanz = Nz - iplanz0;
     126 cout<<"   process "<<nplanz<<" Z planes in ["<<iplanz0<<","<<iplanz0+nplanz<<"["<<endl;
     127 TVector<r_4> V4read(Nz);
     128 TVector<r_4> R(nplanz), V(nplanz);
     129 TVector<r_8> Rdis(nplanz);
     130
     131 // --- Histo des deplacements
     132 Histo* hmpc = NULL;
     133 if(nhfilllos>0) {
     134   cout<<"...Fill Mpc displacement histo with "<<nhfilllos<<" los"<<endl;
     135   double dmin = min(Dx,min(Dy,Dz)); if(fabs(scaldis)>0.) dmin *= fabs(scaldis);
     136   long nmax = max(Nx,max(Ny,Nz));
     137   hmpc = new Histo(-dmin*nmax/10.,dmin*nmax/10.,nmax);
     138   cout<<"   dmin="<<dmin<<" nmax="<<nmax<<endl;
     139   nhfilllos = int((double)nlospred/nhfilllos + 0.5);
     140   if(nhfilllos<=0) nhfilllos = 1;
     141   cout<<"   -> fill one los every "<<nhfilllos<<endl;
     142 }
     143
     144 // --- Vector for PK cross-correlation computation
     145 if(npkmax<0) npkmax = Nx*Ny;
     146 TVector< complex<r_4> > FR, FV;
     147 TVector< complex<r_8> > pkvr, FRdis;
     148 TVector<r_8> pkr, pkrc;
     149 FFTWServer fftserv;
     150 fftserv.setNormalize(false); // pour accord avec GeneFluct3D
     151 if(npkmax>0) {
     152   cout<<"...compute R*conj(R) V*conj(V) V*conj(R) cross-power spectrum with "<<npkmax<<" los"<<endl;
     153   npkmax = int((double)nlospred/npkmax + 0.5);
     154   if(npkmax<=0) npkmax = 1;
     155   cout<<"   -> fill one los every "<<npkmax<<endl;
     156 }
     157 int npkav = 0;
     158 double dkzpk = 2.*M_PI/(nplanz*Dz);  // Mpc^-1
    113159
    114160 // --- Create a Cube for analysis
     
    117163 if(docube) {
    118164   cout<<"...Create and fill 3D cube"<<endl;
    119    fluct3d = new GeneFluct3D(Nx,Ny,Nz,Dx,Dy,Dz,nthread,2);
     165   fluct3d = new GeneFluct3D(Nx,Ny,nplanz,Dx,Dy,Dz,nthread,2);
    120166   fluct3d->Print();
    121167   rgen = &(fluct3d->GetRealArray());
     
    129175 }
    130176
    131  // --- Vector for real-space correlation computation
    132  int imil = Nz-1;
    133  dvlcor("imil") = (int_4)imil;
    134  TVector<int_4> nKsi;
    135  TVector<r_8> Ksirv, Ksirvc, Ksirr, Ksirrc;
    136  if(npixcor>0) {
    137    Ksirv.ReSize(2*Nz-1);  Ksirv  = 0.;
    138    Ksirvc.ReSize(2*Nz-1); Ksirvc = 0.;
    139    Ksirr.ReSize(2*Nz-1);  Ksirr  = 0.;
    140    Ksirrc.ReSize(2*Nz-1); Ksirrc = 0.;
    141    nKsi.ReSize(2*Nz-1);   nKsi   = 0;
    142    cout<<"...Compute R*V correlation on +/-"<<npixcor<<" px"<<endl;
    143  }
    144 
    145  // --- Vector for PK cross-correlation computation
    146  int npk = 0;
    147  TVector< complex<r_4> > FR, FV;
    148  TVector< complex<r_8> > pkvr, FRdis;
    149  TVector<r_8> pkr, pkrc;
    150  FFTWServer fftserv;
    151  if(dopk) cout<<"...compute V*conj(R) cross-power spectrum"<<endl;
    152 
    153  // --- Read and process data
    154  TVector<r_4> R(Nz), V(Nz);
    155  TVector<r_8> Rdis(Nz);
    156  if(nplany>Ny) nplany = Ny;
    157  cout<<"...Will read one Y plane every "<<nplany<<endl;
    158  if(nhfilllos) {
    159    cout<<"...Fill Mpc displacement histo with "<<nhfilllos<<" los"<<endl;
    160    nhfilllos = int((double)Nx*Ny/nplany/nhfilllos + 0.5);
    161    if(nhfilllos<=0) nhfilllos = 1;
    162    cout<<"   -> fill one los every "<<nhfilllos<<endl;
    163  }
    164 
    165  cout<<">>> filling redshift distorted cube"<<endl;
     177 // --- Do the jobs !!!
     178 cout<<">>> filling redshift distorted cube, scale displacement by "<<scaldis<<endl;
    166179 int nlosread = 0;
    167  for(int i=0;i<Nx;i++) {
    168    if(i%(Nx/10)==0) cout<<"   i="<<i<<endl;
     180 int lpri = nlospred/25; if(lpri==0) lpri = 1;
     181 for(int i=0;i<Nx;i+=nplanx) {
    169182   TMatrix<r_4> M2d, M2dv, M2dc;
    170183   if(do2d && (i==0 || i==Nx/2 || i==Nx-1)) {
    171      M2d.ReSize(Ny,Nz); M2d = 0.;
    172      M2dv.ReSize(Ny,Nz); M2dv = 0.;
    173      M2dc.ReSize(Ny,Nz); M2dc = 0.;
     184     M2d.ReSize(Ny,nplanz); M2d = 0.;
     185     M2dv.ReSize(Ny,nplanz); M2dv = 0.;
     186     M2dc.ReSize(Ny,nplanz); M2dc = 0.;
    174187   }
    175188 for(int j=0;j<Ny;j+=nplany) {
    176    bool fhis = false;
    177    if(nhfilllos) if(nlosread%nhfilllos==0) fhis = true;
    178    //for(int l=0;l<Nz;l++) R(l) = f3dr.Read(l,j,i);
    179    //for(int l=0;l<Nz;l++) V(l) = f3dv.Read(l,j,i);
    180    f3dr.Read(j,i,R);
    181    f3dv.Read(j,i,V);
     189   if(nlosread%lpri==0) cout<<"   nlosread="<<nlosread<<" (i="<<i<<",j="<<j<<")"<<endl;
     190   bool fhis = (hmpc != NULL && nlosread%nhfilllos==0) ? true: false;
     191   //for(int l=0;l<nplanz;l++) R(l) = f3dr.Read(iplanz0+l,j,i);
     192   //for(int l=0;l<nplanz;l++) V(l) = f3dv.Read(iplanz0+l,j,i);
     193   f3dr.Read(j,i,V4read);
     194     for(int l=0;l<nplanz;l++) R(l) = V4read(iplanz0+l);
     195   f3dv.Read(j,i,V4read);
     196     for(int l=0;l<nplanz;l++) V(l) = V4read(iplanz0+l);
    182197   Rdis = 0.;
    183198   // Calcul du champ R redshift distordu
    184    for(int l=0;l<Nz;l++) {
    185      double d = V(l) / Href;
    186      if(fhis) hmpc.Add(d);
     199   for(int l=0;l<nplanz;l++) {
     200     double d = scaldis * V(l) / Href;
     201     if(fhis) hmpc->Add(d);
    187202     double lpd = (double)l + d/Dz; // valeur du deplacee
    188203     if(dodistrib) {
     
    191206       long l2 = l1 + 1;  // pixel de droite
    192207       lpd -= (double)l1;  // recouvrement du pixel du dessus
    193        if(l1>=0 && l1<Nz) Rdis(l1) += R(l) * (1.-lpd);
    194        if(l2>=0 && l2<Nz) Rdis(l2) += R(l) * lpd;
     208       if(l1>=0 && l1<nplanz) Rdis(l1) += R(l) * (1.-lpd);
     209       if(l2>=0 && l2<nplanz) Rdis(l2) += R(l) * lpd;
    195210     } else { // take nearest pixel
    196211       long l1 = long(lpd + 0.5);
    197        if(l1>=0 && l1<Nz) Rdis(l1) += R(l);
     212       if(l1>=0 && l1<nplanz) Rdis(l1) += R(l);
    198213     }
    199214   }
    200215   // On remplit eventuellement les matrices 2D
    201216   if(do2d && M2d.Size()>0)
    202      for(int l=0;l<Nz;l++) {M2d(j,l) = R(l); M2dv(j,l) = V(l); M2dc(j,l) = Rdis(l);}
     217     for(int l=0;l<nplanz;l++) {M2d(j,l) = R(l); M2dv(j,l) = V(l); M2dc(j,l) = Rdis(l);}
    203218   // On remplit le cube avec le champ R redshift distordu
    204    if(fluct3d) for(int l=0;l<Nz;l++) (*rgen)(l,j,i) += Rdis(l);
    205    // Calcul eventuel de la fonction de correlation R*V
    206    if(npixcor>0) {
    207      for(long l1=0;l1<Nz;l1++) {
    208        for(long l2=max(0L,l1-npixcor);l2<min(Nz,l1+npixcor);l2++) {
    209          int lc = imil+(l2-l1);
    210          Ksirr(lc)  += R(l1)*R(l2);
    211          Ksirrc(lc) += Rdis(l1)*R(l2);
    212          Ksirv(lc)  += R(l1)*V(l2);
    213          Ksirvc(lc) += Rdis(l1)*V(l2);
    214          nKsi(lc)++;
    215        }
    216      }
    217    }
     219   if(fluct3d) for(int l=0;l<nplanz;l++) (*rgen)(l,j,i) += Rdis(l);
    218220   // Cross-power spectrum computation
    219    if(dopk) {
     221   if(npkmax>0 && nlosread%npkmax==0) {
    220222     fftserv.FFTForward(V,FV);
    221223     int nf = FV.Size();
    222224     if(pkvr.Size()<=0) {
    223        cout<<"...Create vector for cross-power spectrum computation"<<endl;
    224        pkvr.ReSize(nf); pkvr = complex<r_8>(0.);
     225       cout<<"...Create vector for cross-power spectrum computation sz="<<nf<<endl;
    225226       pkr.ReSize(nf);  pkr = 0.;
    226227       pkrc.ReSize(nf); pkrc = 0.;
     228       pkvr.ReSize(nf); pkvr = complex<r_8>(0.);
    227229     }
    228230     fftserv.FFTForward(R,FR);
     231     fftserv.FFTForward(Rdis,FRdis);
    229232     for(int l=0;l<nf;l++) {
     233       pkr(l)  += norm(FR(l));
     234       pkrc(l) += norm(FRdis(l));
    230235       pkvr(l) += FV(l)*conj(FR(l));
    231        pkr(l)  += norm(FR(l));
    232236     }
    233      fftserv.FFTForward(Rdis,FRdis);
    234      for(int l=0;l<nf;l++) pkrc(l) += norm(FRdis(l));
    235      npk++;
     237     npkav++;
    236238   }
    237239   nlosread++;
    238  }
     240 }   // fin boucle sur ny
    239241   if(do2d && M2d.Size()>0) {
    240242     char str[64];
     
    246248     pos.PutObject(M2dc,str);
    247249   }
    248  }
     250 }   // fin boucle sur nx
    249251
    250252 cout<<"Number of processed los: "<<nlosread<<" / "<<Nx*Ny<<endl;
    251  dvlcor("nlosread") = (int_4)nlosread;
    252  if(hmpc.NEntries()>0) {
    253    hmpc.Show();
    254    pos.PutObject(hmpc,"hmpc");
    255  }
    256  if(Ksirr.Size()>0) {
    257    for(int l=0;l<Ksirr.Size();l++) if(nKsi(l)>0) {
    258        Ksirr(l)  /= nKsi(l);
    259        Ksirrc(l) /= nKsi(l);
    260        Ksirv(l)  /= nKsi(l);
    261        Ksirvc(l) /= nKsi(l);
    262      }
    263    pos.PutObject(Ksirr,"ksirr");
    264    pos.PutObject(Ksirrc,"ksirrc");
    265    pos.PutObject(Ksirv,"ksirv");
    266    pos.PutObject(Ksirvc,"ksirvc");
    267    pos.PutObject(nKsi,"nksi");
    268  }
    269  if(npk>0) {
    270    pkvr /= (double)npk;
    271    pkr  /= (double)npk;
    272    pkrc /= (double)npk;
    273    pos.PutObject(pkvr,"pkvr");
     253 if(hmpc != NULL) {
     254   hmpc->Show();
     255   if(hmpc->NEntries()>0) pos.PutObject(*hmpc,"hmpc");
     256 }
     257 if(npkav>0) {
     258   double nn = Dx*Dy*Dz/double(nplanz)/double(npkav); // moyenne + normalisation / hpkrec
     259   cout<<"Number of averaged spectra: npkav="<<npkav<<" norm="<<nn<<endl;
     260   pkr  *= nn;
     261   pkrc *= nn;
     262   pkvr *= nn;
    274263   pos.PutObject(pkr,"pkr");
    275264   pos.PutObject(pkrc,"pkrc");
     265   pos.PutObject(pkvr,"pkvr");
    276266 }
    277267 PrtTim(">>>> End filling redshift distorted cube");
     
    310300
    311301 // --- end of job, write objects in ppf
    312  pos.PutObject(dvlcor,"dvlcor");
    313  if(fluct3d) delete fluct3d;
     302 dvllos("nlosread") = (int_4)nlosread;
     303 dvllos("nlospred") = (int_4)nlospred;
     304 dvllos("Nx") = (int_4)Nx;
     305 dvllos("Ny") = (int_4)Ny;
     306 dvllos("Nz") = (int_4)Nz;
     307 dvllos("Dx") = (r_8)Dx;
     308 dvllos("Dy") = (r_8)Dy;
     309 dvllos("Dz") = (r_8)Dz;
     310 dvllos("nplanz") = (int_4)nplanz;
     311 dvllos("iplanz0") = (int_4)iplanz0;
     312 dvllos("nplany") = (int_4)nplany;
     313 dvllos("nplanx") = (int_4)nplanx;
     314 dvllos("npkav") = (int_4)npkav;
     315 dvllos("dkzpk") = (r_8)dkzpk;
     316 pos.PutObject(dvllos,"dvllos");
     317 if(fluct3d != NULL) delete fluct3d;
     318 if(hmpc != NULL) delete hmpc;
    314319
    315320 //----TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH
     
    334339openppf cmvrvloscor.ppf
    335340
     341c++exec dvllos.Print();
     342set dkz ${dvllos.dkzpk}
     343
    336344disp hmpc
    337345
    338 # cross-correlation
    339 disp nksi
    340 set imil ${dvlcor.imil}
    341 n/plot ksirv.val%n-${imil} ! ! "nsta cpts"
    342 n/plot ksirvc.val%n-${imil} ! ! "nsta cpts same red"
    343 
    344 n/plot ksirr.val%n-${imil} ! ! "nsta cpts"
    345 n/plot ksirrc.val%n-${imil} ! ! "nsta cpts same red"
    346 
    347346# cross-power spectrum
    348 n/plot pkr.val%n ! ! "nsta cpts logx"
    349 n/plot pkrc.val%n ! ! "nsta cpts logx same red"
    350 
    351 n/plot pkvr.val%n ! ! "nsta cpts logx"
     347n/plot pkr.val%n*${dkz} n>0&&val>0 ! "nsta cpts logx logy"
     348n/plot pkrc.val%n*${dkz} n>0&&val>0 ! "nsta cpts logx logy same red"
     349
     350n/plot pkvr.val%n*${dkz} n>0&&val>0 ! "nsta cpts logx logy"
    352351
    353352# reconstructed 1D power spectrum
    354 n/plot hpkrec.val%x x>0 ! "nsta cpts logx"
     353n/plot hpkrec.val%x x>0&&val>0 ! "nsta cpts logx logy"
    355354
    356355# reconstructed 2D power spectrum
  • trunk/Cosmo/SimLSS/cmvtstpk.cc

    r3805 r3821  
    114114   pkcamb = new PkTabulate;
    115115   pkcamb->ReadCAMB(fcmbfile,h100,0.);
    116    pkcamb->SetInterpTyp(1);
     116   pkcamb->SetInterpTyp(2);
    117117   if(pkcamb->NPoints()==0) {delete pkcamb; pkcamb = NULL;}
    118118 }
Note: See TracChangeset for help on using the changeset viewer.