Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef OBSERVABLE_H
0002 #define OBSERVABLE_H
0003 
0004 /**
0005  * @file Observable.h
0006  * @author Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date November 25, 2014
0008  * @version 1.0
0009  */
0010 
0011 #include <ElementaryUtils/logger/CustomException.h>
0012 #include <ElementaryUtils/parameters/Parameters.h>
0013 #include <stddef.h>
0014 #include <iterator>
0015 #include <map>
0016 #include <string>
0017 #include <vector>
0018 
0019 #include "../../beans/automation/BaseObjectData.h"
0020 #include "../../beans/channel/ChannelType.h"
0021 #include "../../beans/gpd/GPDType.h"
0022 #include "../../beans/List.h"
0023 #include "../../ModuleObject.h"
0024 #include "../../utils/type/PhysicalType.h"
0025 
0026 namespace PARTONS {
0027 
0028 /**
0029  * @class Observable
0030  *
0031  * @brief Abstract class that provides a skeleton to implement an Observable module.
0032  */
0033 template<typename KinematicType, typename ResultType>
0034 class Observable: public ModuleObject {
0035 
0036 public:
0037 
0038     /**
0039      * Destructor
0040      */
0041     virtual ~Observable() {
0042     }
0043 
0044     virtual Observable* clone() const = 0;
0045 
0046     virtual std::string toString() const {
0047         return ModuleObject::toString();
0048     }
0049 
0050     virtual void resolveObjectDependencies() {
0051         ModuleObject::resolveObjectDependencies();
0052     }
0053 
0054     virtual void run() {
0055         throw ElemUtils::CustomException(getClassName(), __func__,
0056                 "This must be implemented in daughter class");
0057     }
0058 
0059     virtual void configure(const ElemUtils::Parameters &parameters) {
0060         ModuleObject::configure(parameters);
0061     }
0062 
0063     virtual void prepareSubModules(
0064             const std::map<std::string, BaseObjectData>& subModulesData) {
0065         ModuleObject::prepareSubModules(subModulesData);
0066     }
0067 
0068     /**
0069      * Computes the observable at given kinematics.
0070      * @param kinematic Kinematics.
0071      * @param gpdType Type of GPDs to compute.
0072      * @return Result.
0073      */
0074     virtual ResultType compute(const KinematicType& kinematic,
0075             const List<GPDType> & gpdType = List<GPDType>()) = 0;
0076 
0077     /**
0078      * Must be implemented in child class.
0079      * @return List of GPD/CCF types the child class can compute.
0080      */
0081     virtual List<GPDType> getListOfAvailableGPDTypeForComputation() const = 0;
0082 
0083 protected:
0084 
0085     /**
0086      * Constructor.
0087      * See BaseObject::BaseObject and ModuleObject::ModuleObject for more details.
0088      *
0089      * @param className name of child class.
0090      * @param channelType Channel type.
0091      */
0092     Observable(const std::string &className, ChannelType::Type channelType) :
0093             ModuleObject(className, channelType) {
0094     }
0095 
0096     /**
0097      * Copy constructor.
0098      * @param other Object to be copied.
0099      */
0100     Observable(const Observable& other) :
0101             ModuleObject(other) {
0102     }
0103 
0104     virtual void initModule() {
0105     }
0106 
0107     virtual void isModuleWellConfigured() {
0108     }
0109 
0110     /**
0111      * Evaluate observable. To be implemented in a child class.
0112      */
0113     virtual PhysicalType<double> computeObservable(
0114             const KinematicType& kinematic, const List<GPDType>& gpdType) = 0;
0115 
0116     /**
0117      * Serialize kinematics and list of GPD types to std::vector<double>.
0118      */
0119     std::vector<double> serializeKinematicsAndGPDTypesIntoStdVector(
0120             const KinematicType& kin, const List<GPDType>& list) const {
0121 
0122         std::vector<double> result;
0123 
0124         kin.serializeIntoStdVector(result);
0125 
0126         for (size_t i = 0; i < list.size(); i++) {
0127             result.push_back(static_cast<double>(list[i].getType()));
0128         }
0129 
0130         return result;
0131     }
0132 
0133     /**
0134      * Unserialize kinematics and list of GPD types from std::vector<double>.
0135      */
0136     void unserializeKinematicsAndGPDTypesFromStdVector(
0137             const std::vector<double>& vec, KinematicType& kin,
0138             List<GPDType>& list) const {
0139 
0140         std::vector<double>::const_iterator it = vec.begin();
0141 
0142         kin.unserializeFromStdVector(it, vec.end());
0143 
0144         list.clear();
0145 
0146         for (; it != vec.end(); it++) {
0147             list.add(GPDType(static_cast<GPDType::Type>(*it)));
0148         }
0149     }
0150 
0151 };
0152 
0153 } /* namespace PARTONS */
0154 
0155 #endif /* OBSERVABLE_H */