Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:28

0001 // -*- C++ -*-
0002 //
0003 // GSLIntegrator.h is a part of Herwig - A multi-purpose Monte Carlo event generator
0004 // Copyright (C) 2002-2019 The Herwig Collaboration
0005 //
0006 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef HERWIG_GSLIntegrator_H
0010 #define HERWIG_GSLIntegrator_H
0011 //
0012 // This is the declaration of the GSLIntegrator class.
0013 //
0014 
0015 #include "ThePEG/Pointer/ReferenceCounted.h"
0016 #include "ThePEG/Repository/CurrentGenerator.h"
0017 #include "gsl/gsl_integration.h"
0018 #include "gsl/gsl_errno.h"
0019 
0020 namespace Herwig {
0021 
0022 using namespace ThePEG;
0023 
0024 /** \ingroup Utilities
0025  * This class is designed to integrate a given function between
0026  * 2 limits using the gsl QAGS integration subroutine.
0027  * 
0028  * The function is supplied using a templated class that must define
0029  * operator(argument). The units of the argument ArgType and return 
0030  * type ValType must be supplied in the integrand class using a typedef
0031  * i.e. <br>
0032  * <code> struct integrand { </code><br>
0033  * <code> ... </code> <BR>
0034  * <code>Energy operator(double arg) const;</code><BR>
0035  * <code>typedef double ArgType</code><BR>
0036  * <code>typedef Energy ValType</code><BR>
0037  * <code> ... </code> <BR>
0038  * <code>}</code> <BR>
0039  */
0040 class GSLIntegrator : public Pointer::ReferenceCounted {
0041 
0042 public:
0043 
0044   /** @name Standard constructors and destructors. */
0045   //@{
0046   /**
0047    * Default Constructor uses values in GSL manual as parameters
0048    **/
0049   GSLIntegrator() : _abserr(1.0E-35), _relerr(1.0E-3), _nbins(1000) {}
0050   
0051   /**
0052    * Specify all the parameters.
0053    * @param abserr Absolute error.
0054    * @param relerr Relative error.
0055    * @param nbins Number of bins
0056    */
0057   GSLIntegrator(double abserr, double relerr, int nbins) :
0058     _abserr(abserr), _relerr(relerr), _nbins(nbins) {}
0059   //@}
0060 
0061   /// helper type for the integration result
0062   template <class T>
0063   using ValT = decltype(std::declval<typename T::ValType>() 
0064                       * std::declval<typename T::ArgType>());
0065 
0066   /**
0067    * The value of the integral
0068    * @param function The integrand class that defines operator()
0069    * @param lower The lower limit of integration.
0070    * @param upper The upper limit of integration.
0071    */
0072   template <class T>
0073   inline ValT<T>
0074   value(const T & function, 
0075     const typename T::ArgType lower,
0076     const typename T::ArgType upper) const;
0077 
0078   /**
0079    * The value of the integral
0080    * @param function The integrand class that defines operator()
0081    * @param lower The lower limit of integration.
0082    * @param upper The upper limit of integration.
0083    * @param error Returns the estimated error of the integral
0084    */
0085   template <class T>
0086   inline ValT<T>
0087   value(const T & function, 
0088     const typename T::ArgType lower,
0089     const typename T::ArgType upper,
0090     ValT<T> & error) const;
0091 
0092 private:
0093 
0094   /**
0095    * The assignment operator is private and must never be called.
0096    * In fact, it should not even be implemented.
0097    */
0098   GSLIntegrator & operator=(const GSLIntegrator &) = delete;
0099 
0100 private:
0101 
0102   /**
0103    * The parameters controlling the absolute error.
0104    */
0105   double _abserr;
0106 
0107   /**
0108    * The parameters controlling the relative error.
0109    */
0110   double _relerr;
0111 
0112   /**
0113    * The maximum number of intervals to use.
0114    */
0115   int _nbins;
0116 };
0117 
0118 }
0119 
0120 #include "GSLIntegrator.tcc"
0121 
0122 #endif /* HERWIG_GSLIntegrator_H */