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

Variable.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: Variable.cc,v 1.3 2003/09/06 14:04:14 boudreau Exp $
5 #include <stdexcept>
6 namespace Genfun {
7 FUNCTION_OBJECT_IMP(Variable)
8 
9 Variable::Variable(unsigned int selectionIndex, unsigned int dimensionality):
10  _selectionIndex(selectionIndex),
11  _dimensionality(dimensionality)
12 {}
13 
15  _selectionIndex(right._selectionIndex),
16  _dimensionality(right._dimensionality)
17 {
18 }
19 
21 }
22 
23 double Variable::operator() (double x) const {
24  if (_selectionIndex!=0) throw std::runtime_error("Genfun::Variable: selection index !=0") ;
25  return x;
26 }
27 
28 double Variable::operator () (const Argument & a) const {
29  if (!(_selectionIndex<a.dimension())) throw std::runtime_error("Genfun::Varaible selection index out of bounds");
30  return a[_selectionIndex];
31 }
32 
33 unsigned int Variable::index() const {
34  return _selectionIndex;
35 }
36 
37 
38 Derivative Variable::partial(unsigned int index) const {
39  int kroneckerDelta = index==_selectionIndex ? 1 : 0;
40 
41  const AbsFunction * f= new FixedConstant(kroneckerDelta);
42  for (unsigned int i=1;i<_dimensionality;i++) {
43  const AbsFunction & g = (*f)%FixedConstant(kroneckerDelta);
44  delete f;
45  f=g.clone();
46  }
47  Derivative retVal(f);
48  delete f;
49  return retVal;
50 }
51 
52 unsigned int Variable::dimensionality() const {
53  return _dimensionality;
54 }
55 
56 } // namespace Genfun