Chi2Dist.cxx

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

Generated for HippoDraw Class Library by doxygen