- Timestamp:
- Oct 17, 2011, 10:56:41 AM (14 years ago)
- Location:
- trunk/Cosmo/RadioBeam
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/RadioBeam/pknoise.cc
r4026 r4027 6 6 7 7 Usage: pknoise pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName 8 -parname : -noise , -renmax , -scut , -ngen , -z , -bsize , -cszmpc ,-prt8 -parname : -noise , -renmax, -scut, -ngen, -z, -bsize, -cszmpc, -nbin -prt 9 9 --------------------------------------------------------------- */ 10 10 … … 30 30 #include "timing.h" 31 31 #include "ctimer.h" 32 #include "slininterp.h" 32 33 33 34 typedef DR48RandGen RandomGenerator ; … … 47 48 << " NGen=-1 -> Call ComputeNoisePk(), dont change Four3DPk cell size \n" 48 49 << " -bsize sx,sy,sz : 3D real space box size (default=512x512x256) \n" 49 << " -cszmpc sx,sy,sz : 3D real space box cell size in Mpc (default=3x3x 3) \n"50 << " -z z,dA,H_z : redshift,ComovDist(z),H(z) (default=1.0,3330,120.5) \n"50 << " -cszmpc sx,sy,sz : 3D real space box cell size in Mpc (default=3x3x1.5) \n" 51 << " -z redshift : redshift (default=1.0) \n" 51 52 << " -scut SCutValue (default= -100.) \n" 52 53 << " if SCutValue<0. ==> SCut=MinNoisePower*(-SCutValue) \n" 53 << " -prt PrtLev,PrtModulo (default=0,10) " << endl; 54 << " -prt PrtLev,PrtModulo (default=0,10) \n" 55 << " -nbin PkNBin : nomber of histogram bins for Pnoise(k) (default= 256) \n" 56 << " NOTE : this program needs redshift_da.txt andredshift_Hz.txt files" << endl; 54 57 return; 55 58 } … … 87 90 double H_z=120.5; // Hubble_param(z) 88 91 int box3dsz[3]={512,512,256}; 89 double cellsz[3]={3. 5,3.5,3.5};90 92 double cellsz[3]={3.,3.,1.5}; 93 int NBINPK=256; 91 94 int prtlev=0; 92 95 int prtmod=10; … … 109 112 } 110 113 else if (strcmp(arg[ka],"-z")==0) { 111 sscanf(arg[ka+1],"%lg,%lg,%lg",&z_Redshift,&comov_dA_z,&H_z); ka+=2;114 z_Redshift=atof(arg[ka+1]); ka+=2; 112 115 } 113 116 else if (strcmp(arg[ka],"-bsize")==0) { … … 116 119 else if (strcmp(arg[ka],"-cszmpc")==0) { 117 120 sscanf(arg[ka+1],"%lg,%lg,%lg",cellsz,cellsz+1,cellsz+2); ka+=2; 121 } 122 else if (strcmp(arg[ka],"-nbin")==0) { 123 NBINPK=atoi(arg[ka+1]); ka+=2; 118 124 } 119 125 else if (strcmp(arg[ka],"-prt")==0) { … … 147 153 cout << " pknoise[0] : Executing, output file= " << outfile << endl; 148 154 POutPersist po(outfile); 155 156 cout << " pknoise[0.b] : Creating interpolating objects from redshift_da.txt and redshift_Hz.txt " << endl; 157 SLinInterp1D redshift2da; 158 string interpfilename="redshift_da.txt"; 159 redshift2da.ReadXYFromFile(interpfilename); 160 SLinInterp1D redshift2hz; 161 interpfilename="redshift_hz.txt"; 162 redshift2hz.ReadXYFromFile(interpfilename); 163 comov_dA_z=redshift2da(z_Redshift); 164 H_z=redshift2hz(z_Redshift); 165 cout << " Redshift= " << z_Redshift << " -> ComovdA= " << comov_dA_z 166 << " Mpc H(z)= " << H_z << " km/s/Mpc " << endl; 149 167 150 168 H21Conversions conv; … … 184 202 RandomGenerator rg; 185 203 204 double dfreq=H_z*cellsz[2]/(1+z_Redshift)/lambda/1000.; 205 double freq0=conv.getFrequency()-dfreq*box3dsz[2]/2; 206 186 207 double dkxmpc=2.*DeuxPI; 187 208 double dkympc=2.*DeuxPI; 188 209 double dkzmpc=2.*DeuxPI; 189 210 double angscale=1.; 211 Vector angscales(box3dsz[2]); 212 angscales=angscale; 190 213 if (NMAX<0) { box3dsz[0]=256; box3dsz[1]=256; box3dsz[3]=128; } 191 214 else { 192 215 angscale=comov_dA_z; 216 for(int kz=0; kz<box3dsz[2]; kz++) angscales(kz)=redshift2da(1420.4/(freq0+(double)kz*dfreq)-1.); 193 217 dkxmpc = DeuxPI/(double)box3dsz[0]/cellsz[0]; 194 218 dkympc = DeuxPI/(double)box3dsz[1]/cellsz[1]; 195 219 dkzmpc = DeuxPI/(double)box3dsz[2]/cellsz[2]; 196 220 } 197 cout << " pknoise[2.b]: ComovDist" << comov_dA_z << " Mpc H(z)=" << H_z << " Mpc/km/s -> angscale=" << angscale << endl; 198 cout << " pknoise[2.c]: Four3DPk m3d(rg," << box3dsz[0]/2 << "," << box3dsz[1] << "," 221 cout << " pknoise[2.b]: ComovDist=" << comov_dA_z << " Mpc H(z)=" << H_z << " Mpc/km/s -> angscale=" << angscale << endl; 222 cout << " pknoise[2.c]: Freq0=" << freq0 << " dFreq=" << dfreq << " freq(z=" << z_Redshift << ")=" 223 << conv.getFrequency() << " zmin=" << 1420.4/freq0-1. << " zmax=" << 1420.4/(freq0+box3dsz[2]*dfreq)-1. << endl; 224 cout << " pknoise[2.d]: Four3DPk m3d(rg," << box3dsz[0]/2 << "," << box3dsz[1] << "," 199 225 << box3dsz[2] << ")" << endl; 200 226 Four3DPk m3d(rg,box3dsz[0]/2,box3dsz[1],box3dsz[2]); … … 203 229 m3d.SetPrtLevel(prtlev,prtmod); 204 230 205 cout << " pknoise[3]: Computing Noise P(k) using PkNoiseCalculator ..." << endl;206 231 if (NMAX>0) { 232 cout << " pknoise[3]: Computing Noise P(k) using PkNoiseCalculator ..." << endl; 207 233 PkNoiseCalculator pkn(m3d, *(arep_p), SCut, NMAX, tits.c_str()); 208 double dfreq=H_z*cellsz[2]/(1+z_Redshift)/lambda/1000.;209 double freq0=conv.getFrequency()-dfreq*box3dsz[2]/2;210 cout << " pknoise[3.b]: Freq0=" << freq0 << " dFreq=" << dfreq << " freq(z=" << z_Redshift << ")="211 << conv.getFrequency() << " AngScale=" << angscale << endl;212 234 pkn.SetFreqRange(freq0, dfreq); 213 pkn.SetAngScaleConversion(angscale );235 pkn.SetAngScaleConversion(angscales); 214 236 pkn.SetPrtLevel(prtlev,prtmod); 215 HProf hpn = pkn.Compute(); 216 cout << " pknoise[3.c]: writing hpn noise profile to " << outfile << endl; 217 po << hpn; 237 HProf hpn = pkn.Compute(NBINPK); 218 238 } 219 239 else { 220 Histo fracmodok; 221 DataTable dtnoise; 222 HProf hpn = m3d.ComputeNoisePk(*(arep_p),fracmodok,dtnoise,angscale,SCut); 223 HProf h1dnoise=arep_p->GetProjNoiseLevel(); 224 HProf h1drep=arep_p->GetProjResponse(); 225 cout << " pknoise[3.b]: writing dtnoise,hpn,h2rep... with tags to " << outfile << endl; 226 po << PPFNameTag("dtnoise") << dtnoise; 227 po << PPFNameTag("hpnoise") << hpn; 228 po << PPFNameTag("fracmodok") << fracmodok; 229 po << PPFNameTag("h1dnoise") << h1dnoise; 230 po << PPFNameTag("h1drep") << h1drep; 231 po << PPFNameTag("h2drep") << h2drep; 232 } 240 cout << " pknoise[3]: Computing Noise P(k) m3d.ComputeNoisePk(...) " << endl; 241 HProf hpn = m3d.ComputeNoisePk(*(arep_p),angscale,SCut,NBINPK); 242 } 243 244 HProf hpnoise=m3d.GetPk(); 245 DataTable dtnoise; 246 Histo fracmodok=m3d.FillPkDataTable(dtnoise); 247 HProf h1dnoise=arep_p->GetProjNoiseLevel(); 248 HProf h1drep=arep_p->GetProjResponse(); 249 cout << " pknoise[3.b]: writing dtnoise,hpn,h2rep... with tags to " << outfile << endl; 250 po << PPFNameTag("dtnoise") << dtnoise; 251 po << PPFNameTag("hpnoise") << hpnoise; 252 po << PPFNameTag("fracmodok") << fracmodok; 253 po << PPFNameTag("h1dnoise") << h1dnoise; 254 po << PPFNameTag("h1drep") << h1drep; 255 po << PPFNameTag("h2drep") << h2drep; 256 233 257 rc = 0; 234 258 } // End of try bloc -
trunk/Cosmo/RadioBeam/radutil.h
r3947 r4027 53 53 54 54 static double SpeedOfLight_Cst; // Speed of light m/sec 55 static double Freq021cm_Cst; // Speed of light m/sec55 static double Freq021cm_Cst; // 21 cm transition frequency in MHz 56 56 static double k_Boltzman_Cst; // Boltzmann constant (SI Units) 57 57 -
trunk/Cosmo/RadioBeam/specpk.cc
r4026 r4027 127 127 SetPrtLevel(); 128 128 SetCellSize(); 129 hp_pk_p_=NULL; hmcnt_p_=NULL; hmcntok_p_=NULL; s2cut_=0.; 129 130 } 130 131 // Constructor … … 134 135 SetPrtLevel(); 135 136 SetCellSize(); 136 } 137 137 hp_pk_p_=NULL; hmcnt_p_=NULL; hmcntok_p_=NULL; s2cut_=0.; 138 } 139 140 // Destructor 141 Four3DPk::~Four3DPk() 142 { 143 if (hp_pk_p_) delete hp_pk_p_; 144 if (hmcnt_p_) delete hmcnt_p_; 145 if (hmcntok_p_) delete hmcntok_p_; 146 } 138 147 139 148 // Generate mass field Fourier Coefficient … … 200 209 201 210 // Generate mass field Fourier Coefficient 202 void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, double angscale)211 void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, Vector& angscales) 203 212 // angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers 204 213 // typically = ComovRadialDistance 205 214 { 215 if (angscales.Size() != fourAmp.SizeZ()) 216 throw SzMismatchError("ComputeNoiseFourierAmp(): angscales.Size()!=fourAmp.SizeZ()"); 206 217 H21Conversions conv; 207 218 // fourAmp represent 3-D fourier transform of a real input array. … … 212 223 conv.setFrequency(f0+kz*df); 213 224 resp.setLambda(conv.getLambda()); 225 double angsc=angscales(kz); 226 if (prtlev_>2) 227 cout << " Four3DPk::ComputeNoiseFourierAmp(...) - freq=" << f0+kz*df << " -> AngSc=" << angsc << endl; 214 228 for(sa_size_t ky=0; ky<fourAmp.SizeY(); ky++) { 215 229 kyy = (ky>fourAmp.SizeY()/2) ? -(double)(fourAmp.SizeY()-ky)*dky_ : (double)ky*dky_; 216 230 for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) { 217 231 kxx=(double)kx*dkx_; 218 rep = resp(kxx*angsc ale, kyy*angscale);219 if (rep<1.e- 8) fourAmp(kx, ky, kz) = complex<TF>(9.e9,0.);232 rep = resp(kxx*angsc, kyy*angsc); 233 if (rep<1.e-19) fourAmp(kx, ky, kz) = complex<TF>(9.e19,0.); 220 234 else { 221 235 amp = 1./sqrt(rep)/sqrt(2.); … … 264 278 // cells with amp^2=re^2+im^2>s2cut are ignored 265 279 // Output : power spectrum (profile histogram) 266 HProf Four3DPk::ComputePk(double s2cut, int nbin, double kmin, double kmax )280 HProf Four3DPk::ComputePk(double s2cut, int nbin, double kmin, double kmax, bool fgmodcnt) 267 281 { 268 282 // The second half of the array along Y (matrix rows) contain … … 279 293 kmax=sqrt(maxx*maxx+maxy*maxy+maxz*maxz); 280 294 } 281 if (nbin<2) nbin=128; 282 HProf hp(kmin, kmax, nbin); 283 hp.SetErrOpt(false); 284 ComputePkCumul(hp, s2cut); 285 return hp; 295 if (nbin<2) nbin=256; 296 hp_pk_p_ = new HProf(kmin, kmax, nbin); 297 hp_pk_p_->SetErrOpt(false); 298 if (fgmodcnt) { 299 hmcnt_p_ = new Histo(kmin, kmax, nbin); 300 hmcntok_p_ = new Histo(kmin, kmax, nbin); 301 } 302 s2cut_=s2cut; 303 ComputePkCumul(); 304 return *hp_pk_p_; 286 305 } 287 306 288 307 // Compute power spectrum as a function of wave number k 289 308 // Cumul dans hp - cells with amp^2=re^2+im^2>s2cut are ignored 290 void Four3DPk::ComputePkCumul( HProf& hp, double s2cut)309 void Four3DPk::ComputePkCumul() 291 310 { 292 311 uint_8 nmodeok=0; … … 303 322 double kxx=(double)kx*dkx_; 304 323 complex<TF> za = fourAmp(kx, ky, kz); 305 if (za.real()>8.e9) continue;324 // if (za.real()>8.e19) continue; 306 325 double wk = sqrt(kxx*kxx+kyy*kyy+kzz*kzz); 307 326 double amp2 = za.real()*za.real()+za.imag()*za.imag(); 308 if ((s2cut>1.e-9)&&(amp2>s2cut)) continue; 309 hp.Add(wk, amp2); 327 if (hmcnt_p_) hmcnt_p_->Add(wk); 328 if ((s2cut_>1.e-9)&&(amp2>s2cut_)) continue; 329 if (hmcntok_p_) hmcntok_p_->Add(wk); 330 hp_pk_p_->Add(wk, amp2); 310 331 nmodeok++; 311 332 } 312 333 } 313 334 } 314 if ((prtlev_>1)||((prtlev_>0)&&(s2cut >1.e-9))) {335 if ((prtlev_>1)||((prtlev_>0)&&(s2cut_>1.e-9))) { 315 336 cout << " Four3DPk::ComputePkCumul/Info : NModeOK=" << nmodeok << " / NMode=" << fourAmp.Size() 316 337 << " -> " << 100.*(double)nmodeok/(double)fourAmp.Size() << "%" << endl; … … 325 346 // angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers 326 347 // typically = ComovRadialDistance 327 HProf Four3DPk::ComputeNoisePk(Four2DResponse& resp, Histo& fracmodok, DataTable& dt, 328 double angscale, double s2cut, int nbin, double kmin, double kmax) 348 HProf Four3DPk::ComputeNoisePk(Four2DResponse& resp, double angscale, double s2cut, int nbin, double kmin, double kmax) 329 349 { 330 350 // The second half of the array along Y (matrix rows) contain … … 341 361 kmax=sqrt(maxx*maxx+maxy*maxy+maxz*maxz); 342 362 } 343 if (nbin<2) nbin=128; 344 HProf hp(kmin, kmax, nbin); 345 hp.SetErrOpt(false); 346 Histo hmcnt(kmin, kmax, nbin); 347 Histo hmcntok(kmin, kmax, nbin); 363 if (nbin<2) nbin=256; 364 hp_pk_p_ = new HProf(kmin, kmax, nbin); 365 hp_pk_p_->SetErrOpt(false); 366 hmcnt_p_ = new Histo(kmin, kmax, nbin); 367 hmcntok_p_ = new Histo(kmin, kmax, nbin); 368 s2cut_=s2cut; 348 369 349 370 uint_8 nmodeok=0; … … 362 383 double rep=resp(kxx*angscale, kyy*angscale); 363 384 double amp2 = (rep>1.e-19)?1./rep:1.e19; 364 hmcnt .Add(wk);365 if ((s2cut >1.e-9)&&(amp2>s2cut)) continue;366 hmcntok .Add(wk);367 hp .Add(wk, amp2);385 hmcnt_p_->Add(wk); 386 if ((s2cut_>1.e-9)&&(amp2>s2cut_)) continue; 387 hmcntok_p_->Add(wk); 388 hp_pk_p_->Add(wk, amp2); 368 389 nmodeok++; 369 390 } … … 375 396 } 376 397 377 fracmodok=hmcntok/hmcnt; 378 398 return *hp_pk_p_; 399 } 400 401 // Fills a data table from the computed P(k) profile histogram and mode count 402 Histo Four3DPk::FillPkDataTable(DataTable& dt) 403 { 404 if (hp_pk_p_==NULL) throw ParmError("Four3DPk::FillPkDataTable P(k) NOT computed"); 405 if ((hmcnt_p_==NULL)||(hmcntok_p_==NULL)) throw ParmError("Four3DPk::FillPkDataTable Mode count histos NOT filled"); 406 HProf& hp=(*hp_pk_p_); 407 Histo& hmcnt=(*hmcnt_p_); 408 Histo& hmcntok=(*hmcntok_p_); 409 Histo fracmodok=hmcntok/hmcnt; 379 410 char* nomcol[5] = {"k","pnoise","nmode","nmodok","fracmodok"}; 380 411 dt.Clear(); … … 393 424 dt.AddRow(dtr); 394 425 } 395 return hp;426 return fracmodok; 396 427 } 397 428 … … 403 434 PkNoiseCalculator::PkNoiseCalculator(Four3DPk& pk3, Four2DResponse& rep, double s2cut, int ngen, 404 435 const char* tit) 405 : pkn3d(pk3), frep(rep), S2CUT(s2cut), NGEN(ngen), title(tit) 436 : pkn3d(pk3), frep(rep), S2CUT(s2cut), NGEN(ngen), title(tit), angscales_(pk3.SizeZ()) 406 437 { 407 438 SetFreqRange(); … … 410 441 } 411 442 412 HProf PkNoiseCalculator::Compute( )443 HProf PkNoiseCalculator::Compute(int nbin, double kmin, double kmax) 413 444 { 414 445 Timer tm(title.c_str()); … … 416 447 HProf hnd; 417 448 cout << "PkNoiseCalculator::Compute() " << title << " NGEN=" << NGEN << " S2CUT=" << S2CUT 418 << " Freq0=" << freq0_ << " dFreq=" << dfreq_ << " angscale=" << angscale_ << endl; 449 << " Freq0=" << freq0_ << " dFreq=" << dfreq_ << " angscales=" << angscales_(0) 450 << " ... " << angscales_(angscales_.Size()-1) << endl; 419 451 for(int igen=0; igen<NGEN; igen++) { 420 pkn3d.ComputeNoiseFourierAmp(frep, freq0_, dfreq_, angscale _);421 if (igen==0) hnd = pkn3d.ComputePk(S2CUT );422 else pkn3d.ComputePkCumul( hnd,S2CUT);452 pkn3d.ComputeNoiseFourierAmp(frep, freq0_, dfreq_, angscales_); 453 if (igen==0) hnd = pkn3d.ComputePk(S2CUT,nbin,kmin,kmax,true); 454 else pkn3d.ComputePkCumul(); 423 455 if ((prtlev_>0)&&(igen>0)&&(((igen-1)%prtmodulo_)==0)) 424 456 cout << " PkNoiseCalculator::Compute() - done igen=" << igen << " / MaxNGen=" << NGEN << endl; 425 457 } 426 return hnd;458 return pkn3d.GetPk() ; 427 459 } 428 460 -
trunk/Cosmo/RadioBeam/specpk.h
r4026 r4027 46 46 Four3DPk(TArray< complex<TF> > & fourcoedd, RandomGeneratorInterface& rg); 47 47 Four3DPk(RandomGeneratorInterface& rg, sa_size_t szx=128, sa_size_t szy=256, sa_size_t szz=128); 48 virtual ~Four3DPk(); 49 48 50 inline void SetCellSize(double dkx=DeuxPI, double dky=DeuxPI, double dkz=DeuxPI) 49 51 { dkx_=dkx; dky_=dky; dkz_=dkz; } … … 54 56 // typically = ComovRadialDistance 55 57 void ComputeNoiseFourierAmp(Four2DResponse& resp, double angscale=1., bool crmask=false); 56 void ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, double angscale=1.);58 void ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, Vector& angscales); 57 59 58 60 // Return the array size 59 61 inline sa_size_t NCells() { return fourAmp.Size(); } 62 inline sa_size_t SizeX() { return fourAmp.SizeX(); } 63 inline sa_size_t SizeY() { return fourAmp.SizeY(); } 64 inline sa_size_t SizeZ() { return fourAmp.SizeZ(); } 65 60 66 // Set the cell size/step in Fourier Space 61 67 // Return the fourier amplitude matrix … … 66 72 67 73 // Return the reconstructed power spectrum as a profile histogram 68 HProf ComputePk(double s2cut=0., int nbin=256, double kmin=0., double kmax=-1. );69 void ComputePkCumul( HProf& hp, double s2cut=0.);74 HProf ComputePk(double s2cut=0., int nbin=256, double kmin=0., double kmax=-1., bool fgmodcnt=false); 75 void ComputePkCumul(); 70 76 71 77 // angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers 72 78 // typically = ComovRadialDistance 73 HProf ComputeNoisePk(Four2DResponse& resp, Histo& fracmodok, DataTable& dt, double angscale=1., 74 double s2cut=0., int nbin=256, double kmin=0., double kmax=-1.); 79 HProf ComputeNoisePk(Four2DResponse& resp, double angscale=1., double s2cut=0., 80 int nbin=256, double kmin=0., double kmax=-1.); 81 82 // Fills a data table from the computed P(k) profile histogram and mode count 83 Histo FillPkDataTable(DataTable& dt); 84 inline HProf& GetPk() { return *hp_pk_p_; } 75 85 76 86 protected: … … 81 91 int prtlev_; 82 92 int prtmodulo_; 93 // Profile histograms for power spectrum and number of modes 94 HProf* hp_pk_p_; 95 Histo* hmcnt_p_; 96 Histo* hmcntok_p_; 97 double s2cut_; 83 98 }; 84 99 … … 94 109 { freq0_=freq0; dfreq_=dfreq; } 95 110 inline void SetAngScaleConversion(double angscale=1.) 96 { angscale_=angscale; } 111 { angscales_=angscale; } 112 inline void SetAngScaleConversion(Vector& angscs) 113 { angscales_=angscs; } 97 114 inline void SetS2Cut(double s2cut=100.) 98 115 { S2CUT=s2cut; } 99 116 inline double GetS2Cut() { return S2CUT; } 100 HProf Compute( );117 HProf Compute(int nbin=256, double kmin=0., double kmax=-1.); 101 118 inline int SetPrtLevel(int lev=0, int prtmod=10) 102 119 { int olev=prtlev_; prtlev_=lev; prtmodulo_=prtmod; return olev; } … … 106 123 Four2DResponse& frep; 107 124 double freq0_,dfreq_; 108 double angscale_;125 Vector angscales_; 109 126 double S2CUT; 110 127 int NGEN;
Note:
See TracChangeset
for help on using the changeset viewer.