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