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


Ignore:
Timestamp:
Jul 28, 2000, 6:32:08 PM (25 years ago)
Author:
ansari
Message:

on vire imageop.o de objlis.list
instanciations GNU des fct de dynccd.cc Noise... etc...
des fct passees en const dans GeneralFitData
objfitter prend les Histo/Histo2D/HProf/GeneralFitData

cmv 28/7/00

File:
1 edited

Legend:

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

    r790 r1110  
    11#include "objfitter.h"
     2
     3//===========================================================================
     4//===========================================================================
     5//=========================== ObjectFitter ==================================
     6//===========================================================================
     7//===========================================================================
    28
    39TMatrix<r_4>
     
    5864
    5965
    60 // ---------------------------------------------------------------------------
     66//=============================== Histo =====================================
     67/*! Retourne une classe contenant les residus du fit ``gfit''. */
     68Histo ObjectFitter::FitResidus(Histo const& hh, GeneralFit& gfit)
     69{
     70Histo h(hh);
     71if(h.NBins()<=0)
     72  throw(SzMismatchError("Histo::FitResidus: size mismatch\n"));
     73GeneralFunction* f = gfit.GetFunction();
     74if(f==NULL)
     75  throw(NullPtrError("Histo::FitResidus: NULL pointer\n"));
     76TVector<r_8> par = gfit.GetParm();
     77for(int_4 i=0;i<h.NBins();i++) {
     78  r_8 x =  h.BinCenter(i);
     79  h(i) -=  f->Value(&x,par.Data());
     80}
     81return h;
     82}
     83
     84/*! Retourne une classe contenant la fonction du fit ``gfit''. */
     85Histo ObjectFitter::FitFunction(Histo const& hh, GeneralFit& gfit)
     86{
     87Histo h(hh);
     88if(h.NBins()<=0)
     89  throw(SzMismatchError("Histo::FitFunction: size mismatch\n"));
     90GeneralFunction* f = gfit.GetFunction();
     91if(f==NULL)
     92  throw(NullPtrError("Histo::FitFunction: NULL pointer\n"));
     93TVector<r_8> par = gfit.GetParm();
     94for(int_4 i=0;i<h.NBins();i++) {
     95  r_8 x =  h.BinCenter(i);
     96  h(i) =  f->Value(&x,par.Data());
     97}
     98return h;
     99}
     100
     101/*!
     102  Fit de l'histogramme par ``gfit''.
     103  \verbatim
     104    typ_err = 0 :
     105       - erreur attachee au bin si elle existe
     106       - sinon 1
     107    typ_err = 1 :
     108       - erreur attachee au bin si elle existe
     109       - sinon max( sqrt(abs(bin) ,1 )
     110    typ_err = 2 :
     111       - erreur forcee a 1
     112    typ_err = 3 :
     113       - erreur forcee a max( sqrt(abs(bin) ,1 )
     114    typ_err = 4 :
     115       - erreur forcee a 1, nulle si bin a zero.
     116    typ_err = 5 :
     117       - erreur forcee a max( sqrt(abs(bin) ,1 ),
     118         nulle si bin a zero.
     119  \endverbatim
     120*/
     121int_4 ObjectFitter::Fit(Histo const& h, GeneralFit& gfit,unsigned short typ_err)
     122{
     123if(h.NBins()<=0) return -1000;
     124if(typ_err>5) typ_err=0;
     125
     126GeneralFitData mydata(1,h.NBins());
     127
     128for(int_4 i=0;i<h.NBins();i++) {
     129  r_8 x =  h.BinCenter(i);
     130  r_8 f =  h(i);
     131  r_8 saf = sqrt(fabs( f)); if(saf<1.) saf=1.;
     132  r_8 e=0.;
     133  if(typ_err==0)      {if(h.HasErrors()) e=h.Error(i); else e=1.;}
     134  else if(typ_err==1) {if(h.HasErrors()) e=h.Error(i); else e=saf;}
     135  else if(typ_err==2) e=1.;
     136  else if(typ_err==3) e=saf;
     137  else if(typ_err==4) e=(f==0.)?0.:1.;
     138  else if(typ_err==5) e=(f==0.)?0.:saf;
     139  mydata.AddData1(x,f,e);
     140}
     141
     142gfit.SetData(&mydata);
     143
     144return gfit.Fit();
     145}
     146
     147//============================== Histo2D ====================================
     148/*! Retourne une classe contenant les residus du fit ``gfit''. */
     149Histo2D ObjectFitter::FitResidus(Histo2D const& hh, GeneralFit& gfit)
     150{
     151Histo2D h(hh);
     152if(h.NBinX()<=0 || h.NBinY()<=0)
     153  throw(SzMismatchError("Histo2D::FitResidus: size mismatch\n"));
     154GeneralFunction* f = gfit.GetFunction();
     155if(f==NULL)
     156  throw(NullPtrError("Histo2D::FitResidus: NULL pointer\n"));
     157TVector<r_8> par = gfit.GetParm();
     158for(int_4 i=0;i<h.NBinX();i++) for(int_4 j=0;j<h.NBinY();j++) {
     159  r_8 xc,yc;
     160  h.BinCenter(i,j,xc,yc);
     161  r_8 x[2] = {xc,yc};
     162  h(i,j) -= f->Value(x,par.Data());
     163}
     164return h;
     165}
     166
     167/*! Retourne une classe contenant la fonction du fit ``gfit''. */
     168Histo2D ObjectFitter::FitFunction(Histo2D const& hh, GeneralFit& gfit)
     169{
     170Histo2D h(hh);
     171if(h.NBinX()<=0 || h.NBinY()<=0)
     172  throw(SzMismatchError("Histo2D::FitFunction: size mismatch\n"));
     173GeneralFunction* f = gfit.GetFunction();
     174if(f==NULL)
     175  throw(NullPtrError("Histo2D::FitFunction: NULL pointer\n"));
     176TVector<r_8> par = gfit.GetParm();
     177for(int_4 i=0;i<h.NBinX();i++) for(int_4 j=0;j<h.NBinY();j++) {
     178  r_8 xc,yc;
     179  h.BinCenter(i,j,xc,yc);
     180  r_8 x[2] = {xc,yc};
     181  h(i,j) = f->Value(x,par.Data());
     182}
     183return h;
     184}
     185
     186/*!
     187  Fit de l'histogramme par ``gfit''.
     188  \verbatim
     189    typ_err = 0 :
     190       - erreur attachee au bin si elle existe
     191       - sinon 1
     192    typ_err = 1 :
     193       - erreur attachee au bin si elle existe
     194       - sinon max( sqrt(abs(bin) ,1 )
     195    typ_err = 2 :
     196       - erreur forcee a 1
     197    typ_err = 3 :
     198       - erreur forcee a max( sqrt(abs(bin) ,1 )
     199    typ_err = 4 :
     200       - erreur forcee a 1, nulle si bin a zero.
     201    typ_err = 5 :
     202       - erreur forcee a max( sqrt(abs(bin) ,1 ),
     203         nulle si bin a zero.
     204  \endverbatim
     205*/
     206int_4 ObjectFitter::Fit(Histo2D const & h, GeneralFit& gfit,unsigned short typ_err)
     207{
     208if(h.NBinX()*h.NBinY()<=0) return -1000;
     209if(typ_err>5) typ_err=0;
     210
     211GeneralFitData mydata(2,h.NBinX()*h.NBinY());
     212
     213for(int_4 i=0;i<h.NBinX();i++) for(int_4 j=0;j<h.NBinY();j++) {
     214  r_8 x,y;
     215  h.BinCenter(i,j,x,y);
     216  r_8 f = h(i,j);
     217  r_8 saf = sqrt(fabs(f)); if(saf<1.) saf=1.;
     218  r_8 e=0.;
     219  if(typ_err==0)      {if(h.HasErrors()) e=h.Error(i,j); else e=1.;}
     220  else if(typ_err==1) {if(h.HasErrors()) e=h.Error(i,j); else e=saf;}
     221  else if(typ_err==2) e=1.;
     222  else if(typ_err==3) e=saf;
     223  else if(typ_err==4) e=(f==0.)?0.:1.;
     224  else if(typ_err==5) e=(f==0.)?0.:saf;
     225  mydata.AddData2(x,y,f,e);
     226}
     227
     228gfit.SetData(&mydata);
     229
     230return gfit.Fit();
     231}
     232
     233//===========================================================================
     234//===========================================================================
     235//========================== ArrayFitter<T> =================================
     236//===========================================================================
     237//===========================================================================
    61238
    62239template <class T>
Note: See TracChangeset for help on using the changeset viewer.