Changeset 4027 in Sophya for trunk/Cosmo/RadioBeam/specpk.cc


Ignore:
Timestamp:
Oct 17, 2011, 10:56:41 AM (14 years ago)
Author:
ansari
Message:

Implementatiom prise en compte dA(z) ds la calcul de bruit Pnoise(k) - Reza 17/10/2011

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/RadioBeam/specpk.cc

    r4026 r4027  
    127127  SetPrtLevel();
    128128  SetCellSize();
     129  hp_pk_p_=NULL;  hmcnt_p_=NULL;  hmcntok_p_=NULL;   s2cut_=0.;
    129130}
    130131// Constructor
     
    134135  SetPrtLevel();
    135136  SetCellSize();
    136 }
    137 
     137  hp_pk_p_=NULL;  hmcnt_p_=NULL;  hmcntok_p_=NULL;   s2cut_=0.;
     138}
     139
     140// Destructor
     141Four3DPk::~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}
    138147
    139148// Generate mass field Fourier Coefficient
     
    200209
    201210// Generate mass field Fourier Coefficient
    202 void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, double angscale)
     211void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, Vector& angscales)
    203212// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
    204213// typically = ComovRadialDistance
    205214{
     215  if (angscales.Size() != fourAmp.SizeZ())
     216    throw SzMismatchError("ComputeNoiseFourierAmp(): angscales.Size()!=fourAmp.SizeZ()");
    206217  H21Conversions conv;
    207218  // fourAmp represent 3-D fourier transform of a real input array.
     
    212223    conv.setFrequency(f0+kz*df);
    213224    resp.setLambda(conv.getLambda());
     225    double angsc=angscales(kz);
     226    if (prtlev_>2) 
     227      cout << " Four3DPk::ComputeNoiseFourierAmp(...) - freq=" << f0+kz*df << " -> AngSc=" << angsc << endl;
    214228    for(sa_size_t ky=0; ky<fourAmp.SizeY(); ky++) {
    215229      kyy =  (ky>fourAmp.SizeY()/2) ? -(double)(fourAmp.SizeY()-ky)*dky_ : (double)ky*dky_;
    216230      for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) {
    217231        kxx=(double)kx*dkx_;
    218         rep = resp(kxx*angscale, 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.);
    220234        else {
    221235          amp = 1./sqrt(rep)/sqrt(2.);
     
    264278// cells with amp^2=re^2+im^2>s2cut are ignored
    265279// Output : power spectrum (profile histogram)
    266 HProf Four3DPk::ComputePk(double s2cut, int nbin, double kmin, double kmax)
     280HProf Four3DPk::ComputePk(double s2cut, int nbin, double kmin, double kmax, bool fgmodcnt)
    267281{
    268282  // The second half of the array along Y (matrix rows) contain
     
    279293    kmax=sqrt(maxx*maxx+maxy*maxy+maxz*maxz);
    280294  }
    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_;
    286305}
    287306
    288307// Compute power spectrum as a function of wave number k
    289308// Cumul dans hp - cells with amp^2=re^2+im^2>s2cut are ignored
    290 void Four3DPk::ComputePkCumul(HProf& hp, double s2cut)
     309void Four3DPk::ComputePkCumul()
    291310{
    292311  uint_8 nmodeok=0;
     
    303322        double kxx=(double)kx*dkx_;
    304323        complex<TF> za = fourAmp(kx, ky, kz);
    305         if (za.real()>8.e9) continue;
     324        //      if (za.real()>8.e19) continue;
    306325        double wk = sqrt(kxx*kxx+kyy*kyy+kzz*kzz);
    307326        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);
    310331        nmodeok++;
    311332      }
    312333    }
    313334  }
    314   if ((prtlev_>1)||((prtlev_>0)&&(s2cut>1.e-9))) {
     335  if ((prtlev_>1)||((prtlev_>0)&&(s2cut_>1.e-9))) {
    315336    cout << " Four3DPk::ComputePkCumul/Info : NModeOK=" << nmodeok << " / NMode=" << fourAmp.Size()
    316337         << " -> " << 100.*(double)nmodeok/(double)fourAmp.Size() << "%" << endl;
     
    325346// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
    326347// typically = ComovRadialDistance
    327 HProf Four3DPk::ComputeNoisePk(Four2DResponse& resp, Histo& fracmodok, DataTable& dt,
    328                                double angscale, double s2cut, int nbin, double kmin, double kmax)
     348HProf Four3DPk::ComputeNoisePk(Four2DResponse& resp, double angscale, double s2cut, int nbin, double kmin, double kmax)
    329349{
    330350  // The second half of the array along Y (matrix rows) contain
     
    341361    kmax=sqrt(maxx*maxx+maxy*maxy+maxz*maxz);
    342362  }
    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;
    348369
    349370  uint_8 nmodeok=0;
     
    362383        double rep=resp(kxx*angscale, kyy*angscale);
    363384        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);
    368389        nmodeok++;
    369390      }
     
    375396  }
    376397
    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
     402Histo 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;
    379410  char* nomcol[5] = {"k","pnoise","nmode","nmodok","fracmodok"};
    380411  dt.Clear();
     
    393424    dt.AddRow(dtr);
    394425  }
    395   return hp;
     426  return fracmodok;
    396427}
    397428
     
    403434PkNoiseCalculator::PkNoiseCalculator(Four3DPk& pk3, Four2DResponse& rep, double s2cut, int ngen,
    404435                                     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())
    406437{
    407438  SetFreqRange();
     
    410441}
    411442
    412 HProf PkNoiseCalculator::Compute()
     443HProf PkNoiseCalculator::Compute(int nbin, double kmin, double kmax)
    413444{
    414445  Timer tm(title.c_str());
     
    416447  HProf hnd;
    417448  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;
    419451  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();
    423455    if ((prtlev_>0)&&(igen>0)&&(((igen-1)%prtmodulo_)==0))
    424456      cout << " PkNoiseCalculator::Compute() - done igen=" << igen << " / MaxNGen=" << NGEN << endl;
    425457  }
    426   return hnd;
     458  return pkn3d.GetPk() ;
    427459}
    428460
Note: See TracChangeset for help on using the changeset viewer.