Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Chi2Dist.cxx

Go to the documentation of this file.
00001 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #else
00015 #ifdef _MSC_VER
00016 #include "msdevstudio/MSconfig.h"
00017 #endif
00018 #endif
00019 
00020 #include "Chi2Dist.h"
00021 
00022 #include "FunctionHelper.h"
00023 
00024 #include <cmath>
00025 #include <cassert>
00026 #include <iostream>
00027 
00028 #ifdef ITERATOR_MEMBER_DEFECT
00029 using namespace std;
00030 #else
00031 using std::vector;
00032 #endif
00033 
00034 Chi2Dist::Chi2Dist ( )
00035 {
00036   initialize ();
00037 }
00038 
00039 Chi2Dist::Chi2Dist ( double norm, double nu, double scale )
00040 {
00041   initialize ();
00042 
00043   m_parms[0] = norm;
00044   m_parms[1] = nu;
00045   m_parms[2] = scale;
00046 }
00047 
00048 void Chi2Dist::initialize ()
00049 {
00050    m_name = "Chi-square dist.";
00051    m_parm_names.push_back ( "Norm" );
00052    m_parm_names.push_back ( "#dof" );
00053    m_parm_names.push_back ( "x scale" );
00054 
00055    resize ();
00056 }
00057 
00058 FunctionBase * Chi2Dist::clone () const
00059 {
00060   return new Chi2Dist ( *this );
00061 }
00062 
00063 double Chi2Dist::operator () ( double x ) const
00064 {
00065    return m_parms[0]*exp( -x/2./m_parms[2])
00066       *pow(x/2./m_parms[2], m_parms[1]/2. - 1. );
00067 }
00068 
00069 /* virtual */
00070 void 
00071 Chi2Dist::
00072 initialParameters ( const FunctionHelper * helper )
00073 {
00074    m_parms[2] = 1.;
00075    m_parms[1] = helper->meanCoord();
00076    m_parms[0] = 1.;
00077    m_parms[0] = helper->maxValue()/operator()(m_parms[1]);
00078 }
00079 
00080 double Chi2Dist::derivByParm ( int i, double x ) const
00081 {
00082   switch ( i ) {
00083   case 0 :
00084      return operator()(x)/m_parms[0];
00085     break;
00086 
00087   case 1 :
00088      return operator()(x)/2.*log(x/2./m_parms[2]);
00089     break;
00090 
00091   case 2 :
00092      return operator()(x)*(x/2./m_parms[2] - (m_parms[1]/2.-1.))/m_parms[2];
00093      break;
00094 
00095   default:
00096     assert ( false );
00097     break;
00098   }
00099   return 0.0;
00100 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3