Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:51:42

0001 #ifndef CONVOL_COEFF_FUNCTION_RESULT_H
0002 #define CONVOL_COEFF_FUNCTION_RESULT_H
0003 
0004 /**
0005  * @file ConvolCoeffFunctionResult.h
0006  * @author Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date 22 July 2015
0008  * @version 1.0
0009  */
0010 
0011 #include <ElementaryUtils/logger/CustomException.h>
0012 #include <ElementaryUtils/string_utils/Formatter.h>
0013 #include <ElementaryUtils/string_utils/StringUtils.h>
0014 #include <complex>
0015 #include <map>
0016 #include <string>
0017 #include <utility>
0018 #include <vector>
0019 
0020 #include "../channel/ChannelType.h"
0021 #include "../gpd/GPDType.h"
0022 #include "../Result.h"
0023 
0024 namespace PARTONS {
0025 
0026 /**
0027  * @class ConvolCoeffFunctionResult
0028  *
0029  * @brief Abstract class representing a single result of CCF computation.
0030  *
0031  * This abstract class is used to store results of a single CCF computation.
0032  */
0033 template<typename KinematicType>
0034 class ConvolCoeffFunctionResult: public Result<KinematicType> {
0035 
0036 public:
0037 
0038     /**
0039      * Destructor.
0040      */
0041     virtual ~ConvolCoeffFunctionResult() {
0042     }
0043 
0044     virtual std::string toString() const {
0045 
0046         ElemUtils::Formatter formatter;
0047 
0048         formatter << "\n" << Result<KinematicType>::toString() << "\n\n";
0049         formatter << "Result: " << '\n';
0050 
0051         std::map<GPDType::Type, std::complex<double> >::const_iterator it;
0052 
0053         for (it = m_resultsByGPDType.begin(); it != m_resultsByGPDType.end();
0054                 it++) {
0055             formatter << "CFF " << GPDType(it->first).toString() << ": Re: "
0056                     << (it->second).real() << " Im: " << (it->second).imag()
0057                     << '\n';
0058         }
0059 
0060         return formatter.str();
0061     }
0062 
0063     /**
0064      * Add result for given GPD type.
0065      * @param gpdComputeType GPD type associated to given result.
0066      * @param result Result to be added.
0067      */
0068     void addResult(GPDType::Type gpdType, const std::complex<double>& result) {
0069 
0070         //get iterator
0071         std::map<GPDType::Type, std::complex<double> >::const_iterator it =
0072                 m_resultsByGPDType.find(gpdType);
0073 
0074         //throw exception
0075         if (it != m_resultsByGPDType.end()) {
0076             throw ElemUtils::CustomException(this->getClassName(), __func__,
0077                     ElemUtils::Formatter() << "Result for GPDType = "
0078                             << GPDType(gpdType).toString() << " exists");
0079         }
0080 
0081         //insert
0082         m_resultsByGPDType.insert(std::make_pair(gpdType, result));
0083     }
0084 
0085     /**
0086      * Get reference to result for given GPD type.
0087      * @param gpdType GPD type associated to requested result.
0088      * @return Reference to requested result.
0089      */
0090     const std::complex<double>& getResult(GPDType::Type gpdType) const {
0091 
0092         //get iterator
0093         std::map<GPDType::Type, std::complex<double> >::const_iterator it =
0094                 m_resultsByGPDType.find(gpdType);
0095 
0096         //throw exception
0097         if (it == m_resultsByGPDType.end()) {
0098             throw ElemUtils::CustomException(this->getClassName(), __func__,
0099                     ElemUtils::Formatter()
0100                             << "Cannot find result for GPDType = "
0101                             << GPDType(gpdType).toString());
0102         }
0103 
0104         //return
0105         return (it->second);
0106     }
0107 
0108     /**
0109      * Check if the object stores result associated to given GPD type.
0110      * @param gpdType GPD type to be checked.
0111      * @return True if the object stores result associated to given GPD type, otherwise false.
0112      * @see ConvolCoeffFunctionResult::getLastAvailable()
0113      */
0114     bool isAvailable(GPDType::Type gpdType) {
0115 
0116         //get iterator
0117         m_it = m_resultsByGPDType.find(gpdType);
0118 
0119         //return
0120         return (m_it != m_resultsByGPDType.end());
0121     }
0122 
0123     /**
0124      * Get reference to result marked by the last call of ConvolCoeffFunctionResult::isAvailible() function.
0125      * @return Reference to selected result.
0126      * @see ConvolCoeffFunctionResult::isAvailible()
0127      */
0128     std::complex<double> getLastAvailable() const {
0129         return m_it->second;
0130     }
0131 
0132     /**
0133      * Get list of GPD types associated to stored parton distributions.
0134      * @return Vector of associated types.
0135      */
0136     std::vector<GPDType> listGPDTypeComputed() const {
0137 
0138         //result
0139         std::vector<GPDType> list;
0140 
0141         //iterator
0142         std::map<GPDType::Type, std::complex<double> >::const_iterator it;
0143 
0144         //fill vector
0145         if (m_resultsByGPDType.size() != 0) {
0146 
0147             for (it = m_resultsByGPDType.begin();
0148                     it != m_resultsByGPDType.end(); ++it) {
0149                 list.push_back(it->first);
0150             }
0151         }
0152 
0153         //return
0154         return list;
0155     }
0156 
0157     //********************************************************
0158     //*** SETTERS AND GETTERS ********************************
0159     //********************************************************
0160 
0161     /**
0162      * Get reference to map containing stored results distinguished by associated GPD types.
0163      */
0164     const std::map<GPDType::Type, std::complex<double> >& getResultsByGpdType() const {
0165         return m_resultsByGPDType;
0166     }
0167 
0168     /**
0169      * Set map containing stored results distinguished by associated GPD types.
0170      */
0171     void setResultsByGpdType(
0172             const std::map<GPDType::Type, std::complex<double> >& resultsByGpdType) {
0173         m_resultsByGPDType = resultsByGpdType;
0174     }
0175 
0176 protected:
0177 
0178     /**
0179      * Default constructor.
0180      */
0181     ConvolCoeffFunctionResult(const std::string &className,
0182             ChannelType::Type channelType) :
0183             Result<KinematicType>(className, channelType) {
0184     }
0185 
0186     /**
0187      * Assignment constructor.
0188      * @param kinematic CCF kinematics to be assigned.
0189      */
0190     ConvolCoeffFunctionResult(const std::string &className,
0191             ChannelType::Type channelType, const KinematicType& kinematic) :
0192             Result<KinematicType>(className, channelType, kinematic) {
0193     }
0194 
0195     /**
0196      * Copy constructor.
0197      * @param other Object to be copied.
0198      */
0199     ConvolCoeffFunctionResult(const ConvolCoeffFunctionResult& other) :
0200             Result<KinematicType>(other) {
0201         m_resultsByGPDType = other.m_resultsByGPDType;
0202     }
0203 
0204     /**
0205      * Map containing stored results distinguished by associated GPD types.
0206      */
0207     std::map<GPDType::Type, std::complex<double> > m_resultsByGPDType;
0208 
0209     /**
0210      * Iterator used to mark a specific entry in ConvolCoeffFunctionResult::m_resultsByGPDType.
0211      */
0212     std::map<GPDType::Type, std::complex<double> >::const_iterator m_it;
0213 };
0214 
0215 } /* namespace PARTONS */
0216 
0217 #endif /* CONVOL_COEFF_FUNCTION_RESULT_H */