[585] | 1 | #include "machdefs.h"
|
---|
| 2 | #include <stdlib.h>
|
---|
[594] | 3 | #include <math.h>
|
---|
[585] | 4 | #include <typeinfo>
|
---|
| 5 | #include <iostream.h>
|
---|
| 6 | #include <string>
|
---|
| 7 | #include <complex>
|
---|
| 8 |
|
---|
| 9 | #include "nomskymapadapter.h"
|
---|
[855] | 10 | #include "skymap.h"
|
---|
[594] | 11 | #include "pitvmaad.h"
|
---|
| 12 | #include "complexios.h"
|
---|
[585] | 13 |
|
---|
[594] | 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) :
|
---|
[1164] | 19 | P2DArrayAdapter(lm->SizeX(), lm->SizeY())
|
---|
[594] | 20 | { ad = d; map = lm; }
|
---|
[585] | 21 |
|
---|
[594] | 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 |
|
---|
[585] | 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)
|
---|
[594] | 55 | : NObjMgrAdapter(o)
|
---|
[585] | 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>
|
---|
[1165] | 77 | string NOMAdapter_PixelMap<T>::GetDataObjType()
|
---|
[585] | 78 | {
|
---|
[1165] | 79 | string type = "PixelMap< ";
|
---|
[585] | 80 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
[1165] | 81 | if (lm != NULL) type = "LocalMap< ";
|
---|
| 82 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
|
---|
| 83 | if (st != NULL) type = "SphereThetaPhi< ";
|
---|
| 84 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
| 85 | if (sg != NULL) type = "SphereHEALPix< ";
|
---|
| 86 |
|
---|
| 87 | type += typeid(T).name();
|
---|
| 88 | type += " > ";
|
---|
| 89 | return(type);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /* --Methode-- */
|
---|
| 93 | template <class T>
|
---|
| 94 | AnyDataObj* NOMAdapter_PixelMap<T>::CloneDataObj()
|
---|
| 95 | {
|
---|
| 96 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
[585] | 97 | if (lm != NULL) return( new LocalMap<T>(*lm) );
|
---|
| 98 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
|
---|
| 99 | if (st != NULL) return( new SphereThetaPhi<T>(*st) );
|
---|
[855] | 100 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
| 101 | if (sg != NULL) return( new SphereHEALPix<T>(*sg) );
|
---|
[585] | 102 | return(NULL);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | /* --Methode-- */
|
---|
| 106 | template <class T>
|
---|
| 107 | void NOMAdapter_PixelMap<T>::SavePPF(POutPersist& pos, string const & nom)
|
---|
| 108 | {
|
---|
| 109 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
| 110 | if (lm != NULL) {
|
---|
| 111 | FIO_LocalMap<T> fio(lm);
|
---|
| 112 | fio.Write(pos, nom);
|
---|
| 113 | return;
|
---|
| 114 | }
|
---|
| 115 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
|
---|
| 116 | if (st != NULL) {
|
---|
| 117 | FIO_SphereThetaPhi<T> fio(st);
|
---|
| 118 | fio.Write(pos, nom);
|
---|
| 119 | return;
|
---|
| 120 | }
|
---|
[855] | 121 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
|
---|
[585] | 122 | if (sg != NULL) {
|
---|
[855] | 123 | FIO_SphereHEALPix<T> fio(sg);
|
---|
[585] | 124 | fio.Write(pos, nom);
|
---|
| 125 | return;
|
---|
| 126 | }
|
---|
| 127 | string s = typeid(*mMap).name();
|
---|
| 128 | cout << "NOMAdapter_PixelMap<T>::SavePPF() - Error : Not supported for " << s << endl;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /* --Methode-- */
|
---|
| 132 | template <class T>
|
---|
| 133 | void NOMAdapter_PixelMap<T>::Print(ostream& os)
|
---|
| 134 | {
|
---|
| 135 | string s = typeid(*mMap).name();
|
---|
[594] | 136 | T moy, sig;
|
---|
| 137 | MeanSig(moy, sig);
|
---|
[585] | 138 | cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
|
---|
[594] | 139 | cout << " Mean= " << moy << " Sig2= " << sig << endl;
|
---|
[585] | 140 | }
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 | /* --Methode-- */
|
---|
| 144 | template <class T>
|
---|
| 145 | P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
|
---|
| 146 | {
|
---|
[594] | 147 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
|
---|
| 148 | if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
|
---|
| 149 | int nr = 250;
|
---|
| 150 | int nc = 500;
|
---|
| 151 | SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
|
---|
| 152 | if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels()); nc = 2*nr; }
|
---|
| 153 | TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
|
---|
| 154 | Project_Mol(*mtx);
|
---|
| 155 | return (new POTMatrixAdapter<T>(mtx, true) );
|
---|
[585] | 156 | }
|
---|
| 157 |
|
---|
| 158 | /* --Methode-- */
|
---|
| 159 | template <class T>
|
---|
| 160 | NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel)
|
---|
| 161 | {
|
---|
| 162 | adel = true;
|
---|
| 163 | return( new NTupInt_PixelMap<T>(mMap) );
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[594] | 166 | /* --Methode-- */
|
---|
| 167 | template <class T>
|
---|
| 168 | void NOMAdapter_PixelMap<T>::MeanSig(T& gmoy, T& gsig)
|
---|
| 169 | {
|
---|
| 170 | gmoy=0.;
|
---|
| 171 | gsig = 0.;
|
---|
| 172 | T valok;
|
---|
| 173 | for(int k=0; k<mMap->NbPixels(); k++) {
|
---|
| 174 | valok = (*mMap)(k);
|
---|
| 175 | gmoy += valok; gsig += valok*valok;
|
---|
| 176 | }
|
---|
| 177 | gmoy /= (T)mMap->NbPixels();
|
---|
| 178 | gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy;
|
---|
[585] | 179 |
|
---|
[594] | 180 | }
|
---|
[585] | 181 |
|
---|
[594] | 182 | /* --Methode-- */
|
---|
| 183 | template <class T>
|
---|
| 184 | void NOMAdapter_PixelMap<T>::Project_Mol(TMatrix<T> & mtx, T defval)
|
---|
| 185 | {
|
---|
| 186 | r_8 xa, yd, teta,phi, facteur;
|
---|
| 187 | int_4 l,c,k;
|
---|
| 188 | int_4 nl = mtx.NRows();
|
---|
| 189 | int_4 nc = mtx.NCols();
|
---|
[815] | 190 | mtx = defval; // On met tout a defval
|
---|
[594] | 191 | // cout << " NRows= " << nl << " NCols= " << nc << endl;
|
---|
| 192 | for(l=0; l<nl; l++) {
|
---|
| 193 | yd = (r_8)(l+0.5)/(r_8)nl-0.5;
|
---|
| 194 | facteur=2.*M_PI/sin(acos((double)yd*2));
|
---|
| 195 | teta = (yd+0.5)*Pi;
|
---|
| 196 | // teta = (0.5-yd)*M_PI;
|
---|
| 197 | for(c=0; c<nc; c++) {
|
---|
| 198 | xa = (r_8)(c+0.5)/(r_8)nc-0.5;
|
---|
| 199 | phi = xa*facteur+M_PI;
|
---|
| 200 | if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
|
---|
| 201 | k = mMap->PixIndexSph(teta, phi);
|
---|
| 202 | mtx(l,c) = (*mMap)(k);
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[585] | 208 | // -------------------------------------------------------------
|
---|
| 209 |
|
---|
| 210 | /* --Methode-- */
|
---|
| 211 | template <class T>
|
---|
| 212 | NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m)
|
---|
| 213 | {
|
---|
| 214 | mMap = m;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | /* --Methode-- */
|
---|
| 218 | template <class T>
|
---|
| 219 | NTupInt_PixelMap<T>::~NTupInt_PixelMap()
|
---|
| 220 | {
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | /* --Methode-- */
|
---|
| 224 | template <class T>
|
---|
| 225 | uint_4 NTupInt_PixelMap<T>::NbLines() const
|
---|
| 226 | {
|
---|
| 227 | return( mMap->NbPixels() );
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | /* --Methode-- */
|
---|
| 231 | template <class T>
|
---|
| 232 | uint_4 NTupInt_PixelMap<T>::NbColumns() const
|
---|
| 233 | {
|
---|
| 234 | return(8);
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | /* --Methode-- */
|
---|
| 238 | template <class T>
|
---|
| 239 | r_8* NTupInt_PixelMap<T>::GetLineD(int n) const
|
---|
| 240 | {
|
---|
| 241 | int i;
|
---|
| 242 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
|
---|
| 243 | for(i=0; i<8; i++) mRet[i] = 0.;
|
---|
| 244 | else {
|
---|
| 245 | double teta,phi;
|
---|
| 246 | mMap->PixThetaPhi(n, teta, phi);
|
---|
| 247 | mRet[0] = n; mRet[1] = mMap->PixVal(n);
|
---|
| 248 | mRet[2] = mRet[1]; mRet[3] = 0.;
|
---|
| 249 | mRet[4] = mRet[1]; mRet[5] = 0.;
|
---|
| 250 | mRet[6] = teta; mRet[7] = phi;
|
---|
| 251 | }
|
---|
| 252 | return(mRet);
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | /* --Methode-- */
|
---|
| 256 | template <class T>
|
---|
| 257 | string NTupInt_PixelMap<T>::VarList_C(const char* nx) const
|
---|
| 258 | {
|
---|
| 259 | string nomx;
|
---|
| 260 | if (nx) nomx = nx;
|
---|
| 261 | else nomx = "_xh_";
|
---|
| 262 | string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n";
|
---|
| 263 | vardec += "i = " + nomx + "[0]; k = " + nomx + "[0]; val = " + nomx + "[1]; \n";
|
---|
| 264 | vardec += "real = " + nomx + "[2]; imag = " + nomx + "[3]; \n";
|
---|
| 265 | vardec += "mod = " + nomx + "[4]; phas = " + nomx + "[5]; \n";
|
---|
| 266 | vardec += "teta = " + nomx + "[6]; phi = " + nomx + "[7]; \n";
|
---|
| 267 | return(vardec);
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | r_8* NTupInt_PixelMap< complex<float> >::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 | r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const
|
---|
| 288 | {
|
---|
| 289 | int i;
|
---|
| 290 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
|
---|
| 291 | for(i=0; i<8; i++) mRet[i] = 0.;
|
---|
| 292 | else {
|
---|
| 293 | double teta,phi;
|
---|
| 294 | mMap->PixThetaPhi(n, teta, phi);
|
---|
| 295 | mRet[0] = n;
|
---|
| 296 | mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag();
|
---|
| 297 | mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
|
---|
| 298 | mRet[5] = atan2(mRet[3], mRet[2]);
|
---|
| 299 | mRet[6] = teta; mRet[7] = phi;
|
---|
| 300 | }
|
---|
| 301 | return(mRet);
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 |
|
---|
| 305 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 306 | #pragma define_template NOMAdapter_PixelMap<r_4>
|
---|
| 307 | #pragma define_template NOMAdapter_PixelMap<r_8>
|
---|
| 308 | #pragma define_template NOMAdapter_PixelMap< complex<float> >
|
---|
| 309 | #pragma define_template NOMAdapter_PixelMap< complex<double> >
|
---|
| 310 | #pragma define_template NTupInt_PixelMap<r_4>
|
---|
| 311 | #pragma define_template NTupInt_PixelMap<r_8>
|
---|
| 312 | #pragma define_template NTupInt_PixelMap< complex<float> >
|
---|
| 313 | #pragma define_template NTupInt_PixelMap< complex<double> >
|
---|
| 314 | #endif
|
---|
| 315 |
|
---|
| 316 | #if defined(ANSI_TEMPLATES)
|
---|
| 317 | template class NOMAdapter_PixelMap<r_4>;
|
---|
| 318 | template class NOMAdapter_PixelMap<r_8>;
|
---|
| 319 | template class NOMAdapter_PixelMap< complex<float> >;
|
---|
| 320 | template class NOMAdapter_PixelMap< complex<double> >;
|
---|
| 321 | template class NTupInt_PixelMap<r_4>;
|
---|
| 322 | template class NTupInt_PixelMap<r_8>;
|
---|
| 323 | template class NTupInt_PixelMap< complex<float> >;
|
---|
| 324 | template class NTupInt_PixelMap< complex<double> >;
|
---|
| 325 | #endif
|
---|