Changeset 3192 in Sophya for trunk/Cosmo/RadioBeam/multicyl.cc


Ignore:
Timestamp:
Mar 20, 2007, 11:48:15 AM (19 years ago)
Author:
legoff
Message:

input file read with DVcards by treccyl.cc

and by multiCylinders(char* filename)

using real units (meter and GHz)
using _ for member variables (e.g. x_)

File:
1 edited

Legend:

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

    r3191 r3192  
    66#include "ctimer.h"
    77#include "resusage.h"
     8#include "datacards.h"
     9
     10static double cLight=0.3;       // in 1E9 m/s
     11static double tClock = 2.; // should come from param file !!!!
     12//static double cLight=1;       
     13//static double tClock = 1.;
    814
    915
     
    1218MultiCylinders::MultiCylinders(int nr, int ns)
    1319{
    14   NR = nr;
    15   NS = ns;
     20  NR_ = nr;
     21  NS_ = ns;
    1622
    1723  SetPrintLevel(0);
     
    2228  SetTimeOffsetSigma(0.);
    2329  SetGains(1., 0., 0);
    24   adfg = false; src = NULL;
     30  adfg_ = false; src_ = NULL;
    2531  SetSources(new BRSourceGen, true);
    2632}
    2733
     34//-----------------------------------------------------------------------------
     35MultiCylinders::MultiCylinders(char* fileName)
     36{
     37  adfg_ = false; src_ = NULL;
     38  SetSources(new BRSourceGen, true);
     39 
     40//      read telescope parameters and fill variable members
     41  DataCards dc;
     42  dc.ReadFile(fileName);
     43//      in old versions frequences were in units of 1/T = 0.5 GHz
     44//      and distances in units of cT =3E8 * 2E-9=0.60 m
     45//  double fUnit=0.5;   // 0.5 GHz <=> T = 2 ns
     46//  double dUnit=0.6;   // distance unit in m.
     47//      now f and d in real units
     48  double fUnit=1.;      // 0.5 GHz <=> T = 2 ns
     49  double dUnit=1.;      // distance unit in m.
     50 
     51  NR_=dc.IParam("nAntenna");
     52  NS_=dc.IParam("nSample");
     53  PrtLev_=dc.IParam("printLevel");
     54  Da_=dc.DParam("dAntenna")/dUnit;
     55  freq0_=dc.DParam("freq0")/fUnit;
     56  timejitter_=dc.DParam("sigmaTimeJitt");
     57  toffsig_=dc.DParam("sigmaClockJitt");
     58  signoise_=dc.DParam("noiseSigma");
     59  gain_=dc.DParam("meanGain");
     60  siggain_=dc.DParam("sigmaGain");
     61  ngainzero_=dc.IParam("nDeadAntenna");
     62 
     63//  tClock=dc.DParam("tClock");
     64  int nCyl=dc.IParam("nCyl");
     65  for (int i=0; i<nCyl; i++){
     66    double xCyl=dc.DParam("xCyl",i)/dUnit;
     67    double yCyl=dc.DParam("yCyl",i)/dUnit;
     68    AddCylinder(xCyl,yCyl);
     69  }
     70//  maxangX=dc.DParam("angMaxX");
     71//  double cylDiam=dc.DParam("cylinderDiam")/dUnit;
     72//// thetaMax = lambda_M/d = c/freq_min/d;  freq_min = freq0 + 1/2T
     73//  maxangY=cLight/(freq0+1./2./tClock)/cylDiam;
     74//  halfNY=dc.IParam("halfNY");
     75//  NX=dc.IParam("NX");
     76}
     77
     78//-----------------------------------------------------------------------------
    2879MultiCylinders::~MultiCylinders()
    2980{
    30   if (adfg && src) delete src;
    31   for(int k=0; k<mCyl.size(); k++) delete mCyl[k];
    32 }
    33 
     81  if (adfg_ && src_) delete src_;
     82  for(int k=0; k<(int)mCyl_.size(); k++) delete mCyl_[k];
     83}
     84
     85//-----------------------------------------------------------------------------
    3486MultiBeamCyl& MultiCylinders::GetCylinder(int k)
    3587{
    36   if ((k < 0) || (k >= mCyl.size()))
     88  if ((k < 0) || (k >= (int)mCyl_.size())) {
     89    cout <<"******************************************* k="<<k<<endl;
    3790    throw RangeCheckError("MultiCylinders::GetCylinder(k) k<0 OR k>=NCyl");
    38   return (*mCyl[k]);
    39 }
    40 
     91  }
     92  return (*mCyl_[k]);
     93}
     94
     95//-----------------------------------------------------------------------------
    4196void MultiCylinders::SetSources(BRSourceGen* brs, bool ad)
    4297{
    4398  if (brs == NULL) return;
    44   if (adfg && src) delete src;
    45   src = brs;  adfg=ad;
    46 }
    47 
    48 
     99  if (adfg_ && src_) delete src_;
     100  src_ = brs;  adfg_=ad;
     101}
     102
     103
     104//-----------------------------------------------------------------------------
    49105void MultiCylinders::ConfigureCylinders()
    50106{
    51   cout << " MultiCylinders::ConfigureCylinders() with NCyl= " << mCyl.size() << endl;
    52   for(int k=0; k<mCyl.size(); k++) {
    53     mCyl[k]->SetPrintLevel(PrtLev);
    54     mCyl[k]->SetBaseFreqDa(freq0, Da);
    55     mCyl[k]->SetNoiseSigma(signoise);
    56     mCyl[k]->SetTimeJitter(timejitter);
    57     mCyl[k]->SetTimeOffsetSigma(toffsig);
    58     mCyl[k]->SetGains(gain, siggain, ngainzero);
    59     mCyl[k]->SetSources(src, false);
    60   }
    61 }
    62 
    63 
     107  cout << " MultiCylinders::ConfigureCylinders() with NCyl= " << mCyl_.size() << endl;
     108  for(int k=0; k<(int)mCyl_.size(); k++) {
     109    mCyl_[k]->SetPrintLevel(PrtLev_);
     110    mCyl_[k]->SetBaseFreqDa(freq0_, Da_);
     111    mCyl_[k]->SetNoiseSigma(signoise_);
     112    mCyl_[k]->SetTimeJitter(timejitter_);
     113    mCyl_[k]->SetTimeOffsetSigma(toffsig_);
     114    mCyl_[k]->SetGains(gain_, siggain_, ngainzero_);
     115    mCyl_[k]->SetSources(src_, false);
     116  }
     117}
     118
     119
     120//-----------------------------------------------------------------------------
    64121void MultiCylinders::ReconstructCylinderPlaneS(bool fgzerocentre)
    65122{
    66123  Timer tm("RecCylPlaneS");
    67124  ResourceUsage resu;
    68   cout << " MultiCylinders::ReconstructCylinderPlaneS()/Info - NCyl= " << mCyl.size()
     125  cout << " MultiCylinders::ReconstructCylinderPlaneS()/Info - NCyl= " << mCyl_.size()
    69126       << " MemSize=" << resu.getMemorySize() << " kb" << endl;       
    70127  ConfigureCylinders();
    71128
    72129  char buff[128];
    73   for(int k=0; k<mCyl.size(); k++) {
     130  for(int k=0; k<(int)mCyl_.size(); k++) {
    74131    cout << "---- Cyl[" << k << "] Calling MultiBeamCyl.ReconstructSourcePlane() ..." << endl;
    75     mCyl[k]->ReconstructSourcePlane(fgzerocentre);
     132    mCyl_[k]->ReconstructSourcePlane(fgzerocentre);
    76133    sprintf(buff,"Cyl[%d].RecSrcPlane()",k);
    77134    tm.Split(buff);
     
    82139}
    83140
    84 void MultiCylinders::ReconstructSourceBox(int halfny, double stepangy)
    85 {
     141//-----------------------------------------------------------------------------
     142void MultiCylinders::ReconstructSourceBox(int halfny, double stepangy,
     143        int nx, double stepangx)
     144{
     145  nx=256;
    86146  ReconstructCylinderPlaneS(true);
    87147  TMatrix< complex<r_4> > & mtx = GetCylinder(0).getRecSrcPlane();
    88   // boite 3D X:angX, Y:angY , Z: freq
     148// boite 3D X:angX, Y:angY , Z: freq
     149//      if all cylinders at same x position NX is set to zero
     150//      => x-size = mtx.NCols() = numbers of receptors per cylinders
     151//              move that to readParam() ?
    89152  sa_size_t sz[5] = {0,0,0,0,0};
    90 //  int nx=mtx.NCols(); // uncomment to go back to nxbin = nantenna
    91   int nx=256;
    92153  sz[0] = nx;
    93154  sz[1] = halfny*2+1;
    94155  sz[2] = mtx.NRows();
    95156  TArray< complex<r_4> > & box = getRecSrcBox();
    96   box.ReSize(3, sz);
    97   //  box = complex< r_4 >( 0.f, 0.f );
     157  box.ReSize(3, sz);            //  values initialized to zero ?
    98158  cout << " MultiCylinders::ReconstructSourceBox(" << halfny << "," << stepangy
    99159       << "=" << Angle(stepangy).ToArcMin() << " ) srcbox:" << endl;
     
    102162
    103163
    104   int pmod = mtx.NRows()/10;
    105  
    106   double fstep = 1.0/(double)NS;  // pas en frequence, attention, on a vire la composante continu
     164//  int pmod = mtx.NRows()/10;
     165 
     166  double fstep = 1.0/(double)NS_/tClock;  // pas en frequence,
     167                                // attention, on a vire la composante continu
     168//  bool first=true;
    107169  for(int kf=0; kf<mtx.NRows(); kf++) { // Loop over frequencies
    108     double frq = (double)(kf+1.)*fstep + freq0;  // + 1 car f=0 a ete vire
    109    
    110     for(int lc=0; lc<mCyl.size(); lc++) {  // Loop over cylinders
     170    double frq = (double)(kf+1.)*fstep + freq0_;  // + 1 car f=0 a ete vire
     171//            then up to frq =   (mtx.NRows() +1 ) * fstep            !!?
     172//    cout<<"************"<<mCyl.size()
     173    for(int lc=0; lc<(int)mCyl_.size(); lc++) {  // Loop over cylinders
    111174      MultiBeamCyl& cyl = GetCylinder(lc);
    112175
    113176      TMatrix< complex<r_4> > & recp = cyl.getRecSrcPlane();
    114177
    115       double facl = - 2*M_PI*frq*cyl.getCylinderYPos();  // attention au signe -
    116 //      double facl_x = - 2*M_PI*cyl.getCylinderXPos()/cyl.Da/(double)cyl.NR;
    117       double facl_x = - 2*M_PI*cyl.getCylinderXPos()/cyl.Da;
    118       double dphi;
     178      double facl_y = - 2*M_PI*frq*cyl.getCylinderYPos()/cLight;  // attention signe -
     179      double facl_x = - 2*M_PI*cyl.getCylinderXPos()/cyl.Da_;
    119180      complex< r_4 > phasefactor;
    120181      int jyy = 0;
     182     
    121183      for(int jy=-halfny; jy<=halfny; jy++) {  // Loop over Y angular steps
    122         for(int ix=0; ix<nx; ix++) {  // Loop over AngX directions
    123           double dphi = facl * sin( (double)jy*stepangy )
    124                         + facl_x*(double(ix)/double(nx)-1./2.);
    125           phasefactor = complex< r_4 > ((r_4) cos(dphi) , (r_4) sin(dphi));
    126           // sur recp : index ligne -> frequence  ,    index colonne -> angX ,
    127           int ixx=(int)(ix*(double)cyl.NR/double(nx));
    128           box(ix, jyy, kf) += recp(kf, ixx)*phasefactor;
    129         }  // 
    130         jyy++;
     184      for(int ix=0; ix<nx; ix++) {  // Loop over AngX directions
     185        double dphi = facl_y * sin( (double)jy*stepangy )
     186                      + facl_x*(double(ix)/double(nx)-1./2.);
     187        phasefactor = complex< r_4 > ((r_4) cos(dphi) , (r_4) sin(dphi));
     188        // sur recp : index ligne -> frequence  ,    index colonne -> angX ,
     189        int ixx=(int)(ix*(double)cyl.NR_/double(nx));
     190        box(ix, jyy, kf) += recp(kf, ixx)*phasefactor;
     191      }  // 
     192      jyy++;
    131193      } // End of Loop over Y angles
    132194    } // End of loop over cylinders
     195
    133196    tm.Nop();
    134     if ( (PrtLev>0) && (kf%pmod == 0) )   
     197//    if ( (PrtLev_>0) && (kf%pmod == 0) )   
     198    if ( (PrtLev_>0) && (kf%(mtx.NRows()/10) == 0) )   
    135199      cout << " OK box(angx,angy, freq=kf) done for kf=" << kf
    136            << " / Max_kf=" << mtx.NRows() << endl;
     200         << " / Max_kf=" << mtx.NRows() << endl;
    137201  } // End of loop over over frequencies
    138202
     
    140204}
    141205
     206//-----------------------------------------------------------------------------
    142207inline float myZmodule(complex<r_4>& z)
    143208{
     
    145210}
    146211
     212//-----------------------------------------------------------------------------
    147213TMatrix< r_4 >  MultiCylinders::getRecXYSlice(int kfmin, int kfmax)
    148214{
     
    158224  return(rmtx);
    159225}
     226//-----------------------------------------------------------------------------
     227TMatrix< r_4 >  MultiCylinders::getRecYXSlice(int kfmin, int kfmax)
     228{
     229  TArray< complex<r_4> > & box = getRecSrcBox(); 
     230  if ((kfmin < 0) || (kfmin >=  box.SizeZ()) || (kfmax < kfmin) || (kfmax >=  box.SizeZ()) )
     231    throw RangeCheckError("MultiCylinders::getRecXYSlice(kfmin, kfmax)");
     232  TMatrix< r_4> rmtx(box.SizeX(), box.SizeY());
     233  for(int kf=kfmin; kf<=kfmax; kf++) {
     234    for(int jy=0; jy<box.SizeY(); jy++)
     235      for(int ix=0; ix<box.SizeX(); ix++)
     236        rmtx(ix, jy) += myZmodule(box(ix, jy, kf));
     237  }
     238  return(rmtx);
     239}
Note: See TracChangeset for help on using the changeset viewer.