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

FunctionDirectProduct.cc

Go to the documentation of this file.
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 AbsFunction(right),
00019 _arg1(right._arg1->clone()),
00020 _arg2(right._arg2->clone()),
00021 _m(right._m),
00022 _n(right._n)
00023 {
00024 }
00025 
00026 
00027 FunctionDirectProduct::~FunctionDirectProduct()
00028 {
00029   delete _arg1;
00030   delete _arg2;
00031 }
00032 
00033 
00034 double FunctionDirectProduct::operator() (const Argument & a) const {
00035   unsigned int P = a.dimension();
00036   Argument x1(_m);
00037   Argument x2(_n);
00038   if (_m+_n != P) {
00039     std::cerr
00040       << "Warning: Direct product function/argument dimension mismatch"
00041       <<  std::endl;
00042     assert(0);
00043     return 0;
00044   }
00045   for (unsigned int i = 0; i<_m;i++) {
00046     x1[i]=a[i];
00047   }
00048   for (unsigned int j = 0;j<_n;j++) {
00049     x2[j]=a[j+_m];
00050   }
00051   return (*_arg1)(x1) * (*_arg2)(x2);
00052 }
00053 
00054 unsigned int FunctionDirectProduct::dimensionality() const {
00055   return _m+_n;
00056 }
00057 
00058 double FunctionDirectProduct::operator ()(double) const
00059 {
00060   std::cerr
00061     << "Warning.  direct product called with scalar argument"
00062     << std::endl;
00063   assert(0);
00064   return 0;
00065 }
00066 
00067 
00068 
00069 Derivative FunctionDirectProduct::partial(unsigned int index) const {
00070   assert (index<(_m+_n));
00071   if (index<_m) {
00072     const AbsFunction & fPrime = (_arg1->partial(index))%(*_arg2);
00073     return Derivative(&fPrime);
00074   }
00075   else {
00076     const AbsFunction & fPrime = (*_arg1)%(_arg2->partial(index-_m));
00077     return Derivative(&fPrime);
00078   }
00079 }
00080 
00081 
00082 } // namespace Genfun

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7