#include "machdefs.h" #include #include #include #include #include #include #include "nomskymapadapter.h" #include "spherethetaphi.h" #include "spheregorski.h" #include "localmap.h" #include "pitvmaad.h" #include "complexios.h" // Classe array adapter pour localMap template class LocalMapArrAdapter : public P2DArrayAdapter { public: LocalMapArrAdapter(LocalMap* lm, bool d=false) : P2DArrayAdapter(lm->XSize(), lm->YSize()) { ad = d; map = lm; } virtual ~LocalMapArrAdapter() { if (ad) delete map; } virtual double Value(int ix, int iy) { return((*map)(ix, iy)); } protected : bool ad; LocalMap* map; }; /* --Methode-- */ double LocalMapArrAdapter< complex >::Value(int ix, int iy) { double re,im; re = (*map)(iy, ix).real(); im = (*map)(iy, ix).imag(); return(sqrt(re*re+im*im)); } /* --Methode-- */ double LocalMapArrAdapter< complex >::Value(int ix, int iy) { double re,im; re = (*map)(iy, ix).real(); im = (*map)(iy, ix).imag(); return(sqrt(re*re+im*im)); } //---------------------------------------------------------------- // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet PixelMap //---------------------------------------------------------------- /* --Methode-- */ template NOMAdapter_PixelMap::NOMAdapter_PixelMap(PixelMap * o) : NObjMgrAdapter(o) { mMap = o; } /* --Methode-- */ template NOMAdapter_PixelMap::~NOMAdapter_PixelMap() { } /* --Methode-- */ template NObjMgrAdapter* NOMAdapter_PixelMap::Clone(AnyDataObj* o) { PixelMap* m = dynamic_cast *>(o); if (m) return ( new NOMAdapter_PixelMap(m) ); return ( new NObjMgrAdapter(o) ); } /* --Methode-- */ template AnyDataObj* NOMAdapter_PixelMap::GetCopyObj() { LocalMap* lm = dynamic_cast< LocalMap * >(mMap); if (lm != NULL) return( new LocalMap(*lm) ); SphereThetaPhi* st = dynamic_cast< SphereThetaPhi * >(mMap); if (st != NULL) return( new SphereThetaPhi(*st) ); SphereGorski* sg = dynamic_cast< SphereGorski * >(mMap); if (sg != NULL) return( new SphereGorski(*sg) ); return(NULL); } /* --Methode-- */ template void NOMAdapter_PixelMap::SavePPF(POutPersist& pos, string const & nom) { LocalMap* lm = dynamic_cast< LocalMap * >(mMap); if (lm != NULL) { FIO_LocalMap fio(lm); fio.Write(pos, nom); return; } SphereThetaPhi* st = dynamic_cast< SphereThetaPhi * >(mMap); if (st != NULL) { FIO_SphereThetaPhi fio(st); fio.Write(pos, nom); return; } SphereGorski* sg = dynamic_cast< SphereGorski * >(mMap); if (sg != NULL) { FIO_SphereGorski fio(sg); fio.Write(pos, nom); return; } string s = typeid(*mMap).name(); cout << "NOMAdapter_PixelMap::SavePPF() - Error : Not supported for " << s << endl; } /* --Methode-- */ template void NOMAdapter_PixelMap::Print(ostream& os) { string s = typeid(*mMap).name(); T moy, sig; MeanSig(moy, sig); cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl; cout << " Mean= " << moy << " Sig2= " << sig << endl; } /* --Methode-- */ template P2DArrayAdapter* NOMAdapter_PixelMap::Get2DArray(string &) { LocalMap* lm = dynamic_cast< LocalMap * >(mMap); if (lm != NULL) return(new LocalMapArrAdapter(lm, false)); int nr = 250; int nc = 500; SphericalMap* sm = dynamic_cast< SphericalMap *>(mMap); if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels()); nc = 2*nr; } TMatrix * mtx = new TMatrix(nr, nc); Project_Mol(*mtx); return (new POTMatrixAdapter(mtx, true) ); } /* --Methode-- */ template NTupleInterface* NOMAdapter_PixelMap::GetNTupleInterface(bool& adel) { adel = true; return( new NTupInt_PixelMap(mMap) ); } /* --Methode-- */ template void NOMAdapter_PixelMap::MeanSig(T& gmoy, T& gsig) { gmoy=0.; gsig = 0.; T valok; for(int k=0; kNbPixels(); k++) { valok = (*mMap)(k); gmoy += valok; gsig += valok*valok; } gmoy /= (T)mMap->NbPixels(); gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy; } /* --Methode-- */ template void NOMAdapter_PixelMap::Project_Mol(TMatrix & mtx, T defval) { r_8 xa, yd, teta,phi, facteur; int_4 l,c,k; int_4 nl = mtx.NRows(); int_4 nc = mtx.NCols(); mtx = defval; // On met tout a defval // cout << " NRows= " << nl << " NCols= " << nc << endl; for(l=0; l= 0.) ) { k = mMap->PixIndexSph(teta, phi); mtx(l,c) = (*mMap)(k); } } } } // ------------------------------------------------------------- /* --Methode-- */ template NTupInt_PixelMap::NTupInt_PixelMap(PixelMap* m) { mMap = m; } /* --Methode-- */ template NTupInt_PixelMap::~NTupInt_PixelMap() { } /* --Methode-- */ template uint_4 NTupInt_PixelMap::NbLines() const { return( mMap->NbPixels() ); } /* --Methode-- */ template uint_4 NTupInt_PixelMap::NbColumns() const { return(8); } /* --Methode-- */ template r_8* NTupInt_PixelMap::GetLineD(int n) const { int i; if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) for(i=0; i<8; i++) mRet[i] = 0.; else { double teta,phi; mMap->PixThetaPhi(n, teta, phi); mRet[0] = n; mRet[1] = mMap->PixVal(n); mRet[2] = mRet[1]; mRet[3] = 0.; mRet[4] = mRet[1]; mRet[5] = 0.; mRet[6] = teta; mRet[7] = phi; } return(mRet); } /* --Methode-- */ template string NTupInt_PixelMap::VarList_C(const char* nx) const { string nomx; if (nx) nomx = nx; else nomx = "_xh_"; string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n"; vardec += "i = " + nomx + "[0]; k = " + nomx + "[0]; val = " + nomx + "[1]; \n"; vardec += "real = " + nomx + "[2]; imag = " + nomx + "[3]; \n"; vardec += "mod = " + nomx + "[4]; phas = " + nomx + "[5]; \n"; vardec += "teta = " + nomx + "[6]; phi = " + nomx + "[7]; \n"; return(vardec); } r_8* NTupInt_PixelMap< complex >::GetLineD(int n) const { int i; if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) for(i=0; i<8; i++) mRet[i] = 0.; else { double teta,phi; mMap->PixThetaPhi(n, teta, phi); mRet[0] = n; mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag(); mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]); mRet[5] = atan2(mRet[3], mRet[2]); mRet[6] = teta; mRet[7] = phi; } return(mRet); } r_8* NTupInt_PixelMap< complex >::GetLineD(int n) const { int i; if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) for(i=0; i<8; i++) mRet[i] = 0.; else { double teta,phi; mMap->PixThetaPhi(n, teta, phi); mRet[0] = n; mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag(); mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]); mRet[5] = atan2(mRet[3], mRet[2]); mRet[6] = teta; mRet[7] = phi; } return(mRet); } #ifdef __CXX_PRAGMA_TEMPLATES__ #pragma define_template NOMAdapter_PixelMap #pragma define_template NOMAdapter_PixelMap #pragma define_template NOMAdapter_PixelMap< complex > #pragma define_template NOMAdapter_PixelMap< complex > #pragma define_template NTupInt_PixelMap #pragma define_template NTupInt_PixelMap #pragma define_template NTupInt_PixelMap< complex > #pragma define_template NTupInt_PixelMap< complex > #endif #if defined(ANSI_TEMPLATES) template class NOMAdapter_PixelMap; template class NOMAdapter_PixelMap; template class NOMAdapter_PixelMap< complex >; template class NOMAdapter_PixelMap< complex >; template class NTupInt_PixelMap; template class NTupInt_PixelMap; template class NTupInt_PixelMap< complex >; template class NTupInt_PixelMap< complex >; #endif