CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: 00003 #include "CLHEP/GenericFunctions/LogisticFunction.hh" 00004 #include "CLHEP/GenericFunctions/Variable.hh" 00005 #include <assert.h> 00006 #define MAXRANGE 1000 00007 00008 namespace Genfun { 00009 FUNCTION_OBJECT_IMP(LogisticFunction) 00010 00011 LogisticFunction::LogisticFunction(): 00012 _x0("X0", 0.0,0.0,1.0), 00013 _a("A",2.0,1.0, 4.0) 00014 {} 00015 00016 LogisticFunction::~LogisticFunction() { 00017 } 00018 00019 LogisticFunction::LogisticFunction(const LogisticFunction & right): 00020 AbsFunction(right), 00021 _x0(right._x0), 00022 _a(right._a) 00023 { 00024 } 00025 00026 double LogisticFunction::operator() (double x) const { 00027 int i = (int) (x+0.5), &back = i, end=back+1; 00028 00029 if (i<0 || i>MAXRANGE) { 00030 return 0; 00031 } 00032 else { 00033 // Is the vector of values stale? 00034 if (__a!=_a.getValue() || __x0!=_x0.getValue()) { 00035 00036 // Empty the vector 00037 fx.erase(fx.begin(),fx.end()); 00038 00039 // And update the cache. 00040 __a = _a.getValue(); 00041 __x0 = _x0.getValue(); 00042 00043 } 00044 00045 00046 if (fx.empty()) fx.push_back(__x0); 00047 00048 while (fx.size()<size_t(end)) { 00049 double v = fx.back(); 00050 fx.push_back(__a*v*(1.0-v)); 00051 } 00052 00053 return fx[i]; 00054 } 00055 00056 00057 } 00058 00059 Parameter & LogisticFunction::x0() { 00060 return _x0; 00061 } 00062 00063 Parameter & LogisticFunction::a() { 00064 return _a; 00065 } 00066 00067 const Parameter & LogisticFunction::x0() const { 00068 return _x0; 00069 } 00070 00071 const Parameter & LogisticFunction::a() const { 00072 return _a; 00073 } 00074 00075 00076 } // namespace Genfun