Landau.cxx
Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015 
00016 #include "Landau.h"
00017 
00018 #include "FunctionHelper.h"
00019 
00020 #include <cmath>
00021 #include <cassert>
00022 
00023 using std::distance;
00024 
00025 #ifdef ITERATOR_MEMBER_DEFECT
00026 using namespace std;
00027 #else
00028 using std::exp;
00029 using std::vector;
00030 #endif
00031 
00032 namespace hippodraw {
00033 
00034 Landau::Landau ( )
00035 {
00036   initialize ();
00037 }
00038 
00039 Landau::Landau ( double p, double c, double s )
00040 {
00041   initialize ();
00042   
00043   m_parms[peak] = p;
00044   m_parms[norm] = c;
00045   m_parms[sigma] = s;
00046 }
00047 
00048 void Landau::initialize ()
00049 {
00050   m_name = "Landau";
00051 
00052   m_parm_names.push_back ( "Peak" );
00053   m_parm_names.push_back ( "Normalization" );
00054   m_parm_names.push_back ( "Sigma" );
00055 
00056   resize ();
00057 }
00058 
00059 FunctionBase * Landau::clone () const
00060 {
00061   return new Landau ( *this );
00062 }
00063 
00065 //                            REAL FUNCTION FITLAND(X)
00066 
00067 //                             DOUBLE PRECISION FITEMP
00068 
00069 //                             COMMON/PAWPAR/ PAR(3)
00070 
00071 
00072 //                             PI=3.1415926
00073 
00074 //                            Y=(X-PAR(1))/PAR(3)
00075 
00076 //            FITEMP=DBLE(PAR(2)*EXP(-0.5*(Y+EXP(-1.*Y)))/SQRT(2.*PI))
00077 
00078 //                               FITLAND=REAL(FITEMP)
00079 
00080 //                            END
00081 double Landau::operator () ( double x ) const
00082 {  
00083   double y = calcY ( x );
00084   double t = exp ( -0.5 * ( y + exp ( -1.0 * y ) ) ) 
00085     / sqrt ( 2.0 * M_PI );
00086 
00087   return m_parms[norm] * t;
00088 }
00089 
00090 /* virtual */
00091 void 
00092 Landau::
00093 initialParameters ( const FunctionHelper * helper )
00094 {
00095   m_parms[norm] = helper->maxValue () * sqrt ( 2.0 * M_PI * M_E );
00096   m_parms[peak] = helper->meanCoord ();
00097   m_parms[sigma] = helper->stdCoord ();
00098 }
00099 
00100 double Landau::derivByParm ( int i, double x ) const
00101 {
00102   switch ( i ) {
00103   case peak :
00104     return derivByPeak ( x );
00105     break;
00106 
00107   case norm :
00108     return derivByNorm ( x );
00109     break;
00110 
00111   case sigma :
00112     return derivBySigma ( x );
00113     break;
00114 
00115   default :
00116     assert ( false );
00117     break;
00118   }
00119   return 0.0;
00120 }
00121 
00122 double Landau::derivByNorm ( double x ) const
00123 {
00124   double norm_aux = 0.0001;
00125   if(m_parms[norm] != 0) norm_aux = m_parms[norm];
00126   return operator () (x) / norm_aux;
00127 }
00128 
00129 double Landau::derivByPeak ( double x ) const
00130 {
00131   return operator () ( x ) * calcZ ( x ) * ( ( -1.0 ) / m_parms[sigma] );
00132 }
00133 
00134 double Landau::derivBySigma ( double x ) const
00135 {
00136   return operator () ( x ) * calcZ ( x ) 
00137     * ( - ( x - m_parms[peak] ) / ( m_parms[sigma] * m_parms[sigma] ) );
00138 }
00139 
00140 } // namespace hippodraw
00141 

Generated for HippoDraw Class Library by doxygen