Changeset 3821 in Sophya for trunk/Cosmo
- Timestamp:
- Jul 30, 2010, 12:35:57 PM (15 years ago)
- Location:
- trunk/Cosmo/SimLSS
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/cmvginit3d.cc
r3806 r3821 250 250 pkzt->ReadCAMB(fn,h100tab,ztab); 251 251 pkzt->SetGrowthFactor(&growth); 252 pkzt->SetInterpTyp(2); 252 253 pkzt->SetZ(zref); 253 254 pkz = pkzt; -
trunk/Cosmo/SimLSS/cmvrvloscor.cc
r3802 r3821 19 19 #include "genefluct3d.h" 20 20 // 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 24 22 25 23 void usage(void); … … 28 26 cout 29 27 <<"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 35 35 <<"-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 39 37 <<endl; 40 38 } … … 42 40 int main(int narg,char *arg[]) 43 41 { 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; 46 45 string fnppf = "cmvrvloscor.ppf"; 47 46 48 47 // --- Decodage des arguments 49 48 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) { 51 50 switch (c) { 52 51 case 'n' : 53 sscanf(optarg,"%d,%d",&nplany,&n hfilllos);52 sscanf(optarg,"%d,%d",&nplany,&nplanx); 54 53 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); 55 61 if(nhfilllos<=0) nhfilllos = 0; 56 62 break; 57 case 'K' :58 npixcor = atoi(optarg);59 break;60 63 case 'S' : 61 dopk = true;64 npkmax = atoi(optarg); 62 65 break; 63 66 case 'N' : 64 67 docube = false; 65 68 break; 69 case 'p' : 70 dodistrib = false; 71 break; 66 72 case '2' : 67 73 do2d = true; 68 74 break; 69 case 'p' :70 dodistrib = false;71 break;72 75 case 'o' : 73 76 fnppf = optarg; 77 break; 78 case 's' : 79 scaldis = atof(optarg); 74 80 break; 75 81 case 'h' : … … 104 110 cout<<"Zref="<<Zref<<" Href="<<Href<<endl; 105 111 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 111 112 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 113 159 114 160 // --- Create a Cube for analysis … … 117 163 if(docube) { 118 164 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); 120 166 fluct3d->Print(); 121 167 rgen = &(fluct3d->GetRealArray()); … … 129 175 } 130 176 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; 166 179 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) { 169 182 TMatrix<r_4> M2d, M2dv, M2dc; 170 183 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.; 174 187 } 175 188 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); 182 197 Rdis = 0.; 183 198 // 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); 187 202 double lpd = (double)l + d/Dz; // valeur du deplacee 188 203 if(dodistrib) { … … 191 206 long l2 = l1 + 1; // pixel de droite 192 207 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; 195 210 } else { // take nearest pixel 196 211 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); 198 213 } 199 214 } 200 215 // On remplit eventuellement les matrices 2D 201 216 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);} 203 218 // 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); 218 220 // Cross-power spectrum computation 219 if( dopk) {221 if(npkmax>0 && nlosread%npkmax==0) { 220 222 fftserv.FFTForward(V,FV); 221 223 int nf = FV.Size(); 222 224 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; 225 226 pkr.ReSize(nf); pkr = 0.; 226 227 pkrc.ReSize(nf); pkrc = 0.; 228 pkvr.ReSize(nf); pkvr = complex<r_8>(0.); 227 229 } 228 230 fftserv.FFTForward(R,FR); 231 fftserv.FFTForward(Rdis,FRdis); 229 232 for(int l=0;l<nf;l++) { 233 pkr(l) += norm(FR(l)); 234 pkrc(l) += norm(FRdis(l)); 230 235 pkvr(l) += FV(l)*conj(FR(l)); 231 pkr(l) += norm(FR(l));232 236 } 233 fftserv.FFTForward(Rdis,FRdis); 234 for(int l=0;l<nf;l++) pkrc(l) += norm(FRdis(l)); 235 npk++; 237 npkav++; 236 238 } 237 239 nlosread++; 238 } 240 } // fin boucle sur ny 239 241 if(do2d && M2d.Size()>0) { 240 242 char str[64]; … … 246 248 pos.PutObject(M2dc,str); 247 249 } 248 } 250 } // fin boucle sur nx 249 251 250 252 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; 274 263 pos.PutObject(pkr,"pkr"); 275 264 pos.PutObject(pkrc,"pkrc"); 265 pos.PutObject(pkvr,"pkvr"); 276 266 } 277 267 PrtTim(">>>> End filling redshift distorted cube"); … … 310 300 311 301 // --- 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; 314 319 315 320 //----TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH-TRY-CATCH … … 334 339 openppf cmvrvloscor.ppf 335 340 341 c++exec dvllos.Print(); 342 set dkz ${dvllos.dkzpk} 343 336 344 disp hmpc 337 345 338 # cross-correlation339 disp nksi340 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 347 346 # cross-power spectrum 348 n/plot pkr.val%n ! ! "nsta cpts logx"349 n/plot pkrc.val%n ! ! "nsta cpts logxsame red"350 351 n/plot pkvr.val%n ! ! "nsta cpts logx"347 n/plot pkr.val%n*${dkz} n>0&&val>0 ! "nsta cpts logx logy" 348 n/plot pkrc.val%n*${dkz} n>0&&val>0 ! "nsta cpts logx logy same red" 349 350 n/plot pkvr.val%n*${dkz} n>0&&val>0 ! "nsta cpts logx logy" 352 351 353 352 # reconstructed 1D power spectrum 354 n/plot hpkrec.val%x x>0 ! "nsta cpts logx"353 n/plot hpkrec.val%x x>0&&val>0 ! "nsta cpts logx logy" 355 354 356 355 # reconstructed 2D power spectrum -
trunk/Cosmo/SimLSS/cmvtstpk.cc
r3805 r3821 114 114 pkcamb = new PkTabulate; 115 115 pkcamb->ReadCAMB(fcmbfile,h100,0.); 116 pkcamb->SetInterpTyp( 1);116 pkcamb->SetInterpTyp(2); 117 117 if(pkcamb->NPoints()==0) {delete pkcamb; pkcamb = NULL;} 118 118 }
Note:
See TracChangeset
for help on using the changeset viewer.