Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // APFEL++ 2017
0003 //
0004 // Author: Valerio Bertone: valerio.bertone@cern.ch
0005 //
0006 
0007 #pragma once
0008 
0009 #include "apfel/matrix.h"
0010 
0011 #include <map>
0012 #include <string>
0013 #include <iostream>
0014 
0015 namespace apfel
0016 {
0017   /**
0018    * @brief The ConvolutionMap class encapsulates the set of rules to
0019    * multiply a sets of operators with a set of distributions.
0020    */
0021   class ConvolutionMap
0022   {
0023   public:
0024     /**
0025      * @brief This structure contains the attribute of a single rule.
0026      */
0027     struct rule
0028     {
0029       int    operand;
0030       int    object;
0031       double coefficient;
0032       bool   operator == (rule const& r) const
0033       {
0034         if (r.operand     != operand)     return false;
0035         if (r.object      != object)      return false;
0036         if (r.coefficient != coefficient) return false;
0037         return true;
0038       }
0039       rule& operator *= (double const& s)
0040       {
0041         coefficient *= s;
0042         return *this;
0043       }
0044       rule& operator /= (double const& s)
0045       {
0046         coefficient /= s;
0047         return *this;
0048       }
0049     };
0050 
0051     /**
0052      * @brief ConvolutionMap constructor
0053      * @param name: name of the map
0054      */
0055     ConvolutionMap(std::string const& name);
0056 
0057     /**
0058      * @name Setters
0059      */
0060     ///@{
0061     /**
0062      * @brief Set the rule of the convolution map.
0063      * @param rules: the input set of rules
0064      */
0065     void SetRules(std::map<int, std::vector<rule>> const& rules)  { _rules = rules; }
0066     ///@}
0067 
0068     /**
0069      * @name Getters
0070      */
0071     ///@{
0072     /**
0073      * @brief Retrieve the name of the map.
0074      * @return The name of the map
0075      */
0076     std::string const& GetName() const { return _name; }
0077 
0078     /**
0079      * @brief Retrieve the full set of rules for the multiplications.
0080      * @return The multiplication rules
0081      */
0082     std::map<int, std::vector<rule>> const& GetRules() const { return _rules; }
0083 
0084     /**
0085      * @brief Retrieve the full set of rules for the multiplications
0086      * in the form of a matrix.
0087      */
0088     matrix<std::vector<double>> const GetRuleMatrix() const;
0089 
0090     /**
0091      * @brief Retrieve the operand indices of the full set of rules
0092      * for the multiplications in the form of a matrix. Elements set
0093      * to -1 correspond to empty slots.
0094      */
0095     matrix<std::vector<int>> const GetRuleIndices() const;
0096 
0097     /**
0098      * @brief Print the Operator object
0099      */
0100     void Print() const { std::cout << *this << std::endl; }
0101     ///@}
0102   protected:
0103     std::map<int, std::vector<rule>> _rules; //!< the map container
0104     std::string                      _name;  //!< the name of the derived class
0105 
0106     friend std::ostream& operator << (std::ostream& os, ConvolutionMap const& cm);
0107   };
0108 
0109   /**
0110    * @brief Method which prints ConvolutionMap with cout <<.
0111    */
0112   std::ostream& operator << (std::ostream& os, ConvolutionMap const& cm);
0113 
0114   /**
0115    * @name Ternary operators on ConvolutionMap::rule objects
0116    */
0117   ///@{
0118   ConvolutionMap::rule operator * (double const& s, ConvolutionMap::rule rhs);
0119   ConvolutionMap::rule operator * (ConvolutionMap::rule lhs, double const& s);
0120   ConvolutionMap::rule operator / (ConvolutionMap::rule lhs, double const& s);
0121   std::vector<ConvolutionMap::rule> operator + (std::vector<ConvolutionMap::rule> lhs, std::vector<ConvolutionMap::rule> rhs);
0122   std::vector<ConvolutionMap::rule> operator - (std::vector<ConvolutionMap::rule> lhs, std::vector<ConvolutionMap::rule> rhs);
0123   std::vector<ConvolutionMap::rule> operator * (double const& s, std::vector<ConvolutionMap::rule> lhs);
0124   std::vector<ConvolutionMap::rule> operator * (std::vector<ConvolutionMap::rule> lhs, double const& s);
0125   std::vector<ConvolutionMap::rule> operator / (std::vector<ConvolutionMap::rule> lhs, double const& s);
0126   ///@}
0127 }