| [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" | 
|---|
|  | 13 | #include "piscdrawwdg.h" | 
|---|
|  | 14 | #include "pitvmaad.h" | 
|---|
|  | 15 |  | 
|---|
| [810] | 16 | #include "fioarr.h" | 
|---|
| [585] | 17 |  | 
|---|
|  | 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()); | 
|---|
|  | 58 | type += DataType<T>::getTypeName(); | 
|---|
| [1165] | 59 | type +=  " > "; | 
|---|
|  | 60 | return(type); | 
|---|
|  | 61 | } | 
|---|
|  | 62 |  | 
|---|
|  | 63 | /* --Methode-- */ | 
|---|
|  | 64 | template <class T> | 
|---|
|  | 65 | AnyDataObj* NOMAdapter_TMatrix<T>::CloneDataObj() | 
|---|
|  | 66 | { | 
|---|
| [585] | 67 | if (mMtx == NULL)  return(NULL); | 
|---|
|  | 68 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx); | 
|---|
| [1086] | 69 | if (v != NULL) return( new TVector<T>(*v, false) ); | 
|---|
|  | 70 | else return ( new TMatrix<T>(*mMtx, false) ); | 
|---|
| [585] | 71 | } | 
|---|
|  | 72 |  | 
|---|
|  | 73 | /* --Methode-- */ | 
|---|
|  | 74 | template <class T> | 
|---|
|  | 75 | void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom) | 
|---|
|  | 76 | { | 
|---|
|  | 77 | if (mMtx == NULL)  return; | 
|---|
|  | 78 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx); | 
|---|
|  | 79 | if (v != NULL) { | 
|---|
| [810] | 80 | FIO_TArray<T> fio(v); | 
|---|
| [585] | 81 | fio.Write(pos, nom); | 
|---|
|  | 82 | } | 
|---|
|  | 83 | else { | 
|---|
| [810] | 84 | FIO_TArray<T> fio(mMtx); | 
|---|
| [585] | 85 | fio.Write(pos, nom); | 
|---|
|  | 86 | } | 
|---|
|  | 87 | } | 
|---|
|  | 88 |  | 
|---|
|  | 89 | /* --Methode-- */ | 
|---|
|  | 90 | template <class T> | 
|---|
|  | 91 | void NOMAdapter_TMatrix<T>::Print(ostream& os) | 
|---|
|  | 92 | { | 
|---|
|  | 93 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx); | 
|---|
|  | 94 | if (v != NULL)  os << (*v); | 
|---|
|  | 95 | else os << (*mMtx); | 
|---|
|  | 96 | } | 
|---|
|  | 97 |  | 
|---|
|  | 98 | /* --Methode-- */ | 
|---|
|  | 99 | template <class T> | 
|---|
|  | 100 | PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt) | 
|---|
|  | 101 | { | 
|---|
|  | 102 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx); | 
|---|
|  | 103 | if (v == NULL) return(NULL); | 
|---|
|  | 104 | else { | 
|---|
|  | 105 | dopt = "thinline," + dopt; | 
|---|
|  | 106 | return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) ); | 
|---|
|  | 107 | } | 
|---|
|  | 108 | } | 
|---|
|  | 109 |  | 
|---|
|  | 110 | /* --Methode-- */ | 
|---|
|  | 111 | template <class T> | 
|---|
|  | 112 | P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &) | 
|---|
|  | 113 | { | 
|---|
|  | 114 | return ( new POTMatrixAdapter<T>(mMtx, false) ); | 
|---|
|  | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 | /* --Methode-- */ | 
|---|
|  | 118 | template <class T> | 
|---|
|  | 119 | NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel) | 
|---|
|  | 120 | { | 
|---|
|  | 121 | adel = true; | 
|---|
|  | 122 | return( new NTupInt_TMatrix<T>(mMtx) ); | 
|---|
|  | 123 | } | 
|---|
|  | 124 |  | 
|---|
|  | 125 |  | 
|---|
| [1207] | 126 | /* --Methode-- */ | 
|---|
|  | 127 | template <class T> | 
|---|
|  | 128 | GeneralFitData* NOMAdapter_TMatrix<T>::GetGeneralFitData(bool& adel | 
|---|
|  | 129 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin | 
|---|
|  | 130 | ,int i1,int i2,int j1,int j2) | 
|---|
|  | 131 | { | 
|---|
|  | 132 | adel = false; | 
|---|
|  | 133 | if(!mMtx) return(NULL); | 
|---|
| [585] | 134 |  | 
|---|
| [1207] | 135 | int nx,ny; | 
|---|
|  | 136 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx); | 
|---|
|  | 137 |  | 
|---|
|  | 138 | if(vec) {  // C'est un TVector | 
|---|
|  | 139 | nx = vec->NElts(); | 
|---|
|  | 140 | ny = 1; | 
|---|
|  | 141 | } else { | 
|---|
|  | 142 | nx = mMtx->NRows(); | 
|---|
|  | 143 | ny = mMtx->NCol(); | 
|---|
|  | 144 | if(nx<=0 || ny<=0) return(NULL); | 
|---|
|  | 145 | } | 
|---|
|  | 146 |  | 
|---|
|  | 147 | i1 = (i1<0||i1>=nx)? 0: i1; | 
|---|
|  | 148 | i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2; | 
|---|
|  | 149 | j1 = (j1<0||j1>=ny)? 0: j1; | 
|---|
|  | 150 | j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2; | 
|---|
|  | 151 |  | 
|---|
|  | 152 | GeneralFitData* mGData = NULL; | 
|---|
|  | 153 |  | 
|---|
|  | 154 | if(vec) {  // C'est un TVector | 
|---|
|  | 155 | mGData = new GeneralFitData(1,(i2-i1+1),0); | 
|---|
|  | 156 | adel = true; | 
|---|
|  | 157 | for(int i=i1;i<=i2;i++) { | 
|---|
|  | 158 | double x = (double) i; | 
|---|
|  | 159 | double f = (*vec)(i); | 
|---|
|  | 160 | double e = 1.; | 
|---|
|  | 161 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); | 
|---|
|  | 162 | mGData->AddData1(x,f,e); | 
|---|
|  | 163 | } | 
|---|
|  | 164 | } else { | 
|---|
|  | 165 | mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0); | 
|---|
|  | 166 | adel = true; | 
|---|
|  | 167 | for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) { | 
|---|
|  | 168 | double x = (double) i; | 
|---|
|  | 169 | double y = (double) j; | 
|---|
|  | 170 | double f = (*mMtx)(i,j); | 
|---|
|  | 171 | double e = 1.; | 
|---|
|  | 172 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); | 
|---|
|  | 173 | mGData->AddData2(x,y,f,e); | 
|---|
|  | 174 | } | 
|---|
|  | 175 | } | 
|---|
|  | 176 |  | 
|---|
|  | 177 | return mGData; | 
|---|
|  | 178 | } | 
|---|
|  | 179 |  | 
|---|
|  | 180 | template <class T> | 
|---|
|  | 181 | AnyDataObj* NOMAdapter_TMatrix<T>::FitResidusObj(GeneralFit& mfit) | 
|---|
|  | 182 | { | 
|---|
|  | 183 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx); | 
|---|
|  | 184 | if(vec) { | 
|---|
|  | 185 | TVector<T>* v = new TVector<T>(ObjectFitter::FitResidus(*vec,mfit),true); | 
|---|
|  | 186 | return v; | 
|---|
|  | 187 | } else { | 
|---|
|  | 188 | TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitResidus(*mMtx,mfit),true); | 
|---|
|  | 189 | return m; | 
|---|
|  | 190 | } | 
|---|
|  | 191 | } | 
|---|
|  | 192 |  | 
|---|
|  | 193 | template <class T> | 
|---|
|  | 194 | AnyDataObj* NOMAdapter_TMatrix<T>::FitFunctionObj(GeneralFit& mfit) | 
|---|
|  | 195 | { | 
|---|
|  | 196 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx); | 
|---|
|  | 197 | if(vec) { | 
|---|
|  | 198 | TVector<T>* v = new TVector<T>(ObjectFitter::FitFunction(*vec,mfit),true); | 
|---|
|  | 199 | return v; | 
|---|
|  | 200 | } else { | 
|---|
|  | 201 | TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitFunction(*mMtx,mfit),true); | 
|---|
|  | 202 | return m; | 
|---|
|  | 203 | } | 
|---|
|  | 204 | } | 
|---|
|  | 205 |  | 
|---|
|  | 206 |  | 
|---|
| [585] | 207 | // ------------------------------------------------------------- | 
|---|
|  | 208 |  | 
|---|
|  | 209 | /* --Methode-- */ | 
|---|
|  | 210 | template <class T> | 
|---|
|  | 211 | NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m) | 
|---|
|  | 212 | { | 
|---|
|  | 213 | mMtx = m; | 
|---|
|  | 214 | } | 
|---|
|  | 215 |  | 
|---|
|  | 216 | /* --Methode-- */ | 
|---|
|  | 217 | template <class T> | 
|---|
|  | 218 | NTupInt_TMatrix<T>::~NTupInt_TMatrix() | 
|---|
|  | 219 | { | 
|---|
|  | 220 | } | 
|---|
|  | 221 |  | 
|---|
|  | 222 | /* --Methode-- */ | 
|---|
|  | 223 | template <class T> | 
|---|
|  | 224 | uint_4 NTupInt_TMatrix<T>::NbLines() const | 
|---|
|  | 225 | { | 
|---|
|  | 226 | return( mMtx->NRows()*mMtx->NCols() ); | 
|---|
|  | 227 | } | 
|---|
|  | 228 |  | 
|---|
|  | 229 | /* --Methode-- */ | 
|---|
|  | 230 | template <class T> | 
|---|
|  | 231 | uint_4 NTupInt_TMatrix<T>::NbColumns() const | 
|---|
|  | 232 | { | 
|---|
|  | 233 | return(8); | 
|---|
|  | 234 | } | 
|---|
|  | 235 |  | 
|---|
|  | 236 | /* --Methode-- */ | 
|---|
|  | 237 | template <class T> | 
|---|
|  | 238 | r_8* NTupInt_TMatrix<T>::GetLineD(int n) const | 
|---|
|  | 239 | { | 
|---|
|  | 240 | int i,j; | 
|---|
|  | 241 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) { | 
|---|
|  | 242 | mRet[0] = n; | 
|---|
|  | 243 | for(i=1; i<8; i++)  mRet[i] = 0.; | 
|---|
|  | 244 | } | 
|---|
|  | 245 | else { | 
|---|
|  | 246 | i = n/mMtx->NCols(); j = n%mMtx->NCols(); | 
|---|
|  | 247 | mRet[0] = n;  mRet[1] = i;  mRet[2] = j; | 
|---|
|  | 248 | mRet[3] = (*mMtx)(i,j); | 
|---|
|  | 249 | mRet[4] = mRet[2];  mRet[5] = 0.; | 
|---|
|  | 250 | mRet[6] = mRet[2];  mRet[7] = 0.; | 
|---|
|  | 251 | } | 
|---|
|  | 252 | return(mRet); | 
|---|
|  | 253 | } | 
|---|
|  | 254 |  | 
|---|
|  | 255 | /* --Methode-- */ | 
|---|
|  | 256 | template <class T> | 
|---|
|  | 257 | string NTupInt_TMatrix<T>::VarList_C(const char* nx) const | 
|---|
|  | 258 | { | 
|---|
|  | 259 | string nomx; | 
|---|
|  | 260 | if (nx) nomx = nx; | 
|---|
|  | 261 | else nomx = "_xh_"; | 
|---|
|  | 262 | string vardec = "double n,r,c,val,real,imag,mod,phas; \n"; | 
|---|
|  | 263 | vardec += "n = " + nomx + "[0];  r = " + nomx + "[1]; c = " + nomx + "[2]; \n"; | 
|---|
|  | 264 | vardec += "val = " + nomx + "[3]; \n"; | 
|---|
|  | 265 | vardec += "real = " + nomx + "[4];  imag = " + nomx + "[5]; \n"; | 
|---|
|  | 266 | vardec += "mod  = " + nomx + "[6];  phas = " + nomx + "[7]; \n"; | 
|---|
|  | 267 | return(vardec); | 
|---|
|  | 268 | } | 
|---|
|  | 269 |  | 
|---|
|  | 270 | /* --Methode-- */ | 
|---|
|  | 271 | r_8* NTupInt_TMatrix< complex<float> >::GetLineD(int n) const | 
|---|
|  | 272 | { | 
|---|
|  | 273 | int i,j; | 
|---|
|  | 274 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) { | 
|---|
|  | 275 | mRet[0] = n; | 
|---|
|  | 276 | for(i=1; i<8; i++)  mRet[i] = 0.; | 
|---|
|  | 277 | } | 
|---|
|  | 278 | else { | 
|---|
|  | 279 | i = n/mMtx->NCols(); j = n%mMtx->NCols(); | 
|---|
|  | 280 | mRet[0] = n;   mRet[1] = i;  mRet[2] = j; | 
|---|
|  | 281 | mRet[4] = (*mMtx)(i,j).real();  mRet[5] = (*mMtx)(i,j).imag(); | 
|---|
|  | 282 | mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]); | 
|---|
|  | 283 | mRet[7] = atan2(mRet[5], mRet[4]); | 
|---|
|  | 284 | } | 
|---|
|  | 285 | return(mRet); | 
|---|
|  | 286 | } | 
|---|
|  | 287 |  | 
|---|
|  | 288 | r_8* NTupInt_TMatrix< complex<double> >::GetLineD(int n) const | 
|---|
|  | 289 | { | 
|---|
|  | 290 | int i,j; | 
|---|
|  | 291 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) { | 
|---|
|  | 292 | mRet[0] = n; | 
|---|
|  | 293 | for(i=1; i<8; i++)  mRet[i] = 0.; | 
|---|
|  | 294 | } | 
|---|
|  | 295 | else { | 
|---|
|  | 296 | i = n/mMtx->NCols(); j = n%mMtx->NCols(); | 
|---|
|  | 297 | mRet[0] = n;   mRet[1] = i;  mRet[2] = j; | 
|---|
|  | 298 | mRet[4] = (*mMtx)(i,j).real();  mRet[5] = (*mMtx)(i,j).imag(); | 
|---|
|  | 299 | mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]); | 
|---|
|  | 300 | mRet[7] = atan2(mRet[5], mRet[4]); | 
|---|
|  | 301 | } | 
|---|
|  | 302 | return(mRet); | 
|---|
|  | 303 | } | 
|---|
|  | 304 |  | 
|---|
|  | 305 |  | 
|---|
|  | 306 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
|  | 307 | //#pragma define_template NOMAdapter_TMatrix<uint_2> | 
|---|
|  | 308 | //#pragma define_template NOMAdapter_TMatrix<int_2> | 
|---|
|  | 309 | #pragma define_template NOMAdapter_TMatrix<int_4> | 
|---|
|  | 310 | #pragma define_template NOMAdapter_TMatrix<r_4> | 
|---|
|  | 311 | #pragma define_template NOMAdapter_TMatrix<r_8> | 
|---|
| [1207] | 312 | //#pragma define_template NOMAdapter_TMatrix< complex<r_4> > | 
|---|
|  | 313 | //#pragma define_template NOMAdapter_TMatrix< complex<r_8> > | 
|---|
| [585] | 314 | //#pragma define_template NTupInt_TMatrix<uint_2> | 
|---|
|  | 315 | //#pragma define_template NTupInt_TMatrix<int_2> | 
|---|
|  | 316 | #pragma define_template NTupInt_TMatrix<int_4> | 
|---|
|  | 317 | #pragma define_template NTupInt_TMatrix<r_4> | 
|---|
|  | 318 | #pragma define_template NTupInt_TMatrix<r_8> | 
|---|
| [719] | 319 | #pragma define_template NTupInt_TMatrix< complex<r_4> > | 
|---|
|  | 320 | #pragma define_template NTupInt_TMatrix< complex<r_8> > | 
|---|
| [585] | 321 | #endif | 
|---|
|  | 322 |  | 
|---|
|  | 323 | #if defined(ANSI_TEMPLATES) | 
|---|
|  | 324 | //template class NOMAdapter_TMatrix<uint_2>; | 
|---|
|  | 325 | //template class NOMAdapter_TMatrix<int_2>; | 
|---|
|  | 326 | template class NOMAdapter_TMatrix<int_4>; | 
|---|
|  | 327 | template class NOMAdapter_TMatrix<r_4>; | 
|---|
|  | 328 | template class NOMAdapter_TMatrix<r_8>; | 
|---|
| [1207] | 329 | //template class NOMAdapter_TMatrix< complex<r_4> >; | 
|---|
|  | 330 | //template class NOMAdapter_TMatrix< complex<r_8> >; | 
|---|
| [585] | 331 | // template class NTupInt_TMatrix<uint_2>; | 
|---|
|  | 332 | // template class NTupInt_TMatrix<int_2>; | 
|---|
|  | 333 | template class NTupInt_TMatrix<int_4>; | 
|---|
|  | 334 | template class NTupInt_TMatrix<r_4>; | 
|---|
|  | 335 | template class NTupInt_TMatrix<r_8>; | 
|---|
| [719] | 336 | template class NTupInt_TMatrix< complex<r_4> >; | 
|---|
|  | 337 | template class NTupInt_TMatrix< complex<r_8> >; | 
|---|
| [585] | 338 | #endif | 
|---|