| 1 | #include "machdefs.h"
 | 
|---|
| 2 | #include <stdlib.h>
 | 
|---|
| 3 | #include <math.h>
 | 
|---|
| 4 | #include <typeinfo>
 | 
|---|
| 5 | #include <iostream.h>
 | 
|---|
| 6 | #include <string>
 | 
|---|
| 7 | #include <complex>
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include "nomskymapadapter.h"
 | 
|---|
| 10 | #include "skymap.h"
 | 
|---|
| 11 | #include "pitvmaad.h"
 | 
|---|
| 12 | #include "complexios.h"
 | 
|---|
| 13 | 
 | 
|---|
| 14 | //  Classe array adapter pour localMap
 | 
|---|
| 15 | template <class T> 
 | 
|---|
| 16 | class LocalMapArrAdapter : public P2DArrayAdapter {
 | 
|---|
| 17 | public:
 | 
|---|
| 18 |                 LocalMapArrAdapter(LocalMap<T>* lm, bool d=false) :
 | 
|---|
| 19 |                     P2DArrayAdapter(lm->XSize(), lm->YSize())
 | 
|---|
| 20 |                     { ad = d; map = lm; }
 | 
|---|
| 21 | 
 | 
|---|
| 22 |   virtual       ~LocalMapArrAdapter() { if (ad) delete map; }
 | 
|---|
| 23 |   virtual double  Value(int ix, int iy) { return((*map)(ix, iy)); }
 | 
|---|
| 24 | 
 | 
|---|
| 25 | protected :
 | 
|---|
| 26 |   bool ad;
 | 
|---|
| 27 |   LocalMap<T>* map;
 | 
|---|
| 28 | };
 | 
|---|
| 29 | 
 | 
|---|
| 30 | /* --Methode-- */
 | 
|---|
| 31 | double LocalMapArrAdapter< complex<float> >::Value(int ix, int iy) 
 | 
|---|
| 32 | {
 | 
|---|
| 33 | double re,im;
 | 
|---|
| 34 | re = (*map)(iy, ix).real();
 | 
|---|
| 35 | im = (*map)(iy, ix).imag();
 | 
|---|
| 36 | return(sqrt(re*re+im*im));
 | 
|---|
| 37 | }
 | 
|---|
| 38 | /* --Methode-- */
 | 
|---|
| 39 | double LocalMapArrAdapter< complex<double> >::Value(int ix, int iy) 
 | 
|---|
| 40 | {
 | 
|---|
| 41 | double re,im;
 | 
|---|
| 42 | re = (*map)(iy, ix).real();
 | 
|---|
| 43 | im = (*map)(iy, ix).imag();
 | 
|---|
| 44 | return(sqrt(re*re+im*im));
 | 
|---|
| 45 | }
 | 
|---|
| 46 | 
 | 
|---|
| 47 | //----------------------------------------------------------------
 | 
|---|
| 48 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet PixelMap<T>
 | 
|---|
| 49 | //----------------------------------------------------------------
 | 
|---|
| 50 | 
 | 
|---|
| 51 | 
 | 
|---|
| 52 | /* --Methode-- */
 | 
|---|
| 53 | template <class T> 
 | 
|---|
| 54 | NOMAdapter_PixelMap<T>::NOMAdapter_PixelMap(PixelMap<T> * o)
 | 
|---|
| 55 |   : NObjMgrAdapter(o)
 | 
|---|
| 56 | {
 | 
|---|
| 57 | mMap = o;
 | 
|---|
| 58 | }
 | 
|---|
| 59 | 
 | 
|---|
| 60 | /* --Methode-- */
 | 
|---|
| 61 | template <class T> 
 | 
|---|
| 62 | NOMAdapter_PixelMap<T>::~NOMAdapter_PixelMap()
 | 
|---|
| 63 | {
 | 
|---|
| 64 | }
 | 
|---|
| 65 | 
 | 
|---|
| 66 | /* --Methode-- */
 | 
|---|
| 67 | template <class T> 
 | 
|---|
| 68 | NObjMgrAdapter* NOMAdapter_PixelMap<T>::Clone(AnyDataObj* o)
 | 
|---|
| 69 | {
 | 
|---|
| 70 | PixelMap<T>* m = dynamic_cast<PixelMap<T> *>(o);
 | 
|---|
| 71 | if (m) return ( new NOMAdapter_PixelMap<T>(m) );
 | 
|---|
| 72 | return ( new NObjMgrAdapter(o) );
 | 
|---|
| 73 | }
 | 
|---|
| 74 | 
 | 
|---|
| 75 | /* --Methode-- */
 | 
|---|
| 76 | template <class T> 
 | 
|---|
| 77 | AnyDataObj* NOMAdapter_PixelMap<T>::GetCopyObj()
 | 
|---|
| 78 | {
 | 
|---|
| 79 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); 
 | 
|---|
| 80 | if (lm != NULL) return( new LocalMap<T>(*lm) );
 | 
|---|
| 81 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap); 
 | 
|---|
| 82 | if (st != NULL) return( new SphereThetaPhi<T>(*st) );
 | 
|---|
| 83 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap); 
 | 
|---|
| 84 | if (sg != NULL) return( new SphereHEALPix<T>(*sg) );
 | 
|---|
| 85 | return(NULL);
 | 
|---|
| 86 | }
 | 
|---|
| 87 | 
 | 
|---|
| 88 | /* --Methode-- */
 | 
|---|
| 89 | template <class T> 
 | 
|---|
| 90 | void NOMAdapter_PixelMap<T>::SavePPF(POutPersist& pos, string const & nom)
 | 
|---|
| 91 | {
 | 
|---|
| 92 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); 
 | 
|---|
| 93 | if (lm != NULL) {
 | 
|---|
| 94 |   FIO_LocalMap<T> fio(lm);
 | 
|---|
| 95 |   fio.Write(pos, nom);
 | 
|---|
| 96 |   return;
 | 
|---|
| 97 |   }
 | 
|---|
| 98 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap); 
 | 
|---|
| 99 | if (st != NULL) {
 | 
|---|
| 100 |   FIO_SphereThetaPhi<T> fio(st);
 | 
|---|
| 101 |   fio.Write(pos, nom);
 | 
|---|
| 102 |   return;
 | 
|---|
| 103 |   }
 | 
|---|
| 104 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap); 
 | 
|---|
| 105 | if (sg != NULL) {
 | 
|---|
| 106 |   FIO_SphereHEALPix<T> fio(sg);
 | 
|---|
| 107 |   fio.Write(pos, nom);
 | 
|---|
| 108 |   return;
 | 
|---|
| 109 |   }
 | 
|---|
| 110 | string s = typeid(*mMap).name();
 | 
|---|
| 111 | cout << "NOMAdapter_PixelMap<T>::SavePPF() - Error : Not supported for " << s << endl;
 | 
|---|
| 112 | }
 | 
|---|
| 113 | 
 | 
|---|
| 114 | /* --Methode-- */
 | 
|---|
| 115 | template <class T> 
 | 
|---|
| 116 | void NOMAdapter_PixelMap<T>::Print(ostream& os)
 | 
|---|
| 117 | {
 | 
|---|
| 118 | string s = typeid(*mMap).name();
 | 
|---|
| 119 | T moy, sig;
 | 
|---|
| 120 | MeanSig(moy, sig);
 | 
|---|
| 121 | cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
 | 
|---|
| 122 | cout << "  Mean= " << moy << "  Sig2= " << sig << endl;
 | 
|---|
| 123 | }
 | 
|---|
| 124 | 
 | 
|---|
| 125 | 
 | 
|---|
| 126 | /* --Methode-- */
 | 
|---|
| 127 | template <class T> 
 | 
|---|
| 128 | P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
 | 
|---|
| 129 | {
 | 
|---|
| 130 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); 
 | 
|---|
| 131 | if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
 | 
|---|
| 132 | int nr = 250;
 | 
|---|
| 133 | int nc = 500;
 | 
|---|
| 134 | SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
 | 
|---|
| 135 | if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels());  nc = 2*nr; }
 | 
|---|
| 136 | TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
 | 
|---|
| 137 | Project_Mol(*mtx);
 | 
|---|
| 138 | return (new POTMatrixAdapter<T>(mtx, true) );
 | 
|---|
| 139 | }
 | 
|---|
| 140 | 
 | 
|---|
| 141 | /* --Methode-- */
 | 
|---|
| 142 | template <class T> 
 | 
|---|
| 143 | NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel)
 | 
|---|
| 144 | {
 | 
|---|
| 145 | adel = true;
 | 
|---|
| 146 | return( new NTupInt_PixelMap<T>(mMap) );
 | 
|---|
| 147 | }
 | 
|---|
| 148 | 
 | 
|---|
| 149 | /* --Methode-- */
 | 
|---|
| 150 | template <class T> 
 | 
|---|
| 151 | void NOMAdapter_PixelMap<T>::MeanSig(T& gmoy, T& gsig)
 | 
|---|
| 152 | {
 | 
|---|
| 153 |   gmoy=0.;
 | 
|---|
| 154 |   gsig = 0.;
 | 
|---|
| 155 |   T valok;
 | 
|---|
| 156 |   for(int k=0; k<mMap->NbPixels(); k++) {
 | 
|---|
| 157 |     valok = (*mMap)(k);
 | 
|---|
| 158 |     gmoy += valok;  gsig += valok*valok;
 | 
|---|
| 159 |   }
 | 
|---|
| 160 |   gmoy /= (T)mMap->NbPixels();
 | 
|---|
| 161 |   gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy;
 | 
|---|
| 162 | 
 | 
|---|
| 163 | }
 | 
|---|
| 164 | 
 | 
|---|
| 165 | /* --Methode-- */
 | 
|---|
| 166 | template <class T> 
 | 
|---|
| 167 | void NOMAdapter_PixelMap<T>::Project_Mol(TMatrix<T> & mtx, T defval)
 | 
|---|
| 168 | {
 | 
|---|
| 169 |   r_8 xa, yd, teta,phi, facteur;
 | 
|---|
| 170 |   int_4 l,c,k;
 | 
|---|
| 171 |   int_4 nl = mtx.NRows();
 | 
|---|
| 172 |   int_4 nc = mtx.NCols();
 | 
|---|
| 173 |   mtx = defval;   // On met tout a defval
 | 
|---|
| 174 | //  cout << " NRows= " << nl << "  NCols= " << nc  << endl;
 | 
|---|
| 175 |   for(l=0; l<nl; l++) {
 | 
|---|
| 176 |     yd = (r_8)(l+0.5)/(r_8)nl-0.5;
 | 
|---|
| 177 |     facteur=2.*M_PI/sin(acos((double)yd*2));
 | 
|---|
| 178 |     teta = (yd+0.5)*Pi;
 | 
|---|
| 179 |     //    teta = (0.5-yd)*M_PI;
 | 
|---|
| 180 |     for(c=0; c<nc; c++)  {
 | 
|---|
| 181 |       xa = (r_8)(c+0.5)/(r_8)nc-0.5;
 | 
|---|
| 182 |       phi = xa*facteur+M_PI;
 | 
|---|
| 183 |       if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
 | 
|---|
| 184 |         k = mMap->PixIndexSph(teta, phi);
 | 
|---|
| 185 |         mtx(l,c) = (*mMap)(k);
 | 
|---|
| 186 |       }
 | 
|---|
| 187 |     }
 | 
|---|
| 188 |   }
 | 
|---|
| 189 | }
 | 
|---|
| 190 | 
 | 
|---|
| 191 | // -------------------------------------------------------------
 | 
|---|
| 192 | 
 | 
|---|
| 193 | /* --Methode-- */
 | 
|---|
| 194 | template <class T> 
 | 
|---|
| 195 | NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m)
 | 
|---|
| 196 | {
 | 
|---|
| 197 | mMap = m;
 | 
|---|
| 198 | }
 | 
|---|
| 199 | 
 | 
|---|
| 200 | /* --Methode-- */
 | 
|---|
| 201 | template <class T> 
 | 
|---|
| 202 | NTupInt_PixelMap<T>::~NTupInt_PixelMap()
 | 
|---|
| 203 | {
 | 
|---|
| 204 | }
 | 
|---|
| 205 | 
 | 
|---|
| 206 | /* --Methode-- */
 | 
|---|
| 207 | template <class T> 
 | 
|---|
| 208 | uint_4 NTupInt_PixelMap<T>::NbLines() const
 | 
|---|
| 209 | {
 | 
|---|
| 210 | return( mMap->NbPixels() );
 | 
|---|
| 211 | }
 | 
|---|
| 212 | 
 | 
|---|
| 213 | /* --Methode-- */
 | 
|---|
| 214 | template <class T> 
 | 
|---|
| 215 | uint_4 NTupInt_PixelMap<T>::NbColumns() const 
 | 
|---|
| 216 | {
 | 
|---|
| 217 | return(8);
 | 
|---|
| 218 | }
 | 
|---|
| 219 | 
 | 
|---|
| 220 | /* --Methode-- */
 | 
|---|
| 221 | template <class T> 
 | 
|---|
| 222 | r_8* NTupInt_PixelMap<T>::GetLineD(int n) const 
 | 
|---|
| 223 | {
 | 
|---|
| 224 | int i;
 | 
|---|
| 225 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) 
 | 
|---|
| 226 |     for(i=0; i<8; i++)  mRet[i] = 0.;
 | 
|---|
| 227 | else { 
 | 
|---|
| 228 |   double teta,phi;
 | 
|---|
| 229 |   mMap->PixThetaPhi(n, teta, phi);
 | 
|---|
| 230 |   mRet[0] = n;  mRet[1] = mMap->PixVal(n);
 | 
|---|
| 231 |   mRet[2] = mRet[1];  mRet[3] = 0.;
 | 
|---|
| 232 |   mRet[4] = mRet[1];  mRet[5] = 0.;
 | 
|---|
| 233 |   mRet[6] = teta;     mRet[7] = phi;
 | 
|---|
| 234 |   }
 | 
|---|
| 235 | return(mRet);
 | 
|---|
| 236 | }
 | 
|---|
| 237 | 
 | 
|---|
| 238 | /* --Methode-- */
 | 
|---|
| 239 | template <class T> 
 | 
|---|
| 240 | string NTupInt_PixelMap<T>::VarList_C(const char* nx) const 
 | 
|---|
| 241 | {
 | 
|---|
| 242 | string nomx;
 | 
|---|
| 243 | if (nx) nomx = nx;
 | 
|---|
| 244 | else nomx = "_xh_";
 | 
|---|
| 245 | string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n";
 | 
|---|
| 246 | vardec += "i = " + nomx + "[0]; k = " + nomx + "[0];  val = " + nomx + "[1]; \n";
 | 
|---|
| 247 | vardec += "real = " + nomx + "[2];  imag = " + nomx + "[3]; \n";
 | 
|---|
| 248 | vardec += "mod  = " + nomx + "[4];  phas = " + nomx + "[5]; \n";
 | 
|---|
| 249 | vardec += "teta = " + nomx + "[6];  phi  = " + nomx + "[7]; \n";
 | 
|---|
| 250 | return(vardec);
 | 
|---|
| 251 | }
 | 
|---|
| 252 | 
 | 
|---|
| 253 | r_8* NTupInt_PixelMap< complex<float> >::GetLineD(int n) const 
 | 
|---|
| 254 | {
 | 
|---|
| 255 | int i;
 | 
|---|
| 256 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) 
 | 
|---|
| 257 |     for(i=0; i<8; i++)  mRet[i] = 0.;
 | 
|---|
| 258 | else { 
 | 
|---|
| 259 |   double teta,phi;
 | 
|---|
| 260 |   mMap->PixThetaPhi(n, teta, phi);
 | 
|---|
| 261 |   mRet[0] = n;  
 | 
|---|
| 262 |   mRet[2] = mMap->PixVal(n).real();  mRet[3] = mMap->PixVal(n).imag();
 | 
|---|
| 263 |   mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
 | 
|---|
| 264 |   mRet[5] = atan2(mRet[3], mRet[2]);
 | 
|---|
| 265 |   mRet[6] = teta;     mRet[7] = phi;
 | 
|---|
| 266 |   }
 | 
|---|
| 267 | return(mRet);
 | 
|---|
| 268 | }
 | 
|---|
| 269 | 
 | 
|---|
| 270 | r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const 
 | 
|---|
| 271 | {
 | 
|---|
| 272 | int i;
 | 
|---|
| 273 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) 
 | 
|---|
| 274 |     for(i=0; i<8; i++)  mRet[i] = 0.;
 | 
|---|
| 275 | else { 
 | 
|---|
| 276 |   double teta,phi;
 | 
|---|
| 277 |   mMap->PixThetaPhi(n, teta, phi);
 | 
|---|
| 278 |   mRet[0] = n;  
 | 
|---|
| 279 |   mRet[2] = mMap->PixVal(n).real();  mRet[3] = mMap->PixVal(n).imag();
 | 
|---|
| 280 |   mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
 | 
|---|
| 281 |   mRet[5] = atan2(mRet[3], mRet[2]);
 | 
|---|
| 282 |   mRet[6] = teta;     mRet[7] = phi;
 | 
|---|
| 283 |   }
 | 
|---|
| 284 | return(mRet);
 | 
|---|
| 285 | }
 | 
|---|
| 286 | 
 | 
|---|
| 287 | 
 | 
|---|
| 288 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| 289 | #pragma define_template NOMAdapter_PixelMap<r_4>
 | 
|---|
| 290 | #pragma define_template NOMAdapter_PixelMap<r_8>
 | 
|---|
| 291 | #pragma define_template NOMAdapter_PixelMap< complex<float> >
 | 
|---|
| 292 | #pragma define_template NOMAdapter_PixelMap< complex<double> >
 | 
|---|
| 293 | #pragma define_template NTupInt_PixelMap<r_4>
 | 
|---|
| 294 | #pragma define_template NTupInt_PixelMap<r_8>
 | 
|---|
| 295 | #pragma define_template NTupInt_PixelMap< complex<float> >
 | 
|---|
| 296 | #pragma define_template NTupInt_PixelMap< complex<double> >
 | 
|---|
| 297 | #endif
 | 
|---|
| 298 | 
 | 
|---|
| 299 | #if defined(ANSI_TEMPLATES) 
 | 
|---|
| 300 | template class NOMAdapter_PixelMap<r_4>;
 | 
|---|
| 301 | template class NOMAdapter_PixelMap<r_8>;
 | 
|---|
| 302 | template class NOMAdapter_PixelMap< complex<float> >;
 | 
|---|
| 303 | template class NOMAdapter_PixelMap< complex<double> >;
 | 
|---|
| 304 | template class NTupInt_PixelMap<r_4>;
 | 
|---|
| 305 | template class NTupInt_PixelMap<r_8>;
 | 
|---|
| 306 | template class NTupInt_PixelMap< complex<float> >;
 | 
|---|
| 307 | template class NTupInt_PixelMap< complex<double> >;
 | 
|---|
| 308 | #endif
 | 
|---|