inlib  1.2.0
Classes | Functions
inlib::f2cmn Namespace Reference

Classes

class  fitter
class  point
class  parameter
class  command
class  func_fitter

Functions

template<class T >
TMath_Min (const T &a, const T &b)
template<class T >
TMath_Max (const T &a, const T &b)
double TMath_Log (double a)
double TMath_Log10 (double a)
double TMath_Sqrt (double a)
double TMath_Power (double a, double b)
double TMath_Abs (double a)
double TMath_Sin (double a)
double TMath_Cos (double a)
double TMath_ATan (double a)
double TMath_ASin (double a)
int TMath_int_abs (int a)
std::string Form (const char *aFormat,...)
void Printf (std::ostream *a_out, const char *aFormat,...)
bool fit_data (std::ostream &a_out, const std::vector< inlib::f2cmn::point > &a_data, const std::vector< inlib::f2cmn::parameter > &a_params, inlib::fit_func &a_func, std::vector< double > &a_output, const std::vector< command > &a_cmds=std::vector< command >(1, command("MIGRAD")))
template<class T >
bool fit_1D (std::ostream &a_out, T &a_histo, const std::vector< inlib::f2cmn::parameter > &a_params, inlib::fit_func &a_func, std::vector< double > &a_output, const std::vector< command > &a_cmds=std::vector< command >(1, command("MIGRAD")))
template<class T >
bool fit_xve (std::ostream &a_out, const std::vector< T > &a_xs, const std::vector< T > &a_vs, const std::vector< T > &a_es, const std::vector< inlib::f2cmn::parameter > &a_params, inlib::fit_func &a_func, std::vector< double > &a_output, const std::vector< command > &a_cmds=std::vector< command >(1, command("MIGRAD")))

Function Documentation

template<class T >
bool inlib::f2cmn::fit_1D ( std::ostream &  a_out,
T &  a_histo,
const std::vector< inlib::f2cmn::parameter > &  a_params,
inlib::fit_func a_func,
std::vector< double > &  a_output,
const std::vector< command > &  a_cmds = std::vector<command>(1,command("MIGRAD")) 
) [inline]

Definition at line 7857 of file f2cmn.

                                                              {

  //NOTE : the size of a_output is : 
  //         2 + a_params.size() * 4
  //       with :
  //         a_output[0] = chi2
  //         a_output[1] = number of degree of freedom

  if(a_histo.entries()==0) {
    a_out << "inlib::f2cmn::fit_1D :"
          << " histogram has no entries."
          << std::endl;
    return false;
  }

  int nbin = a_histo.axis().bins();
  if(nbin<=0) {
    a_out << "inlib::f2cmn::fit_1D :"
          << " has no bins."
          << std::endl;
    return false;
  }

  std::vector<double> pt;
  pt.resize(1,0);

  std::vector< inlib::f2cmn::point > data;

  for(int index=0;index<nbin;index++) { 
    int nent = a_histo.bin_entries(index);
    if(nent==0) continue;  // Do not take bin without entry.
    // Take middle of bin.
    double xx = 
      (a_histo.axis().bin_lower_edge(index)+
       a_histo.axis().bin_upper_edge(index))/2.;
    double val = a_histo.bin_height(index);
    double err = ::sqrt(::fabs(val)); // Take statistical error.
    if(err==0.) { 
      a_out << "inlib::f2cmn::fit_1D :"
          << " null error for bin " << index 
          << " x " << xx << " value " << val
          << ". Set error to 0.01."
          << std::endl;
      //return 0;
      err = 0.01; //FIXME
    }
    inlib::f2cmn::point fpt;
    pt[0] = xx;
    fpt.m_coords = pt;
    fpt.m_value = val;
    fpt.m_error = err;
    data.push_back(fpt); 
  }
  if(data.empty()) {
    a_out << "inlib::f2cmn::fit_1D :"
          << " no starting points."
          << std::endl;
    return false;
  }

  if(!func_fitter::fit(a_out,data,a_params,a_func,a_output,a_cmds)) {
    a_out << "inlib::f2cmn::fit_1D :"
          << " fit failed."
          << std::endl;
    return false;
  }

  return true;
}
bool inlib::f2cmn::fit_data ( std::ostream &  a_out,
const std::vector< inlib::f2cmn::point > &  a_data,
const std::vector< inlib::f2cmn::parameter > &  a_params,
inlib::fit_func a_func,
std::vector< double > &  a_output,
const std::vector< command > &  a_cmds = std::vector<command>(1,command("MIGRAD")) 
) [inline]

Definition at line 7824 of file f2cmn.

                                                               {

  //NOTE : the size of a_output is : 
  //         2 + a_params.size() * 4
  //       with :
  //         a_output[0] = chi2
  //         a_output[1] = number of degree of freedom

  if(a_data.empty()) {
    a_out << "inlib::f2cmn::fit_data :"
          << " no starting points."
          << std::endl;
    return false;
  }

  if(!func_fitter::fit(a_out,a_data,a_params,a_func,a_output,a_cmds)) {
    a_out << "inlib::f2cmn::fit_data :"
          << " fit failed."
          << std::endl;
    return false;
  }

  return true;
}
template<class T >
bool inlib::f2cmn::fit_xve ( std::ostream &  a_out,
const std::vector< T > &  a_xs,
const std::vector< T > &  a_vs,
const std::vector< T > &  a_es,
const std::vector< inlib::f2cmn::parameter > &  a_params,
inlib::fit_func a_func,
std::vector< double > &  a_output,
const std::vector< command > &  a_cmds = std::vector<command>(1,command("MIGRAD")) 
) [inline]

Definition at line 7934 of file f2cmn.

                                                             {

  //NOTE : the size of a_output is : 
  //         2 + a_params.size() * 4
  //       with :
  //         a_output[0] = chi2
  //         a_output[1] = number of degree of freedom

  if(a_vs.size() != a_xs.size() ) {
    a_out << "inlib::f2cmn::fit_xve :"
          << " coordinate and value vectors have different sizes."
          << std::endl;
    return false;
  }
  
  if(a_es.size() != a_xs.size() ) {
    a_out << "inlib::f2cmn::fit_xve :"
          << " coordinate and error vectors have different sizes."
          << std::endl;
    return false;
  }
  
  int nbin = a_xs.size();

  std::vector<double> pt;
  pt.resize(1,0);

  std::vector< inlib::f2cmn::point > data;

  for(int index=0;index<nbin;index++) {     
    inlib::f2cmn::point fpt;
    pt[0] = a_xs[index];
    fpt.m_coords = pt;
    fpt.m_value = a_vs[index];
    fpt.m_error = a_es[index];
    data.push_back(fpt); 
  }
  if(data.empty()) {
    a_out << "inlib::f2cmn::fit_xve :"
          << " no starting points."
          << std::endl;
    return false;
  }

  if(!func_fitter::fit(a_out,data,a_params,a_func,a_output,a_cmds)) {
    a_out << "inlib::f2cmn::fit_xve :"
          << " fit failed."
          << std::endl;
    return false;
  }

  return true;
}
std::string inlib::f2cmn::Form ( const char *  aFormat,
  ... 
) [inline]

Definition at line 286 of file f2cmn.

                                              {
  char sBuffer[1024];
  va_list args;
  va_start(args,aFormat);
#ifdef WIN32
  _vsnprintf(sBuffer,sizeof(sBuffer),aFormat,args);
#else
  ::vsnprintf(sBuffer,sizeof(sBuffer),aFormat,args);
#endif
  va_end(args);
  return sBuffer;
}
void inlib::f2cmn::Printf ( std::ostream *  a_out,
const char *  aFormat,
  ... 
) [inline]

Definition at line 299 of file f2cmn.

                                                             {
  char s[2048];
  va_list args;
  va_start(args,aFormat);
#ifdef WIN32
  _vsnprintf(s,sizeof(s),aFormat,args);
#else
  ::vsnprintf(s,sizeof(s),aFormat,args);
#endif
  va_end(args);
  if(a_out) {
    (*a_out) << s << std::endl;
  } else {
    ::printf("%s\n",s);
  }
}
double inlib::f2cmn::TMath_Abs ( double  a) [inline]

Definition at line 278 of file f2cmn.

{return ::fabs(a);}
double inlib::f2cmn::TMath_ASin ( double  a) [inline]

Definition at line 282 of file f2cmn.

{return ::asin(a);}
double inlib::f2cmn::TMath_ATan ( double  a) [inline]

Definition at line 281 of file f2cmn.

{return ::atan(a);}
double inlib::f2cmn::TMath_Cos ( double  a) [inline]

Definition at line 280 of file f2cmn.

{return ::cos(a);}
int inlib::f2cmn::TMath_int_abs ( int  a) [inline]

Definition at line 284 of file f2cmn.

{return a>=0?a:-a;} /*G.Barrand*/
double inlib::f2cmn::TMath_Log ( double  a) [inline]

Definition at line 274 of file f2cmn.

double inlib::f2cmn::TMath_Log10 ( double  a) [inline]

Definition at line 275 of file f2cmn.

{return ::log10(a);}
template<class T >
T inlib::f2cmn::TMath_Max ( const T &  a,
const T &  b 
) [inline]

Definition at line 269 of file f2cmn.

                                          {
  return (a>b?a:b);
}    
template<class T >
T inlib::f2cmn::TMath_Min ( const T &  a,
const T &  b 
) [inline]

Definition at line 264 of file f2cmn.

                                          {
  return (a<b?a:b);
}    
double inlib::f2cmn::TMath_Power ( double  a,
double  b 
) [inline]

Definition at line 277 of file f2cmn.

{return ::pow(a,b);}
double inlib::f2cmn::TMath_Sin ( double  a) [inline]

Definition at line 279 of file f2cmn.

{return ::sin(a);}
double inlib::f2cmn::TMath_Sqrt ( double  a) [inline]

Definition at line 276 of file f2cmn.

{return ::sqrt(a);}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines