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