1 | #include "sopnamsp.h"
|
---|
2 | #include "machdefs.h"
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <typeinfo>
|
---|
5 | #include <iostream>
|
---|
6 | #include <string>
|
---|
7 | #include <complex>
|
---|
8 |
|
---|
9 | #include "datatype.h"
|
---|
10 |
|
---|
11 | #include "tvector.h"
|
---|
12 | #include "objfitter.h"
|
---|
13 | #include "nomtmatvecadapter.h"
|
---|
14 | #include "piyfxdrw.h"
|
---|
15 | #include "pitvmaad.h"
|
---|
16 |
|
---|
17 | #include "fioarr.h"
|
---|
18 | #include "fitstarray.h"
|
---|
19 |
|
---|
20 |
|
---|
21 | //----------------------------------------------------------------
|
---|
22 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet TMatrix<T>
|
---|
23 | //----------------------------------------------------------------
|
---|
24 |
|
---|
25 |
|
---|
26 | /* --Methode-- */
|
---|
27 | template <class T>
|
---|
28 | NOMAdapter_TMatrix<T>::NOMAdapter_TMatrix(TMatrix<T>* o)
|
---|
29 | : NObjMgrAdapter(o)
|
---|
30 | {
|
---|
31 | mMtx = o;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /* --Methode-- */
|
---|
35 | template <class T>
|
---|
36 | NOMAdapter_TMatrix<T>::~NOMAdapter_TMatrix()
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | /* --Methode-- */
|
---|
41 | template <class T>
|
---|
42 | NObjMgrAdapter* NOMAdapter_TMatrix<T>::Clone(AnyDataObj* o)
|
---|
43 | {
|
---|
44 | TMatrix<T>* m = dynamic_cast<TMatrix<T> *>(o);
|
---|
45 | if (m) return ( new NOMAdapter_TMatrix<T>(m) );
|
---|
46 | return ( new NObjMgrAdapter(o) );
|
---|
47 | }
|
---|
48 |
|
---|
49 | /* --Methode-- */
|
---|
50 | template <class T>
|
---|
51 | string NOMAdapter_TMatrix<T>::GetDataObjType()
|
---|
52 | {
|
---|
53 | string type = "TMatrix< ";
|
---|
54 |
|
---|
55 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
56 | if (v != NULL) type = "TVector< ";
|
---|
57 |
|
---|
58 | // type += DecodeTypeIdName(typeid(T).name());
|
---|
59 | type += DataTypeInfo<T>::getTypeName();
|
---|
60 | type += " > ";
|
---|
61 | return(type);
|
---|
62 | }
|
---|
63 |
|
---|
64 | /* --Methode-- */
|
---|
65 | template <class T>
|
---|
66 | AnyDataObj* NOMAdapter_TMatrix<T>::CloneDataObj(bool share)
|
---|
67 | {
|
---|
68 | if (mMtx == NULL) return(NULL);
|
---|
69 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
70 | if (v != NULL) return( new TVector<T>(*v, share) );
|
---|
71 | else return ( new TMatrix<T>(*mMtx, share) );
|
---|
72 | }
|
---|
73 |
|
---|
74 | /* --Methode-- */
|
---|
75 | template <class T>
|
---|
76 | void NOMAdapter_TMatrix<T>::ReadFits(string const & flnm)
|
---|
77 | {
|
---|
78 | FitsInFile fis(flnm);
|
---|
79 | fis >> (*mMtx);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /* --Methode-- */
|
---|
83 | template <class T>
|
---|
84 | void NOMAdapter_TMatrix<T>::SaveFits(string const & flnm)
|
---|
85 | {
|
---|
86 | FitsOutFile fos(flnm);
|
---|
87 | fos << (*mMtx);
|
---|
88 | }
|
---|
89 | // ---- Specialisation pour complexes -----
|
---|
90 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
91 | void NOMAdapter_TMatrix< complex<r_4> >::ReadFits(string const & flnm)
|
---|
92 | {
|
---|
93 | cout << " NOMAdapter_TMatrix< complex<r_4> >::ReadFits() - Error "
|
---|
94 | << " Not supported (complex data type)" << endl;
|
---|
95 | }
|
---|
96 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
97 | void NOMAdapter_TMatrix< complex<r_4> >::SaveFits(string const & flnm)
|
---|
98 | {
|
---|
99 | cout << " NOMAdapter_TMatrix< complex<r_4> >::SaveFits() - Error "
|
---|
100 | << " Not supported (complex data type)" << endl;
|
---|
101 | }
|
---|
102 |
|
---|
103 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
104 | void NOMAdapter_TMatrix< complex<r_8> >::ReadFits(string const & flnm)
|
---|
105 | {
|
---|
106 | cout << " NOMAdapter_TMatrix< complex<r_8> >::ReadFits() - Error "
|
---|
107 | << " Not supported (complex data type)" << endl;
|
---|
108 | }
|
---|
109 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
110 | void NOMAdapter_TMatrix< complex<r_8> >::SaveFits(string const & flnm)
|
---|
111 | {
|
---|
112 | cout << " NOMAdapter_TMatrix< complex<r_8> >::SaveFits() - Error "
|
---|
113 | << " Not supported (complex data type)" << endl;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /* --Methode-- */
|
---|
117 | template <class T>
|
---|
118 | void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
|
---|
119 | {
|
---|
120 | if (mMtx == NULL) return;
|
---|
121 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
122 | if (v != NULL) {
|
---|
123 | FIO_TArray<T> fio(v);
|
---|
124 | fio.Write(pos, nom);
|
---|
125 | }
|
---|
126 | else {
|
---|
127 | FIO_TArray<T> fio(mMtx);
|
---|
128 | fio.Write(pos, nom);
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* --Methode-- */
|
---|
133 | template <class T>
|
---|
134 | void NOMAdapter_TMatrix<T>::Print(ostream& os)
|
---|
135 | {
|
---|
136 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
137 | if (v != NULL) os << (*v);
|
---|
138 | else os << (*mMtx);
|
---|
139 | }
|
---|
140 |
|
---|
141 | /* --Methode-- */
|
---|
142 | template <class T>
|
---|
143 | PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
|
---|
144 | {
|
---|
145 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
146 | if (v == NULL) return(NULL);
|
---|
147 | else {
|
---|
148 | dopt = "thinline " + dopt;
|
---|
149 | return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | /* --Methode-- */
|
---|
154 | template <class T>
|
---|
155 | P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
|
---|
156 | {
|
---|
157 | return ( new POTMatrixAdapter<T>(mMtx, false) );
|
---|
158 | }
|
---|
159 |
|
---|
160 | /* --Methode-- */
|
---|
161 | template <class T>
|
---|
162 | NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
|
---|
163 | {
|
---|
164 | adel = true;
|
---|
165 | return( new NTupInt_TMatrix<T>(mMtx) );
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | /* --Methode-- */
|
---|
170 | template <class T>
|
---|
171 | GeneralFitData* NOMAdapter_TMatrix<T>::GetGeneralFitData(bool& adel
|
---|
172 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
173 | ,int i1,int i2,int j1,int j2)
|
---|
174 | {
|
---|
175 | adel = false;
|
---|
176 | if(!mMtx) return(NULL);
|
---|
177 |
|
---|
178 | int nx,ny;
|
---|
179 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
180 |
|
---|
181 | if(vec) { // C'est un TVector
|
---|
182 | nx = vec->NElts();
|
---|
183 | ny = 1;
|
---|
184 | } else {
|
---|
185 | nx = mMtx->NRows();
|
---|
186 | ny = mMtx->NCol();
|
---|
187 | if(nx<=0 || ny<=0) return(NULL);
|
---|
188 | }
|
---|
189 |
|
---|
190 | i1 = (i1<0||i1>=nx)? 0: i1;
|
---|
191 | i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
|
---|
192 | j1 = (j1<0||j1>=ny)? 0: j1;
|
---|
193 | j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2;
|
---|
194 |
|
---|
195 | GeneralFitData* mGData = NULL;
|
---|
196 |
|
---|
197 | if(vec) { // C'est un TVector
|
---|
198 | mGData = new GeneralFitData(1,(i2-i1+1),0);
|
---|
199 | adel = true;
|
---|
200 | for(int i=i1;i<=i2;i++) {
|
---|
201 | double x = (double) i;
|
---|
202 | double f = (*vec)(i);
|
---|
203 | double e = 1.;
|
---|
204 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
|
---|
205 | mGData->AddData1(x,f,e);
|
---|
206 | }
|
---|
207 | } else {
|
---|
208 | mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0);
|
---|
209 | adel = true;
|
---|
210 | for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
|
---|
211 | double x = (double) i;
|
---|
212 | double y = (double) j;
|
---|
213 | double f = (*mMtx)(i,j);
|
---|
214 | double e = 1.;
|
---|
215 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
|
---|
216 | mGData->AddData2(x,y,f,e);
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | return mGData;
|
---|
221 | }
|
---|
222 |
|
---|
223 | template <class T>
|
---|
224 | AnyDataObj* NOMAdapter_TMatrix<T>::FitResidusObj(GeneralFit& mfit)
|
---|
225 | {
|
---|
226 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
227 | if(vec) {
|
---|
228 | TVector<T>* v = new TVector<T>(ObjectFitter::FitResidus(*vec,mfit),true);
|
---|
229 | return v;
|
---|
230 | } else {
|
---|
231 | TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitResidus(*mMtx,mfit),true);
|
---|
232 | return m;
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | template <class T>
|
---|
237 | AnyDataObj* NOMAdapter_TMatrix<T>::FitFunctionObj(GeneralFit& mfit)
|
---|
238 | {
|
---|
239 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
240 | if(vec) {
|
---|
241 | TVector<T>* v = new TVector<T>(ObjectFitter::FitFunction(*vec,mfit),true);
|
---|
242 | return v;
|
---|
243 | } else {
|
---|
244 | TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitFunction(*mMtx,mfit),true);
|
---|
245 | return m;
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | // ---- Specialisation pour complexes -----
|
---|
250 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
251 | GeneralFitData* NOMAdapter_TMatrix< complex<r_4> >::GetGeneralFitData(bool& adel
|
---|
252 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
253 | ,int i1,int i2,int j1,int j2)
|
---|
254 | {
|
---|
255 | return(NULL);
|
---|
256 | }
|
---|
257 |
|
---|
258 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
259 | AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitResidusObj(GeneralFit& mfit)
|
---|
260 | {
|
---|
261 | return(NULL);
|
---|
262 | }
|
---|
263 |
|
---|
264 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
265 | AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitFunctionObj(GeneralFit& mfit)
|
---|
266 | {
|
---|
267 | return(NULL);
|
---|
268 | }
|
---|
269 |
|
---|
270 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
271 | GeneralFitData* NOMAdapter_TMatrix< complex<r_8> >::GetGeneralFitData(bool& adel
|
---|
272 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
273 | ,int i1,int i2,int j1,int j2)
|
---|
274 | {
|
---|
275 | return(NULL);
|
---|
276 | }
|
---|
277 |
|
---|
278 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
279 | AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitResidusObj(GeneralFit& mfit)
|
---|
280 | {
|
---|
281 | return(NULL);
|
---|
282 | }
|
---|
283 |
|
---|
284 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
285 | AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitFunctionObj(GeneralFit& mfit)
|
---|
286 | {
|
---|
287 | return(NULL);
|
---|
288 | }
|
---|
289 |
|
---|
290 | // -------------------------------------------------------------
|
---|
291 |
|
---|
292 | /* --Methode-- */
|
---|
293 | template <class T>
|
---|
294 | NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
|
---|
295 | {
|
---|
296 | mMtx = m;
|
---|
297 | }
|
---|
298 |
|
---|
299 | /* --Methode-- */
|
---|
300 | template <class T>
|
---|
301 | NTupInt_TMatrix<T>::~NTupInt_TMatrix()
|
---|
302 | {
|
---|
303 | }
|
---|
304 |
|
---|
305 | /* --Methode-- */
|
---|
306 | template <class T>
|
---|
307 | uint_4 NTupInt_TMatrix<T>::NbLines() const
|
---|
308 | {
|
---|
309 | return( mMtx->NRows()*mMtx->NCols() );
|
---|
310 | }
|
---|
311 |
|
---|
312 | /* --Methode-- */
|
---|
313 | template <class T>
|
---|
314 | uint_4 NTupInt_TMatrix<T>::NbColumns() const
|
---|
315 | {
|
---|
316 | return(8);
|
---|
317 | }
|
---|
318 |
|
---|
319 | /* --Methode-- */
|
---|
320 | template <class T>
|
---|
321 | r_8* NTupInt_TMatrix<T>::GetLineD(int n) const
|
---|
322 | {
|
---|
323 | int i,j;
|
---|
324 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
325 | mRet[0] = n;
|
---|
326 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
327 | }
|
---|
328 | else {
|
---|
329 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
330 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
331 | mRet[3] = (*mMtx)(i,j);
|
---|
332 | mRet[4] = mRet[2]; mRet[5] = 0.;
|
---|
333 | mRet[6] = mRet[2]; mRet[7] = 0.;
|
---|
334 | }
|
---|
335 | return(mRet);
|
---|
336 | }
|
---|
337 |
|
---|
338 | /* --Methode-- */
|
---|
339 | template <class T>
|
---|
340 | string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
|
---|
341 | {
|
---|
342 | string nomx;
|
---|
343 | if (nx) nomx = nx;
|
---|
344 | else nomx = "_xh_";
|
---|
345 | string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
|
---|
346 | vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
|
---|
347 | vardec += "val = " + nomx + "[3]; \n";
|
---|
348 | vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
|
---|
349 | vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
|
---|
350 | return(vardec);
|
---|
351 | }
|
---|
352 |
|
---|
353 | /* --Methode-- */
|
---|
354 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
355 | r_8* NTupInt_TMatrix< complex<r_4> >::GetLineD(int n) const
|
---|
356 | {
|
---|
357 | int i,j;
|
---|
358 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
359 | mRet[0] = n;
|
---|
360 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
361 | }
|
---|
362 | else {
|
---|
363 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
364 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
365 | mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
|
---|
366 | mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
|
---|
367 | mRet[7] = atan2(mRet[5], mRet[4]);
|
---|
368 | }
|
---|
369 | return(mRet);
|
---|
370 | }
|
---|
371 |
|
---|
372 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
373 | r_8* NTupInt_TMatrix< complex<r_8> >::GetLineD(int n) const
|
---|
374 | {
|
---|
375 | int i,j;
|
---|
376 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
377 | mRet[0] = n;
|
---|
378 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
379 | }
|
---|
380 | else {
|
---|
381 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
382 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
383 | mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
|
---|
384 | mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
|
---|
385 | mRet[7] = atan2(mRet[5], mRet[4]);
|
---|
386 | }
|
---|
387 | return(mRet);
|
---|
388 | }
|
---|
389 |
|
---|
390 |
|
---|
391 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
392 | //#pragma define_template NOMAdapter_TMatrix<uint_2>
|
---|
393 | //#pragma define_template NOMAdapter_TMatrix<int_2>
|
---|
394 | #pragma define_template NOMAdapter_TMatrix<int_4>
|
---|
395 | #pragma define_template NOMAdapter_TMatrix<r_4>
|
---|
396 | #pragma define_template NOMAdapter_TMatrix<r_8>
|
---|
397 | #pragma define_template NOMAdapter_TMatrix< complex<r_4> >
|
---|
398 | #pragma define_template NOMAdapter_TMatrix< complex<r_8> >
|
---|
399 | //#pragma define_template NTupInt_TMatrix<uint_2>
|
---|
400 | //#pragma define_template NTupInt_TMatrix<int_2>
|
---|
401 | #pragma define_template NTupInt_TMatrix<int_4>
|
---|
402 | #pragma define_template NTupInt_TMatrix<r_4>
|
---|
403 | #pragma define_template NTupInt_TMatrix<r_8>
|
---|
404 | #pragma define_template NTupInt_TMatrix< complex<r_4> >
|
---|
405 | #pragma define_template NTupInt_TMatrix< complex<r_8> >
|
---|
406 | #endif
|
---|
407 |
|
---|
408 | #if defined(ANSI_TEMPLATES)
|
---|
409 | //template class NOMAdapter_TMatrix<uint_2>;
|
---|
410 | //template class NOMAdapter_TMatrix<int_2>;
|
---|
411 | template class NOMAdapter_TMatrix<int_4>;
|
---|
412 | template class NOMAdapter_TMatrix<r_4>;
|
---|
413 | template class NOMAdapter_TMatrix<r_8>;
|
---|
414 | template class NOMAdapter_TMatrix< complex<r_4> >;
|
---|
415 | template class NOMAdapter_TMatrix< complex<r_8> >;
|
---|
416 | // template class NTupInt_TMatrix<uint_2>;
|
---|
417 | // template class NTupInt_TMatrix<int_2>;
|
---|
418 | template class NTupInt_TMatrix<int_4>;
|
---|
419 | template class NTupInt_TMatrix<r_4>;
|
---|
420 | template class NTupInt_TMatrix<r_8>;
|
---|
421 | template class NTupInt_TMatrix< complex<r_4> >;
|
---|
422 | template class NTupInt_TMatrix< complex<r_8> >;
|
---|
423 | #endif
|
---|