Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 // $Id: AbsFunction.hh,v 1.3 2007/01/21 20:20:40 boudreau Exp $
0003 //------------------------AbsFunction-----------------------------------//
0004 //                                                                      //
0005 //  AbsFunction, base class for function objects                        //
0006 //  Joe Boudreau, Petar Maksimovic                                      //
0007 //  Nov 1999                                                            //
0008 //                                                                      //
0009 //----------------------------------------------------------------------//
0010 #ifndef AbsFunction_h
0011 #define AbsFunction_h 1
0012 #include "CLHEP/GenericFunctions/Argument.hh"
0013 
0014 namespace Genfun {
0015 
0016   class AbsParameter;
0017 
0018   //-----------------------------------------------------------------------//
0019   // Exact return type of arithmentic operations.  To the user, the return //
0020   // type is GENFUNCTION, or const AbsFunction &.                          //
0021   //-----------------------------------------------------------------------//
0022 
0023   class FunctionProduct;
0024   class FunctionSum;
0025   class FunctionDifference;
0026   class FunctionQuotient;
0027   class FunctionNegation;
0028   class FunctionConvolution;
0029   class FunctionDirectProduct;
0030   class FunctionComposition;
0031   class ConstPlusFunction;
0032   class ConstTimesFunction;
0033   class ConstMinusFunction;
0034   class ConstOverFunction;
0035   class FunctionPlusParameter;
0036   class FunctionTimesParameter;
0037   class FunctionNumDeriv;
0038   class Variable;
0039   class FunctionNoop;
0040   class ParameterComposition;
0041 
0042   typedef FunctionNoop Derivative;
0043 
0044   /**
0045    * @author
0046    * @ingroup genfun
0047    */
0048   class AbsFunction {
0049   
0050   public:
0051   
0052     // Default Constructor
0053     AbsFunction();
0054   
0055     // Copy Constructor:
0056     AbsFunction(const AbsFunction &right);
0057   
0058     // Destructor
0059     virtual ~AbsFunction();
0060   
0061     // Function value:  N-dimensional functions must override these:
0062     virtual unsigned int dimensionality() const;      // returns 1;
0063 
0064     // Function value
0065     virtual double operator() (double argument)          const=0;   
0066     virtual double operator() (const Argument &argument) const=0; 
0067 
0068     // Every function must override this:
0069     virtual AbsFunction * clone() const=0;
0070   
0071     // Function composition.  Do not attempt to override:
0072     virtual FunctionComposition operator () (const AbsFunction &f) const;
0073     
0074     // Parameter composition.  Do not attempt to override:
0075     virtual ParameterComposition operator() ( const AbsParameter &p) const;
0076 
0077     // Derivative, (All functions)  (do not override)
0078     Derivative derivative(const Variable &v) const;
0079 
0080     // Derivative (1D functions only) (do not override)
0081     Derivative prime() const;
0082 
0083     // Does this function have an analytic derivative?
0084     virtual bool hasAnalyticDerivative() const {return false;}
0085 
0086     // Derivative.  Overriders may be provided, numerical method by default!
0087     virtual Derivative partial(unsigned int) const;
0088   
0089   private:
0090 
0091     // It is illegal to assign a function.
0092     const AbsFunction & operator=(const AbsFunction &right);
0093   
0094   };
0095 
0096 FunctionProduct           operator * (const AbsFunction &op1, const AbsFunction &op2);
0097 FunctionSum               operator + (const AbsFunction &op1, const AbsFunction &op2);
0098 FunctionDifference        operator - (const AbsFunction &op1, const AbsFunction &op2);
0099 FunctionQuotient          operator / (const AbsFunction &op1, const AbsFunction &op2);
0100 FunctionNegation          operator - (const AbsFunction &op1);
0101 
0102 ConstTimesFunction        operator * (double c, const AbsFunction &op2);
0103 ConstPlusFunction         operator + (double c, const AbsFunction &op2);
0104 ConstMinusFunction        operator - (double c, const AbsFunction &op2);
0105 ConstOverFunction         operator / (double c, const AbsFunction &op2);
0106 
0107 ConstTimesFunction        operator * (const AbsFunction &op2, double c);
0108 ConstPlusFunction         operator + (const AbsFunction &op2, double c);
0109 ConstPlusFunction         operator - (const AbsFunction &op2, double c);
0110 ConstTimesFunction        operator / (const AbsFunction &op2, double c);
0111 
0112 FunctionTimesParameter    operator * (const AbsFunction &op1, const AbsParameter &op2);
0113 FunctionPlusParameter     operator + (const AbsFunction &op1, const AbsParameter &op2);
0114 FunctionPlusParameter     operator - (const AbsFunction &op1, const AbsParameter &op2);
0115 FunctionTimesParameter    operator / (const AbsFunction &op1, const AbsParameter &op2);
0116 
0117 FunctionTimesParameter    operator * (const AbsParameter   &op1, const AbsFunction &op2);
0118 FunctionPlusParameter     operator + (const AbsParameter   &op1, const AbsFunction &op2);
0119 FunctionPlusParameter     operator - (const AbsParameter   &op1, const AbsFunction &op2);
0120 FunctionTimesParameter    operator / (const AbsParameter   &op1, const AbsFunction &op2);
0121 
0122 FunctionConvolution       convolve   (const AbsFunction &op1, const AbsFunction &op2, double x0, double x1);
0123 FunctionDirectProduct     operator % (const AbsFunction &op1, const AbsFunction &op2);
0124 
0125 typedef const AbsFunction & GENFUNCTION;
0126 
0127 } // namespace Genfun
0128 
0129 
0130 //----------------------------------------------------------------------------
0131 //
0132 // These macros do all the ugly boilerplate.  
0133 //
0134 //----------------------------------------------------------------------------
0135 
0136 
0137 
0138 
0139 
0140 
0141 // A more modern way to accomplish this, which is slicker:
0142 
0143 #define FUNCTION_OBJECT_DEF(classname) \
0144 public:                                \
0145  using Genfun::AbsFunction::operator();         \
0146  virtual classname *clone() const override;     \
0147 private:                               
0148 
0149 #define FUNCTION_OBJECT_IMP(classname)       \
0150 inline classname *classname::clone() const          \
0151 {                                            \
0152   return new classname(*this);               \
0153 }
0154 
0155 
0156 //----------------------------------------------------------------------------
0157 
0158 
0159 #include "CLHEP/GenericFunctions/FunctionProduct.hh"
0160 #include "CLHEP/GenericFunctions/FunctionSum.hh"
0161 #include "CLHEP/GenericFunctions/FunctionDifference.hh"
0162 #include "CLHEP/GenericFunctions/FunctionQuotient.hh"
0163 #include "CLHEP/GenericFunctions/FunctionConvolution.hh"
0164 #include "CLHEP/GenericFunctions/FunctionNegation.hh"
0165 #include "CLHEP/GenericFunctions/FunctionDirectProduct.hh"
0166 #include "CLHEP/GenericFunctions/FunctionComposition.hh"
0167 #include "CLHEP/GenericFunctions/ConstPlusFunction.hh"
0168 #include "CLHEP/GenericFunctions/ConstTimesFunction.hh"
0169 #include "CLHEP/GenericFunctions/ConstMinusFunction.hh"
0170 #include "CLHEP/GenericFunctions/ConstOverFunction.hh"
0171 #include "CLHEP/GenericFunctions/FunctionPlusParameter.hh"
0172 #include "CLHEP/GenericFunctions/FunctionTimesParameter.hh"
0173 #include "CLHEP/GenericFunctions/FunctionNoop.hh"
0174 #include "CLHEP/GenericFunctions/ParameterComposition.hh"
0175 
0176 #endif