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

LogNormal.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 "LogNormal.h"
00021 
00022 #include "FunctionHelper.h"
00023 
00024 #include <cmath>
00025 #include <cassert>
00026 
00027 using std::distance;
00028 
00029 #ifdef ITERATOR_MEMBER_DEFECT
00030 using namespace std;
00031 #else
00032 using std::exp;
00033 using std::vector;
00034 #endif
00035 
00036 namespace {
00039   enum { norm = 0, mean = 1, sigma = 2, //< FWHM/2.36
00040          tail = 3 };
00041 }
00042 
00043 LogNormal::LogNormal ( )
00044 {
00045   initialize ();
00046 }
00047 
00048 LogNormal::LogNormal ( double n, double m, double s, double t )
00049 {
00050   initialize ();
00051   
00052   m_parms[norm] = n;
00053   m_parms[mean] = m;
00054   m_parms[sigma] = s;
00055   m_parms[tail] = t;
00056 }
00057 
00058 void LogNormal::initialize ()
00059 {
00060   m_name = "LogNormal";
00061 
00062   m_parm_names.push_back ( "Norm" );
00063   m_parm_names.push_back ( "Mean" );
00064   m_parm_names.push_back ( "Sigma" );
00065   m_parm_names.push_back ( "Tail" );
00066 
00067   resize ();
00068 }
00069 
00070 FunctionBase * LogNormal::clone () const
00071 {
00072   return new LogNormal ( *this );
00073 }
00074 
00075 double LogNormal::operator () ( double x ) const
00076 {
00077 //---- If tail is small then Gauss
00078 
00079   double  qa=0,qb=0,qc=0,qx=0,qy=0;
00080   double result=0;
00081 
00082   if(fabs(m_parms[3]) < 1.e-7)
00083     qc = 0.5*pow((( x -m_parms[1])/m_parms[2]),2);
00084   else {
00085     qa = m_parms[3]*sqrt(log(4.));
00086     qb = sinh(qa)/qa;
00087     qx = ( x - m_parms[1])/m_parms[2]*qb;
00088     qy = 1.+m_parms[3]*qx;
00089 
00090     //---- Cutting curve from right side
00091 
00092     if( qy > 1.E-7)
00093       qc = 0.5*(pow((log(qy)/m_parms[3]),2) + m_parms[3]*m_parms[3]);
00094     else
00095       qc = 15.;
00096   }
00097   //----
00098 
00099   result =  m_parms[0] * exp(-qc);
00100 
00101   return result;
00102 }
00103 
00104 void 
00105 LogNormal::
00106 initialParameters ( const FunctionHelper * helper )
00107 {
00108   double min_x = helper->minCoord ();
00109   double max_x = helper->maxCoord ();
00110   int size = helper->size();
00111   double total = helper->getTotal ();
00112 
00113   m_parms[norm] = total * ( max_x - min_x ) / size;
00114   m_parms[mean] = helper->meanCoord ();
00115   m_parms[sigma] = helper->stdCoord ();
00116   m_parms[tail] = 0.;
00117 }
00118 
00119 double LogNormal::derivByParm ( int i, double x ) const
00120 {
00121   assert ( false );
00122   return 0.;
00123 }
00124 
00125 bool
00126 LogNormal::
00127 hasDerivatives () const
00128 {
00129   return false;
00130 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3