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

Last change on this file since 1287 was 1237, checked in by ercodmgr, 25 years ago
  • DataType -> DataTypeInfo
  • modifs cxxexecutor pour

nom de variable: var -> $var
pour #include "cxx_spiapp.h"

cmv 18/10/00

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