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

Last change on this file since 3810 was 3077, checked in by cmv, 19 years ago

remplacement nbrandom.h (obsolete) -> srandgen.h cmv 14/09/2006

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