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