Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef CONVOL_COEFF_FUNCTION_MODULE_H
0002 #define CONVOL_COEFF_FUNCTION_MODULE_H
0003 
0004 /**
0005  * @file ConvolCoeffFunctionModule.h
0006  * @author Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date July 22, 2015
0008  * @version 1.0
0009  */
0010 
0011 #include <ElementaryUtils/logger/CustomException.h>
0012 #include <ElementaryUtils/parameters/Parameters.h>
0013 #include <ElementaryUtils/string_utils/Formatter.h>
0014 #include <map>
0015 #include <string>
0016 #include <utility>
0017 
0018 #include "../../beans/automation/BaseObjectData.h"
0019 #include "../../beans/channel/ChannelType.h"
0020 #include "../../beans/gpd/GPDType.h"
0021 #include "../../beans/List.h"
0022 #include "../../ModuleObjectFactory.h"
0023 #include "../../Partons.h"
0024 #include "../../utils/type/PhysicalUnit.h"
0025 #include "../gpd/GPDModule.h"
0026 #include "../MathIntegratorModule.h"
0027 
0028 namespace PARTONS {
0029 
0030 /**
0031  * @class ConvolCoeffFunctionModule
0032  *
0033  * @brief Abstract class that provides a skeleton to implement a Convolution of Coefficient Function module.
0034  */
0035 template<typename KinematicType, typename ResultType>
0036 class ConvolCoeffFunctionModule: public ModuleObject,
0037         public MathIntegratorModule {
0038 
0039 public:
0040 
0041     /**
0042      * Destructor.
0043      */
0044     virtual ~ConvolCoeffFunctionModule() {
0045 
0046         if (m_pGPDModule != 0) {
0047             setGPDModule(0);
0048             m_pGPDModule = 0;
0049         }
0050     }
0051 
0052     virtual ConvolCoeffFunctionModule* clone() const = 0;
0053 
0054     virtual std::string toString() const {
0055         return ModuleObject::toString();
0056     }
0057 
0058     virtual void resolveObjectDependencies() {
0059         ModuleObject::resolveObjectDependencies();
0060     }
0061 
0062     virtual void run() {
0063         throw ElemUtils::CustomException("Thread", __func__,
0064                 "This must be implemented in daughter class");
0065     }
0066 
0067     virtual void configure(const ElemUtils::Parameters &parameters) {
0068 
0069         ModuleObject::configure(parameters);
0070         configureIntegrator(parameters);
0071     }
0072 
0073     virtual void prepareSubModules(
0074             const std::map<std::string, BaseObjectData>& subModulesData) {
0075 
0076         //run for mother
0077         ModuleObject::prepareSubModules(subModulesData);
0078 
0079         //iterator
0080         std::map<std::string, BaseObjectData>::const_iterator it;
0081 
0082         //check if GPD module dependent
0083         if (isGPDModuleDependent()) {
0084 
0085             //search for GPD module
0086             it = subModulesData.find(GPDModule::GPD_MODULE_CLASS_NAME);
0087 
0088             //check if there
0089             if (it != subModulesData.end()) {
0090 
0091                 //check if already set
0092                 if (m_pGPDModule != 0) {
0093 
0094                     setGPDModule(0);
0095                     m_pGPDModule = 0;
0096                 }
0097 
0098                 //set
0099                 if (m_pGPDModule == 0) {
0100 
0101                     m_pGPDModule =
0102                             Partons::getInstance()->getModuleObjectFactory()->newGPDModule(
0103                                     (it->second).getModuleClassName());
0104 
0105                     info(__func__,
0106                             ElemUtils::Formatter()
0107                                     << "Configured with GPDModule = "
0108                                     << m_pGPDModule->getClassName());
0109 
0110                     m_pGPDModule->configure((it->second).getParameters());
0111                     m_pGPDModule->prepareSubModules(
0112                             (it->second).getSubModules());
0113                 }
0114 
0115             } else {
0116 
0117                 //throw error
0118                 throw ElemUtils::CustomException(getClassName(), __func__,
0119                         ElemUtils::Formatter() << getClassName()
0120                                 << " is GPDModule dependent and you have not provided one");
0121             }
0122         }
0123     }
0124 
0125     /**
0126      * Computes the coefficient functions at given kinematics.
0127      * @param kinematic Kinematics.
0128      * @param gpdType Type of CCF to compute.
0129      * @return Complex result.
0130      */
0131     virtual ResultType compute(const KinematicType& kinematic,
0132             const List<GPDType>& gpdType) = 0;
0133 
0134     /**
0135      * Must be implemented in child class.
0136      * @return List of GPD/CCF types the child class can compute.
0137      */
0138     virtual List<GPDType> getListOfAvailableGPDTypeForComputation() const = 0;
0139 
0140     // ##### GETTERS & SETTERS #####
0141 
0142     /**
0143      * Get pointer to the underlying GPD module.
0144      */
0145     GPDModule* getGPDModule() const {
0146         return m_pGPDModule;
0147     }
0148 
0149     /**
0150      * Set pointer to the underlying GPD module.
0151      */
0152     void setGPDModule(GPDModule* gpdModule) {
0153 
0154         m_pModuleObjectFactory->updateModulePointerReference(m_pGPDModule,
0155                 gpdModule);
0156         m_pGPDModule = gpdModule;
0157     }
0158 
0159     /**
0160      * True if this CCF module depends on a GPD module.
0161      */
0162     bool isGPDModuleDependent() const {
0163         return m_isGPDModuleDependent;
0164     }
0165 
0166     /**
0167      * True if this CCF module depends on a GPD module.
0168      */
0169     void setIsGPDModuleDependent(bool isGPDModuleDependent) {
0170         m_isGPDModuleDependent = isGPDModuleDependent;
0171     }
0172 
0173 protected:
0174 
0175     /**
0176      * Constructor.
0177      * See BaseObject::BaseObject and ModuleObject::ModuleObject for more details.
0178      *
0179      * @param className name of child class.
0180      * @param channelType Channel type.
0181      */
0182     ConvolCoeffFunctionModule(const std::string &className,
0183             ChannelType::Type channelType) :
0184             ModuleObject(className, channelType), MathIntegratorModule(), m_xi(
0185                     0.), m_t(0.), m_MuF2(0.), m_MuR2(0.), m_currentGPDComputeType(
0186                     GPDType::UNDEFINED), m_pGPDModule(0), m_isGPDModuleDependent(
0187                     true) {
0188     }
0189 
0190     /**
0191      * Copy constructor.
0192      * @param other Object to be copied.
0193      */
0194     ConvolCoeffFunctionModule(const ConvolCoeffFunctionModule &other) :
0195             ModuleObject(other), MathIntegratorModule(other), m_xi(other.m_xi), m_t(
0196                     other.m_t), m_MuF2(other.m_MuF2), m_MuR2(other.m_MuR2), m_currentGPDComputeType(
0197                     other.m_currentGPDComputeType), m_pGPDModule(0), m_isGPDModuleDependent(
0198                     other.m_isGPDModuleDependent) {
0199 
0200         if (other.m_pGPDModule != 0) {
0201             m_pGPDModule = m_pModuleObjectFactory->cloneModuleObject(
0202                     other.m_pGPDModule);
0203         }
0204     }
0205 
0206     /**
0207      * Set internal kinematics.
0208      * @param kinematic Kinematics to be set.
0209      */
0210     virtual void setKinematics(const KinematicType& kinematic) {
0211 
0212         m_xi = kinematic.getXi().makeSameUnitAs(PhysicalUnit::NONE).getValue();
0213         m_t = kinematic.getT().makeSameUnitAs(PhysicalUnit::GEV2).getValue();
0214         m_MuF2 =
0215                 kinematic.getMuF2().makeSameUnitAs(PhysicalUnit::GEV2).getValue();
0216         m_MuR2 =
0217                 kinematic.getMuR2().makeSameUnitAs(PhysicalUnit::GEV2).getValue();
0218     }
0219 
0220     /**
0221      * Set current GPD type to be computed.
0222      */
0223     void setCurrentGPDType(GPDType::Type gpdType) {
0224         m_currentGPDComputeType = gpdType;
0225     }
0226 
0227     virtual void initModule() {
0228     }
0229 
0230     virtual void isModuleWellConfigured() {
0231 
0232         if (m_xi < 0. || m_xi > 1.) {
0233             warn(__func__,
0234                     ElemUtils::Formatter() << "Input value of Xi = " << m_xi
0235                             << " do not lay between 0 and 1.");
0236         }
0237 
0238         if (m_t > 0) {
0239             warn(__func__,
0240                     ElemUtils::Formatter() << " Input value of t = " << m_t
0241                             << " is not <= 0.");
0242         }
0243 
0244         if (m_MuF2 < 0) {
0245             warn(__func__,
0246                     ElemUtils::Formatter() << "Input value of muF2 = " << m_MuF2
0247                             << " is not > 0.");
0248         }
0249 
0250         if (m_MuR2 < 0) {
0251             warn(__func__,
0252                     ElemUtils::Formatter() << "Input value of muR2 = " << m_MuR2
0253                             << " is not > 0.");
0254         }
0255 
0256         if (isGPDModuleDependent() && m_pGPDModule == 0) {
0257             throw ElemUtils::CustomException(this->getClassName(), __func__,
0258                     "m_pGPDModule is NULL");
0259         }
0260     }
0261 
0262     /**
0263      * ConvolCoeffFunctionResult to std::vector<double> (used by test()).
0264      */
0265     void convolCoeffFunctionResultToStdVector(const ResultType& r, std::vector<double>& v) const {
0266 
0267         std::vector<GPDType> gpds = r.listGPDTypeComputed();
0268 
0269         for (std::vector<GPDType>::const_iterator it = gpds.begin(); it != gpds.end(); it++) {
0270 
0271             const std::complex<double>& e = r.getResult(*it);
0272 
0273             v.push_back(e.real());
0274             v.push_back(e.imag());
0275         }
0276     }
0277 
0278     double m_xi; ///< Skewness.
0279     double m_t; ///< Mandelstam variable, momentum transfer on the hadron target (in GeV^2).
0280     double m_MuF2; ///< Factorization scale (in GeV^2).
0281     double m_MuR2; ///< Renormalization scale (in GeV^2)
0282 
0283     GPDType::Type m_currentGPDComputeType; ///< GPDType of the current CFF computation.
0284 
0285     GPDModule* m_pGPDModule; ///< Pointer to the underlying GPD module.
0286 
0287     bool m_isGPDModuleDependent; ///< Boolean (true if this CCF module depends on a GPD module).
0288 };
0289 
0290 } /* namespace PARTONS */
0291 
0292 #endif /* CONVOL_COEFF_FUNCTION_MODULE_H */