Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:35

0001 // -*- C++ -*-
0002 // $Id: ParamToArgAdaptor.icc,v 1.2 2003/09/06 14:04:13 boudreau Exp $
0003 #include "CLHEP/GenericFunctions/ParamToArgAdaptor.hh"
0004 #include <assert.h>
0005 #include <iostream>
0006 #include <cfloat>
0007 
0008 namespace Genfun {
0009 
0010 
0011 //FUNCTION_OBJECT_IMP(ParamToArgAdaptor) Do it by hand here:
0012 
0013 template <class F>
0014 FunctionComposition ParamToArgAdaptor<F>::operator()(const AbsFunction & function) const
0015 {                                            
0016   return AbsFunction::operator() (function); 
0017 }     
0018                  
0019 template <class F>                      
0020 ParamToArgAdaptor<F> *ParamToArgAdaptor<F>::clone () const {       
0021   return (ParamToArgAdaptor<F> *) _clone();             
0022 }
0023                                             
0024 template <class F>                      
0025 AbsFunction *ParamToArgAdaptor<F>::_clone () const {    
0026   return new ParamToArgAdaptor<F>(*this);                       
0027 }
0028 
0029 
0030 
0031 template<class F> 
0032 ParamToArgAdaptor<F>::ParamToArgAdaptor(const F        &function,
0033                         ParamToArgAdaptor<F>::ScopedMethodPtr parameterFetchMethod):
0034   _scaleFactor("Sigma",  1.0,  0, 10),
0035   _function(function.clone()),
0036   _parameterFetchMethod(parameterFetchMethod)
0037 {
0038   _parameterFetchMethod(*_function).setLowerLimit(-DBL_MAX);
0039   _parameterFetchMethod(*_function).setUpperLimit(+DBL_MAX);
0040 }
0041 
0042 template <class F>
0043 ParamToArgAdaptor<F>::~ParamToArgAdaptor() {
0044   delete _function;
0045 }
0046 
0047 template <class F>
0048 ParamToArgAdaptor<F>::ParamToArgAdaptor(const ParamToArgAdaptor & right):
0049   _scaleFactor(right._scaleFactor),
0050   _parameterFetchMethod(right._parameterFetchMethod),
0051   _function(right._function->clone())
0052 {
0053   _parameterFetchMethod(*_function).setLowerLimit(-DBL_MAX);
0054   _parameterFetchMethod(*_function).setUpperLimit(+DBL_MAX);
0055 }
0056 
0057 
0058 template <class F>
0059 double ParamToArgAdaptor<F>::operator ()(double x) const
0060 {
0061   std::cerr
0062     << "Warning.  ParamToArgAdaptor called with scalar argument"
0063     << std::endl;
0064   assert(0);
0065   return 0;
0066 }
0067 
0068 template <class F>
0069 Parameter & ParamToArgAdaptor<F>::scaleFactor() {
0070   return _scaleFactor;
0071 }
0072 
0073 template <class F>
0074 const Parameter & ParamToArgAdaptor<F>::scaleFactor() const {
0075   return _scaleFactor;
0076 }
0077 
0078 template <class F>
0079 unsigned int ParamToArgAdaptor<F>::dimensionality() const {
0080   return _function->dimensionality()+1;
0081 }
0082 
0083 template <class F> 
0084 double ParamToArgAdaptor<F>::operator() (const Argument & a) const {
0085   if (dimensionality()!= a.dimension()) {
0086     std::cerr
0087       << "Warning: ParamToArgAdaptor function/argument dimension mismatch"
0088       <<  std::endl;
0089     assert(0);
0090     return 0;
0091   }
0092   int dMinus = a.dimension()-1;
0093   Argument aPrime(dMinus);
0094   for (int i=0;i<dMinus;i++) aPrime[i]=a[i];
0095   (_parameterFetchMethod(*_function)).setValue(_scaleFactor.getValue()*a[dMinus]);
0096   return (*_function)(a);
0097 }
0098 
0099 } // end of namespace Genfun 
0100