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