CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: FunctionDirectProduct.cc,v 1.3 2003/09/06 14:04:14 boudreau Exp $ 00003 #include "CLHEP/GenericFunctions/FunctionDirectProduct.hh" 00004 #include <assert.h> 00005 00006 namespace Genfun { 00007 FUNCTION_OBJECT_IMP(FunctionDirectProduct) 00008 00009 FunctionDirectProduct::FunctionDirectProduct(const AbsFunction *arg1, const AbsFunction *arg2): 00010 _arg1(arg1->clone()), 00011 _arg2(arg2->clone()), 00012 _m(arg1->dimensionality()), 00013 _n(arg2->dimensionality()) 00014 { 00015 } 00016 00017 FunctionDirectProduct::FunctionDirectProduct(const FunctionDirectProduct & right): 00018 _arg1(right._arg1->clone()), 00019 _arg2(right._arg2->clone()), 00020 _m(right._m), 00021 _n(right._n) 00022 { 00023 } 00024 00025 00026 FunctionDirectProduct::~FunctionDirectProduct() 00027 { 00028 delete _arg1; 00029 delete _arg2; 00030 } 00031 00032 00033 double FunctionDirectProduct::operator() (const Argument & a) const { 00034 unsigned int P = a.dimension(); 00035 Argument x1(_m); 00036 Argument x2(_n); 00037 if (_m+_n != P) { 00038 std::cerr 00039 << "Warning: Direct product function/argument dimension mismatch" 00040 << std::endl; 00041 assert(0); 00042 return 0; 00043 } 00044 for (unsigned int i = 0; i<_m;i++) { 00045 x1[i]=a[i]; 00046 } 00047 for (unsigned int j = 0;j<_n;j++) { 00048 x2[j]=a[j+_m]; 00049 } 00050 return (*_arg1)(x1) * (*_arg2)(x2); 00051 } 00052 00053 unsigned int FunctionDirectProduct::dimensionality() const { 00054 return _m+_n; 00055 } 00056 00057 double FunctionDirectProduct::operator ()(double x) const 00058 { 00059 std::cerr 00060 << "Warning. direct product called with scalar argument" 00061 << std::endl; 00062 assert(0); 00063 return 0; 00064 } 00065 00066 00067 00068 Derivative FunctionDirectProduct::partial(unsigned int index) const { 00069 assert (index<(_m+_n)); 00070 if (index<_m) { 00071 const AbsFunction & fPrime = (_arg1->partial(index))%(*_arg2); 00072 return Derivative(&fPrime); 00073 } 00074 else { 00075 const AbsFunction & fPrime = (*_arg1)%(_arg2->partial(index-_m)); 00076 return Derivative(&fPrime); 00077 } 00078 } 00079 00080 00081 } // namespace Genfun