Changeset 1204 in Sophya


Ignore:
Timestamp:
Sep 29, 2000, 12:15:55 AM (25 years ago)
Author:
ansari
Message:

pour les adaptateurs de fit cmv 29/9/00

Location:
trunk/SophyaLib/NTools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/cimage.h

    r1169 r1204  
    3939  inline r_8     XPixSize() const {return pxsz_x;}
    4040  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;}
    4144
    4245  inline void    SetOrg(r_8 orgx=0., r_8 orgy=0.)
  • trunk/SophyaLib/NTools/generaldata.cc

    r1110 r1204  
    704704/*!
    705705  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''
    707707  le fit prend en compte les erreurs stoquees dans EVal,
    708708  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''.
    710710  \verbatim
    711711  Return:
     
    714714     -   -2 si probleme sur numero de variable X
    715715     -   -4 si NDataGood<0
    716      -   -5 si nombre de data trouves different de NDataGood
     716     -   -5 si nombre de data trouves differents de NDataGood
    717717  \endverbatim
    718718*/
    719 double GeneralFitData::PolFit(int varx,Poly& pol,int degre,bool ey) const
     719double GeneralFitData::PolFit(int varx,Poly& pol,int degre,bool ey,double xc) const
    720720{
    721721if(degre<0) return -1.;
     
    730730  if( ! IsValid(i) ) continue;
    731731  if(ntest>=mNDataGood) return -5.;
    732   x(ntest) = Absc(varx,i);
     732  x(ntest) = Absc(varx,i) - xc;
    733733  y(ntest) = Val(i);
    734734  if(ey) ey2(ntest) = EVal(i)*EVal(i);
     
    747747/*!
    748748  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).
    750750  Si ``ey'' est ``true'' le fit prend en compte les erreurs
    751751  stoquees dans EVal, sinon fit sans erreurs. Si ``degre2''
     
    754754  demande un fit de ``degre1'' pour la variable X et de degre
    755755  ``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''.
    757758  \verbatim
    758759    Return:
     
    765766  \endverbatim
    766767*/
    767 double GeneralFitData::PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2,bool ez) const
     768double GeneralFitData::PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2,bool ez
     769                             ,double xc,double yc) const
    768770{
    769771if(degre1<0) return -1.;
     
    780782  if( ! IsValid(i) ) continue;
    781783  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;
    784786  z(ntest) = Val(i);
    785787  if(ez) ez2(ntest) = EVal(i)*EVal(i);
     
    993995
    994996return(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 */
     1024double 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;
    9951052}
    9961053
  • trunk/SophyaLib/NTools/generaldata.h

    r1110 r1204  
    138138                 double min=1.,double max=-1.,double coeff=0.8) const;
    139139  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;
    142143  GeneralFitData FitResidus(GeneralFit& gfit) const;
    143144  GeneralFitData FitFunction(GeneralFit& gfit) const;
     
    154155  virtual string        ColumnName(int k) const;
    155156  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);
    156161
    157162protected:
  • trunk/SophyaLib/NTools/objfitter.cc

    r1110 r1204  
    66//===========================================================================
    77//===========================================================================
     8
     9TMatrix<int_4>
     10ObjectFitter::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}
    815
    916TMatrix<r_4>
     
    2128}
    2229
     30TMatrix<int_4>
     31ObjectFitter::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
    2337TMatrix<r_4>
    2438ObjectFitter::FitFunction(TMatrix<r_4> const & mtx, GeneralFit& gfit,
     
    3549}
    3650
     51TVector<int_4>
     52ObjectFitter::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
    3758TVector<r_4>
    3859ObjectFitter::FitResidus(TVector<r_4> const & vec, GeneralFit& gfit,
     
    4768
    4869  return( ArrayFitter<r_8>::FitResidus(vec, gfit, xorg, dx) );
     70}
     71
     72TVector<int_4>
     73ObjectFitter::FitFunction(TVector<int_4> const & vec, GeneralFit& gfit,
     74                               double xorg, double dx)
     75
     76  return( ArrayFitter<int_4>::FitFunction(vec, gfit, xorg, dx) );
    4977}
    5078
     
    356384///////////////////////////////////////////////////////////////
    357385#ifdef __CXX_PRAGMA_TEMPLATES__
     386#pragma define_template ArrayFitter<int_4>
    358387#pragma define_template ArrayFitter<r_4>
    359388#pragma define_template ArrayFitter<r_8>
     389#pragma define_template ArrayFitter< complex<r_4> >
     390#pragma define_template ArrayFitter< complex<r_8> >
    360391#endif
    361392
    362393#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
     394template class ArrayFitter<int_4>;
    363395template class ArrayFitter<r_4>;
    364396template class ArrayFitter<r_8>;
     397template class ArrayFitter< complex<r_4> >;
     398template class ArrayFitter< complex<r_8> >;
    365399#endif
    366400
  • trunk/SophyaLib/NTools/objfitter.h

    r1110 r1204  
    2222public:
    2323  // 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.);
    2426  static TMatrix<r_4> FitResidus(TMatrix<r_4> const & mtx, GeneralFit& gfit,
    2527                               double xorg=0.,double yorg=0.,double dx=1.,double dy=1.);
    2628  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,
    2736                               double xorg=0.,double yorg=0.,double dx=1.,double dy=1.);
    2837  static TMatrix<r_4> FitFunction(TMatrix<r_4> const & mtx, GeneralFit& gfit,
     
    3039  static TMatrix<r_8> FitFunction(TMatrix<r_8> const & mtx, GeneralFit& gfit,
    3140                               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
    3246  // 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.);
    3349  static TVector<r_4> FitResidus(TVector<r_4> const & vec, GeneralFit& gfit,
    3450                               double xorg=0.,double dx=1.);
    3551  static TVector<r_8> FitResidus(TVector<r_8> const & vec, GeneralFit& gfit,
    3652                               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.);
    3760  static TVector<r_4> FitFunction(TVector<r_4> const & vec, GeneralFit& gfit,
    3861                                double xorg=0.,double dx=1.);
    3962  static TVector<r_8> FitFunction(TVector<r_8> const & vec, GeneralFit& gfit,
    4063                                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
    4169  // Residus et fonction fittees sur Histo
    4270  static Histo FitResidus(Histo const& h, GeneralFit& gfit);
    4371  static Histo FitFunction(Histo const& h, GeneralFit& gfit);
    4472  static int_4 Fit(Histo const & h, GeneralFit& gfit,unsigned short typ_err=0);
     73
    4574  // Residus et fonction fittees sur Histo2D
    4675  static Histo2D FitResidus(Histo2D const& h, GeneralFit& gfit);
    4776  static Histo2D FitFunction(Histo2D const& h, GeneralFit& gfit);
    4877  static int_4 Fit(Histo2D const & h, GeneralFit& gfit,unsigned short typ_err=0);
     78
    4979  // Residus et fonction fittees sur HProf
    5080  static inline Histo FitResidus(HProf const& h, GeneralFit& gfit)
     
    5484  static int_4 Fit(HProf const & h, GeneralFit& gfit)
    5585         {h.UpdateHisto(); return Fit((Histo const&) h,gfit,0);}
     86
    5687  // Residus et fonction fittees sur GeneralFitData
    5788  static inline GeneralFitData FitResidus(GeneralFitData const& g, GeneralFit& gfit)
Note: See TracChangeset for help on using the changeset viewer.