| [2615] | 1 | #include "sopnamsp.h" | 
|---|
| [756] | 2 | #include "objfitter.h" | 
|---|
|  | 3 |  | 
|---|
| [1110] | 4 | //=========================================================================== | 
|---|
|  | 5 | //=========================================================================== | 
|---|
|  | 6 | //=========================== ObjectFitter ================================== | 
|---|
|  | 7 | //=========================================================================== | 
|---|
|  | 8 | //=========================================================================== | 
|---|
|  | 9 |  | 
|---|
| [1206] | 10 | //============================= Matrix et Vector ============================ | 
|---|
| [1204] | 11 | TMatrix<int_4> | 
|---|
| [1206] | 12 | ObjectFitter::FitResidus(TMatrix<int_4> const & mtx,GeneralFit& gfit, | 
|---|
|  | 13 | double xorg,double yorg,double dx,double dy) | 
|---|
|  | 14 | {return( ArrayFitter<int_4>::FitResidus(mtx,gfit,xorg,yorg,dx,dy) );} | 
|---|
| [1204] | 15 |  | 
|---|
| [756] | 16 | TMatrix<r_4> | 
|---|
| [1206] | 17 | ObjectFitter::FitResidus(TMatrix<r_4> const & mtx,GeneralFit& gfit, | 
|---|
|  | 18 | double xorg,double yorg,double dx,double dy) | 
|---|
|  | 19 | {return( ArrayFitter<r_4>::FitResidus(mtx,gfit,xorg,yorg,dx,dy) );} | 
|---|
| [756] | 20 |  | 
|---|
|  | 21 | TMatrix<r_8> | 
|---|
| [1206] | 22 | ObjectFitter::FitResidus(TMatrix<r_8> const & mtx,GeneralFit& gfit, | 
|---|
|  | 23 | double xorg,double yorg,double dx,double dy) | 
|---|
|  | 24 | {return( ArrayFitter<r_8>::FitResidus(mtx,gfit,xorg,yorg,dx,dy) );} | 
|---|
| [756] | 25 |  | 
|---|
| [1204] | 26 | TMatrix<int_4> | 
|---|
| [1206] | 27 | ObjectFitter::FitFunction(TMatrix<int_4> const & mtx,GeneralFit& gfit, | 
|---|
|  | 28 | double xorg,double yorg,double dx,double dy) | 
|---|
|  | 29 | {return( ArrayFitter<int_4>::FitFunction(mtx,gfit,xorg,yorg,dx,dy) );} | 
|---|
| [1204] | 30 |  | 
|---|
| [756] | 31 | TMatrix<r_4> | 
|---|
| [1206] | 32 | ObjectFitter::FitFunction(TMatrix<r_4> const & mtx,GeneralFit& gfit, | 
|---|
|  | 33 | double xorg,double yorg,double dx,double dy) | 
|---|
|  | 34 | {return( ArrayFitter<r_4>::FitFunction(mtx,gfit,xorg,yorg,dx,dy) );} | 
|---|
| [756] | 35 |  | 
|---|
|  | 36 | TMatrix<r_8> | 
|---|
| [1206] | 37 | ObjectFitter::FitFunction(TMatrix<r_8> const & mtx,GeneralFit& gfit, | 
|---|
|  | 38 | double xorg,double yorg,double dx,double dy) | 
|---|
|  | 39 | {return( ArrayFitter<r_8>::FitFunction(mtx,gfit,xorg,yorg,dx,dy) );} | 
|---|
| [756] | 40 |  | 
|---|
| [1204] | 41 | TVector<int_4> | 
|---|
| [1206] | 42 | ObjectFitter::FitResidus(TVector<int_4> const & vec,GeneralFit& gfit, | 
|---|
|  | 43 | double xorg,double dx) | 
|---|
|  | 44 | {return( ArrayFitter<int_4>::FitResidus(vec,gfit,xorg,dx) );} | 
|---|
| [1204] | 45 |  | 
|---|
| [756] | 46 | TVector<r_4> | 
|---|
| [1206] | 47 | ObjectFitter::FitResidus(TVector<r_4> const & vec,GeneralFit& gfit, | 
|---|
|  | 48 | double xorg,double dx) | 
|---|
|  | 49 | {return( ArrayFitter<r_4>::FitResidus(vec,gfit,xorg,dx) );} | 
|---|
| [756] | 50 |  | 
|---|
|  | 51 | TVector<r_8> | 
|---|
| [1206] | 52 | ObjectFitter::FitResidus(TVector<r_8> const & vec,GeneralFit& gfit, | 
|---|
|  | 53 | double xorg,double dx) | 
|---|
|  | 54 | {return( ArrayFitter<r_8>::FitResidus(vec,gfit,xorg,dx) );} | 
|---|
| [756] | 55 |  | 
|---|
| [1204] | 56 | TVector<int_4> | 
|---|
| [1206] | 57 | ObjectFitter::FitFunction(TVector<int_4> const & vec,GeneralFit& gfit, | 
|---|
|  | 58 | double xorg,double dx) | 
|---|
|  | 59 | {return( ArrayFitter<int_4>::FitFunction(vec,gfit,xorg,dx) );} | 
|---|
| [1204] | 60 |  | 
|---|
| [756] | 61 | TVector<r_4> | 
|---|
| [1206] | 62 | ObjectFitter::FitFunction(TVector<r_4> const & vec,GeneralFit& gfit, | 
|---|
|  | 63 | double xorg,double dx) | 
|---|
|  | 64 | {return( ArrayFitter<r_4>::FitFunction(vec,gfit,xorg,dx) );} | 
|---|
| [756] | 65 |  | 
|---|
|  | 66 | TVector<r_8> | 
|---|
| [1206] | 67 | ObjectFitter::FitFunction(TVector<r_8> const & vec,GeneralFit& gfit, | 
|---|
|  | 68 | double xorg,double dx) | 
|---|
|  | 69 | {return( ArrayFitter<r_8>::FitFunction(vec,gfit,xorg,dx) );} | 
|---|
| [756] | 70 |  | 
|---|
| [1206] | 71 | //============================= Matrix et Vector ============================ | 
|---|
|  | 72 | Image<uint_2> ObjectFitter::FitResidus(Image<uint_2> const & im,GeneralFit& gfit) | 
|---|
|  | 73 | { return( ImageFitter<uint_2>::FitResidus(im,gfit) ); } | 
|---|
|  | 74 | Image<int_4> ObjectFitter::FitResidus(Image<int_4> const & im,GeneralFit& gfit) | 
|---|
|  | 75 | { return( ImageFitter<int_4>::FitResidus(im,gfit) ); } | 
|---|
|  | 76 | Image<int_8> ObjectFitter::FitResidus(Image<int_8> const & im,GeneralFit& gfit) | 
|---|
|  | 77 | { return( ImageFitter<int_8>::FitResidus(im,gfit) ); } | 
|---|
|  | 78 | Image<r_4> ObjectFitter::FitResidus(Image<r_4> const & im,GeneralFit& gfit) | 
|---|
|  | 79 | { return( ImageFitter<r_4>::FitResidus(im,gfit) ); } | 
|---|
|  | 80 | Image<r_8> ObjectFitter::FitResidus(Image<r_8> const & im,GeneralFit& gfit) | 
|---|
|  | 81 | { return( ImageFitter<r_8>::FitResidus(im,gfit) ); } | 
|---|
| [756] | 82 |  | 
|---|
| [1206] | 83 | Image<uint_2> ObjectFitter::FitFunction(Image<uint_2> const & im,GeneralFit& gfit) | 
|---|
|  | 84 | { return( ImageFitter<uint_2>::FitFunction(im,gfit) ); } | 
|---|
|  | 85 | Image<int_4> ObjectFitter::FitFunction(Image<int_4> const & im,GeneralFit& gfit) | 
|---|
|  | 86 | { return( ImageFitter<int_4>::FitFunction(im,gfit) ); } | 
|---|
|  | 87 | Image<int_8> ObjectFitter::FitFunction(Image<int_8> const & im,GeneralFit& gfit) | 
|---|
|  | 88 | { return( ImageFitter<int_8>::FitFunction(im,gfit) ); } | 
|---|
|  | 89 | Image<r_4> ObjectFitter::FitFunction(Image<r_4> const & im,GeneralFit& gfit) | 
|---|
|  | 90 | { return( ImageFitter<r_4>::FitFunction(im,gfit) ); } | 
|---|
|  | 91 | Image<r_8> ObjectFitter::FitFunction(Image<r_8> const & im,GeneralFit& gfit) | 
|---|
|  | 92 | { return( ImageFitter<r_8>::FitFunction(im,gfit) ); } | 
|---|
|  | 93 |  | 
|---|
| [1110] | 94 | //=============================== Histo ===================================== | 
|---|
|  | 95 | /*! Retourne une classe contenant les residus du fit ``gfit''. */ | 
|---|
|  | 96 | Histo ObjectFitter::FitResidus(Histo const& hh, GeneralFit& gfit) | 
|---|
|  | 97 | { | 
|---|
|  | 98 | Histo h(hh); | 
|---|
|  | 99 | if(h.NBins()<=0) | 
|---|
|  | 100 | throw(SzMismatchError("Histo::FitResidus: size mismatch\n")); | 
|---|
|  | 101 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 102 | if(f==NULL) | 
|---|
|  | 103 | throw(NullPtrError("Histo::FitResidus: NULL pointer\n")); | 
|---|
|  | 104 | TVector<r_8> par = gfit.GetParm(); | 
|---|
|  | 105 | for(int_4 i=0;i<h.NBins();i++) { | 
|---|
|  | 106 | r_8 x =  h.BinCenter(i); | 
|---|
|  | 107 | h(i) -=  f->Value(&x,par.Data()); | 
|---|
|  | 108 | } | 
|---|
|  | 109 | return h; | 
|---|
|  | 110 | } | 
|---|
| [756] | 111 |  | 
|---|
| [1110] | 112 | /*! Retourne une classe contenant la fonction du fit ``gfit''. */ | 
|---|
|  | 113 | Histo ObjectFitter::FitFunction(Histo const& hh, GeneralFit& gfit) | 
|---|
|  | 114 | { | 
|---|
|  | 115 | Histo h(hh); | 
|---|
|  | 116 | if(h.NBins()<=0) | 
|---|
|  | 117 | throw(SzMismatchError("Histo::FitFunction: size mismatch\n")); | 
|---|
|  | 118 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 119 | if(f==NULL) | 
|---|
|  | 120 | throw(NullPtrError("Histo::FitFunction: NULL pointer\n")); | 
|---|
|  | 121 | TVector<r_8> par = gfit.GetParm(); | 
|---|
|  | 122 | for(int_4 i=0;i<h.NBins();i++) { | 
|---|
|  | 123 | r_8 x =  h.BinCenter(i); | 
|---|
|  | 124 | h(i) =  f->Value(&x,par.Data()); | 
|---|
|  | 125 | } | 
|---|
|  | 126 | return h; | 
|---|
|  | 127 | } | 
|---|
|  | 128 |  | 
|---|
|  | 129 | /*! | 
|---|
|  | 130 | Fit de l'histogramme par ``gfit''. | 
|---|
| [1206] | 131 | \param errtype,errscale,errmin : pour definir les erreurs | 
|---|
|  | 132 | \sa GeneralFitData::ComputeError(double,err,FitErrType,double,double,bool) | 
|---|
| [1110] | 133 | */ | 
|---|
| [1206] | 134 | int_4 ObjectFitter::Fit(Histo const& h, GeneralFit& gfit | 
|---|
|  | 135 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin) | 
|---|
| [1110] | 136 | { | 
|---|
|  | 137 | if(h.NBins()<=0) return -1000; | 
|---|
|  | 138 |  | 
|---|
|  | 139 | GeneralFitData mydata(1,h.NBins()); | 
|---|
|  | 140 |  | 
|---|
|  | 141 | for(int_4 i=0;i<h.NBins();i++) { | 
|---|
|  | 142 | r_8 x =  h.BinCenter(i); | 
|---|
|  | 143 | r_8 f =  h(i); | 
|---|
| [1206] | 144 | r_8 e = (h.HasErrors()) ? h.Error(i) : 1.; | 
|---|
|  | 145 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); | 
|---|
| [1110] | 146 | mydata.AddData1(x,f,e); | 
|---|
|  | 147 | } | 
|---|
|  | 148 |  | 
|---|
|  | 149 | gfit.SetData(&mydata); | 
|---|
|  | 150 |  | 
|---|
|  | 151 | return gfit.Fit(); | 
|---|
|  | 152 | } | 
|---|
|  | 153 |  | 
|---|
|  | 154 | //============================== Histo2D ==================================== | 
|---|
|  | 155 | /*! Retourne une classe contenant les residus du fit ``gfit''. */ | 
|---|
|  | 156 | Histo2D ObjectFitter::FitResidus(Histo2D const& hh, GeneralFit& gfit) | 
|---|
|  | 157 | { | 
|---|
|  | 158 | Histo2D h(hh); | 
|---|
|  | 159 | if(h.NBinX()<=0 || h.NBinY()<=0) | 
|---|
|  | 160 | throw(SzMismatchError("Histo2D::FitResidus: size mismatch\n")); | 
|---|
|  | 161 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 162 | if(f==NULL) | 
|---|
|  | 163 | throw(NullPtrError("Histo2D::FitResidus: NULL pointer\n")); | 
|---|
|  | 164 | TVector<r_8> par = gfit.GetParm(); | 
|---|
|  | 165 | for(int_4 i=0;i<h.NBinX();i++) for(int_4 j=0;j<h.NBinY();j++) { | 
|---|
|  | 166 | r_8 xc,yc; | 
|---|
|  | 167 | h.BinCenter(i,j,xc,yc); | 
|---|
|  | 168 | r_8 x[2] = {xc,yc}; | 
|---|
|  | 169 | h(i,j) -= f->Value(x,par.Data()); | 
|---|
|  | 170 | } | 
|---|
|  | 171 | return h; | 
|---|
|  | 172 | } | 
|---|
|  | 173 |  | 
|---|
|  | 174 | /*! Retourne une classe contenant la fonction du fit ``gfit''. */ | 
|---|
|  | 175 | Histo2D ObjectFitter::FitFunction(Histo2D const& hh, GeneralFit& gfit) | 
|---|
|  | 176 | { | 
|---|
|  | 177 | Histo2D h(hh); | 
|---|
|  | 178 | if(h.NBinX()<=0 || h.NBinY()<=0) | 
|---|
|  | 179 | throw(SzMismatchError("Histo2D::FitFunction: size mismatch\n")); | 
|---|
|  | 180 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 181 | if(f==NULL) | 
|---|
|  | 182 | throw(NullPtrError("Histo2D::FitFunction: NULL pointer\n")); | 
|---|
|  | 183 | TVector<r_8> par = gfit.GetParm(); | 
|---|
|  | 184 | for(int_4 i=0;i<h.NBinX();i++) for(int_4 j=0;j<h.NBinY();j++) { | 
|---|
|  | 185 | r_8 xc,yc; | 
|---|
|  | 186 | h.BinCenter(i,j,xc,yc); | 
|---|
|  | 187 | r_8 x[2] = {xc,yc}; | 
|---|
|  | 188 | h(i,j) = f->Value(x,par.Data()); | 
|---|
|  | 189 | } | 
|---|
|  | 190 | return h; | 
|---|
|  | 191 | } | 
|---|
|  | 192 |  | 
|---|
|  | 193 | /*! | 
|---|
|  | 194 | Fit de l'histogramme par ``gfit''. | 
|---|
| [1206] | 195 | \param errtype,errscale,errmin : pour definir les erreurs | 
|---|
|  | 196 | \sa GeneralFitData::ComputeError(double,err,FitErrType,double,double,bool) | 
|---|
| [1110] | 197 | */ | 
|---|
| [1206] | 198 | int_4 ObjectFitter::Fit(Histo2D const & h, GeneralFit& gfit | 
|---|
|  | 199 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin) | 
|---|
| [1110] | 200 | { | 
|---|
|  | 201 | if(h.NBinX()*h.NBinY()<=0) return -1000; | 
|---|
|  | 202 |  | 
|---|
|  | 203 | GeneralFitData mydata(2,h.NBinX()*h.NBinY()); | 
|---|
|  | 204 |  | 
|---|
|  | 205 | for(int_4 i=0;i<h.NBinX();i++) for(int_4 j=0;j<h.NBinY();j++) { | 
|---|
| [1206] | 206 | r_8 x,y; h.BinCenter(i,j,x,y); | 
|---|
| [1110] | 207 | r_8 f = h(i,j); | 
|---|
| [1206] | 208 | r_8 e = (h.HasErrors()) ? h.Error(i,j) : 1.; | 
|---|
|  | 209 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); | 
|---|
| [1110] | 210 | mydata.AddData2(x,y,f,e); | 
|---|
|  | 211 | } | 
|---|
|  | 212 |  | 
|---|
|  | 213 | gfit.SetData(&mydata); | 
|---|
|  | 214 |  | 
|---|
|  | 215 | return gfit.Fit(); | 
|---|
|  | 216 | } | 
|---|
|  | 217 |  | 
|---|
|  | 218 | //=========================================================================== | 
|---|
|  | 219 | //=========================================================================== | 
|---|
|  | 220 | //========================== ArrayFitter<T> ================================= | 
|---|
|  | 221 | //=========================================================================== | 
|---|
|  | 222 | //=========================================================================== | 
|---|
|  | 223 |  | 
|---|
| [1206] | 224 | /*! Retourne une classe contenant les residus du fit ``gfit''. */ | 
|---|
| [756] | 225 | template <class T> | 
|---|
|  | 226 | TMatrix<T> | 
|---|
|  | 227 | ArrayFitter<T>::FitResidus(TMatrix<T> const & mtx, GeneralFit& gfit, | 
|---|
| [1206] | 228 | double xorg,double yorg,double dx,double dy) | 
|---|
| [756] | 229 | // Retourne une classe contenant les residus du fit ``gfit''. | 
|---|
|  | 230 | // On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j). | 
|---|
|  | 231 | // Les coordonnees de l'element (i,j) sont : | 
|---|
|  | 232 | //    (i,j) -> x = xorg+j*dx , y = yorg+i*dy | 
|---|
|  | 233 | { | 
|---|
|  | 234 | if(mtx.NCols()<=0||mtx.NRows()<=0) | 
|---|
|  | 235 | throw(SzMismatchError("ArrayFitter::FitResidus(TMatrix<T>...) size mismatch\n")); | 
|---|
|  | 236 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 237 | if(f==NULL) | 
|---|
|  | 238 | throw(NullPtrError("ArrayFitter::FitResidus(TMatrix<T>...) GeneraFit==NULL\n")); | 
|---|
|  | 239 | int npar =  gfit.GetNPar(); | 
|---|
|  | 240 | if(npar==0) | 
|---|
|  | 241 | throw(SzMismatchError("ArrayFitter::FitResidus(TMatrix<T>...) GeneraFit 0 parametre\n")); | 
|---|
|  | 242 | double* par = new double[npar]; | 
|---|
|  | 243 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} | 
|---|
| [1206] | 244 | TMatrix<T> m(mtx,false); | 
|---|
| [756] | 245 | for(uint_4 i=0;i<mtx.NRows();i++) for(uint_4 j=0;j<mtx.NCols();j++) { | 
|---|
|  | 246 | double x[2] = {xorg+j*dx,yorg+i*dy}; | 
|---|
|  | 247 | m(i,j) -= f->Value(x,par); | 
|---|
|  | 248 | } | 
|---|
|  | 249 | delete [] par; | 
|---|
|  | 250 | return m; | 
|---|
|  | 251 | } | 
|---|
|  | 252 |  | 
|---|
|  | 253 |  | 
|---|
| [1206] | 254 | /*! Retourne une classe contenant la fonction du fit ``gfit''. */ | 
|---|
| [756] | 255 | template <class T> | 
|---|
|  | 256 | TMatrix<T> | 
|---|
|  | 257 | ArrayFitter<T>::FitFunction(TMatrix<T> const & mtx, GeneralFit& gfit, | 
|---|
| [1206] | 258 | double xorg,double yorg,double dx,double dy) | 
|---|
| [756] | 259 |  | 
|---|
|  | 260 | // Retourne une classe contenant la fonction du fit ``gfit''. | 
|---|
|  | 261 | // On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j). | 
|---|
|  | 262 | // Les coordonnees de l'element (i,j) sont : | 
|---|
|  | 263 | //    (i,j) -> x = xorg + j*dx , y = yorg + i*dy | 
|---|
|  | 264 |  | 
|---|
|  | 265 | { | 
|---|
|  | 266 | if(mtx.NCols()<=0||mtx.NRows()<=0) | 
|---|
|  | 267 | throw(SzMismatchError("ArrayFitter::FitFunction(TMatrix<T>...) size mismatch\n")); | 
|---|
|  | 268 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 269 | if(f==NULL) | 
|---|
|  | 270 | throw(NullPtrError("ArrayFitter::FitFunction(TMatrix<T>...) GeneraFit==NULL\n")); | 
|---|
|  | 271 | int npar =  gfit.GetNPar(); | 
|---|
|  | 272 | if(npar==0) | 
|---|
|  | 273 | throw(SzMismatchError("ArrayFitter::FitFunction(TMatrix<T>...) GeneraFit 0 parametre\n")); | 
|---|
|  | 274 | double* par = new double[npar]; | 
|---|
|  | 275 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} | 
|---|
|  | 276 | TMatrix<T> m(mtx.NRows(), mtx.NCols()); | 
|---|
|  | 277 | for(uint_4 i=0;i<mtx.NRows();i++) for(uint_4 j=0;j<mtx.NCols();j++) { | 
|---|
|  | 278 | double x[2] = {xorg+j*dx,yorg+i*dy}; | 
|---|
|  | 279 | m(i,j) = f->Value(x,par); | 
|---|
|  | 280 | } | 
|---|
|  | 281 | delete [] par; | 
|---|
|  | 282 | return m; | 
|---|
|  | 283 |  | 
|---|
|  | 284 | } | 
|---|
|  | 285 |  | 
|---|
| [1206] | 286 | /*! Retourne une classe contenant les residus du fit ``gfit''. */ | 
|---|
| [756] | 287 | template <class T> | 
|---|
|  | 288 | TVector<T> | 
|---|
|  | 289 | ArrayFitter<T>::FitResidus(TVector<T> const & vec, GeneralFit& gfit, | 
|---|
| [1206] | 290 | double xorg,double dx) | 
|---|
|  | 291 | // Retourne une classe contenant la fonction fittee du fit ``gfit''. | 
|---|
| [756] | 292 | // La coordonnee de l'element (i) est -> x = xorg + i*dx | 
|---|
|  | 293 | { | 
|---|
|  | 294 | if(vec.NElts()<=0) | 
|---|
|  | 295 | throw(SzMismatchError("ArrayFitter::FitResidus(TVector<T>...)  size mismatch\n")); | 
|---|
|  | 296 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 297 | if(f==NULL) | 
|---|
|  | 298 | throw(NullPtrError("ArrayFitter::FitResidus(TVector<T>...) GeneraFit==NULL\n")); | 
|---|
|  | 299 | int npar =  gfit.GetNPar(); | 
|---|
|  | 300 | if(npar==0) | 
|---|
|  | 301 | throw(SzMismatchError("ArrayFitter::FitResidus(TVector<T>...) GeneraFit 0 parametre\n")); | 
|---|
|  | 302 | double* par = new double[npar]; | 
|---|
|  | 303 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} | 
|---|
| [1206] | 304 | TVector<T> v(vec,false); | 
|---|
| [756] | 305 | for(uint_4 i=0;i<vec.NElts();i++) { | 
|---|
|  | 306 | double x = xorg+i*dx; | 
|---|
|  | 307 | v(i) -= f->Value(&x,par); | 
|---|
|  | 308 | } | 
|---|
|  | 309 | delete [] par; | 
|---|
|  | 310 | return v; | 
|---|
|  | 311 | } | 
|---|
|  | 312 |  | 
|---|
| [1206] | 313 | /*! Retourne une classe contenant la fonction du fit ``gfit''. */ | 
|---|
| [756] | 314 | template <class T> | 
|---|
|  | 315 | TVector<T> | 
|---|
|  | 316 | ArrayFitter<T>::FitFunction(TVector<T> const & vec, GeneralFit& gfit, | 
|---|
| [1206] | 317 | double xorg,double dx) | 
|---|
|  | 318 | // Retourne une classe contenant la function fittee du fit ``gfit''. | 
|---|
| [756] | 319 | // La coordonnee de l'element (i) est -> x = xorg + i*dx | 
|---|
|  | 320 | { | 
|---|
|  | 321 | if(vec.NElts()<=0) | 
|---|
|  | 322 | throw(SzMismatchError("ArrayFitter::FitResidus(TVector<T>...)  size mismatch\n")); | 
|---|
|  | 323 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 324 | if(f==NULL) | 
|---|
|  | 325 | throw(NullPtrError("ArrayFitter::FitResidus(TVector<T>...) GeneraFit==NULL\n")); | 
|---|
|  | 326 | int npar =  gfit.GetNPar(); | 
|---|
|  | 327 | if(npar==0) | 
|---|
|  | 328 | throw(SzMismatchError("ArrayFitter::FitResidus(TVector<T>...) GeneraFit 0 parametre\n")); | 
|---|
|  | 329 | double* par = new double[npar]; | 
|---|
|  | 330 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} | 
|---|
|  | 331 | TVector<T> v(vec.NElts()); | 
|---|
|  | 332 | for(uint_4 i=0;i<vec.NElts();i++) { | 
|---|
|  | 333 | double x = xorg+i*dx; | 
|---|
|  | 334 | v(i) = f->Value(&x,par); | 
|---|
|  | 335 | } | 
|---|
|  | 336 | delete [] par; | 
|---|
|  | 337 | return v; | 
|---|
|  | 338 | } | 
|---|
|  | 339 |  | 
|---|
| [1206] | 340 | //=========================================================================== | 
|---|
|  | 341 | //=========================================================================== | 
|---|
|  | 342 | //========================== ImageFitter<T> ================================= | 
|---|
|  | 343 | //=========================================================================== | 
|---|
|  | 344 | //=========================================================================== | 
|---|
| [756] | 345 |  | 
|---|
| [1206] | 346 | /*! Retourne une classe contenant les residus du fit ``gfit''. */ | 
|---|
|  | 347 | template <class T> | 
|---|
|  | 348 | Image<T> | 
|---|
|  | 349 | ImageFitter<T>::FitResidus(Image<T> const & ima, GeneralFit& gfit) | 
|---|
|  | 350 | { | 
|---|
|  | 351 | if(ima.XSize()<=0||ima.YSize()<=0) | 
|---|
|  | 352 | throw(SzMismatchError("ImageFitter::FitResidus(Image<T>...) size mismatch\n")); | 
|---|
|  | 353 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 354 | if(f==NULL) | 
|---|
|  | 355 | throw(NullPtrError("ImageFitter::FitResidus(Image<T>...) GeneraFit==NULL\n")); | 
|---|
|  | 356 | int npar =  gfit.GetNPar(); | 
|---|
|  | 357 | if(npar==0) | 
|---|
|  | 358 | throw(SzMismatchError("ImageFitter::FitResidus(Image<T>...) GeneraFit 0 parametre\n")); | 
|---|
|  | 359 | double* par = new double[npar]; | 
|---|
|  | 360 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} | 
|---|
|  | 361 | Image<T> im(ima,false); | 
|---|
|  | 362 | for(uint_4 i=0;i<ima.XSize();i++) for(uint_4 j=0;j<ima.YSize();j++) { | 
|---|
|  | 363 | double x[2] = {ima.XPos(i),ima.YPos(j)}; | 
|---|
|  | 364 | im(i,j) -= f->Value(x,par); | 
|---|
|  | 365 | } | 
|---|
|  | 366 | delete [] par; | 
|---|
|  | 367 | return im; | 
|---|
|  | 368 | } | 
|---|
|  | 369 |  | 
|---|
|  | 370 | /*! Retourne une classe contenant la function fittee du fit ``gfit''. */ | 
|---|
|  | 371 | template <class T> | 
|---|
|  | 372 | Image<T> | 
|---|
|  | 373 | ImageFitter<T>::FitFunction(Image<T> const & ima, GeneralFit& gfit) | 
|---|
|  | 374 | { | 
|---|
|  | 375 | if(ima.XSize()<=0||ima.YSize()<=0) | 
|---|
|  | 376 | throw(SzMismatchError("ImageFitter::FitFunction(Image<T>...) size mismatch\n")); | 
|---|
|  | 377 | GeneralFunction* f = gfit.GetFunction(); | 
|---|
|  | 378 | if(f==NULL) | 
|---|
|  | 379 | throw(NullPtrError("ImageFitter::FitFunction(Image<T>...) GeneraFit==NULL\n")); | 
|---|
|  | 380 | int npar =  gfit.GetNPar(); | 
|---|
|  | 381 | if(npar==0) | 
|---|
|  | 382 | throw(SzMismatchError("ImageFitter::FitFunction(Image<T>...) GeneraFit 0 parametre\n")); | 
|---|
|  | 383 | double* par = new double[npar]; | 
|---|
|  | 384 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} | 
|---|
|  | 385 | Image<T> im(ima.XSize(),ima.YSize()); | 
|---|
|  | 386 | for(uint_4 i=0;i<ima.XSize();i++) for(uint_4 j=0;j<ima.YSize();j++) { | 
|---|
|  | 387 | double x[2] = {ima.XPos(i),ima.YPos(j)}; | 
|---|
|  | 388 | im(i,j) = f->Value(x,par); | 
|---|
|  | 389 | } | 
|---|
|  | 390 | delete [] par; | 
|---|
|  | 391 | return im; | 
|---|
|  | 392 | } | 
|---|
|  | 393 |  | 
|---|
| [756] | 394 | /////////////////////////////////////////////////////////////// | 
|---|
|  | 395 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
| [1204] | 396 | #pragma define_template ArrayFitter<int_4> | 
|---|
| [756] | 397 | #pragma define_template ArrayFitter<r_4> | 
|---|
|  | 398 | #pragma define_template ArrayFitter<r_8> | 
|---|
| [1204] | 399 | #pragma define_template ArrayFitter< complex<r_4> > | 
|---|
|  | 400 | #pragma define_template ArrayFitter< complex<r_8> > | 
|---|
| [1206] | 401 | #pragma define_template ImageFitter<uint_2> | 
|---|
|  | 402 | #pragma define_template ImageFitter<int_4> | 
|---|
|  | 403 | #pragma define_template ImageFitter<int_8> | 
|---|
|  | 404 | #pragma define_template ImageFitter<r_4> | 
|---|
|  | 405 | #pragma define_template ImageFitter<r_8> | 
|---|
| [756] | 406 | #endif | 
|---|
|  | 407 |  | 
|---|
|  | 408 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
| [1204] | 409 | template class ArrayFitter<int_4>; | 
|---|
| [756] | 410 | template class ArrayFitter<r_4>; | 
|---|
|  | 411 | template class ArrayFitter<r_8>; | 
|---|
| [1204] | 412 | template class ArrayFitter< complex<r_4> >; | 
|---|
|  | 413 | template class ArrayFitter< complex<r_8> >; | 
|---|
| [1206] | 414 | template class ImageFitter<uint_2>; | 
|---|
|  | 415 | template class ImageFitter<int_4>; | 
|---|
|  | 416 | template class ImageFitter<int_8>; | 
|---|
|  | 417 | template class ImageFitter<r_4>; | 
|---|
|  | 418 | template class ImageFitter<r_8>; | 
|---|
| [756] | 419 | #endif | 
|---|