Commit f8c95515 authored by Arkadiusz P. Trawinski's avatar Arkadiusz P. Trawinski
Browse files

Loading GPDModel in MellinMomentModule as subModule.

parent 4932b8fc
......@@ -36,7 +36,7 @@ class MellinMomentFromGPD: public MellinMomentModule, public MathIntegratorModul
public:
static const std::string MELLIN_MOMENT_MODULE_CLASS_NAME; ///< Type of the module in XML automation.
static const std::string MELLIN_MOMENT_MODULE_GPD_TYPE; ///< Parameter used in configure() or XML automation to set the type of the GPD to compute.
static const std::string MELLIN_MOMENT_MODULE_GPD_MODEL; ///< Parameter used in configure() or XML automation to set the type of the GPD to compute.
/**
* ID assigned by BaseObjectRegistry.
......@@ -50,11 +50,18 @@ public:
virtual MellinMomentFromGPD* clone() const;
void virtual configure(const ElemUtils::Parameters &parameters);
virtual void configure(const ElemUtils::Parameters &parameters);
virtual void prepareSubModules(
const std::map<std::string, BaseObjectData>& subModulesData);
GPDModule* getGPDModule() const;
void setGPDModule(GPDModule* pGPDModel);
virtual List<QuarkFlavor> getListOfAvailableQuarkFlavor(MellinMomentKinematic mKinematic, const GPDType &gpdType);
virtual List<GPDType> getListOfAvailableGPDType();
protected:
virtual void isModuleWellConfigured();
virtual void initModule();
......@@ -67,8 +74,6 @@ private:
virtual double compute(MellinMomentKinematic mKinematic);
double integrant(double x, std::vector<double> par);
virtual List<QuarkFlavor> getQuarkFlavorList(MellinMomentKinematic mKinematic, const GPDType &gpdType);
}
;
......
......@@ -34,7 +34,7 @@ class MellinMomentModule: public ModuleObject {
public:
static const std::string MELLIN_MOMENT_MODULE_CLASS_NAME; ///< Type of the module in XML automation.
static const std::string PARAMETER_NAME_MELLIN_MODEL_MODULE_N; ///< Index of the Mellin Model in XML automation.
static const std::string PARAMETER_NAME_MELLIN_MOMENT_MODULE_N; ///< Index of the Mellin Model in XML automation.
/**
......@@ -54,7 +54,7 @@ public:
virtual MellinMomentModule* clone() const = 0;
void configure(const ElemUtils::Parameters &parameters);
virtual void configure(const ElemUtils::Parameters &parameters);
/*
* @param n index of Mellin Moment.
......@@ -83,6 +83,10 @@ public:
int getN();
void setN(int n);
virtual List<QuarkFlavor> getListOfAvailableQuarkFlavor(MellinMomentKinematic mKinematic, const GPDType &gpdType) = 0;
virtual List<GPDType> getListOfAvailableGPDType() = 0;
protected:
virtual void isModuleWellConfigured();
virtual void initModule();
......@@ -93,7 +97,7 @@ protected:
QuarkFlavor m_flavor; ///< For witch quark flavor compute.
GPDType m_type; ///< Witch type of GPD compute.
virtual List<QuarkFlavor> getQuarkFlavorList(MellinMomentKinematic mKinematic, const GPDType &gpdType) = 0;
private:
virtual double compute(MellinMomentKinematic mKinematic) = 0;
......
......@@ -98,7 +98,7 @@ public:
* @param task Automation task.
* @return GPDModule pointer.
*/
GPDModule* newGPDModuleFromTask(const Task &task) const;
MellinMomentModule* newMellinMomentModuleFromTask(const Task &task) const;
// GPDModule* configureGPDModule(GPDModule* pGPDModule) const;
......@@ -118,14 +118,14 @@ public:
List<MellinMomentKinematic> newListOfKinematicFromTask(const Task &task) const;
private:
GPDModule* m_pGPDModule; ///< Pointer to the currently used GPD module.
//MellinMomentModule* m_pMellinModule; ///< Pointer to the currently used GPD module.
/**
* Method used in the automated interface to compute GPD.
* @param task Automated XML task.
* @return GPDResult object.
*/
MellinMomentResult computeMellinMomentTask(Task &task);
MellinMomentResult computeOneKinematicTask(Task &task);
/**
* Method used in the automated interface to compute GPDs for a list of kinematics.
* @param task Automated XML task.
......
......@@ -76,16 +76,16 @@ void computeSingleKinematicsForMellinMoment() {
formatter << pMoment->computeAll(mkinematic, PARTONS::GPDType::H).toString() << '\n';
// Retrieve Mellin Moment service
//PARTONS::MellinMomentService* pMellinService = static_cast<PARTONS::MellinMomentService*>(PARTONS::Partons::getInstance()->getServiceObjectRegistry()->get(PARTONS::MellinMomentService::classId));
PARTONS::MellinMomentService* pMellinService = static_cast<PARTONS::MellinMomentService*>(PARTONS::Partons::getInstance()->getServiceObjectRegistry()->get(PARTONS::MellinMomentService::classId));
// Run computation
PARTONS::List<PARTONS::GPDType> gpdTypeList;
//gpdTypeList.add(PARTONS::GPDType::H);
gpdTypeList.add(PARTONS::GPDType::E);
gpdTypeList.add(PARTONS::GPDType::Et);
gpdTypeList.add(PARTONS::GPDType::Ht);
//PARTONS::MellinMomentResult result = pMellinService->compute(mkinematic,pGPDModel,gpdTypeList);
gpdTypeList.add(PARTONS::GPDType::H);
//gpdTypeList.add(PARTONS::GPDType::E);
//gpdTypeList.add(PARTONS::GPDType::Et);
//gpdTypeList.add(PARTONS::GPDType::Ht);
//PARTONS::MellinMomentResult result = pMellinService->compute(mkinematic,pMoment,gpdTypeList);
// Print results
//PARTONS::Partons::getInstance()->getLoggerManager()->info("main", __func__, result.toString());
......
#include "../../include/mellin_moment/MellinMomentFromGPD.h"
#include <ElementaryUtils/logger/CustomException.h>
#include <ElementaryUtils/parameters/Parameters.h>
#include <ElementaryUtils/string_utils/Formatter.h>
#include <NumA/functor/one_dimension/Functor1D.h>
#include <NumA/integration/one_dimension/Integrator1D.h>
#include <NumA/integration/one_dimension/IntegratorType1D.h>
#include <partons/beans/automation/BaseObjectData.h>
#include <partons/beans/gpd/GPDKinematic.h>
#include <partons/beans/parton_distribution/GluonDistribution.h>
#include <partons/beans/parton_distribution/PartonDistribution.h>
#include <partons/beans/parton_distribution/QuarkDistribution.h>
#include <partons/BaseObjectRegistry.h>
#include <partons/ModuleObjectFactory.h>
#include <partons/Partons.h>
#include <cmath>
#include <map>
#include <string>
......@@ -23,8 +27,8 @@ const unsigned int MellinMomentFromGPD::classId =
const std::string MellinMomentFromGPD::MELLIN_MOMENT_MODULE_CLASS_NAME =
"MellinMomentFromGPD";
const std::string MellinMomentFromGPD::MELLIN_MOMENT_MODULE_GPD_TYPE =
"GPD_MODULE_GPD_TYPE";
const std::string MellinMomentFromGPD::MELLIN_MOMENT_MODULE_GPD_MODEL =
"GPD_MODULE_GPD_MODEL";
MellinMomentFromGPD::MellinMomentFromGPD(const std::string &className) :
MellinMomentModule(className) {
......@@ -32,19 +36,19 @@ MellinMomentFromGPD::MellinMomentFromGPD(const std::string &className) :
m_pint = NumA::Integrator1D::newIntegrationFunctor(this,
&MellinMomentFromGPD::integrant);
NumA::IntegratorType1D::Type integratorType = NumA::IntegratorType1D::DEXP;
setIntegrator(integratorType);
initModule();
}
MellinMomentFromGPD::MellinMomentFromGPD(const MellinMomentFromGPD& other) :
MellinMomentModule(other), MathIntegratorModule(other) {
m_pGPDModel = 0;
m_pGPDModel = other.m_pGPDModel;
m_pint = NumA::Integrator1D::newIntegrationFunctor(this,
&MellinMomentFromGPD::integrant);
initModule();
}
MellinMomentFromGPD* MellinMomentFromGPD::clone() const {
......@@ -52,10 +56,20 @@ MellinMomentFromGPD* MellinMomentFromGPD::clone() const {
}
void MellinMomentFromGPD::isModuleWellConfigured() {
debug(__func__, ElemUtils::Formatter() << "executed");
MellinMomentModule::isModuleWellConfigured();
if (m_pGPDModel == 0)
throw ElemUtils::CustomException(getClassName(), __func__,
ElemUtils::Formatter()
<< "GPDModule not provided.");
}
void MellinMomentFromGPD::initModule() {
debug(__func__, ElemUtils::Formatter() << "executed");
MellinMomentModule::initModule();
NumA::IntegratorType1D::Type integratorType = NumA::IntegratorType1D::DEXP;
setIntegrator(integratorType);
}
void MellinMomentFromGPD::configure(const ElemUtils::Parameters &parameters) {
......@@ -63,6 +77,39 @@ void MellinMomentFromGPD::configure(const ElemUtils::Parameters &parameters) {
MellinMomentModule::configure(parameters);
}
void MellinMomentFromGPD::prepareSubModules(
const std::map<std::string, BaseObjectData>& subModulesData)
{
ModuleObject::prepareSubModules(subModulesData);
std::map<std::string, BaseObjectData>::const_iterator it;
if (m_pGPDModel != 0) setGPDModule(0);
it = subModulesData.find(
GPDModule::GPD_MODULE_CLASS_NAME);
if (it != subModulesData.end()) {
m_pGPDModel = Partons::getInstance()->getModuleObjectFactory()->newGPDModule(
(it->second).getModuleClassName());
info(__func__,
ElemUtils::Formatter() << "GPD Module is set to: "
<< m_pGPDModel->getClassName());
m_pGPDModel->configure((it->second).getParameters());
m_pGPDModel->prepareSubModules(
(it->second).getSubModules());
} else
{
throw ElemUtils::CustomException(getClassName(), __func__,
ElemUtils::Formatter()
<< "GPDModule not provided.");
}
}
double MellinMomentFromGPD::compute(MellinMomentKinematic mKinematic) ///< Compute when everything is set.
{
std::vector<double> parameters;
......@@ -71,6 +118,8 @@ double MellinMomentFromGPD::compute(MellinMomentKinematic mKinematic) ///< Compu
parameters.push_back(mKinematic.getMuF2());
parameters.push_back(mKinematic.getMuR2());
isModuleWellConfigured();
return integrate(m_pint, -1.0, 1.0, parameters);
}
......@@ -91,24 +140,26 @@ double MellinMomentFromGPD::integrant(double x, std::vector<double> par) ///< In
}
}
List<QuarkFlavor> MellinMomentFromGPD::getQuarkFlavorList(
List<QuarkFlavor> MellinMomentFromGPD::getListOfAvailableQuarkFlavor(
MellinMomentKinematic mKinematic, const GPDType &gpdType) {
List<QuarkFlavor> result;
List<GPDType> gpdTypeList =
m_pGPDModel->getListOfAvailableGPDTypeForComputation();
List<GPDType> gpdTypeList = getListOfAvailableGPDType();
bool isGPDType = false;
for (unsigned int i = 0; i != gpdTypeList.size(); i++) {
if (gpdTypeList[i].getType() == gpdType.getType())
isGPDType = true;
}
if (isGPDType) {
GPDKinematic kinematic(1, mKinematic.getXi, mKinematic.getT,
mKinematic.getMuF2, mKinematic.getMuR2);
GPDKinematic kinematic(1., mKinematic.getXi(), mKinematic.getT(),
mKinematic.getMuF2(), mKinematic.getMuR2());
List<QuarkDistribution> list =
m_pGPDModel->compute(kinematic, gpdType).getListOfQuarkDistribution();
for (unsigned int i = 0; i != list.size(); i++) {
QuarkFlavor flavor = list[i].getQuarkFlavor();
result.add(flavor);
......@@ -118,6 +169,10 @@ List<QuarkFlavor> MellinMomentFromGPD::getQuarkFlavorList(
return result;
}
List<GPDType> MellinMomentFromGPD::getListOfAvailableGPDType(){
return m_pGPDModel -> getListOfAvailableGPDTypeForComputation();
}
GPDModule* MellinMomentFromGPD::getGPDModule() const {
return m_pGPDModel;
}
......@@ -126,14 +181,6 @@ void MellinMomentFromGPD::setGPDModule(GPDModule* pGPDModel) {
m_pModuleObjectFactory->updateModulePointerReference(m_pGPDModel,
pGPDModel);
m_pGPDModel = pGPDModel;
if (m_pGPDModel != 0) {
info(__func__,
ElemUtils::Formatter() << "GPD Module is set to : "
<< m_pGPDModel->getClassName());
} else {
info(__func__, "GPDModule is set to : 0");
}
}
} /* namespace PARTONS */
......@@ -17,12 +17,14 @@ namespace PARTONS {
const std::string MellinMomentModule::MELLIN_MOMENT_MODULE_CLASS_NAME =
"MellinMomentModule";
const std::string MellinMomentModule::PARAMETER_NAME_MELLIN_MODEL_MODULE_N = "MELLIN_INDEX_N";
const std::string MellinMomentModule::PARAMETER_NAME_MELLIN_MOMENT_MODULE_N = "MELLIN_INDEX_N";
MellinMomentModule::MellinMomentModule(const std::string &className) :
ModuleObject(className) {
m_n = 0;
m_gluon = false;
initModule();
}
MellinMomentModule::MellinMomentModule(const MellinMomentModule& other) :
......@@ -33,6 +35,8 @@ MellinMomentModule::MellinMomentModule(const MellinMomentModule& other) :
m_flavor = other.m_flavor;
m_type = other.m_type;
initModule();
}
MellinMomentModule::~MellinMomentModule(){
......@@ -48,12 +52,12 @@ void MellinMomentModule::initModule() {
void MellinMomentModule::configure(const ElemUtils::Parameters &parameters) {
if (parameters.isAvailable(MellinMomentModule::PARAMETER_NAME_MELLIN_MODEL_MODULE_N)) {
if (parameters.isAvailable(MellinMomentModule::PARAMETER_NAME_MELLIN_MOMENT_MODULE_N)) {
m_n = parameters.getLastAvailable().toDouble();
info(__func__,
ElemUtils::Formatter() << "Parameter "
<< MellinMomentModule::PARAMETER_NAME_MELLIN_MODEL_MODULE_N << " changed to "
<< MellinMomentModule::PARAMETER_NAME_MELLIN_MOMENT_MODULE_N << " changed to "
<< m_n);
}
}
......@@ -64,7 +68,7 @@ PartonValues MellinMomentModule::computeAll(MellinMomentKinematic mKinematic, GP
GluonValue gluon = computeGluonValue(mKinematic,mGPDtype);
result.setGluonValue(gluon);
List<QuarkFlavor> flavorList = getQuarkFlavorList(mKinematic, mGPDtype);
List<QuarkFlavor> flavorList = getListOfAvailableQuarkFlavor(mKinematic, mGPDtype);
for (unsigned int i = 0; i != flavorList.size(); i++) {
result.addQuarkValue(computeQuarkValue(mKinematic, mGPDtype,
......
......@@ -35,8 +35,7 @@ const unsigned int MellinMomentService::classId =
new MellinMomentService("MellinMomentService"));
MellinMomentService::MellinMomentService(const std::string &className) :
ServiceObjectTyped<MellinMomentKinematic, MellinMomentResult>(
className), m_pGPDModule(0) {
ServiceObjectTyped<MellinMomentKinematic, MellinMomentResult>(className) {
}
MellinMomentService::~MellinMomentService() {
......@@ -58,7 +57,7 @@ MellinMomentResult MellinMomentService::compute(const MellinMomentKinematic &kin
MellinMomentResult result;
List<GPDType> restrictedByGPDTypeListFinal; // = getFinalGPDTypeList(pGPDModule,gpdTypeList);
List<GPDType> restrictedByGPDTypeListFinal = getFinalGPDTypeList(pMellinMoment,gpdTypeList);
for (unsigned int i = 0; i != restrictedByGPDTypeListFinal.size(); i++) {
PartonValues values = pMellinMoment->computeAll(kinematic, restrictedByGPDTypeListFinal[i]);
......@@ -68,12 +67,6 @@ MellinMomentResult MellinMomentService::compute(const MellinMomentKinematic &kin
result.setKinematic(kinematic);
result.setComputationModuleName(pMellinMoment->getClassName());
// Remove pointer references
// Module pointers are managed by PARTONS
PARTONS::Partons::getInstance()->getModuleObjectFactory()->updateModulePointerReference(
pMellinMoment, 0);
pMellinMoment = 0;
return result;
}
......@@ -91,7 +84,7 @@ List<MellinMomentResult> MellinMomentService::computeManyKinematic(
List<MellinMomentResult> results;
List<ElemUtils::Packet> listOfPacket;
List<GPDType> finalGPDTypeList;// = getFinalGPDTypeList(pGPDModule,gpdTypeList);
List<GPDType> finalGPDTypeList = getFinalGPDTypeList(pMellinModule,gpdTypeList);
if (finalGPDTypeList.size() == 0) {
info(__func__,
......@@ -153,10 +146,45 @@ List<MellinMomentResult> MellinMomentService::computeManyKinematic(
return results;
}
MellinMomentResult MellinMomentService::computeMellinMomentTask(Task& task) {
void MellinMomentService::computeTask(Task &task) {
debug(__func__, "Processing ...");
ServiceObjectTyped<MellinMomentKinematic, MellinMomentResult>::computeTask(task);
List<MellinMomentResult> resultList;
if (ElemUtils::StringUtils::equals(task.getFunctionName(),
MellinMomentService::MELLIN_MOMENT_SERVICE_COMPUTE_MANY_KINEMATIC)) {
resultList.add(computeManyKinematicTask(task));
} else {
if (ElemUtils::StringUtils::equals(task.getFunctionName(),
MellinMomentService::MELLIN_MOMENT_SERVICE_COMPUTE_ONE_KINEMATIC)) {
resultList.add(computeOneKinematicTask(task));
} else if (ElemUtils::StringUtils::equals(task.getFunctionName(),
MellinMomentService::FUNCTION_NAME_GENERATE_PLOT_FILE)) {
generatePlotFileTask(task);
} else if (!ServiceObjectTyped<MellinMomentKinematic, MellinMomentResult>::computeGeneralTask(
task)) {
errorUnknownMethod(task);
}
updateResultInfo(resultList, m_resultInfo);
if (task.isStoreInDB()) {
//TODO implemented connection with Data Base
//GPDResultDaoService gpdResultDaoService;
//gpdResultDaoService.insert(resultList);
}
}
m_resultListBuffer = resultList;
}
MellinMomentResult MellinMomentService::computeOneKinematicTask(Task& task) {
MellinMomentKinematic kinematic = newKinematicFromTask(task);
MellinMomentModule* pMellinModule;// = newGPDModuleFromTask(task);
MellinMomentModule* pMellinModule = newMellinMomentModuleFromTask(task);
int n = getNFromTask(task);
MellinMomentResult result = compute(kinematic,pMellinModule);
......@@ -176,7 +204,7 @@ List<MellinMomentResult> MellinMomentService::computeManyKinematicTask(
int n = getNFromTask(task);
MellinMomentModule* pMellinModule;// = newGPDModuleFromTask(task);
MellinMomentModule* pMellinModule = newMellinMomentModuleFromTask(task);
List<MellinMomentResult> result = computeManyKinematic(listOfKinematic,pMellinModule,
gpdTypeList, task.isStoreInDB());
......@@ -195,8 +223,8 @@ void MellinMomentService::generatePlotFileTask(Task& task) {
List<GPDType> MellinMomentService::getFinalGPDTypeList(MellinMomentModule* pMellinModule,
const List<GPDType> &gpdTypeList) const {
List<GPDType> restrictedByGPDTypeListFinal;/* =
pGPDModule->getListOfAvailableGPDTypeForComputation();
List<GPDType> restrictedByGPDTypeListFinal =
pMellinModule->getListOfAvailableGPDType();
if (!gpdTypeList.isEmpty()) {
restrictedByGPDTypeListFinal = VectorUtils::intersection(
......@@ -206,63 +234,24 @@ List<GPDType> MellinMomentService::getFinalGPDTypeList(MellinMomentModule* pMell
info(__func__,
ElemUtils::Formatter() << restrictedByGPDTypeListFinal.size()
<< " GPDType will be computed");
*/
return restrictedByGPDTypeListFinal;
}
void MellinMomentService::computeTask(Task &task) {
debug(__func__, "Processing ...");
ServiceObjectTyped<MellinMomentKinematic, MellinMomentResult>::computeTask(task);
List<MellinMomentResult> resultList;
if (ElemUtils::StringUtils::equals(task.getFunctionName(),
MellinMomentService::MELLIN_MOMENT_SERVICE_COMPUTE_MANY_KINEMATIC)) {
resultList.add(computeManyKinematicTask(task));
} else {
if (ElemUtils::StringUtils::equals(task.getFunctionName(),
MellinMomentService::MELLIN_MOMENT_SERVICE_COMPUTE_ONE_KINEMATIC)) {
resultList.add(computeMellinMomentTask(task));
} else if (ElemUtils::StringUtils::equals(task.getFunctionName(),
MellinMomentService::FUNCTION_NAME_GENERATE_PLOT_FILE)) {
generatePlotFileTask(task);
} else if (!ServiceObjectTyped<MellinMomentKinematic, MellinMomentResult>::computeGeneralTask(
task)) {
errorUnknownMethod(task);
}
updateResultInfo(resultList, m_resultInfo);
if (task.isStoreInDB()) {
//TODO implemented connection with Data Base
//GPDResultDaoService gpdResultDaoService;
//gpdResultDaoService.insert(resultList);
}
}
m_resultListBuffer = resultList;
return restrictedByGPDTypeListFinal;
}
GPDModule* MellinMomentService::newGPDModuleFromTask(const Task& task) const {
GPDModule* pGPDModule = 0;
MellinMomentModule* MellinMomentService::newMellinMomentModuleFromTask(const Task& task) const {
MellinMomentModule* pMellinModule = 0;
if (ElemUtils::StringUtils::equals(
task.getModuleComputationConfiguration().getModuleType(),
GPDModule::GPD_MODULE_CLASS_NAME)) {
pGPDModule =
Partons::getInstance()->getModuleObjectFactory()->newGPDModule(
task.getModuleComputationConfiguration().getModuleClassName());
MellinMomentModule::MELLIN_MOMENT_MODULE_CLASS_NAME)) {
pMellinModule = static_cast<PARTONS::MellinMomentModule*>(
PARTONS::Partons::getInstance()->getModuleObjectFactory()->newModuleObject(
task.getModuleComputationConfiguration().getModuleClassName()));
pGPDModule->configure(
pMellinModule->configure(
task.getModuleComputationConfiguration().getParameters());
pGPDModule->prepareSubModules(
pMellinModule->prepareSubModules(
task.getModuleComputationConfiguration().getSubModules());
} else {
throw ElemUtils::CustomException(getClassName(), __func__,
......@@ -270,7 +259,7 @@ GPDModule* MellinMomentService::newGPDModuleFromTask(const Task& task) const {
<< "You have not provided any GPDModule");
}
return pGPDModule;
return pMellinModule;
}
int MellinMomentService::getNFromTask(const Task& task) const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment