source: Sophya/trunk/Cosmo/RadioBeam/mbeamcyl.cc@ 3743

Last change on this file since 3743 was 3621, checked in by cmv, 16 years ago

GauRnd() -> NorRand(), cmv 11/05/2009

File size: 6.8 KB
RevLine 
[3160]1#include "mbeamcyl.h"
2#include "fftpserver.h"
3#include "vector3d.h"
4#include "matharr.h"
5#include "srandgen.h"
6
[3192]7static double cLight=0.3; // in 1E9 m/s
8static double tClock = 2.; // should come from param file !!!!
9//static double cLight=1;
10//static double tClock = 1.;
11
[3160]12//=================================================
13
[3191]14MultiBeamCyl::MultiBeamCyl(int nr, int ns, double posx, double posy)
[3192]15 : texact_(ns) , tjitt_(ns) , toffset_(nr) ,
16 gain_(nr), signal_(ns), sigjitt_(ns)
[3160]17{
[3192]18 NR_ = nr;
19 NS_ = ns;
20 posY_ = posy;
21 posX_ = posx;
[3160]22
23 SetPrintLevel(0);
24
25 SetBaseFreqDa(2., 0.25);
26 SetNoiseSigma(0.);
27 SetTimeJitter(0.);
28 SetTimeOffsetSigma(0.);
29 SetGains(1., 0., 0);
[3192]30 adfg_ = false; src_ = NULL;
[3160]31 SetSources(new BRSourceGen, true);
32}
33
[3192]34//-----------------------------------------------------------------------------
[3160]35MultiBeamCyl::~MultiBeamCyl()
36{
[3192]37 if (adfg_ && src_) delete src_;
[3160]38}
39
[3192]40//-----------------------------------------------------------------------------
[3160]41void MultiBeamCyl::SetSources(BRSourceGen* brs, bool ad)
42{
43 if (brs == NULL) return;
[3192]44 if (adfg_ && src_) delete src_;
45 src_ = brs; adfg_=ad;
46 if (PrtLev_ > 1)
[3160]47 cout << " MultiBeamCyl::SetSources(brs=" << brs <<" ,bool) NbSrc="
[3192]48 << src_->NbSources() << endl;
[3160]49
50}
51
[3192]52//-----------------------------------------------------------------------------
[3160]53void MultiBeamCyl::SetGains(double g, double sigg, int nzerogain)
54{
[3192]55 if (sigg < 1.e-6) gain_ = g;
56 else gain_ = RandomSequence(RandomSequence::Gaussian, g, sigg);
[3160]57 int k;
[3192]58 for (k=0; k<NR_; k++) if (gain_(k) < 0) gain_(k) = 0.;
[3160]59 for(k=0; k<nzerogain; k++) {
[3192]60 int zg = random()%NR_;
61 if ((zg >=0) && (zg < NR_)) gain_(zg) = 0.;
[3160]62 }
[3192]63 if (PrtLev_ > 1)
[3160]64 cout << " MultiBeamCyl::SetGains(g=" << g <<" ,sigg=" << sigg
65 << " ,nzg=" << nzerogain << " )" << endl;
66}
67
[3192]68//-----------------------------------------------------------------------------
[3160]69void MultiBeamCyl::ComputeTimeVectors()
70{
[3192]71 texact_ = RegularSequence(0., tClock); // 0, tClock, 2*tClock, ...
72// for (int i=0;i<1024;i++) {cout << texact(i)<< endl;};
73 toffset_ = RandomSequence(RandomSequence::Gaussian, 0., toffsig_);
[3160]74 NewTJitVector();
75}
76
[3192]77//-----------------------------------------------------------------------------
[3160]78void MultiBeamCyl::NewTJitVector(int num)
79{
[3192]80 if (timejitter_ > 1.e-19) {
81 tjitt_ = RandomSequence(RandomSequence::Gaussian, 0., timejitter_);
82 tjitt_ += texact_;
[3160]83 }
[3192]84 else tjitt_ = texact_;
85 if (num >= 0) tjitt_ += toffset_(num);
[3160]86
87}
88
[3192]89//-----------------------------------------------------------------------------
[3160]90int MultiBeamCyl::ComputeSignalVector(int num, bool fgsignojit)
91{
92 int nok = 0;
[3192]93 signal_ = 0.;
94 sigjitt_ = 0.;
95 for(int is=0; is<src_->freq.Size(); is++) {
96 double fr = src_->freq(is);
[3160]97 if ((fr < 0.) || (fr > 0.5)) continue;
98 nok++;
99 // Pour le dephasage entre recepteurs, on doit utiliser la frequence vraie,
100 // pas celle apres shift (freq-reduite)
101 // lambda = c T = c/freq avec c = 1, dephasage = 2*pi*num*Da*sin(ang)/lambda
[3192]102 double dephasage = (posX_+num*Da_)*sin(src_->angX(is))
103 + posY_*sin(src_->angY(is)) ;
104 dephasage *= 2*M_PI*(fr+freq0_)/cLight;
[3160]105 // On ajoute alors la phase propre de chaque source
[3192]106 dephasage += src_->phase(is);
107 double amprep = src_->amp(is)*AngResponse(src_->angX(is), src_->angY(is));
108 for(int k=0; k<NS_; k++) {
109 sigjitt_(k) += amprep*sin(2.*M_PI*fr*tjitt_(k)+dephasage);
[3160]110 if (fgsignojit)
[3192]111 signal_(k) += amprep*sin(2.*M_PI*fr*texact_(k)+dephasage);
[3160]112 }
113 }
114 // Application du gain du detecteur
[3192]115 r_4 ga = gain_(num);
[3160]116 if (fabs(ga-1.) > 1.e-9) {
[3192]117 signal_ *= ga;
118 sigjitt_ *= ga;
[3160]119 }
120 // Ajout de bruit (ampli ...)
[3192]121 if (signoise_ > 1.e-18) {
122 for(int k=0; k<NS_; k++) {
[3621]123 sigjitt_(k) += signoise_ * NorRand();
124 if (fgsignojit) signal_(k) += signoise_ * NorRand();
[3160]125 }
126 }
[3192]127//............ FFT in time
[3160]128 FFTPackServer ffts;
[3192]129 ffts.FFTForward(sigjitt_, f_sigjit_);
130 if (fgsignojit) ffts.FFTForward(signal_, f_sig_);
[3160]131
132 return nok;
133}
134
135
[3192]136//-----------------------------------------------------------------------------
[3160]137/* --- a supprimer ?
138inline float myZmodule(complex<r_4>& z)
139{
140 return (float)sqrt((double)(z.real()*z.real()+z.imag()*z.imag()));
141}
142----- */
143
[3192]144//-----------------------------------------------------------------------------
[3160]145void MultiBeamCyl::ReconstructSourcePlane(bool fgzerocentre)
146{
147 ComputeTimeVectors();
148 int noksrc = ComputeSignalVector(0, false);
149 vector<TVector< complex<r_4> > > vvfc;
[3192]150 cout << "MultiBeamCyl::ReconstructSourcePlane() NR=" << NR_
151 << " PosY=" << posY_ << " NFreq=" << f_sigjit_.Size()-1 << " NOkSrc=" << noksrc << endl;
152 if (PrtLev_ > 0) {
153 cout << " ... posY= " << posY_ << " MeanGain=" << Mean(gain_) << " MeanAmpSrc="
154 << Mean(src_->amp) << endl;
155 cout << " ...SigNoise=" << signoise_ << " TimeJitter=" << timejitter_
156 << " TOffSig=" << toffsig_ << " Da=" << Da_ << " Freq0=" << freq0_ << endl;
[3160]157 }
158 // On ne s'occupe pas de la composante continue
[3192]159 for(int jf=1; jf<f_sigjit_.Size(); jf++) {
160 TVector<complex<r_4> > cf(NR_);
[3160]161 vvfc.push_back(cf);
162 }
163 cout << "ReconstructSourcePlane()/Info: computing s(t) for each receptor ..." << endl;
[3192]164 int pmod = NR_/10;
165 for(int ir=0; ir<NR_; ir++) {
166 if (timejitter_ > 1.e-19) NewTJitVector(ir);
[3160]167 noksrc = ComputeSignalVector(ir, false);
[3192]168 for(int jf=1; jf<f_sigjit_.Size(); jf++)
169 vvfc[jf-1](ir) = f_sigjit_(jf);
170 if ( (PrtLev_>0) && (ir%pmod == 0) )
171 cout << " OK s(t) for ir=" << ir << " / NR=" << NR_ << " NOkSrc=" << noksrc << endl;
[3160]172 }
173
174 cout << "ReconstructSourcePlane()/Info: computing s(ang) for each freq by FFT" << endl;
[3192]175 cmplx_srcplane_.SetSize(f_sigjit_.Size()-1, NR_);
176 // rec_srcplane.SetSize(f_sigjit_.Size()-1, NR_);
[3160]177 FFTPackServer ffts;
178 TVector<complex<r_4> > fcf;
179 pmod = vvfc.size()/10;
[3192]180 for(int jf=0; jf<(int)vvfc.size(); jf++) { // loop over frequencies
181 ffts.FFTForward(vvfc[jf], fcf); // FFT alomg cylinder
182 if (fcf.Size() != NR_) {
[3160]183 cout << "ReconstructSourcePlane()/BUG jf=" << jf << " fcf.Size() != NR "
[3192]184 << fcf.Size() << " != " << NR_ << endl;
[3160]185 continue;
186 }
187 if (fgzerocentre) { // On veut avoir la direction angle=0 au milieu de la matrice
[3192]188 int milieu = (NR_-1)/2;
189 if (NR_%2 == 0) milieu++;
190 int decal = NR_ - milieu - 1;
[3160]191 for (int ir=0; ir<=milieu; ir++)
[3192]192 cmplx_srcplane_(jf, ir+decal) = fcf(ir);
[3160]193 // rec_srcplane(jf, ir+decal) = myZmodule(fcf(ir));
194
[3192]195 for (int ir=milieu+1; ir<NR_; ir++)
196 cmplx_srcplane_(jf, decal-(NR_-ir)) = fcf(ir);
197 // rec_srcplane_(jf, decal-(NR_-ir)) = myZmodule(fcf(ir));
[3160]198
199 }
[3192]200 else for (int ir=0; ir<NR_; ir++)
201 cmplx_srcplane_(jf, ir) = fcf(ir);
[3160]202 // rec_srcplane(jf, ir) = myZmodule(fcf(ir));
203
[3192]204 if ( (PrtLev_ > 0) && (jf%pmod == 0))
[3160]205 cout << " OK rec_srcplane(jf, ir) for jf=" << jf << endl;
206 }
207
208
209 cout << "ReconstructSourcePlane()/Info: rec_srcplane computed OK" << endl;
210}
211
212
Note: See TracBrowser for help on using the repository browser.