[228] | 1 | #include "mlobe.h"
|
---|
[262] | 2 | #include "unitvector.h"
|
---|
[228] | 3 |
|
---|
| 4 | #include "timing.h"
|
---|
[1371] | 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.
|
---|
| 14 | */
|
---|
| 15 |
|
---|
[228] | 16 | // #include "nbrandom.h"
|
---|
[568] | 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 | //--
|
---|
[228] | 33 | /* --Methode-- */
|
---|
[568] | 34 | //++
|
---|
[228] | 35 | MainLobe::MainLobe(float sig, float dels, int nc)
|
---|
[568] | 36 | //
|
---|
| 37 | //--
|
---|
[228] | 38 | {
|
---|
| 39 | if (sig < 1.e-9) sig = M_PI/100.; // Sigma du lobe gaussien (radians)
|
---|
| 40 | mSigma = sig;
|
---|
| 41 | mDels = (dels < 1.e-5) ? 0.5 : dels; // Epaisseur de chaque couche en unite de sigma
|
---|
| 42 | mNC = (nc < 1) ? 1 : nc;
|
---|
| 43 | mNpix = 1; // Nb total de pixels du lobe
|
---|
| 44 |
|
---|
| 45 | int i,j,k;
|
---|
| 46 | for(i=1; i<=mNC; i++) mNpix += 6*i;
|
---|
| 47 | // mT0 , mP0 Teta et Phi des pixels, Pixel 0 oriente vers (0, 0)
|
---|
| 48 | mT0 = new float[mNpix];
|
---|
| 49 | mP0 = new float[mNpix];
|
---|
| 50 | // mTC , mPC Teta et Phi des pixels, Pixel 0 oriente vers (Teta, phi)
|
---|
| 51 | mTC = new float[mNpix];
|
---|
| 52 | mPC = new float[mNpix];
|
---|
| 53 | mDx = new float[mNpix];
|
---|
| 54 | mDy = new float[mNpix];
|
---|
| 55 | mDr = new float[mNpix];
|
---|
| 56 | // Valeurs des pixels
|
---|
| 57 | mVal = new double[mNpix];
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | double teta,phi,dphi;
|
---|
| 61 | double val;
|
---|
| 62 | mT0[0] = mP0[0] = mTC[0] = mPC[0] = 0.;
|
---|
| 63 | mVal[0] = 1.; mDx[0] = mDy[0] = 0.;
|
---|
| 64 | k = 1; mTotVal = 1.;
|
---|
| 65 | for(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 | }
|
---|
| 84 | mDirTet = mDirPhi = 0.;
|
---|
| 85 | return;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
[568] | 89 | //++
|
---|
| 90 | // Titre Constructor
|
---|
| 91 | //--
|
---|
[228] | 92 | /* --Methode-- */
|
---|
[568] | 93 | //++
|
---|
[228] | 94 | MainLobe::~MainLobe()
|
---|
[568] | 95 | //
|
---|
| 96 | //--
|
---|
[228] | 97 | {
|
---|
| 98 | delete mT0;
|
---|
| 99 | delete mP0;
|
---|
| 100 | delete mTC;
|
---|
| 101 | delete mPC;
|
---|
| 102 | delete mDx;
|
---|
| 103 | delete mDy;
|
---|
| 104 | delete mDr;
|
---|
| 105 | delete mVal;
|
---|
| 106 | }
|
---|
[568] | 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 | //--
|
---|
[228] | 117 | /* --Methode-- */
|
---|
[568] | 118 | //++
|
---|
[228] | 119 | void MainLobe::SetDirection(float teta, float phi)
|
---|
[568] | 120 | //
|
---|
| 121 | // orientate the lobe toward the direction (theta, phi)
|
---|
| 122 | //--
|
---|
[228] | 123 | {
|
---|
| 124 | int k;
|
---|
| 125 |
|
---|
| 126 | mDirTet = teta;
|
---|
| 127 | mDirPhi = phi;
|
---|
| 128 |
|
---|
| 129 | if (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 | /*
|
---|
| 138 | if (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 |
|
---|
| 151 | double dx,dy,dz;
|
---|
| 152 | double sphi = sin((double)phi);
|
---|
| 153 | double cphi = cos((double)phi);
|
---|
| 154 | double stet = sin((double)teta);
|
---|
| 155 | double ctet = cos((double)teta);
|
---|
| 156 |
|
---|
| 157 | UnitVector pd((double)teta, (double)phi);
|
---|
| 158 | UnitVector vc;
|
---|
| 159 | for(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;
|
---|
[262] | 163 | vc.Setxyz(pd.X()+dx, pd.Y()+dy, pd.Z()+dz);
|
---|
| 164 | mTC[k] = vc.Theta();
|
---|
[228] | 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 | }
|
---|
| 170 | return;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | /* --Methode-- */
|
---|
[568] | 174 | //++
|
---|
[228] | 175 | double MainLobe::Value(int kpx, float& teta, float& phi)
|
---|
[568] | 176 | //
|
---|
| 177 | // return the value of the lobe as also the (theta, phi) of the
|
---|
| 178 | // pixel "kpx"
|
---|
| 179 | //--
|
---|
[228] | 180 | {
|
---|
| 181 | if ( (kpx < 0) || (kpx >= mNpix) ) { teta = phi = 0.; return(0.); }
|
---|
| 182 | teta = mTC[kpx];
|
---|
| 183 | phi = mPC[kpx];
|
---|
| 184 | return(mVal[kpx]);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | /* --Methode-- */
|
---|
[568] | 188 | //++
|
---|
[470] | 189 | double MainLobe::Convol(SphericalMap<double>& sph)
|
---|
[568] | 190 | //
|
---|
| 191 | // return the value of the lobe convolved with the sky (sphere) "sph"
|
---|
| 192 | //--
|
---|
[228] | 193 | {
|
---|
| 194 | double ret=0.;
|
---|
| 195 | int k;
|
---|
| 196 | for(k=0; k<mNpix; k++) ret += mVal[k]*sph(mTC[k], mPC[k]);
|
---|
| 197 | /*
|
---|
| 198 | if( (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 | */
|
---|
| 202 | return(ret/mTotVal);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[568] | 205 | //++
|
---|
| 206 | //
|
---|
| 207 | // inline void Print()
|
---|
| 208 | //--
|
---|
| 209 |
|
---|
| 210 | //++
|
---|
| 211 | // Titre Operators
|
---|
| 212 | //--
|
---|
| 213 |
|
---|
[228] | 214 | /* --Methode-- */
|
---|
[568] | 215 | //++
|
---|
[228] | 216 | ostream& operator << (ostream& s, MainLobe const& lob)
|
---|
[568] | 217 | //
|
---|
| 218 | //--
|
---|
[228] | 219 | {
|
---|
| 220 | s << "MainLobe_Info() : Sigma= " << lob.mSigma << " Dels= " << lob.mDels << " NC= "
|
---|
| 221 | << lob.mNC << " NTotPix= " << lob.mNpix << " Integ= " << lob.mTotVal << endl;
|
---|
| 222 |
|
---|
| 223 | int i,j,k;
|
---|
| 224 | cout << " Direction Teta,Phi = " << lob.mDirTet << " , " << lob.mDirPhi << endl;
|
---|
| 225 | cout << " Pixel 0 , Teta= " << lob.mT0[0] << " Phi= " << lob.mP0[0]
|
---|
| 226 | << " Val= " << lob.mVal[0] << endl;
|
---|
| 227 | k = 1;
|
---|
| 228 | for(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 |
|
---|
| 239 | return s;
|
---|
| 240 | }
|
---|
| 241 |
|
---|