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

FunctionConvolution.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: FunctionConvolution.cc,v 1.3 2003/09/06 14:04:14 boudreau Exp $
4 #include <assert.h>
5 
6 namespace Genfun {
7 FUNCTION_OBJECT_IMP(FunctionConvolution)
8 
9 FunctionConvolution::FunctionConvolution(const AbsFunction *arg1, const AbsFunction *arg2, double x0, double x1):_arg1(arg1->clone()),_arg2(arg2->clone()),_x0(x0), _x1(x1)
10 {
11  if ((arg1->dimensionality()!=1) || arg2->dimensionality()!=1) {
12  std::cout
13  << "Warning: dimension mismatch in function convolution"
14  << std::endl;
15  assert(0);
16  }
17 }
18 
20 _arg1(right._arg1->clone()),
21 _arg2(right._arg2->clone()),
22 _x0(right._x0),
23 _x1(right._x1)
24 {}
25 
27 {
28  delete _arg1;
29  delete _arg2;
30 }
31 
32 
33 
34 double FunctionConvolution::operator ()(double argument) const
35 {
36  const double NDIVISIONS=200.0;
37  double dx = (_x1-_x0)/NDIVISIONS;
38  double result=0.0;
39  for (double x=_x0; x<_x1; x+=dx) {
40  result += (*_arg1)(argument-x)*(*_arg2)(x);
41  }
42  result/=NDIVISIONS;
43  return result;
44 }
45 
46 } // namespace Genfun