Changeset 1204 in Sophya for trunk/SophyaLib
- Timestamp:
- Sep 29, 2000, 12:15:55 AM (25 years ago)
- Location:
- trunk/SophyaLib/NTools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/cimage.h
r1169 r1204 39 39 inline r_8 XPixSize() const {return pxsz_x;} 40 40 inline r_8 YPixSize() const {return pxsz_y;} 41 42 inline r_8 XPos(uint_4 i) const {return org_x + i*pxsz_x;} 43 inline r_8 YPos(uint_4 j) const {return org_y + j*pxsz_y;} 41 44 42 45 inline void SetOrg(r_8 orgx=0., r_8 orgy=0.) -
trunk/SophyaLib/NTools/generaldata.cc
r1110 r1204 704 704 /*! 705 705 Pour fiter un polynome de degre ``degre''. On fite 706 Y=f(X ) ou Y=Val et X=Absc(varx). Si ``ey'' est ``true''706 Y=f(X-xc) ou Y=Val et X=Absc(varx). Si ``ey'' est ``true'' 707 707 le fit prend en compte les erreurs stoquees dans EVal, 708 708 sinon fit sans erreurs. Le resultat du fit est retourne 709 dans le polynome ``pol''. 709 dans le polynome ``pol''. On re-centre les abscisses X de ``xc''. 710 710 \verbatim 711 711 Return: … … 714 714 - -2 si probleme sur numero de variable X 715 715 - -4 si NDataGood<0 716 - -5 si nombre de data trouves different de NDataGood716 - -5 si nombre de data trouves differents de NDataGood 717 717 \endverbatim 718 718 */ 719 double GeneralFitData::PolFit(int varx,Poly& pol,int degre,bool ey ) const719 double GeneralFitData::PolFit(int varx,Poly& pol,int degre,bool ey,double xc) const 720 720 { 721 721 if(degre<0) return -1.; … … 730 730 if( ! IsValid(i) ) continue; 731 731 if(ntest>=mNDataGood) return -5.; 732 x(ntest) = Absc(varx,i) ;732 x(ntest) = Absc(varx,i) - xc; 733 733 y(ntest) = Val(i); 734 734 if(ey) ey2(ntest) = EVal(i)*EVal(i); … … 747 747 /*! 748 748 Pour fiter un polynome de degre ``degre1''. On fite 749 Z=f(X ,Y) ou Z=Val et X=Absc(varx) et Y=Absc(vary).749 Z=f(X-xc,Y-yc) ou Z=Val et X=Absc(varx) et Y=Absc(vary). 750 750 Si ``ey'' est ``true'' le fit prend en compte les erreurs 751 751 stoquees dans EVal, sinon fit sans erreurs. Si ``degre2'' … … 754 754 demande un fit de ``degre1'' pour la variable X et de degre 755 755 ``degre2'' sur la variable Y. Le resultat du fit est retourne 756 dans le polynome ``pol''. 756 dans le polynome ``pol''. On re-centre les abscisses X de ``xc'' 757 et Y de ``yc''. 757 758 \verbatim 758 759 Return: … … 765 766 \endverbatim 766 767 */ 767 double GeneralFitData::PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2,bool ez) const 768 double GeneralFitData::PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2,bool ez 769 ,double xc,double yc) const 768 770 { 769 771 if(degre1<0) return -1.; … … 780 782 if( ! IsValid(i) ) continue; 781 783 if(ntest>=mNDataGood) return -5.; 782 x(ntest) = Absc(varx,i) ;783 y(ntest) = Absc(vary,i) ;784 x(ntest) = Absc(varx,i) - xc; 785 y(ntest) = Absc(vary,i) - yc; 784 786 z(ntest) = Val(i); 785 787 if(ez) ez2(ntest) = EVal(i)*EVal(i); … … 993 995 994 996 return(rets); 997 } 998 999 1000 //! Compute errors according to specifications 1001 /*! 1002 \param val : value of the function 1003 \param err : value of the default error 1004 \param errtype : type of error according to enum FitErrType (def=DefaultError) 1005 \param errscale : scaling (or value) of the error (def=1.) 1006 \param errmin : minimum value of the error (def=0.) 1007 \param nozero : if true, do not return negative errors but 1008 set them to zero (def=false) 1009 \return : return the error computed according to specifications 1010 \verbatim 1011 - val is the value to be fitted ex: val = f(x,y,...) 1012 - err is the error by default we want to set. 1013 - errtype = DefaultError : errtmp = errscale*err 1014 errtype = ConstantError : errtmp = errscale 1015 errtype = SqrtError : errtmp = errscale*sqrt(|val|) 1016 errtype = ProporError : errtmp = errscale*|val| 1017 - errscale <=0 then errscale=1 1018 - errmin >=0 if errtmp>0 return max(errtmp,errmin) 1019 if errtmp<=0 return errtmp 1020 errmin <0 if errtmp>0 return max(errtmp,|errmin|) 1021 if errtmp<=0 return |errmin| 1022 \endverbatim 1023 */ 1024 double GeneralFitData::ComputeError(double val,double err,FitErrType errtype 1025 ,double errscale,double errmin,bool nozero) 1026 { 1027 bool errminneg=false; 1028 if(errmin<0.) {errminneg=true; errmin*=-1.;} 1029 if(errscale<0.) errscale=1.; 1030 1031 // Choix du type d'erreur 1032 if(errtype==ConstantError) err = errscale; 1033 else if(errtype==SqrtError) err = errscale*sqrt(fabs(val)); 1034 else if(errtype==ProporError) err = errscale*fabs(val); 1035 1036 // Gestion du minimum a partir de la valeur calculee precedemment "err" 1037 // Ex1: errmin=1., err=10. ==> 10. 1038 // err=0.5 ==> 1. 1039 // err=0. ==> 0. 1040 // err=-2. ==> -2. 1041 // Ex2: errmin=-1., err=10. ==> 10. 1042 // err=0.5 ==> 1. 1043 // err=0. ==> 1. 1044 // err=-2. ==> 11. 1045 if(err>0.) err = (err>errmin) ? err: errmin; 1046 else if(errminneg) err = errmin; 1047 1048 // ne pas retourner d'erreurs negatives si demande 1049 if(nozero && err<0.) err=0.; 1050 1051 return err; 995 1052 } 996 1053 -
trunk/SophyaLib/NTools/generaldata.h
r1110 r1204 138 138 double min=1.,double max=-1.,double coeff=0.8) const; 139 139 int GetMode(int var,double& mode,double min=1.,double max=-1.,double coeff=0.8) const; 140 double PolFit(int varx,Poly& pol,int degre,bool ey=true) const; 141 double PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2=-1,bool ez=true) const; 140 double PolFit(int varx,Poly& pol,int degre,bool ey=true,double xc=0.) const; 141 double PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2=-1,bool ez=true 142 ,double xc=0.,double yc=0.) const; 142 143 GeneralFitData FitResidus(GeneralFit& gfit) const; 143 144 GeneralFitData FitFunction(GeneralFit& gfit) const; … … 154 155 virtual string ColumnName(int k) const; 155 156 virtual string VarList_C(const char* nomx=NULL) const; 157 158 enum FitErrType {DefaultError,ConstantError,SqrtError,ProporError}; 159 static double ComputeError(double val,double err,FitErrType errtype=DefaultError 160 ,double errscale=1.,double errmin=0.,bool nozero=false); 156 161 157 162 protected: -
trunk/SophyaLib/NTools/objfitter.cc
r1110 r1204 6 6 //=========================================================================== 7 7 //=========================================================================== 8 9 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 } 8 15 9 16 TMatrix<r_4> … … 21 28 } 22 29 30 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 } 36 23 37 TMatrix<r_4> 24 38 ObjectFitter::FitFunction(TMatrix<r_4> const & mtx, GeneralFit& gfit, … … 35 49 } 36 50 51 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 } 57 37 58 TVector<r_4> 38 59 ObjectFitter::FitResidus(TVector<r_4> const & vec, GeneralFit& gfit, … … 47 68 { 48 69 return( ArrayFitter<r_8>::FitResidus(vec, gfit, xorg, dx) ); 70 } 71 72 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) ); 49 77 } 50 78 … … 356 384 /////////////////////////////////////////////////////////////// 357 385 #ifdef __CXX_PRAGMA_TEMPLATES__ 386 #pragma define_template ArrayFitter<int_4> 358 387 #pragma define_template ArrayFitter<r_4> 359 388 #pragma define_template ArrayFitter<r_8> 389 #pragma define_template ArrayFitter< complex<r_4> > 390 #pragma define_template ArrayFitter< complex<r_8> > 360 391 #endif 361 392 362 393 #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) 394 template class ArrayFitter<int_4>; 363 395 template class ArrayFitter<r_4>; 364 396 template class ArrayFitter<r_8>; 397 template class ArrayFitter< complex<r_4> >; 398 template class ArrayFitter< complex<r_8> >; 365 399 #endif 366 400 -
trunk/SophyaLib/NTools/objfitter.h
r1110 r1204 22 22 public: 23 23 // Residus et fonction fittees sur matrix 24 static TMatrix<int_4> FitResidus(TMatrix<int_4> const & mtx, GeneralFit& gfit, 25 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 24 26 static TMatrix<r_4> FitResidus(TMatrix<r_4> const & mtx, GeneralFit& gfit, 25 27 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 26 28 static TMatrix<r_8> FitResidus(TMatrix<r_8> const & mtx, GeneralFit& gfit, 29 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 30 static TMatrix< complex<r_4> > FitResidus(TMatrix< complex<r_4> > const & mtx, GeneralFit& gfit, 31 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 32 static TMatrix< complex<r_8> > FitResidus(TMatrix< complex<r_8> > const & mtx, GeneralFit& gfit, 33 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 34 35 static TMatrix<int_4> FitFunction(TMatrix<int_4> const & mtx, GeneralFit& gfit, 27 36 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 28 37 static TMatrix<r_4> FitFunction(TMatrix<r_4> const & mtx, GeneralFit& gfit, … … 30 39 static TMatrix<r_8> FitFunction(TMatrix<r_8> const & mtx, GeneralFit& gfit, 31 40 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 41 static TMatrix< complex<r_4> > FitFunction(TMatrix< complex<r_4> > const & mtx, GeneralFit& gfit, 42 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 43 static TMatrix< complex<r_8> > FitFunction(TMatrix< complex<r_8> > const & mtx, GeneralFit& gfit, 44 double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 45 32 46 // Residus et fonction fittees sur vecteurs 47 static TVector<int_4> FitResidus(TVector<int_4> const & vec, GeneralFit& gfit, 48 double xorg=0.,double dx=1.); 33 49 static TVector<r_4> FitResidus(TVector<r_4> const & vec, GeneralFit& gfit, 34 50 double xorg=0.,double dx=1.); 35 51 static TVector<r_8> FitResidus(TVector<r_8> const & vec, GeneralFit& gfit, 36 52 double xorg=0.,double dx=1.); 53 static TVector< complex<r_4> > FitResidus(TVector< complex<r_4> > const & vec, GeneralFit& gfit, 54 double xorg=0.,double dx=1.); 55 static TVector< complex<r_8> > FitResidus(TVector< complex<r_8> > const & vec, GeneralFit& gfit, 56 double xorg=0.,double dx=1.); 57 58 static TVector<int_4> FitFunction(TVector<int_4> const & vec, GeneralFit& gfit, 59 double xorg=0.,double dx=1.); 37 60 static TVector<r_4> FitFunction(TVector<r_4> const & vec, GeneralFit& gfit, 38 61 double xorg=0.,double dx=1.); 39 62 static TVector<r_8> FitFunction(TVector<r_8> const & vec, GeneralFit& gfit, 40 63 double xorg=0.,double dx=1.); 64 static TVector< complex<r_4> > FitFunction(TVector< complex<r_4> > const & vec, GeneralFit& gfit, 65 double xorg=0.,double dx=1.); 66 static TVector< complex<r_8> > FitFunction(TVector< complex<r_8> > const & vec, GeneralFit& gfit, 67 double xorg=0.,double dx=1.); 68 41 69 // Residus et fonction fittees sur Histo 42 70 static Histo FitResidus(Histo const& h, GeneralFit& gfit); 43 71 static Histo FitFunction(Histo const& h, GeneralFit& gfit); 44 72 static int_4 Fit(Histo const & h, GeneralFit& gfit,unsigned short typ_err=0); 73 45 74 // Residus et fonction fittees sur Histo2D 46 75 static Histo2D FitResidus(Histo2D const& h, GeneralFit& gfit); 47 76 static Histo2D FitFunction(Histo2D const& h, GeneralFit& gfit); 48 77 static int_4 Fit(Histo2D const & h, GeneralFit& gfit,unsigned short typ_err=0); 78 49 79 // Residus et fonction fittees sur HProf 50 80 static inline Histo FitResidus(HProf const& h, GeneralFit& gfit) … … 54 84 static int_4 Fit(HProf const & h, GeneralFit& gfit) 55 85 {h.UpdateHisto(); return Fit((Histo const&) h,gfit,0);} 86 56 87 // Residus et fonction fittees sur GeneralFitData 57 88 static inline GeneralFitData FitResidus(GeneralFitData const& g, GeneralFit& gfit)
Note:
See TracChangeset
for help on using the changeset viewer.