1 // -*- C++ -*- 2 // $Id: FunctionSum.cc,v 1.3 2003/09/06 14:04:14 boudreau Exp $ 3 #include "CLHEP/GenericFunctions/FunctionSum.hh" 4 #include <assert.h> 5 6 namespace Genfun { FUNCTION_OBJECT_IMP(FunctionSum)7FUNCTION_OBJECT_IMP(FunctionSum) 8 9 FunctionSum::FunctionSum(const AbsFunction *arg1, const AbsFunction *arg2): 10 _arg1(arg1->clone()), 11 _arg2(arg2->clone()) 12 { 13 if (arg1->dimensionality()!=arg2->dimensionality()) { 14 std::cout 15 << "Warning: dimension mismatch in function sum" 16 << std::endl; 17 assert(0); 18 } 19 } 20 FunctionSum(const FunctionSum & right)21FunctionSum::FunctionSum(const FunctionSum & right) : 22 AbsFunction(right), 23 _arg1(right._arg1->clone()), 24 _arg2(right._arg2->clone()) 25 {} 26 dimensionality() const27unsigned int FunctionSum::dimensionality() const { 28 return _arg1->dimensionality(); 29 } 30 ~FunctionSum()31FunctionSum::~FunctionSum() 32 { 33 delete _arg1; 34 delete _arg2; 35 } 36 37 38 operator ()(double x) const39double FunctionSum::operator ()(double x) const 40 { 41 return (*_arg1)(x)+(*_arg2)(x); 42 } 43 44 operator ()(const Argument & x) const45double FunctionSum::operator ()(const Argument & x) const 46 { 47 return (*_arg1)(x)+(*_arg2)(x); 48 } 49 50 51 partial(unsigned int index) const52Derivative FunctionSum::partial(unsigned int index) const { 53 const AbsFunction & fPrime = _arg1->partial(index) + _arg2->partial(index); 54 return Derivative(&fPrime); 55 } 56 57 58 59 } // namespace Genfun 60