CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: AbsFunction.hh,v 1.2 2003/09/06 14:04:13 boudreau Exp $ 00003 //------------------------AbsFunction-----------------------------------// 00004 // // 00005 // AbsFunction, base class for function objects // 00006 // Joe Boudreau, Petar Maksimovic // 00007 // Nov 1999 // 00008 // // 00009 //----------------------------------------------------------------------// 00010 #ifndef AbsFunction_h 00011 #define AbsFunction_h 1 00012 #include "CLHEP/GenericFunctions/Argument.hh" 00013 00014 namespace Genfun { 00015 00016 class AbsParameter; 00017 00018 //-----------------------------------------------------------------------// 00019 // Exact return type of arithmentic operations. To the user, the return // 00020 // type is GENFUNCTION, or const AbsFunction &. // 00021 //-----------------------------------------------------------------------// 00022 00023 class FunctionProduct; 00024 class FunctionSum; 00025 class FunctionDifference; 00026 class FunctionQuotient; 00027 class FunctionNegation; 00028 class FunctionConvolution; 00029 class FunctionDirectProduct; 00030 class FunctionComposition; 00031 class ConstPlusFunction; 00032 class ConstTimesFunction; 00033 class ConstMinusFunction; 00034 class ConstOverFunction; 00035 class FunctionPlusParameter; 00036 class FunctionTimesParameter; 00037 class FunctionNumDeriv; 00038 class Variable; 00039 class FunctionNoop; 00040 00041 typedef FunctionNoop Derivative; 00042 00047 class AbsFunction { 00048 00049 public: 00050 00051 // Default Constructor 00052 AbsFunction(); 00053 00054 // Copy Constructor: 00055 AbsFunction(const AbsFunction &right); 00056 00057 // Destructor 00058 virtual ~AbsFunction(); 00059 00060 // Function value: N-dimensional functions must override these: 00061 virtual unsigned int dimensionality() const ; // returns 1; 00062 00063 // Function value 00064 virtual double operator() (double argument) const=0; 00065 virtual double operator() (const Argument &argument) const=0; 00066 00067 // Every function must override this: 00068 AbsFunction * clone() const; 00069 00070 // Function composition. Do not attempt to override: 00071 virtual FunctionComposition operator () (const AbsFunction &f) const; 00072 00073 // Derivative, (All functions) (do not override) 00074 Derivative derivative(const Variable &v) const; 00075 00076 // Derivative (1D functions only) (do not override) 00077 Derivative prime() const; 00078 00079 // Does this function have an analytic derivative? 00080 virtual bool hasAnalyticDerivative() const {return false;} 00081 00082 // Derivative. Overriders may be provided, numerical method by default! 00083 virtual Derivative partial(unsigned int) const; 00084 00085 private: 00086 00087 virtual AbsFunction *_clone() const=0; 00088 00089 // It is illegal to assign a function. 00090 const AbsFunction & operator=(const AbsFunction &right); 00091 00092 }; 00093 00094 FunctionProduct operator * (const AbsFunction &op1, const AbsFunction &op2); 00095 FunctionSum operator + (const AbsFunction &op1, const AbsFunction &op2); 00096 FunctionDifference operator - (const AbsFunction &op1, const AbsFunction &op2); 00097 FunctionQuotient operator / (const AbsFunction &op1, const AbsFunction &op2); 00098 FunctionNegation operator - (const AbsFunction &op1); 00099 00100 ConstTimesFunction operator * (double c, const AbsFunction &op2); 00101 ConstPlusFunction operator + (double c, const AbsFunction &op2); 00102 ConstMinusFunction operator - (double c, const AbsFunction &op2); 00103 ConstOverFunction operator / (double c, const AbsFunction &op2); 00104 00105 ConstTimesFunction operator * (const AbsFunction &op2, double c); 00106 ConstPlusFunction operator + (const AbsFunction &op2, double c); 00107 ConstPlusFunction operator - (const AbsFunction &op2, double c); 00108 ConstTimesFunction operator / (const AbsFunction &op2, double c); 00109 00110 FunctionTimesParameter operator * (const AbsFunction &op1, const AbsParameter &op2); 00111 FunctionPlusParameter operator + (const AbsFunction &op1, const AbsParameter &op2); 00112 FunctionPlusParameter operator - (const AbsFunction &op1, const AbsParameter &op2); 00113 FunctionTimesParameter operator / (const AbsFunction &op1, const AbsParameter &op2); 00114 00115 FunctionTimesParameter operator * (const AbsParameter &op1, const AbsFunction &op2); 00116 FunctionPlusParameter operator + (const AbsParameter &op1, const AbsFunction &op2); 00117 FunctionPlusParameter operator - (const AbsParameter &op1, const AbsFunction &op2); 00118 FunctionTimesParameter operator / (const AbsParameter &op1, const AbsFunction &op2); 00119 00120 FunctionConvolution convolve (const AbsFunction &op1, const AbsFunction &op2, double x0, double x1); 00121 FunctionDirectProduct operator % (const AbsFunction &op1, const AbsFunction &op2); 00122 00123 typedef const AbsFunction & GENFUNCTION; 00124 00125 } // namespace Genfun 00126 00127 00128 //---------------------------------------------------------------------------- 00129 // 00130 // This macro does all the ugly boilerplate. For reference I will lis what 00131 // it is doing: 00132 // 00133 // 1). It uses the base class function composition operator. It would be 00134 // nice to just use the 00135 // 00136 // using AbsFunction::operator(); 00137 // 00138 // directive but unfortunately this is compiler-dependent! 00139 // 00140 // 2) It defines the clone methods, using a poor-man's covariant return type. 00141 // again this is for compiler independence. 00142 // 00143 00144 #define FUNCTION_OBJECT_DEF(classname) \ 00145 public: \ 00146 virtual FunctionComposition operator()(const AbsFunction &function) const; \ 00147 classname *clone() const; \ 00148 private: \ 00149 virtual AbsFunction *_clone() const; 00150 00151 //---------------------------------------------------------------------------- 00152 // 00153 // This macro implements the ugly boilerplate 00154 // 00155 00156 #define FUNCTION_OBJECT_IMP(classname) \ 00157 FunctionComposition classname::operator()(const AbsFunction & function) const\ 00158 { \ 00159 return AbsFunction::operator() (function); \ 00160 } \ 00161 classname *classname::clone () const { \ 00162 return (classname *) _clone(); \ 00163 } \ 00164 AbsFunction *classname::_clone () const { \ 00165 return new classname(*this); \ 00166 } 00167 00168 //---------------------------------------------------------------------------- 00169 00170 00171 #include "CLHEP/GenericFunctions/FunctionProduct.hh" 00172 #include "CLHEP/GenericFunctions/FunctionSum.hh" 00173 #include "CLHEP/GenericFunctions/FunctionDifference.hh" 00174 #include "CLHEP/GenericFunctions/FunctionQuotient.hh" 00175 #include "CLHEP/GenericFunctions/FunctionConvolution.hh" 00176 #include "CLHEP/GenericFunctions/FunctionNegation.hh" 00177 #include "CLHEP/GenericFunctions/FunctionDirectProduct.hh" 00178 #include "CLHEP/GenericFunctions/FunctionComposition.hh" 00179 #include "CLHEP/GenericFunctions/ConstPlusFunction.hh" 00180 #include "CLHEP/GenericFunctions/ConstTimesFunction.hh" 00181 #include "CLHEP/GenericFunctions/ConstMinusFunction.hh" 00182 #include "CLHEP/GenericFunctions/ConstOverFunction.hh" 00183 #include "CLHEP/GenericFunctions/FunctionPlusParameter.hh" 00184 #include "CLHEP/GenericFunctions/FunctionTimesParameter.hh" 00185 #include "CLHEP/GenericFunctions/FunctionNoop.hh" 00186 00187 #endif