CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

LogisticFunction.cc

Go to the documentation of this file.
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 _x0(right._x0),
00021 _a(right._a)
00022 {
00023 }
00024 
00025 double LogisticFunction::operator() (double x) const {
00026   unsigned int i  = (unsigned int) (x+0.5), &back = i, end=back+1;
00027 
00028   if (i<0 || i>MAXRANGE) {
00029     return 0;
00030   }
00031   else {
00032     // Is the vector of values stale?
00033     if (__a!=_a.getValue() || __x0!=_x0.getValue()) {
00034 
00035       // Empty the vector
00036       fx.erase(fx.begin(),fx.end());
00037 
00038       // And update the cache.
00039       __a  = _a.getValue(); 
00040       __x0 = _x0.getValue();
00041       
00042     }
00043     
00044 
00045     if (fx.empty()) fx.push_back(__x0);
00046 
00047     while (fx.size()<end) {
00048       double v = fx.back();
00049       fx.push_back(__a*v*(1.0-v));
00050     }
00051     
00052     return fx[i];
00053   }
00054 
00055   
00056 }
00057 
00058 Parameter & LogisticFunction::x0() {
00059   return _x0;
00060 }
00061 
00062 Parameter & LogisticFunction::a() {
00063   return _a;
00064 }
00065 
00066 const Parameter & LogisticFunction::x0() const {
00067   return _x0;
00068 }
00069 
00070 const Parameter & LogisticFunction::a() const {
00071   return _a;
00072 }
00073 
00074 
00075 } // namespace Genfun

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7