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


Ignore:
Timestamp:
Oct 10, 2011, 11:31:03 PM (14 years ago)
Author:
ansari
Message:

Modif programme pknoise.cc et classes Four3DPk, PkNoiseCalculator pour calcul spectre de bruit en faisant varier la reponse instrumentale avec la frequence, Reza 10/10/2011

File:
1 edited

Legend:

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

    r3947 r4026  
    66
    77#include "specpk.h"
     8#include "radutil.h"
    89#include "randr48.h"     
    910#include "ctimer.h"     
     
    162163}
    163164
     165
    164166// Generate mass field Fourier Coefficient
    165 void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, bool crmask)
     167void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double angscale, bool crmask)
     168// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
     169// typically = ComovRadialDistance
    166170{
    167171  TMatrix<r_4> mask(fourAmp.SizeY(), fourAmp.SizeX());
     
    176180      for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) {
    177181        kxx=(double)kx*dkx_;
    178         rep = resp(kxx, kyy);
     182        rep = resp(kxx*angscale, kyy*angscale);
    179183        if (crmask&&(kz==0))  mask(ky,kx)=((rep<1.e-8)?9.e9:(1./rep));
    180184        if (rep<1.e-8)  fourAmp(kx, ky, kz) = complex<TF>(9.e9,0.);
     
    193197  if (prtlev_>0)
    194198    cout << " Four3DPk::ComputeNoiseFourierAmp() done ..." << endl;
     199}
     200
     201// Generate mass field Fourier Coefficient
     202void Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, double angscale)
     203// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
     204// typically = ComovRadialDistance
     205{
     206  H21Conversions conv;
     207  // fourAmp represent 3-D fourier transform of a real input array.
     208  // The second half of the array along Y and Z contain negative frequencies
     209  double kxx, kyy, kzz, rep, amp;
     210  // sa_size_t is large integer type 
     211  for(sa_size_t kz=0; kz<fourAmp.SizeZ(); kz++) {
     212    conv.setFrequency(f0+kz*df);
     213    resp.setLambda(conv.getLambda());
     214    for(sa_size_t ky=0; ky<fourAmp.SizeY(); ky++) {
     215      kyy =  (ky>fourAmp.SizeY()/2) ? -(double)(fourAmp.SizeY()-ky)*dky_ : (double)ky*dky_;
     216      for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) {
     217        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.);
     220        else {
     221          amp = 1./sqrt(rep)/sqrt(2.);
     222          fourAmp(kx, ky, kz) = complex<TF>(rg_.Gaussian(amp), rg_.Gaussian(amp));   
     223        }
     224      }
     225    }
     226  }
     227
     228  if (prtlev_>1)
     229    cout << " Four3DPk::ComputeNoiseFourierAmp(...) Computing FFT along frequency ..." << endl;
     230  TVector< complex<TF> >  veczin(fourAmp.SizeZ()), veczout(fourAmp.SizeZ());
     231  FFTWServer ffts(true);                     
     232  ffts.setNormalize(true);
     233
     234  for(sa_size_t ky=0; ky<fourAmp.SizeY(); ky++) {
     235    for(sa_size_t kx=0; kx<fourAmp.SizeX(); kx++) {
     236      //      veczin=fourAmp(Range(kx), Range(ky), Range::all());
     237      for(sa_size_t kz=0; kz<fourAmp.SizeZ(); kz++)  veczin(kz)=fourAmp(kx,ky,kz);
     238      ffts.FFTBackward(veczin,veczout);
     239      veczout /= (TF)sqrt((double)fourAmp.SizeZ());
     240      //      fourAmp(Range(kx), Range(ky), Range::all())=veczout;
     241      for(sa_size_t kz=0; kz<fourAmp.SizeZ(); kz++)  fourAmp(kx,ky,kz)=veczout(kz);
     242    }
     243  }
     244
     245  if (prtlev_>2)  fourAmp.Show();
     246  if (prtlev_>0)
     247    cout << " Four3DPk::ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df) done ..." << endl;
    195248}
    196249
     
    270323// cells with amp^2=re^2+im^2>s2cut are ignored
    271324// Output : noise power spectrum (profile histogram)
     325// angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers
     326// typically = ComovRadialDistance
    272327HProf Four3DPk::ComputeNoisePk(Four2DResponse& resp, Histo& fracmodok, DataTable& dt,
    273                                double s2cut, int nbin, double kmin, double kmax)
     328                               double angscale, double s2cut, int nbin, double kmin, double kmax)
    274329{
    275330  // The second half of the array along Y (matrix rows) contain
     
    305360        double kxx=(double)kx*dkx_;
    306361        double wk = sqrt(kxx*kxx+kyy*kyy+kzz*kzz);
    307         double amp2 = 1./resp(kxx, kyy);
     362        double rep=resp(kxx*angscale, kyy*angscale);
     363        double amp2 = (rep>1.e-19)?1./rep:1.e19;
    308364        hmcnt.Add(wk);
    309365        if ((s2cut>1.e-9)&&(amp2>s2cut))  continue;
     
    349405  : pkn3d(pk3), frep(rep), S2CUT(s2cut), NGEN(ngen), title(tit)
    350406{
     407  SetFreqRange();
     408  SetAngScaleConversion();
    351409  SetPrtLevel();
    352410}
     
    357415  tm.Nop();
    358416  HProf hnd;
    359   cout << "PkNoiseCalculator::Compute() " << title << "  NGEN=" << NGEN << " S2CUT=" << S2CUT << endl;
     417  cout << "PkNoiseCalculator::Compute() " << title << "  NGEN=" << NGEN << " S2CUT=" << S2CUT 
     418       << " Freq0=" << freq0_ << " dFreq=" << dfreq_ << " angscale=" << angscale_ << endl;
    360419  for(int igen=0; igen<NGEN; igen++) {
    361     pkn3d.ComputeNoiseFourierAmp(frep);
     420    pkn3d.ComputeNoiseFourierAmp(frep, freq0_, dfreq_, angscale_);
    362421    if (igen==0) hnd = pkn3d.ComputePk(S2CUT);
    363422    else pkn3d.ComputePkCumul(hnd,S2CUT);
Note: See TracChangeset for help on using the changeset viewer.