LogParabola.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015 
00016 #include "LogParabola.h"
00017 
00018 #include "FunctionHelper.h"
00019 
00020 #include <cmath>
00021 #include <cassert>
00022 #include <iostream>
00023 
00024 using std::distance;
00025 
00026 #ifdef ITERATOR_MEMBER_DEFECT
00027 using namespace std;
00028 #else
00029 using std::log;
00030 using std::exp;
00031 using std::pow;
00032 using std::vector;
00033 #endif
00034 
00035 namespace hippodraw {
00036 
00037 LogParabola::LogParabola ( )
00038 {
00039   initialize ();
00040 }
00041 
00042 LogParabola::LogParabola ( double n, double a, double b)
00043 {
00044   initialize ();
00045   
00046   m_parms[NORM] = n;
00047   m_parms[ALPHA] = a;
00048   m_parms[BETA] = b;
00049 }
00050 
00051 void LogParabola::initialize ()
00052 {
00053   m_name = "LogParabola";
00054 
00055   m_parm_names.push_back ( "norm" );
00056   m_parm_names.push_back ( "alpha" );
00057   m_parm_names.push_back ( "beta" );
00058 
00059   resize ();
00060 }
00061 
00062 FunctionBase * LogParabola::clone () const
00063 {
00064   return new LogParabola ( *this );
00065 }
00066 
00067 double LogParabola::operator () ( double x ) const
00068 {
00069   double logx = log(x);
00070   return m_parms[0]*pow(x,(-(m_parms[1] + m_parms[2]*logx)));
00071 }
00072 
00073 void 
00074 LogParabola::initialParameters ( const FunctionHelper * helper )
00075 {
00076   double min_x = helper->minCoord ();
00077   double max_x = helper->maxCoord ();
00078   int size = helper->size();
00079   double total = helper->getTotal ();
00080 
00081   m_parms[NORM] = total * ( max_x - min_x ) / size;
00082   m_parms[ALPHA] = 0.1;
00083   m_parms[BETA] = 0.1;
00084 }
00085 
00086 double LogParabola::derivByParm ( int ipar, double x) const
00087 {
00088   double  logx = log(x);
00089   double dfdnorm = pow(x,( -(m_parms[1] + m_parms[2]*logx)));
00090 
00091   double deriv =0.;
00092 
00093   switch (ipar){
00094   case NORM:
00095     deriv = dfdnorm;
00096     break;
00097   case ALPHA:
00098     deriv = -m_parms[0]*logx*dfdnorm;
00099     break;
00100   case BETA:
00101     deriv = -m_parms[0]*logx*logx*dfdnorm;
00102     break;
00103   default:
00104     std::cout<<"parameter index not found : "<<ipar<<std::endl;
00105     std::cout<<"I know about "<<NORM<<" "<<ALPHA<<" "<<BETA<<" "<<std::endl;
00106     assert ( false ); 
00107     break;
00108   }
00109   return deriv;
00110 }
00111 
00112 bool
00113 LogParabola::hasDerivatives () const
00114 {
00115   return true;
00116 }
00117 
00118 } // namespace hippodraw
00119 

Generated for HippoDraw Class Library by doxygen