Changeset 4027 in Sophya for trunk/Cosmo/RadioBeam/specpk.cc
- Timestamp:
- Oct 17, 2011, 10:56:41 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.