Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:17:14

0001 //
0002 // APFEL++ 2017
0003 //
0004 // Author: Valerio Bertone: valerio.bertone@cern.ch
0005 //
0006 
0007 #pragma once
0008 
0009 #include "apfel/convolutionmap.h"
0010 #include "apfel/distribution.h"
0011 
0012 #include <functional>
0013 
0014 namespace apfel
0015 {
0016   /**
0017    * @brief The Set template class allocates a collection of objects
0018    * of type T along the ConvolutionMap and provides the methods to
0019    * perform operations between different types of objects T.
0020    */
0021   template<class T>
0022   class Set
0023   {
0024   public:
0025     /**
0026      * @brief The Set constructor.
0027      * @param Map: the convolution map (defualt: empty ConvolutionMap)
0028      * @param in: a map of objects of type T (defualt: empty map of objects)
0029      */
0030     Set(ConvolutionMap const& Map = ConvolutionMap{"UNDEFINED"}, std::map<int, T> const& in = std::map<int, T> {});
0031 
0032     /**
0033      * @brief The Set constructor.
0034      * @param in: a map of objects of type T (defualt: empty map of objects)
0035      * @note When invoking this constructor a diagonal convolution map
0036      * is automatically constructed.
0037      */
0038     Set(std::map<int, T> const& in);
0039 
0040     /**
0041      * @name Binary operators
0042      */
0043     ///@{
0044     /**
0045      * @brief operator *= product object
0046      * @param d: the left hand side object of type V
0047      * @return a new object of type V
0048      */
0049     template<class V> Set<V> operator *= (Set<V> const& d) const;
0050 
0051     Set<T>& operator *= (double const& s);                                      //!< this *= scalar
0052     Set<T>& operator *= (std::function<double(double const&)> f);               //!< this *= function of the integration variable (for distributions only)
0053     Set<T>& operator *= (std::function<std::vector<double>(double const&)> f);  //!< this *= function of the integration variable that returns a vector (for distributions only)
0054     Set<T>& operator *= (std::vector<double> const& v);                         //!< this *= vector of scalars
0055     Set<T>& operator *= (std::map<int, double> const& v);                       //!< this *= map of scalars
0056     Set<T>& operator /= (double const& s);                                      //!< this /= scalar
0057     Set<T>& operator += (Set<T> const& d);                                      //!< this += Set
0058     Set<T>& operator -= (Set<T> const& d);                                      //!< this -= Set
0059     ///@}
0060 
0061     /**
0062      * @name Getters
0063      */
0064     ///@{
0065     /**
0066      * @brief This returns object with ID "id" in the map.
0067      * @param id: objects ID
0068      */
0069     T const& at(int const& id) const { return _objects.at(id); }
0070     /**
0071      * @brief This returns the convolution map.
0072      */
0073     ConvolutionMap const& GetMap() const { return _map; }
0074     /**
0075      * @brief This returns the full map of objects.
0076      */
0077     std::map<int, T> const& GetObjects() const { return _objects; }
0078     ///@}
0079 
0080     /**
0081      * @brief This function (re)sets the convolution map.
0082      */
0083     void SetMap(ConvolutionMap const& map) { _map = map; }
0084 
0085     /**
0086      * @brief This function (re)sets the map of objects.
0087      * @param objects: set of objects
0088      */
0089     void SetObjects(std::map<int, T> const& objects) { _objects = objects; }
0090 
0091     /**
0092      * @brief This function sums up all the objects of the set into
0093      * one.
0094      */
0095     T Combine() const;
0096 
0097     /**
0098      * @brief This function sums up all the objects of the set into
0099      * one using the components of input vector as weights.
0100      * @param weigths: set of weights
0101      */
0102     T Combine(std::vector<double> const& weigths) const;
0103 
0104     /**
0105      * @brief This function trasforms the set of objects (only
0106      * Distributions) given a set of functions, one for each
0107      * distribution in the set. This function is diagonal in the sense
0108      * that each transforming function can only transform one single
0109      * distribution.
0110      * @param TranformationFuncs: set of transformation functions
0111      */
0112     Set<T> Transform(std::map<int, std::function<double(double const&)>> const& TranformationFuncs) const;
0113 
0114     /**
0115      * @brief This function trasforms the set of objects (only
0116      * Distributions) given a set of functions, one for each
0117      * distribution in the set. This function is not diagonal in the
0118      * sense that different distributions can mix upon transformation.
0119      * @param TranformationFuncs: set of transformation functions
0120      */
0121     Set<T> Transform(std::map<int, std::map<int, std::function<double(double const&)>>> const& TranformationFuncs) const;
0122 
0123     /**
0124      * @brief This function trasforms the set of objects (only
0125      * Distributions) given a set of functions, one for each
0126      * distribution in the set. This function is not diagonal in the
0127      * sense that different distributions can mix upon transformation.
0128      * @param TranformationFuncs: set of transformation functions
0129      */
0130     Set<T> Transform(std::map<int, std::function<double(std::map<int, double> const&)>> const& TranformationFuncs) const;
0131 
0132 
0133     /**
0134      * @brief This function interpolates the single objects of the set
0135      * (only Operators) over the first index and returns a set of
0136      * Distributions.
0137      * @param x: value of the variable to be interpolated
0138      */
0139     Set<Distribution> Evaluate(double const& x) const;
0140 
0141     /**
0142      * @brief This function squashes the single objects of the set
0143      * (only Distributions) and returns a map of integers to doubles.
0144      */
0145     std::map<int, double> Squash() const;
0146 
0147     /**
0148      * @brief Print the Operator object
0149      */
0150     void Print() const { std::cout << *this << std::endl; }
0151 
0152   private:
0153     ConvolutionMap   _map;     //!< The shared pointer containing the convolution map
0154     std::map<int, T> _objects; //!< The container for the map
0155 
0156     template<class U>
0157     friend std::ostream& operator << (std::ostream& os, Set<U> const& s);
0158   };
0159 
0160   /**
0161    * @name Ternary operators
0162    */
0163   ///@{
0164   template<class A, class B>
0165   Set<B> operator * (Set<A> lhs, Set<B> const& rhs) { return lhs *= rhs; }
0166 
0167   // other operators
0168   template<class T>
0169   Set<T> operator * (double const& s, Set<T> rhs) { return rhs *= s; }
0170 
0171   template<class T>
0172   Set<T> operator * (Set<T> lhs, double const& s) { return lhs *= s; }
0173 
0174   template<class T>
0175   Set<T> operator * (std::function<double(double const&)> f, Set<T> rhs) { return rhs *= f; }
0176 
0177   template<class T>
0178   Set<T> operator * (std::function<std::vector<double>(double const&)> f, Set<T> rhs) { return rhs *= f; }
0179 
0180   template<class T>
0181   Set<T> operator * (Set<T> lhs, std::function<double(double const&)> f) { return lhs *= f; }
0182 
0183   template<class T>
0184   Set<T> operator * (std::vector<double> const& v, Set<T> rhs) { return rhs *= v; }
0185 
0186   template<class T>
0187   Set<T> operator * (Set<T> lhs, std::vector<double> const& v) { return lhs *= v; }
0188 
0189   template<class T>
0190   Set<T> operator * (std::map<int, double> const& v, Set<T> rhs) { return rhs *= v; }
0191 
0192   template<class T>
0193   Set<T> operator * (Set<T> lhs, std::map<int, double> const& v) { return lhs *= v; }
0194 
0195   template<class T>
0196   Set<T> operator / (Set<T> lhs, double const& s) { return lhs /= s; }
0197 
0198   template<class T>
0199   Set<T> operator * (Set<T> lhs, Set<T> const& rhs) { return lhs *= rhs; }
0200 
0201   template<class T>
0202   Set<T> operator + (Set<T> lhs, Set<T> const& rhs) { return lhs += rhs; }
0203 
0204   template<class T>
0205   Set<T> operator - (Set<T> lhs, Set<T> const& rhs) { return lhs -= rhs; }
0206   ///@}
0207 }