Changeset 1206 in Sophya for trunk/SophyaLib/NTools/objfitter.cc


Ignore:
Timestamp:
Sep 29, 2000, 4:24:45 PM (25 years ago)
Author:
ansari
Message:

objfitter pour les Image<T> cmv 29/9/00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/objfitter.cc

    r1204 r1206  
    77//===========================================================================
    88
     9//============================= Matrix et Vector ============================
    910TMatrix<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 }
     11ObjectFitter::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) );}
    1514
    1615TMatrix<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 }
     16ObjectFitter::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) );}
    2219
    2320TMatrix<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 }
     21ObjectFitter::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) );}
    2924
    3025TMatrix<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 }
     26ObjectFitter::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) );}
    3629
    3730TMatrix<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 }
     31ObjectFitter::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) );}
    4334
    4435TMatrix<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 }
     36ObjectFitter::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) );}
    5039
    5140TVector<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 }
     41ObjectFitter::FitResidus(TVector<int_4> const & vec,GeneralFit& gfit,
     42                         double xorg,double dx)
     43{return( ArrayFitter<int_4>::FitResidus(vec,gfit,xorg,dx) );}
    5744
    5845TVector<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 }
     46ObjectFitter::FitResidus(TVector<r_4> const & vec,GeneralFit& gfit,
     47                         double xorg,double dx)
     48{return( ArrayFitter<r_4>::FitResidus(vec,gfit,xorg,dx) );}
    6449
    6550TVector<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 }
     51ObjectFitter::FitResidus(TVector<r_8> const & vec,GeneralFit& gfit,
     52                         double xorg,double dx)
     53{return( ArrayFitter<r_8>::FitResidus(vec,gfit,xorg,dx) );}
    7154
    7255TVector<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 }
     56ObjectFitter::FitFunction(TVector<int_4> const & vec,GeneralFit& gfit,
     57                          double xorg,double dx)
     58{return( ArrayFitter<int_4>::FitFunction(vec,gfit,xorg,dx) );}
    7859
    7960TVector<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 }
     61ObjectFitter::FitFunction(TVector<r_4> const & vec,GeneralFit& gfit,
     62                          double xorg,double dx)
     63{return( ArrayFitter<r_4>::FitFunction(vec,gfit,xorg,dx) );}
    8564
    8665TVector<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 
     66ObjectFitter::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 ============================
     71Image<uint_2> ObjectFitter::FitResidus(Image<uint_2> const & im,GeneralFit& gfit)
     72{ return( ImageFitter<uint_2>::FitResidus(im,gfit) ); }
     73Image<int_4> ObjectFitter::FitResidus(Image<int_4> const & im,GeneralFit& gfit)
     74{ return( ImageFitter<int_4>::FitResidus(im,gfit) ); }
     75Image<int_8> ObjectFitter::FitResidus(Image<int_8> const & im,GeneralFit& gfit)
     76{ return( ImageFitter<int_8>::FitResidus(im,gfit) ); }
     77Image<r_4> ObjectFitter::FitResidus(Image<r_4> const & im,GeneralFit& gfit)
     78{ return( ImageFitter<r_4>::FitResidus(im,gfit) ); }
     79Image<r_8> ObjectFitter::FitResidus(Image<r_8> const & im,GeneralFit& gfit)
     80{ return( ImageFitter<r_8>::FitResidus(im,gfit) ); }
     81
     82Image<uint_2> ObjectFitter::FitFunction(Image<uint_2> const & im,GeneralFit& gfit)
     83{ return( ImageFitter<uint_2>::FitFunction(im,gfit) ); }
     84Image<int_4> ObjectFitter::FitFunction(Image<int_4> const & im,GeneralFit& gfit)
     85{ return( ImageFitter<int_4>::FitFunction(im,gfit) ); }
     86Image<int_8> ObjectFitter::FitFunction(Image<int_8> const & im,GeneralFit& gfit)
     87{ return( ImageFitter<int_8>::FitFunction(im,gfit) ); }
     88Image<r_4> ObjectFitter::FitFunction(Image<r_4> const & im,GeneralFit& gfit)
     89{ return( ImageFitter<r_4>::FitFunction(im,gfit) ); }
     90Image<r_8> ObjectFitter::FitFunction(Image<r_8> const & im,GeneralFit& gfit)
     91{ return( ImageFitter<r_8>::FitFunction(im,gfit) ); }
    9392
    9493//=============================== Histo =====================================
     
    129128/*!
    130129  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)
    148132*/
    149 int_4 ObjectFitter::Fit(Histo const& h, GeneralFit& gfit,unsigned short typ_err)
     133int_4 ObjectFitter::Fit(Histo const& h, GeneralFit& gfit
     134      ,GeneralFitData::FitErrType errtype,double errscale,double errmin)
    150135{
    151136if(h.NBins()<=0) return -1000;
    152 if(typ_err>5) typ_err=0;
    153137
    154138GeneralFitData mydata(1,h.NBins());
     
    157141  r_8 x =  h.BinCenter(i);
    158142  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);
    167145  mydata.AddData1(x,f,e);
    168146}
     
    214192/*!
    215193  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)
    233196*/
    234 int_4 ObjectFitter::Fit(Histo2D const & h, GeneralFit& gfit,unsigned short typ_err)
     197int_4 ObjectFitter::Fit(Histo2D const & h, GeneralFit& gfit
     198      ,GeneralFitData::FitErrType errtype,double errscale,double errmin)
    235199{
    236200if(h.NBinX()*h.NBinY()<=0) return -1000;
    237 if(typ_err>5) typ_err=0;
    238201
    239202GeneralFitData mydata(2,h.NBinX()*h.NBinY());
    240203
    241204for(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);
    244206  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);
    253209  mydata.AddData2(x,y,f,e);
    254210}
     
    265221//===========================================================================
    266222
     223/*! Retourne une classe contenant les residus du fit ``gfit''. */
    267224template <class T>
    268225TMatrix<T>
    269226ArrayFitter<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)
    271228// Retourne une classe contenant les residus du fit ``gfit''.
    272229// On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j).
     
    284241double* par = new double[npar];
    285242{for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
    286 TMatrix<T> m(mtx);
     243TMatrix<T> m(mtx,false);
    287244m.SetTemp(true);
    288245for(uint_4 i=0;i<mtx.NRows();i++) for(uint_4 j=0;j<mtx.NCols();j++) {
     
    295252
    296253
     254/*! Retourne une classe contenant la fonction du fit ``gfit''. */
    297255template <class T>
    298256TMatrix<T>
    299257ArrayFitter<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)
    301259
    302260// Retourne une classe contenant la fonction du fit ``gfit''.
     
    327285}
    328286
     287/*! Retourne une classe contenant les residus du fit ``gfit''. */
    329288template <class T>
    330289TVector<T>
    331290ArrayFitter<T>::FitResidus(TVector<T> const & vec, GeneralFit& gfit,
    332                          double xorg,double dx)
    333 // Retourne une classe contenant les residus du fit ``gfit''.
     291                           double xorg,double dx)
     292// Retourne une classe contenant la fonction fittee du fit ``gfit''.
    334293// La coordonnee de l'element (i) est -> x = xorg + i*dx
    335294{
     
    344303double* par = new double[npar];
    345304{for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
    346 TVector<T> v(vec);
     305TVector<T> v(vec,false);
    347306v.SetTemp(true);
    348307for(uint_4 i=0;i<vec.NElts();i++) {
     
    354313}
    355314
     315/*! Retourne une classe contenant la fonction du fit ``gfit''. */
    356316template <class T>
    357317TVector<T>
    358318ArrayFitter<T>::FitFunction(TVector<T> const & vec, GeneralFit& gfit,
    359                           double xorg,double dx)
    360 // Retourne une classe contenant les residus du fit ``gfit''.
     319                            double xorg,double dx)
     320// Retourne une classe contenant la function fittee du fit ``gfit''.
    361321// La coordonnee de l'element (i) est -> x = xorg + i*dx
    362322{
     
    381341}
    382342
     343//===========================================================================
     344//===========================================================================
     345//========================== ImageFitter<T> =================================
     346//===========================================================================
     347//===========================================================================
     348
     349/*! Retourne une classe contenant les residus du fit ``gfit''. */
     350template <class T>
     351Image<T>
     352ImageFitter<T>::FitResidus(Image<T> const & ima, GeneralFit& gfit)
     353{
     354if(ima.XSize()<=0||ima.YSize()<=0)
     355  throw(SzMismatchError("ImageFitter::FitResidus(Image<T>...) size mismatch\n"));
     356GeneralFunction* f = gfit.GetFunction();
     357if(f==NULL)
     358  throw(NullPtrError("ImageFitter::FitResidus(Image<T>...) GeneraFit==NULL\n"));
     359int npar =  gfit.GetNPar();
     360if(npar==0)
     361  throw(SzMismatchError("ImageFitter::FitResidus(Image<T>...) GeneraFit 0 parametre\n"));
     362double* par = new double[npar];
     363{for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
     364Image<T> im(ima,false);
     365im.SetTemp(true);
     366for(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}
     370delete [] par;
     371return im;
     372}
     373
     374/*! Retourne une classe contenant la function fittee du fit ``gfit''. */
     375template <class T>
     376Image<T>
     377ImageFitter<T>::FitFunction(Image<T> const & ima, GeneralFit& gfit)
     378{
     379if(ima.XSize()<=0||ima.YSize()<=0)
     380  throw(SzMismatchError("ImageFitter::FitFunction(Image<T>...) size mismatch\n"));
     381GeneralFunction* f = gfit.GetFunction();
     382if(f==NULL)
     383  throw(NullPtrError("ImageFitter::FitFunction(Image<T>...) GeneraFit==NULL\n"));
     384int npar =  gfit.GetNPar();
     385if(npar==0)
     386  throw(SzMismatchError("ImageFitter::FitFunction(Image<T>...) GeneraFit 0 parametre\n"));
     387double* par = new double[npar];
     388{for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
     389Image<T> im(ima.XSize(),ima.YSize());
     390im.SetTemp(true);
     391for(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}
     395delete [] par;
     396return im;
     397}
    383398
    384399///////////////////////////////////////////////////////////////
     
    389404#pragma define_template ArrayFitter< complex<r_4> >
    390405#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>
    391411#endif
    392412
     
    397417template class ArrayFitter< complex<r_4> >;
    398418template class ArrayFitter< complex<r_8> >;
     419template class ImageFitter<uint_2>;
     420template class ImageFitter<int_4>;
     421template class ImageFitter<int_8>;
     422template class ImageFitter<r_4>;
     423template class ImageFitter<r_8>;
    399424#endif
    400 
Note: See TracChangeset for help on using the changeset viewer.