CLHEP/GenericFunctions/AbsFunction.hh

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

Class Library for High Energy Physics (version 1.8)