CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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 $
3#include "CLHEP/GenericFunctions/Variable.hh"
4#include "CLHEP/GenericFunctions/FixedConstant.hh"
5#include <stdexcept>
6namespace Genfun {
8
9Variable::Variable(unsigned int selectionIndex, unsigned int dmsnlty):
10 _selectionIndex(selectionIndex),
11 _dimensionality(dmsnlty)
12{}
13
15 AbsFunction(right),
16 _selectionIndex(right._selectionIndex),
17 _dimensionality(right._dimensionality)
18{
19}
20
22}
23
24double Variable::operator() (double x) const {
25 if (_selectionIndex!=0) throw std::runtime_error("Genfun::Variable: selection index !=0") ;
26 return x;
27}
28
29double Variable::operator () (const Argument & a) const {
30 if (!(_selectionIndex<a.dimension())) throw std::runtime_error("Genfun::Varaible selection index out of bounds");
31 return a[_selectionIndex];
32}
33
34unsigned int Variable::index() const {
35 return _selectionIndex;
36}
37
38
39Derivative Variable::partial(unsigned int mindex) const {
40 int kroneckerDelta = mindex==_selectionIndex ? 1 : 0;
41
42 const AbsFunction * f= new FixedConstant(kroneckerDelta);
43 for (unsigned int i=1;i<_dimensionality;i++) {
44 const AbsFunction & g = (*f)%FixedConstant(kroneckerDelta);
45 delete f;
46 f=g.clone();
47 }
48 Derivative retVal(f);
49 delete f;
50 return retVal;
51}
52
53unsigned int Variable::dimensionality() const {
54 return _dimensionality;
55}
56
57} // namespace Genfun
#define FUNCTION_OBJECT_IMP(classname)
Definition: AbsFunction.hh:149
unsigned int dimension() const
Definition: Argument.hh:61
Variable(unsigned int selectionIndex=0, unsigned int dimensionality=1)
Definition: Variable.cc:9
Derivative partial(unsigned int) const override
Definition: Variable.cc:39
unsigned int index() const
Definition: Variable.cc:34
virtual double operator()(double argument) const override
Definition: Variable.cc:24
virtual ~Variable()
Definition: Variable.cc:21
virtual unsigned int dimensionality() const override
Definition: Variable.cc:53
void f(void g())
Definition: excDblThrow.cc:38
Definition: Abs.hh:14
int g(shared_ptr< X >)