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

Last change on this file since 698 was 568, checked in by ansari, 26 years ago

ajout doc GLM

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