[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 | for(uint_4 i=0;i<mtx.NRows();i++) for(uint_4 j=0;j<mtx.NCols();j++) {
|
---|
| 245 | double x[2] = {xorg+j*dx,yorg+i*dy};
|
---|
| 246 | m(i,j) -= f->Value(x,par);
|
---|
| 247 | }
|
---|
| 248 | delete [] par;
|
---|
| 249 | return m;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 |
|
---|
[1206] | 253 | /*! Retourne une classe contenant la fonction du fit ``gfit''. */
|
---|
[756] | 254 | template <class T>
|
---|
| 255 | TMatrix<T>
|
---|
| 256 | ArrayFitter<T>::FitFunction(TMatrix<T> const & mtx, GeneralFit& gfit,
|
---|
[1206] | 257 | double xorg,double yorg,double dx,double dy)
|
---|
[756] | 258 |
|
---|
| 259 | // Retourne une classe contenant la fonction du fit ``gfit''.
|
---|
| 260 | // On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j).
|
---|
| 261 | // Les coordonnees de l'element (i,j) sont :
|
---|
| 262 | // (i,j) -> x = xorg + j*dx , y = yorg + i*dy
|
---|
| 263 |
|
---|
| 264 | {
|
---|
| 265 | if(mtx.NCols()<=0||mtx.NRows()<=0)
|
---|
| 266 | throw(SzMismatchError("ArrayFitter::FitFunction(TMatrix<T>...) size mismatch\n"));
|
---|
| 267 | GeneralFunction* f = gfit.GetFunction();
|
---|
| 268 | if(f==NULL)
|
---|
| 269 | throw(NullPtrError("ArrayFitter::FitFunction(TMatrix<T>...) GeneraFit==NULL\n"));
|
---|
| 270 | int npar = gfit.GetNPar();
|
---|
| 271 | if(npar==0)
|
---|
| 272 | throw(SzMismatchError("ArrayFitter::FitFunction(TMatrix<T>...) GeneraFit 0 parametre\n"));
|
---|
| 273 | double* par = new double[npar];
|
---|
| 274 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
|
---|
| 275 | TMatrix<T> m(mtx.NRows(), mtx.NCols());
|
---|
| 276 | for(uint_4 i=0;i<mtx.NRows();i++) for(uint_4 j=0;j<mtx.NCols();j++) {
|
---|
| 277 | double x[2] = {xorg+j*dx,yorg+i*dy};
|
---|
| 278 | m(i,j) = f->Value(x,par);
|
---|
| 279 | }
|
---|
| 280 | delete [] par;
|
---|
| 281 | return m;
|
---|
| 282 |
|
---|
| 283 | }
|
---|
| 284 |
|
---|
[1206] | 285 | /*! Retourne une classe contenant les residus du fit ``gfit''. */
|
---|
[756] | 286 | template <class T>
|
---|
| 287 | TVector<T>
|
---|
| 288 | ArrayFitter<T>::FitResidus(TVector<T> const & vec, GeneralFit& gfit,
|
---|
[1206] | 289 | double xorg,double dx)
|
---|
| 290 | // Retourne une classe contenant la fonction fittee du fit ``gfit''.
|
---|
[756] | 291 | // La coordonnee de l'element (i) est -> x = xorg + i*dx
|
---|
| 292 | {
|
---|
| 293 | if(vec.NElts()<=0)
|
---|
| 294 | throw(SzMismatchError("ArrayFitter::FitResidus(TVector<T>...) size mismatch\n"));
|
---|
| 295 | GeneralFunction* f = gfit.GetFunction();
|
---|
| 296 | if(f==NULL)
|
---|
| 297 | throw(NullPtrError("ArrayFitter::FitResidus(TVector<T>...) GeneraFit==NULL\n"));
|
---|
| 298 | int npar = gfit.GetNPar();
|
---|
| 299 | if(npar==0)
|
---|
| 300 | throw(SzMismatchError("ArrayFitter::FitResidus(TVector<T>...) GeneraFit 0 parametre\n"));
|
---|
| 301 | double* par = new double[npar];
|
---|
| 302 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
|
---|
[1206] | 303 | TVector<T> v(vec,false);
|
---|
[756] | 304 | for(uint_4 i=0;i<vec.NElts();i++) {
|
---|
| 305 | double x = xorg+i*dx;
|
---|
| 306 | v(i) -= f->Value(&x,par);
|
---|
| 307 | }
|
---|
| 308 | delete [] par;
|
---|
| 309 | return v;
|
---|
| 310 | }
|
---|
| 311 |
|
---|
[1206] | 312 | /*! Retourne une classe contenant la fonction du fit ``gfit''. */
|
---|
[756] | 313 | template <class T>
|
---|
| 314 | TVector<T>
|
---|
| 315 | ArrayFitter<T>::FitFunction(TVector<T> const & vec, GeneralFit& gfit,
|
---|
[1206] | 316 | double xorg,double dx)
|
---|
| 317 | // Retourne une classe contenant la function fittee du fit ``gfit''.
|
---|
[756] | 318 | // La coordonnee de l'element (i) est -> x = xorg + i*dx
|
---|
| 319 | {
|
---|
| 320 | if(vec.NElts()<=0)
|
---|
| 321 | throw(SzMismatchError("ArrayFitter::FitResidus(TVector<T>...) size mismatch\n"));
|
---|
| 322 | GeneralFunction* f = gfit.GetFunction();
|
---|
| 323 | if(f==NULL)
|
---|
| 324 | throw(NullPtrError("ArrayFitter::FitResidus(TVector<T>...) GeneraFit==NULL\n"));
|
---|
| 325 | int npar = gfit.GetNPar();
|
---|
| 326 | if(npar==0)
|
---|
| 327 | throw(SzMismatchError("ArrayFitter::FitResidus(TVector<T>...) GeneraFit 0 parametre\n"));
|
---|
| 328 | double* par = new double[npar];
|
---|
| 329 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
|
---|
| 330 | TVector<T> v(vec.NElts());
|
---|
| 331 | for(uint_4 i=0;i<vec.NElts();i++) {
|
---|
| 332 | double x = xorg+i*dx;
|
---|
| 333 | v(i) = f->Value(&x,par);
|
---|
| 334 | }
|
---|
| 335 | delete [] par;
|
---|
| 336 | return v;
|
---|
| 337 | }
|
---|
| 338 |
|
---|
[1206] | 339 | //===========================================================================
|
---|
| 340 | //===========================================================================
|
---|
| 341 | //========================== ImageFitter<T> =================================
|
---|
| 342 | //===========================================================================
|
---|
| 343 | //===========================================================================
|
---|
[756] | 344 |
|
---|
[1206] | 345 | /*! Retourne une classe contenant les residus du fit ``gfit''. */
|
---|
| 346 | template <class T>
|
---|
| 347 | Image<T>
|
---|
| 348 | ImageFitter<T>::FitResidus(Image<T> const & ima, GeneralFit& gfit)
|
---|
| 349 | {
|
---|
| 350 | if(ima.XSize()<=0||ima.YSize()<=0)
|
---|
| 351 | throw(SzMismatchError("ImageFitter::FitResidus(Image<T>...) size mismatch\n"));
|
---|
| 352 | GeneralFunction* f = gfit.GetFunction();
|
---|
| 353 | if(f==NULL)
|
---|
| 354 | throw(NullPtrError("ImageFitter::FitResidus(Image<T>...) GeneraFit==NULL\n"));
|
---|
| 355 | int npar = gfit.GetNPar();
|
---|
| 356 | if(npar==0)
|
---|
| 357 | throw(SzMismatchError("ImageFitter::FitResidus(Image<T>...) GeneraFit 0 parametre\n"));
|
---|
| 358 | double* par = new double[npar];
|
---|
| 359 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
|
---|
| 360 | Image<T> im(ima,false);
|
---|
| 361 | for(uint_4 i=0;i<ima.XSize();i++) for(uint_4 j=0;j<ima.YSize();j++) {
|
---|
| 362 | double x[2] = {ima.XPos(i),ima.YPos(j)};
|
---|
| 363 | im(i,j) -= f->Value(x,par);
|
---|
| 364 | }
|
---|
| 365 | delete [] par;
|
---|
| 366 | return im;
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | /*! Retourne une classe contenant la function fittee du fit ``gfit''. */
|
---|
| 370 | template <class T>
|
---|
| 371 | Image<T>
|
---|
| 372 | ImageFitter<T>::FitFunction(Image<T> const & ima, GeneralFit& gfit)
|
---|
| 373 | {
|
---|
| 374 | if(ima.XSize()<=0||ima.YSize()<=0)
|
---|
| 375 | throw(SzMismatchError("ImageFitter::FitFunction(Image<T>...) size mismatch\n"));
|
---|
| 376 | GeneralFunction* f = gfit.GetFunction();
|
---|
| 377 | if(f==NULL)
|
---|
| 378 | throw(NullPtrError("ImageFitter::FitFunction(Image<T>...) GeneraFit==NULL\n"));
|
---|
| 379 | int npar = gfit.GetNPar();
|
---|
| 380 | if(npar==0)
|
---|
| 381 | throw(SzMismatchError("ImageFitter::FitFunction(Image<T>...) GeneraFit 0 parametre\n"));
|
---|
| 382 | double* par = new double[npar];
|
---|
| 383 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
|
---|
| 384 | Image<T> im(ima.XSize(),ima.YSize());
|
---|
| 385 | for(uint_4 i=0;i<ima.XSize();i++) for(uint_4 j=0;j<ima.YSize();j++) {
|
---|
| 386 | double x[2] = {ima.XPos(i),ima.YPos(j)};
|
---|
| 387 | im(i,j) = f->Value(x,par);
|
---|
| 388 | }
|
---|
| 389 | delete [] par;
|
---|
| 390 | return im;
|
---|
| 391 | }
|
---|
| 392 |
|
---|
[756] | 393 | ///////////////////////////////////////////////////////////////
|
---|
| 394 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
[1204] | 395 | #pragma define_template ArrayFitter<int_4>
|
---|
[756] | 396 | #pragma define_template ArrayFitter<r_4>
|
---|
| 397 | #pragma define_template ArrayFitter<r_8>
|
---|
[1204] | 398 | #pragma define_template ArrayFitter< complex<r_4> >
|
---|
| 399 | #pragma define_template ArrayFitter< complex<r_8> >
|
---|
[1206] | 400 | #pragma define_template ImageFitter<uint_2>
|
---|
| 401 | #pragma define_template ImageFitter<int_4>
|
---|
| 402 | #pragma define_template ImageFitter<int_8>
|
---|
| 403 | #pragma define_template ImageFitter<r_4>
|
---|
| 404 | #pragma define_template ImageFitter<r_8>
|
---|
[756] | 405 | #endif
|
---|
| 406 |
|
---|
| 407 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[1204] | 408 | template class ArrayFitter<int_4>;
|
---|
[756] | 409 | template class ArrayFitter<r_4>;
|
---|
| 410 | template class ArrayFitter<r_8>;
|
---|
[1204] | 411 | template class ArrayFitter< complex<r_4> >;
|
---|
| 412 | template class ArrayFitter< complex<r_8> >;
|
---|
[1206] | 413 | template class ImageFitter<uint_2>;
|
---|
| 414 | template class ImageFitter<int_4>;
|
---|
| 415 | template class ImageFitter<int_8>;
|
---|
| 416 | template class ImageFitter<r_4>;
|
---|
| 417 | template class ImageFitter<r_8>;
|
---|
[756] | 418 | #endif
|
---|