CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: AbsFunction.hh,v 1.3 2007/01/21 20:20:40 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 class ParameterComposition; 00041 00042 typedef FunctionNoop Derivative; 00043 00048 class AbsFunction { 00049 00050 public: 00051 00052 // Default Constructor 00053 AbsFunction(); 00054 00055 // Copy Constructor: 00056 AbsFunction(const AbsFunction &right); 00057 00058 // Destructor 00059 virtual ~AbsFunction(); 00060 00061 // Function value: N-dimensional functions must override these: 00062 virtual unsigned int dimensionality() const ; // returns 1; 00063 00064 // Function value 00065 virtual double operator() (double argument) const=0; 00066 virtual double operator() (const Argument &argument) const=0; 00067 00068 // Every function must override this: 00069 virtual AbsFunction * clone() const=0; 00070 00071 // Function composition. Do not attempt to override: 00072 virtual FunctionComposition operator () (const AbsFunction &f) const; 00073 00074 // Parameter composition. Do not attempt to override: 00075 virtual ParameterComposition operator() ( const AbsParameter &p) const; 00076 00077 // Derivative, (All functions) (do not override) 00078 Derivative derivative(const Variable &v) const; 00079 00080 // Derivative (1D functions only) (do not override) 00081 Derivative prime() const; 00082 00083 // Does this function have an analytic derivative? 00084 virtual bool hasAnalyticDerivative() const {return false;} 00085 00086 // Derivative. Overriders may be provided, numerical method by default! 00087 virtual Derivative partial(unsigned int) const; 00088 00089 private: 00090 00091 // It is illegal to assign a function. 00092 const AbsFunction & operator=(const AbsFunction &right); 00093 00094 }; 00095 00096 FunctionProduct operator * (const AbsFunction &op1, const AbsFunction &op2); 00097 FunctionSum operator + (const AbsFunction &op1, const AbsFunction &op2); 00098 FunctionDifference operator - (const AbsFunction &op1, const AbsFunction &op2); 00099 FunctionQuotient operator / (const AbsFunction &op1, const AbsFunction &op2); 00100 FunctionNegation operator - (const AbsFunction &op1); 00101 00102 ConstTimesFunction operator * (double c, const AbsFunction &op2); 00103 ConstPlusFunction operator + (double c, const AbsFunction &op2); 00104 ConstMinusFunction operator - (double c, const AbsFunction &op2); 00105 ConstOverFunction operator / (double c, const AbsFunction &op2); 00106 00107 ConstTimesFunction operator * (const AbsFunction &op2, double c); 00108 ConstPlusFunction operator + (const AbsFunction &op2, double c); 00109 ConstPlusFunction operator - (const AbsFunction &op2, double c); 00110 ConstTimesFunction operator / (const AbsFunction &op2, double c); 00111 00112 FunctionTimesParameter operator * (const AbsFunction &op1, const AbsParameter &op2); 00113 FunctionPlusParameter operator + (const AbsFunction &op1, const AbsParameter &op2); 00114 FunctionPlusParameter operator - (const AbsFunction &op1, const AbsParameter &op2); 00115 FunctionTimesParameter operator / (const AbsFunction &op1, const AbsParameter &op2); 00116 00117 FunctionTimesParameter operator * (const AbsParameter &op1, const AbsFunction &op2); 00118 FunctionPlusParameter operator + (const AbsParameter &op1, const AbsFunction &op2); 00119 FunctionPlusParameter operator - (const AbsParameter &op1, const AbsFunction &op2); 00120 FunctionTimesParameter operator / (const AbsParameter &op1, const AbsFunction &op2); 00121 00122 FunctionConvolution convolve (const AbsFunction &op1, const AbsFunction &op2, double x0, double x1); 00123 FunctionDirectProduct operator % (const AbsFunction &op1, const AbsFunction &op2); 00124 00125 typedef const AbsFunction & GENFUNCTION; 00126 00127 } // namespace Genfun 00128 00129 00130 //---------------------------------------------------------------------------- 00131 // 00132 // This macro does all the ugly boilerplate. For reference I will lis what 00133 // it is doing: 00134 // 00135 // 1). It uses the base class function composition operator. It would be 00136 // nice to just use the 00137 // 00138 // using AbsFunction::operator(); 00139 // 00140 // directive but unfortunately this is compiler-dependent! 00141 // 00142 00143 00144 #define FUNCTION_OBJECT_DEF(classname) \ 00145 public: \ 00146 virtual FunctionComposition operator()(const AbsFunction &function) const; \ 00147 virtual ParameterComposition operator()(const AbsParameter &p) const; \ 00148 virtual classname *clone() const; \ 00149 private: 00150 00151 //---------------------------------------------------------------------------- 00152 // 00153 // This macro implements the ugly boilerplate 00154 // 00155 00156 #define FUNCTION_OBJECT_IMP(classname) \ 00157 inline FunctionComposition classname::operator()(const AbsFunction & function) const\ 00158 { \ 00159 return AbsFunction::operator() (function); \ 00160 } \ 00161 inline ParameterComposition classname::operator()(const AbsParameter & p) const\ 00162 { \ 00163 return AbsFunction::operator() (p); \ 00164 } \ 00165 inline classname *classname::clone() const \ 00166 { \ 00167 return new classname(*this); \ 00168 } 00169 00170 00171 //---------------------------------------------------------------------------- 00172 00173 00174 #include "CLHEP/GenericFunctions/FunctionProduct.hh" 00175 #include "CLHEP/GenericFunctions/FunctionSum.hh" 00176 #include "CLHEP/GenericFunctions/FunctionDifference.hh" 00177 #include "CLHEP/GenericFunctions/FunctionQuotient.hh" 00178 #include "CLHEP/GenericFunctions/FunctionConvolution.hh" 00179 #include "CLHEP/GenericFunctions/FunctionNegation.hh" 00180 #include "CLHEP/GenericFunctions/FunctionDirectProduct.hh" 00181 #include "CLHEP/GenericFunctions/FunctionComposition.hh" 00182 #include "CLHEP/GenericFunctions/ConstPlusFunction.hh" 00183 #include "CLHEP/GenericFunctions/ConstTimesFunction.hh" 00184 #include "CLHEP/GenericFunctions/ConstMinusFunction.hh" 00185 #include "CLHEP/GenericFunctions/ConstOverFunction.hh" 00186 #include "CLHEP/GenericFunctions/FunctionPlusParameter.hh" 00187 #include "CLHEP/GenericFunctions/FunctionTimesParameter.hh" 00188 #include "CLHEP/GenericFunctions/FunctionNoop.hh" 00189 #include "CLHEP/GenericFunctions/ParameterComposition.hh" 00190 00191 #endif