Changeset 1206 in Sophya
- Timestamp:
- Sep 29, 2000, 4:24:45 PM (25 years ago)
- Location:
- trunk/SophyaLib/NTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/objfitter.cc
r1204 r1206 7 7 //=========================================================================== 8 8 9 //============================= Matrix et Vector ============================ 9 10 TMatrix<int_4> 10 ObjectFitter::FitResidus(TMatrix<int_4> const & mtx, GeneralFit& gfit, 11 double xorg, double yorg, double dx, double dy) 12 { 13 return( ArrayFitter<int_4>::FitResidus(mtx, gfit, xorg, yorg, dx, dy) ); 14 } 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) );} 15 14 16 15 TMatrix<r_4> 17 ObjectFitter::FitResidus(TMatrix<r_4> const & mtx, GeneralFit& gfit, 18 double xorg, double yorg, double dx, double dy) 19 { 20 return( ArrayFitter<r_4>::FitResidus(mtx, gfit, xorg, yorg, dx, dy) ); 21 } 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) );} 22 19 23 20 TMatrix<r_8> 24 ObjectFitter::FitResidus(TMatrix<r_8> const & mtx, GeneralFit& gfit, 25 double xorg, double yorg, double dx, double dy) 26 { 27 return( ArrayFitter<r_8>::FitResidus(mtx, gfit, xorg, yorg, dx, dy) ); 28 } 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) );} 29 24 30 25 TMatrix<int_4> 31 ObjectFitter::FitFunction(TMatrix<int_4> const & mtx, GeneralFit& gfit, 32 double xorg, double yorg, double dx, double dy) 33 { 34 return( ArrayFitter<int_4>::FitFunction(mtx, gfit, xorg, yorg, dx, dy) ); 35 } 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) );} 36 29 37 30 TMatrix<r_4> 38 ObjectFitter::FitFunction(TMatrix<r_4> const & mtx, GeneralFit& gfit, 39 double xorg, double yorg, double dx, double dy) 40 { 41 return( ArrayFitter<r_4>::FitFunction(mtx, gfit, xorg, yorg, dx, dy) ); 42 } 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) );} 43 34 44 35 TMatrix<r_8> 45 ObjectFitter::FitFunction(TMatrix<r_8> const & mtx, GeneralFit& gfit, 46 double xorg, double yorg, double dx, double dy) 47 { 48 return( ArrayFitter<r_8>::FitFunction(mtx, gfit, xorg, yorg, dx, dy) ); 49 } 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) );} 50 39 51 40 TVector<int_4> 52 ObjectFitter::FitResidus(TVector<int_4> const & vec, GeneralFit& gfit, 53 double xorg, double dx) 54 { 55 return( ArrayFitter<int_4>::FitResidus(vec, gfit, xorg, dx) ); 56 } 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) );} 57 44 58 45 TVector<r_4> 59 ObjectFitter::FitResidus(TVector<r_4> const & vec, GeneralFit& gfit, 60 double xorg, double dx) 61 { 62 return( ArrayFitter<r_4>::FitResidus(vec, gfit, xorg, dx) ); 63 } 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) );} 64 49 65 50 TVector<r_8> 66 ObjectFitter::FitResidus(TVector<r_8> const & vec, GeneralFit& gfit, 67 double xorg, double dx) 68 { 69 return( ArrayFitter<r_8>::FitResidus(vec, gfit, xorg, dx) ); 70 } 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) );} 71 54 72 55 TVector<int_4> 73 ObjectFitter::FitFunction(TVector<int_4> const & vec, GeneralFit& gfit, 74 double xorg, double dx) 75 { 76 return( ArrayFitter<int_4>::FitFunction(vec, gfit, xorg, dx) ); 77 } 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) );} 78 59 79 60 TVector<r_4> 80 ObjectFitter::FitFunction(TVector<r_4> const & vec, GeneralFit& gfit, 81 double xorg, double dx) 82 { 83 return( ArrayFitter<r_4>::FitFunction(vec, gfit, xorg, dx) ); 84 } 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) );} 85 64 86 65 TVector<r_8> 87 ObjectFitter::FitFunction(TVector<r_8> const & vec, GeneralFit& gfit, 88 double xorg, double dx) 89 { 90 return( ArrayFitter<r_8>::FitFunction(vec, gfit, xorg, dx) ); 91 } 92 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) );} 69 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) ); } 81 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) ); } 93 92 94 93 //=============================== Histo ===================================== … … 129 128 /*! 130 129 Fit de l'histogramme par ``gfit''. 131 \verbatim 132 typ_err = 0 : 133 - erreur attachee au bin si elle existe 134 - sinon 1 135 typ_err = 1 : 136 - erreur attachee au bin si elle existe 137 - sinon max( sqrt(abs(bin) ,1 ) 138 typ_err = 2 : 139 - erreur forcee a 1 140 typ_err = 3 : 141 - erreur forcee a max( sqrt(abs(bin) ,1 ) 142 typ_err = 4 : 143 - erreur forcee a 1, nulle si bin a zero. 144 typ_err = 5 : 145 - erreur forcee a max( sqrt(abs(bin) ,1 ), 146 nulle si bin a zero. 147 \endverbatim 130 \param errtype,errscale,errmin : pour definir les erreurs 131 \sa GeneralFitData::ComputeError(double,err,FitErrType,double,double,bool) 148 132 */ 149 int_4 ObjectFitter::Fit(Histo const& h, GeneralFit& gfit,unsigned short typ_err) 133 int_4 ObjectFitter::Fit(Histo const& h, GeneralFit& gfit 134 ,GeneralFitData::FitErrType errtype,double errscale,double errmin) 150 135 { 151 136 if(h.NBins()<=0) return -1000; 152 if(typ_err>5) typ_err=0;153 137 154 138 GeneralFitData mydata(1,h.NBins()); … … 157 141 r_8 x = h.BinCenter(i); 158 142 r_8 f = h(i); 159 r_8 saf = sqrt(fabs( f)); if(saf<1.) saf=1.; 160 r_8 e=0.; 161 if(typ_err==0) {if(h.HasErrors()) e=h.Error(i); else e=1.;} 162 else if(typ_err==1) {if(h.HasErrors()) e=h.Error(i); else e=saf;} 163 else if(typ_err==2) e=1.; 164 else if(typ_err==3) e=saf; 165 else if(typ_err==4) e=(f==0.)?0.:1.; 166 else if(typ_err==5) e=(f==0.)?0.:saf; 143 r_8 e = (h.HasErrors()) ? h.Error(i) : 1.; 144 e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); 167 145 mydata.AddData1(x,f,e); 168 146 } … … 214 192 /*! 215 193 Fit de l'histogramme par ``gfit''. 216 \verbatim 217 typ_err = 0 : 218 - erreur attachee au bin si elle existe 219 - sinon 1 220 typ_err = 1 : 221 - erreur attachee au bin si elle existe 222 - sinon max( sqrt(abs(bin) ,1 ) 223 typ_err = 2 : 224 - erreur forcee a 1 225 typ_err = 3 : 226 - erreur forcee a max( sqrt(abs(bin) ,1 ) 227 typ_err = 4 : 228 - erreur forcee a 1, nulle si bin a zero. 229 typ_err = 5 : 230 - erreur forcee a max( sqrt(abs(bin) ,1 ), 231 nulle si bin a zero. 232 \endverbatim 194 \param errtype,errscale,errmin : pour definir les erreurs 195 \sa GeneralFitData::ComputeError(double,err,FitErrType,double,double,bool) 233 196 */ 234 int_4 ObjectFitter::Fit(Histo2D const & h, GeneralFit& gfit,unsigned short typ_err) 197 int_4 ObjectFitter::Fit(Histo2D const & h, GeneralFit& gfit 198 ,GeneralFitData::FitErrType errtype,double errscale,double errmin) 235 199 { 236 200 if(h.NBinX()*h.NBinY()<=0) return -1000; 237 if(typ_err>5) typ_err=0;238 201 239 202 GeneralFitData mydata(2,h.NBinX()*h.NBinY()); 240 203 241 204 for(int_4 i=0;i<h.NBinX();i++) for(int_4 j=0;j<h.NBinY();j++) { 242 r_8 x,y; 243 h.BinCenter(i,j,x,y); 205 r_8 x,y; h.BinCenter(i,j,x,y); 244 206 r_8 f = h(i,j); 245 r_8 saf = sqrt(fabs(f)); if(saf<1.) saf=1.; 246 r_8 e=0.; 247 if(typ_err==0) {if(h.HasErrors()) e=h.Error(i,j); else e=1.;} 248 else if(typ_err==1) {if(h.HasErrors()) e=h.Error(i,j); else e=saf;} 249 else if(typ_err==2) e=1.; 250 else if(typ_err==3) e=saf; 251 else if(typ_err==4) e=(f==0.)?0.:1.; 252 else if(typ_err==5) e=(f==0.)?0.:saf; 207 r_8 e = (h.HasErrors()) ? h.Error(i,j) : 1.; 208 e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); 253 209 mydata.AddData2(x,y,f,e); 254 210 } … … 265 221 //=========================================================================== 266 222 223 /*! Retourne une classe contenant les residus du fit ``gfit''. */ 267 224 template <class T> 268 225 TMatrix<T> 269 226 ArrayFitter<T>::FitResidus(TMatrix<T> const & mtx, GeneralFit& gfit, 270 double xorg,double yorg,double dx,double dy)227 double xorg,double yorg,double dx,double dy) 271 228 // Retourne une classe contenant les residus du fit ``gfit''. 272 229 // On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j). … … 284 241 double* par = new double[npar]; 285 242 {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} 286 TMatrix<T> m(mtx );243 TMatrix<T> m(mtx,false); 287 244 m.SetTemp(true); 288 245 for(uint_4 i=0;i<mtx.NRows();i++) for(uint_4 j=0;j<mtx.NCols();j++) { … … 295 252 296 253 254 /*! Retourne une classe contenant la fonction du fit ``gfit''. */ 297 255 template <class T> 298 256 TMatrix<T> 299 257 ArrayFitter<T>::FitFunction(TMatrix<T> const & mtx, GeneralFit& gfit, 300 double xorg,double yorg,double dx,double dy)258 double xorg,double yorg,double dx,double dy) 301 259 302 260 // Retourne une classe contenant la fonction du fit ``gfit''. … … 327 285 } 328 286 287 /*! Retourne une classe contenant les residus du fit ``gfit''. */ 329 288 template <class T> 330 289 TVector<T> 331 290 ArrayFitter<T>::FitResidus(TVector<T> const & vec, GeneralFit& gfit, 332 double xorg,double dx)333 // Retourne une classe contenant l es residusdu fit ``gfit''.291 double xorg,double dx) 292 // Retourne une classe contenant la fonction fittee du fit ``gfit''. 334 293 // La coordonnee de l'element (i) est -> x = xorg + i*dx 335 294 { … … 344 303 double* par = new double[npar]; 345 304 {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} 346 TVector<T> v(vec );305 TVector<T> v(vec,false); 347 306 v.SetTemp(true); 348 307 for(uint_4 i=0;i<vec.NElts();i++) { … … 354 313 } 355 314 315 /*! Retourne une classe contenant la fonction du fit ``gfit''. */ 356 316 template <class T> 357 317 TVector<T> 358 318 ArrayFitter<T>::FitFunction(TVector<T> const & vec, GeneralFit& gfit, 359 double xorg,double dx)360 // Retourne une classe contenant l es residusdu fit ``gfit''.319 double xorg,double dx) 320 // Retourne une classe contenant la function fittee du fit ``gfit''. 361 321 // La coordonnee de l'element (i) est -> x = xorg + i*dx 362 322 { … … 381 341 } 382 342 343 //=========================================================================== 344 //=========================================================================== 345 //========================== ImageFitter<T> ================================= 346 //=========================================================================== 347 //=========================================================================== 348 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 } 383 398 384 399 /////////////////////////////////////////////////////////////// … … 389 404 #pragma define_template ArrayFitter< complex<r_4> > 390 405 #pragma define_template ArrayFitter< complex<r_8> > 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> 391 411 #endif 392 412 … … 397 417 template class ArrayFitter< complex<r_4> >; 398 418 template class ArrayFitter< complex<r_8> >; 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>; 399 424 #endif 400 -
trunk/SophyaLib/NTools/objfitter.h
r1204 r1206 10 10 11 11 #include "tmatrix.h" 12 #include "cimage.h" 12 13 #include "tvector.h" 13 14 #include "histos.h" … … 67 68 double xorg=0.,double dx=1.); 68 69 70 // Residus et fonction fittees sur Image 71 static Image<uint_2> FitResidus(Image<uint_2> const & im, GeneralFit& gfit); 72 static Image<int_4> FitResidus(Image<int_4> const & im, GeneralFit& gfit); 73 static Image<int_8> FitResidus(Image<int_8> const & im, GeneralFit& gfit); 74 static Image<r_4> FitResidus(Image<r_4> const & im, GeneralFit& gfit); 75 static Image<r_8> FitResidus(Image<r_8> const & im, GeneralFit& gfit); 76 77 static Image<uint_2> FitFunction(Image<uint_2> const & im, GeneralFit& gfit); 78 static Image<int_4> FitFunction(Image<int_4> const & im, GeneralFit& gfit); 79 static Image<int_8> FitFunction(Image<int_8> const & im, GeneralFit& gfit); 80 static Image<r_4> FitFunction(Image<r_4> const & im, GeneralFit& gfit); 81 static Image<r_8> FitFunction(Image<r_8> const & im, GeneralFit& gfit); 82 69 83 // Residus et fonction fittees sur Histo 70 84 static Histo FitResidus(Histo const& h, GeneralFit& gfit); 71 85 static Histo FitFunction(Histo const& h, GeneralFit& gfit); 72 static int_4 Fit(Histo const & h, GeneralFit& gfit,unsigned short typ_err=0); 86 static int_4 Fit(Histo const & h, GeneralFit& gfit 87 ,GeneralFitData::FitErrType errtype=GeneralFitData::DefaultError 88 ,double errscale=1.,double errmin=1.); 73 89 74 90 // Residus et fonction fittees sur Histo2D 75 91 static Histo2D FitResidus(Histo2D const& h, GeneralFit& gfit); 76 92 static Histo2D FitFunction(Histo2D const& h, GeneralFit& gfit); 77 static int_4 Fit(Histo2D const & h, GeneralFit& gfit,unsigned short typ_err=0); 93 static int_4 Fit(Histo2D const & h, GeneralFit& gfit 94 ,GeneralFitData::FitErrType errtype=GeneralFitData::DefaultError 95 ,double errscale=1.,double errmin=0.); 78 96 79 97 // Residus et fonction fittees sur HProf … … 82 100 static inline Histo FitFunction(HProf const& h, GeneralFit& gfit) 83 101 {h.UpdateHisto(); return FitFunction((Histo const&) h,gfit);} 84 static int_4 Fit(HProf const & h, GeneralFit& gfit) 85 {h.UpdateHisto(); return Fit((Histo const&) h,gfit,0);} 102 static int_4 Fit(HProf const & h, GeneralFit& gfit 103 ,GeneralFitData::FitErrType errtype=GeneralFitData::DefaultError 104 ,double errscale=1.,double errmin=0.) 105 {h.UpdateHisto(); 106 return Fit((Histo const&) h,gfit,errtype,errscale,errmin);} 86 107 87 108 // Residus et fonction fittees sur GeneralFitData … … 108 129 }; 109 130 131 // Classe template pour ajustement sur images 132 template <class T> 133 class ImageFitter { 134 public: 135 static Image<T> FitResidus(Image<T> const & mtx, GeneralFit& gfit); 136 static Image<T> FitFunction(Image<T> const & mtx, GeneralFit& gfit); 137 }; 138 110 139 } // Fin du namespace 111 140
Note:
See TracChangeset
for help on using the changeset viewer.