File indexing completed on 2025-01-30 10:03:25
0001
0002
0003 #include "CLHEP/GenericFunctions/DoubleParamToArgAdaptor.hh"
0004 #include <assert.h>
0005 #include <iostream>
0006
0007 namespace Genfun {
0008
0009
0010
0011
0012 template <class F>
0013 FunctionComposition DoubleParamToArgAdaptor<F>::operator()(const AbsFunction & function) const
0014 {
0015 return AbsFunction::operator() (function);
0016 }
0017
0018 template <class F>
0019 DoubleParamToArgAdaptor<F> *DoubleParamToArgAdaptor<F>::clone () const {
0020 return (DoubleParamToArgAdaptor<F> *) _clone();
0021 }
0022
0023 template <class F>
0024 AbsFunction *DoubleParamToArgAdaptor<F>::_clone () const {
0025 return new DoubleParamToArgAdaptor<F>(*this);
0026 }
0027
0028
0029
0030 template<class F>
0031 DoubleParamToArgAdaptor<F>::DoubleParamToArgAdaptor(const F &function,
0032 DoubleParamToArgAdaptor<F>::ScopedMethodPtr parameterFetchMethod0,
0033 DoubleParamToArgAdaptor<F>::ScopedMethodPtr parameterFetchMethod1):
0034 _scaleFactor0("Scale 0", 1.0, 0, 10),
0035 _scaleFactor1("Scale 1", 1.0, 0, 10),
0036 _function(function.clone()),
0037 _parameterFetchMethod0(parameterFetchMethod0),
0038 _parameterFetchMethod1(parameterFetchMethod1)
0039 {
0040 _parameterFetchMethod0(*_function).setLowerLimit(-std::numeric_limits<double>::max());
0041 _parameterFetchMethod0(*_function).setUpperLimit(+std::numeric_limits<double>::max());
0042 _parameterFetchMethod1(*_function).setLowerLimit(-std::numeric_limits<double>::max());
0043 _parameterFetchMethod1(*_function).setUpperLimit(+std::numeric_limits<double>::max());
0044 }
0045
0046 template <class F>
0047 DoubleParamToArgAdaptor<F>::~DoubleParamToArgAdaptor() {
0048 delete _function;
0049 }
0050
0051 template <class F>
0052 DoubleParamToArgAdaptor<F>::DoubleParamToArgAdaptor(const DoubleParamToArgAdaptor & right):
0053 _scaleFactor0(right._scaleFactor0),
0054 _scaleFactor1(right._scaleFactor1),
0055 _parameterFetchMethod0(right._parameterFetchMethod0),
0056 _parameterFetchMethod1(right._parameterFetchMethod1),
0057 _function(right._function->clone())
0058 {
0059 _parameterFetchMethod0(*_function).setLowerLimit(-std::numeric_limits<double>::max());
0060 _parameterFetchMethod0(*_function).setUpperLimit(+std::numeric_limits<double>::max());
0061 _parameterFetchMethod1(*_function).setLowerLimit(-std::numeric_limits<double>::max());
0062 _parameterFetchMethod1(*_function).setUpperLimit(+std::numeric_limits<double>::max());
0063 }
0064
0065
0066 template <class F>
0067 double DoubleParamToArgAdaptor<F>::operator ()(double x) const
0068 {
0069 std::cerr
0070 << "Warning. DoubleParamToArgAdaptor called with scalar argument"
0071 << std::endl;
0072 assert(0);
0073 return 0;
0074 }
0075
0076 template <class F>
0077 Parameter & DoubleParamToArgAdaptor<F>::scaleFactor0() {
0078 return _scaleFactor0;
0079 }
0080
0081 template <class F>
0082 const Parameter & DoubleParamToArgAdaptor<F>::scaleFactor0() const {
0083 return _scaleFactor0;
0084 }
0085
0086 template <class F>
0087 Parameter & DoubleParamToArgAdaptor<F>::scaleFactor1() {
0088 return _scaleFactor1;
0089 }
0090
0091 template <class F>
0092 const Parameter & DoubleParamToArgAdaptor<F>::scaleFactor1() const {
0093 return _scaleFactor1;
0094 }
0095
0096 template <class F>
0097 unsigned int DoubleParamToArgAdaptor<F>::dimensionality() const {
0098 return _function->dimensionality()+1;
0099 }
0100
0101 template <class F>
0102 double DoubleParamToArgAdaptor<F>::operator() (const Argument & a) const {
0103 if (dimensionality()!= a.dimension()) {
0104 std::cerr
0105 << "Warning: DoubleParamToArgAdaptor function/argument dimension mismatch"
0106 << std::endl;
0107 assert(0);
0108 return 0;
0109 }
0110 int dMinus = a.dimension()-1;
0111 Argument aPrime(dMinus);
0112 for (int i=0;i<dMinus;i++) aPrime[i]=a[i];
0113 (_parameterFetchMethod0(*_function)).setValue(_scaleFactor0.getValue()*a[dMinus]);
0114 (_parameterFetchMethod1(*_function)).setValue(_scaleFactor1.getValue()*a[dMinus]);
0115 return (*_function)(a);
0116 }
0117
0118 }
0119