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