CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: Variable.cc,v 1.3 2003/09/06 14:04:14 boudreau Exp $ 00003 #include "CLHEP/GenericFunctions/Variable.hh" 00004 #include "CLHEP/GenericFunctions/FixedConstant.hh" 00005 #include <stdexcept> 00006 namespace Genfun { 00007 FUNCTION_OBJECT_IMP(Variable) 00008 00009 Variable::Variable(unsigned int selectionIndex, unsigned int dmsnlty): 00010 _selectionIndex(selectionIndex), 00011 _dimensionality(dmsnlty) 00012 {} 00013 00014 Variable::Variable(const Variable & right): 00015 AbsFunction(right), 00016 _selectionIndex(right._selectionIndex), 00017 _dimensionality(right._dimensionality) 00018 { 00019 } 00020 00021 Variable::~Variable() { 00022 } 00023 00024 double Variable::operator() (double x) const { 00025 if (_selectionIndex!=0) throw std::runtime_error("Genfun::Variable: selection index !=0") ; 00026 return x; 00027 } 00028 00029 double Variable::operator () (const Argument & a) const { 00030 if (!(_selectionIndex<a.dimension())) throw std::runtime_error("Genfun::Varaible selection index out of bounds"); 00031 return a[_selectionIndex]; 00032 } 00033 00034 unsigned int Variable::index() const { 00035 return _selectionIndex; 00036 } 00037 00038 00039 Derivative Variable::partial(unsigned int mindex) const { 00040 int kroneckerDelta = mindex==_selectionIndex ? 1 : 0; 00041 00042 const AbsFunction * f= new FixedConstant(kroneckerDelta); 00043 for (unsigned int i=1;i<_dimensionality;i++) { 00044 const AbsFunction & g = (*f)%FixedConstant(kroneckerDelta); 00045 delete f; 00046 f=g.clone(); 00047 } 00048 Derivative retVal(f); 00049 delete f; 00050 return retVal; 00051 } 00052 00053 unsigned int Variable::dimensionality() const { 00054 return _dimensionality; 00055 } 00056 00057 } // namespace Genfun