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