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

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

intro corrections typeid(T).name() pour Linux cmv 1/10/00

File size: 8.3 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->SizeX(), lm->SizeY())
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>
77string NOMAdapter_PixelMap<T>::GetDataObjType()
78{
79string type = "PixelMap< ";
80LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
81if (lm != NULL) type = "LocalMap< ";
82SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
83if (st != NULL) type = "SphereThetaPhi< ";
84SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
85if (sg != NULL) type = "SphereHEALPix< ";
86
87type += DecodeTypeIdName(typeid(T).name());
88type += " > ";
89return(type);
90}
91
92/* --Methode-- */
93template <class T>
94AnyDataObj* NOMAdapter_PixelMap<T>::CloneDataObj()
95{
96LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
97if (lm != NULL) return( new LocalMap<T>(*lm) );
98SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
99if (st != NULL) return( new SphereThetaPhi<T>(*st) );
100SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
101if (sg != NULL) return( new SphereHEALPix<T>(*sg) );
102return(NULL);
103}
104
105/* --Methode-- */
106template <class T>
107void NOMAdapter_PixelMap<T>::SavePPF(POutPersist& pos, string const & nom)
108{
109LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
110if (lm != NULL) {
111 FIO_LocalMap<T> fio(lm);
112 fio.Write(pos, nom);
113 return;
114 }
115SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
116if (st != NULL) {
117 FIO_SphereThetaPhi<T> fio(st);
118 fio.Write(pos, nom);
119 return;
120 }
121SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap);
122if (sg != NULL) {
123 FIO_SphereHEALPix<T> fio(sg);
124 fio.Write(pos, nom);
125 return;
126 }
127string s = typeid(*mMap).name();
128cout << "NOMAdapter_PixelMap<T>::SavePPF() - Error : Not supported for " << s << endl;
129}
130
131/* --Methode-- */
132template <class T>
133void NOMAdapter_PixelMap<T>::Print(ostream& os)
134{
135string s = typeid(*mMap).name();
136T moy, sig;
137MeanSig(moy, sig);
138cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
139cout << " Mean= " << moy << " Sig2= " << sig << endl;
140}
141
142
143/* --Methode-- */
144template <class T>
145P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
146{
147LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
148if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
149int nr = 250;
150int nc = 500;
151SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
152if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels()); nc = 2*nr; }
153TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
154Project_Mol(*mtx);
155return (new POTMatrixAdapter<T>(mtx, true) );
156}
157
158/* --Methode-- */
159template <class T>
160NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel)
161{
162adel = true;
163return( new NTupInt_PixelMap<T>(mMap) );
164}
165
166/* --Methode-- */
167template <class T>
168void 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;
179
180}
181
182/* --Methode-- */
183template <class T>
184void 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();
190 mtx = defval; // On met tout a defval
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
208// -------------------------------------------------------------
209
210/* --Methode-- */
211template <class T>
212NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m)
213{
214mMap = m;
215}
216
217/* --Methode-- */
218template <class T>
219NTupInt_PixelMap<T>::~NTupInt_PixelMap()
220{
221}
222
223/* --Methode-- */
224template <class T>
225uint_4 NTupInt_PixelMap<T>::NbLines() const
226{
227return( mMap->NbPixels() );
228}
229
230/* --Methode-- */
231template <class T>
232uint_4 NTupInt_PixelMap<T>::NbColumns() const
233{
234return(8);
235}
236
237/* --Methode-- */
238template <class T>
239r_8* NTupInt_PixelMap<T>::GetLineD(int n) const
240{
241int i;
242if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
243 for(i=0; i<8; i++) mRet[i] = 0.;
244else {
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 }
252return(mRet);
253}
254
255/* --Methode-- */
256template <class T>
257string NTupInt_PixelMap<T>::VarList_C(const char* nx) const
258{
259string nomx;
260if (nx) nomx = nx;
261else nomx = "_xh_";
262string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n";
263vardec += "i = " + nomx + "[0]; k = " + nomx + "[0]; val = " + nomx + "[1]; \n";
264vardec += "real = " + nomx + "[2]; imag = " + nomx + "[3]; \n";
265vardec += "mod = " + nomx + "[4]; phas = " + nomx + "[5]; \n";
266vardec += "teta = " + nomx + "[6]; phi = " + nomx + "[7]; \n";
267return(vardec);
268}
269
270r_8* NTupInt_PixelMap< complex<float> >::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
287r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const
288{
289int i;
290if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
291 for(i=0; i<8; i++) mRet[i] = 0.;
292else {
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 }
301return(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)
317template class NOMAdapter_PixelMap<r_4>;
318template class NOMAdapter_PixelMap<r_8>;
319template class NOMAdapter_PixelMap< complex<float> >;
320template class NOMAdapter_PixelMap< complex<double> >;
321template class NTupInt_PixelMap<r_4>;
322template class NTupInt_PixelMap<r_8>;
323template class NTupInt_PixelMap< complex<float> >;
324template class NTupInt_PixelMap< complex<double> >;
325#endif
Note: See TracBrowser for help on using the repository browser.