CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Variable.cc
Go to the documentation of this file.
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 dimensionality):
00010   _selectionIndex(selectionIndex),
00011   _dimensionality(dimensionality)
00012 {}
00013 
00014 Variable::Variable(const Variable & right):
00015   _selectionIndex(right._selectionIndex),
00016   _dimensionality(right._dimensionality)
00017 {
00018 }
00019 
00020 Variable::~Variable() {
00021 }
00022 
00023 double Variable::operator() (double x) const {
00024   if (_selectionIndex!=0) throw std::runtime_error("Genfun::Variable: selection index !=0") ;
00025   return x;
00026 }
00027 
00028 double Variable::operator () (const Argument & a) const {
00029   if  (!(_selectionIndex<a.dimension())) throw std::runtime_error("Genfun::Varaible selection index out of bounds");
00030   return a[_selectionIndex];
00031 }
00032 
00033 unsigned int Variable::index() const {
00034   return _selectionIndex;
00035 }
00036 
00037 
00038 Derivative Variable::partial(unsigned int index) const {
00039   int kroneckerDelta = index==_selectionIndex ? 1 : 0;
00040 
00041   const AbsFunction * f= new FixedConstant(kroneckerDelta);
00042   for (unsigned int i=1;i<_dimensionality;i++) {
00043     const AbsFunction & g = (*f)%FixedConstant(kroneckerDelta);
00044     delete f;
00045     f=g.clone();
00046   }
00047   Derivative retVal(f);
00048   delete f;
00049   return retVal;
00050 }
00051 
00052 unsigned int Variable::dimensionality() const {
00053   return _dimensionality;
00054 } 
00055 
00056 } // namespace Genfun