source: Sophya/trunk/SophyaLib/Samba/mlobe.cc@ 2277

Last change on this file since 2277 was 2213, checked in by ansari, 23 years ago

Mise a jour de la documentation mlobe.cc , Reza 15/10/2002

File size: 5.2 KB
Line 
1#include "mlobe.h"
2#include "unitvector.h"
3
4#include "timing.h"
5
6/*!
7 \class SOPHYA::MainLobe
8 \ingroup Samba
9 Class for computation of main lobe.
10 The lobe values are computed in pixels laying on nc slices
11 with hexagonal pavement around theta=0 , phi=0. The lobe is
12 gaussian with sigma=sig. The slices are built every
13 dels*sigma. all angles and the sigma are specified in radians.
14*/
15
16// #include "nbrandom.h"
17//++
18// Class MainLobe
19//
20// include mlobe.h sphericalmap.h unitvector.h math.h
21//
22// Class for computation of main lobe.
23//
24// The lobe values are computed in pixels laying on "nc" slices
25// with hexagonal pavement around theta=0 , phi=0. The lobe is
26// gaussian with sigma="sig". The slices are built every
27// "dels"*sigma.
28//
29//--
30//++
31// Titre Constructor
32//--
33/* --Methode-- */
34//++
35MainLobe::MainLobe(float sig, float dels, int nc)
36//
37//--
38{
39if (sig < 1.e-9) sig = M_PI/100.; // Sigma du lobe gaussien (radians)
40mSigma = sig;
41mDels = (dels < 1.e-5) ? 0.5 : dels; // Epaisseur de chaque couche en unite de sigma
42mNC = (nc < 1) ? 1 : nc;
43mNpix = 1; // Nb total de pixels du lobe
44
45int i,j,k;
46for(i=1; i<=mNC; i++) mNpix += 6*i;
47// mT0 , mP0 Teta et Phi des pixels, Pixel 0 oriente vers (0, 0)
48mT0 = new float[mNpix];
49mP0 = new float[mNpix];
50// mTC , mPC Teta et Phi des pixels, Pixel 0 oriente vers (Teta, phi)
51mTC = new float[mNpix];
52mPC = new float[mNpix];
53mDx = new float[mNpix];
54mDy = new float[mNpix];
55mDr = new float[mNpix];
56// Valeurs des pixels
57mVal = new double[mNpix];
58
59
60double teta,phi,dphi;
61double val;
62mT0[0] = mP0[0] = mTC[0] = mPC[0] = 0.;
63mVal[0] = 1.; mDx[0] = mDy[0] = 0.;
64k = 1; mTotVal = 1.;
65for(i=1; i<=mNC; i++) {
66 teta = (double)i*mDels;
67 val = exp(-teta*teta);
68 teta *= mSigma;
69 if (i%2) phi = M_PI/6.;
70 else phi = 0.;
71 dphi = M_PI/(3.*i);
72 for(j=0; j<6*i; j++) {
73 mT0[k] = mTC[k] = teta;
74 phi += dphi;
75 mP0[k] = mPC[k] = phi;
76 mVal[k] = val;
77 mTotVal += val;
78 mDx[k] = teta*cos(phi);
79 mDy[k] = teta*sin(phi);
80 mDr[k] = teta;
81 k++;
82 }
83 }
84mDirTet = mDirPhi = 0.;
85return;
86}
87
88
89//++
90// Titre Constructor
91//--
92/* --Methode-- */
93//++
94MainLobe::~MainLobe()
95//
96//--
97{
98delete mT0;
99delete mP0;
100delete mTC;
101delete mPC;
102delete mDx;
103delete mDy;
104delete mDr;
105delete mVal;
106}
107//++
108// Titre Public Methods
109//--
110//++
111//
112// inline int NPix()
113// Return the total number of pixels of the lobe
114// inline float Sigma()
115// inline double Integral()
116//--
117/* --Methode-- */
118//++
119void MainLobe::SetDirection(float teta, float phi)
120//
121// orientate the lobe toward the direction (theta, phi)
122//--
123{
124int k;
125
126mDirTet = teta;
127mDirPhi = phi;
128
129if (teta < 0.1*mDels*mSigma) {
130 for(k=0; k<mNpix; k++) {
131 mTC[k] = mT0[k]; mPC[k] = mP0[k];
132 }
133 return;
134 }
135
136
137/*
138if (teta > 10.*mSigma*mDels*mNC) { // On utilise des formules approchees
139 float stet = sin((double)teta);
140 float ctet = cos((double)teta);
141 for(k=0; k<mNpix; k++) {
142 mTC[k] = teta - mDy[k]*stet - mDr[k]*ctet;
143 mPC[k] = phi + mDx[k];
144 }
145 return;
146 }
147 */
148
149// Formules compliquees
150
151double dx,dy,dz;
152double sphi = sin((double)phi);
153double cphi = cos((double)phi);
154double stet = sin((double)teta);
155double ctet = cos((double)teta);
156
157UnitVector pd((double)teta, (double)phi);
158UnitVector vc;
159for(k=0; k<mNpix; k++) {
160 dz = mDy[k]*stet;
161 dx = -(mDx[k]*sphi+mDy[k]*ctet*cphi);
162 dy = mDx[k]*cphi-mDy[k]*ctet*sphi;
163 vc.Setxyz(pd.X()+dx, pd.Y()+dy, pd.Z()+dz);
164 mTC[k] = vc.Theta();
165 mPC[k] = vc.Phi();
166 if (mTC[k] < 0.) printf("ERREUR !!!! mTC[%d] = %g \n", k, mTC[k]);
167 if (mPC[k] < 0.) mPC[k] += M_PI*2.;
168 if (mPC[k] >= M_PI*2.) mPC[k] -= M_PI*2.;
169 }
170return;
171}
172
173/* --Methode-- */
174//++
175double MainLobe::Value(int kpx, float& teta, float& phi)
176//
177// return the value of the lobe as also the (theta, phi) of the
178// pixel "kpx"
179//--
180{
181if ( (kpx < 0) || (kpx >= mNpix) ) { teta = phi = 0.; return(0.); }
182teta = mTC[kpx];
183phi = mPC[kpx];
184return(mVal[kpx]);
185}
186
187/* --Methode-- */
188//++
189double MainLobe::Convol(SphericalMap<double>& sph)
190//
191// return the value of the lobe convolved with the sky (sphere) "sph"
192//--
193{
194double ret=0.;
195int k;
196for(k=0; k<mNpix; k++) ret += mVal[k]*sph(mTC[k], mPC[k]);
197/*
198if( (dbg > 0) && (k%dbg) )
199 printf("MainLobe::Convol k= %d T,P= %g %g , Lobe=%g Sph= %g Ret=%g\n",
200 k, mTC[k], mPC[k], mVal[k], sph(mTC[k], mPC[k]), ret );
201*/
202return(ret/mTotVal);
203}
204
205//++
206//
207// inline void Print()
208//--
209
210//++
211// Titre Operators
212//--
213
214/* --Methode-- */
215//++
216ostream& operator << (ostream& s, MainLobe const& lob)
217//
218//--
219{
220s << "MainLobe_Info() : Sigma= " << lob.mSigma << " Dels= " << lob.mDels << " NC= "
221 << lob.mNC << " NTotPix= " << lob.mNpix << " Integ= " << lob.mTotVal << endl;
222
223int i,j,k;
224cout << " Direction Teta,Phi = " << lob.mDirTet << " , " << lob.mDirPhi << endl;
225cout << " Pixel 0 , Teta= " << lob.mT0[0] << " Phi= " << lob.mP0[0]
226 << " Val= " << lob.mVal[0] << endl;
227k = 1;
228for(i=1; i<lob.mNC; i++) {
229 cout << " Couche # " << i << " NPix= " << i*6 << endl;
230 for(j=0;j<6*i;j++) {
231 cout << "K= " << k << "Teta,Phi= " << lob.mTC[k] << ", " << lob.mPC[k]
232 << " (" << lob.mT0[k] << ", " << lob.mP0[k] << ") "
233 << " Val= " << lob.mVal[k] << endl;
234 k++;
235 }
236 }
237
238
239return s;
240}
241
Note: See TracBrowser for help on using the repository browser.