source: Sophya/trunk/SophyaPI/PIext/nomskymapadapter.cc@ 1134

Last change on this file since 1134 was 855, checked in by ercodmgr, 25 years ago

Adapatation a SphereHEALPix - Reza 10/4/2000

File size: 7.9 KB
Line 
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
15template <class T>
16class LocalMapArrAdapter : public P2DArrayAdapter {
17public:
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
25protected :
26 bool ad;
27 LocalMap<T>* map;
28};
29
30/* --Methode-- */
31double LocalMapArrAdapter< complex<float> >::Value(int ix, int iy)
32{
33double re,im;
34re = (*map)(iy, ix).real();
35im = (*map)(iy, ix).imag();
36return(sqrt(re*re+im*im));
37}
38/* --Methode-- */
39double LocalMapArrAdapter< complex<double> >::Value(int ix, int iy)
40{
41double re,im;
42re = (*map)(iy, ix).real();
43im = (*map)(iy, ix).imag();
44return(sqrt(re*re+im*im));
45}
46
47//----------------------------------------------------------------
48// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet PixelMap<T>
49//----------------------------------------------------------------
50
51
52/* --Methode-- */
53template <class T>
54NOMAdapter_PixelMap<T>::NOMAdapter_PixelMap(PixelMap<T> * o)
55 : NObjMgrAdapter(o)
56{
57mMap = o;
58}
59
60/* --Methode-- */
61template <class T>
62NOMAdapter_PixelMap<T>::~NOMAdapter_PixelMap()
63{
64}
65
66/* --Methode-- */
67template <class T>
68NObjMgrAdapter* NOMAdapter_PixelMap<T>::Clone(AnyDataObj* o)
69{
70PixelMap<T>* m = dynamic_cast<PixelMap<T> *>(o);
71if (m) return ( new NOMAdapter_PixelMap<T>(m) );
72return ( new NObjMgrAdapter(o) );
73}
74
75/* --Methode-- */
76template <class T>
77AnyDataObj* NOMAdapter_PixelMap<T>::GetCopyObj()
78{
79LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
80if (lm != NULL) return( new LocalMap<T>(*lm) );
81SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
82if (st != NULL) return( new SphereThetaPhi<T>(*st) );
83SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
84if (sg != NULL) return( new SphereHEALPix<T>(*sg) );
85return(NULL);
86}
87
88/* --Methode-- */
89template <class T>
90void NOMAdapter_PixelMap<T>::SavePPF(POutPersist& pos, string const & nom)
91{
92LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
93if (lm != NULL) {
94 FIO_LocalMap<T> fio(lm);
95 fio.Write(pos, nom);
96 return;
97 }
98SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
99if (st != NULL) {
100 FIO_SphereThetaPhi<T> fio(st);
101 fio.Write(pos, nom);
102 return;
103 }
104SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
105if (sg != NULL) {
106 FIO_SphereHEALPix<T> fio(sg);
107 fio.Write(pos, nom);
108 return;
109 }
110string s = typeid(*mMap).name();
111cout << "NOMAdapter_PixelMap<T>::SavePPF() - Error : Not supported for " << s << endl;
112}
113
114/* --Methode-- */
115template <class T>
116void NOMAdapter_PixelMap<T>::Print(ostream& os)
117{
118string s = typeid(*mMap).name();
119T moy, sig;
120MeanSig(moy, sig);
121cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
122cout << " Mean= " << moy << " Sig2= " << sig << endl;
123}
124
125
126/* --Methode-- */
127template <class T>
128P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
129{
130LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
131if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
132int nr = 250;
133int nc = 500;
134SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
135if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels()); nc = 2*nr; }
136TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
137Project_Mol(*mtx);
138return (new POTMatrixAdapter<T>(mtx, true) );
139}
140
141/* --Methode-- */
142template <class T>
143NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel)
144{
145adel = true;
146return( new NTupInt_PixelMap<T>(mMap) );
147}
148
149/* --Methode-- */
150template <class T>
151void 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-- */
166template <class T>
167void 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-- */
194template <class T>
195NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m)
196{
197mMap = m;
198}
199
200/* --Methode-- */
201template <class T>
202NTupInt_PixelMap<T>::~NTupInt_PixelMap()
203{
204}
205
206/* --Methode-- */
207template <class T>
208uint_4 NTupInt_PixelMap<T>::NbLines() const
209{
210return( mMap->NbPixels() );
211}
212
213/* --Methode-- */
214template <class T>
215uint_4 NTupInt_PixelMap<T>::NbColumns() const
216{
217return(8);
218}
219
220/* --Methode-- */
221template <class T>
222r_8* NTupInt_PixelMap<T>::GetLineD(int n) const
223{
224int i;
225if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
226 for(i=0; i<8; i++) mRet[i] = 0.;
227else {
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 }
235return(mRet);
236}
237
238/* --Methode-- */
239template <class T>
240string NTupInt_PixelMap<T>::VarList_C(const char* nx) const
241{
242string nomx;
243if (nx) nomx = nx;
244else nomx = "_xh_";
245string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n";
246vardec += "i = " + nomx + "[0]; k = " + nomx + "[0]; val = " + nomx + "[1]; \n";
247vardec += "real = " + nomx + "[2]; imag = " + nomx + "[3]; \n";
248vardec += "mod = " + nomx + "[4]; phas = " + nomx + "[5]; \n";
249vardec += "teta = " + nomx + "[6]; phi = " + nomx + "[7]; \n";
250return(vardec);
251}
252
253r_8* NTupInt_PixelMap< complex<float> >::GetLineD(int n) const
254{
255int i;
256if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
257 for(i=0; i<8; i++) mRet[i] = 0.;
258else {
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 }
267return(mRet);
268}
269
270r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const
271{
272int i;
273if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
274 for(i=0; i<8; i++) mRet[i] = 0.;
275else {
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 }
284return(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)
300template class NOMAdapter_PixelMap<r_4>;
301template class NOMAdapter_PixelMap<r_8>;
302template class NOMAdapter_PixelMap< complex<float> >;
303template class NOMAdapter_PixelMap< complex<double> >;
304template class NTupInt_PixelMap<r_4>;
305template class NTupInt_PixelMap<r_8>;
306template class NTupInt_PixelMap< complex<float> >;
307template class NTupInt_PixelMap< complex<double> >;
308#endif
Note: See TracBrowser for help on using the repository browser.