Commit 751a3d8a authored by Pawel Sznajder's avatar Pawel Sznajder
Browse files

add GPD module selecting a specific parton type from other GPD module

parent 0fd9a9a0
......@@ -104,6 +104,13 @@ public:
*/
std::string getShortName();
/**
* Try to match quark flavor from given string.
* @param quarkFlavorStr String to be matched.
* @return Matched type or QuarkFlavor::UNDEFINED if unable to match.
*/
static QuarkFlavor::Type fromString(const std::string & quarkFlavorStr);
//********************************************************
//*** SETTERS AND GETTERS ********************************
//********************************************************
......
#ifndef GPDSELECTONEPARTONTYPE_H
#define GPDSELECTONEPARTONTYPE_H
/**
* @file GPDSelectOnePartonType.h
* @author Pawel Sznajder (IPNO)
* @date March 29, 2015
* @version 1.0
*/
#include <ElementaryUtils/parameters/Parameters.h>
#include <map>
#include <string>
#include "../../beans/automation/BaseObjectData.h"
#include "GPDModule.h"
namespace PARTONS {
/**
* @class GPDSelectOnePartonType
*
* @brief This model allows to select a single parton type.
*/
class GPDSelectOnePartonType: public GPDModule {
public:
static const std::string PARAMETER_NAME_SELECTONEPARTONTYPE_PARTONTYPE; ///< Name of parameter to set parton type via configure()
static const unsigned int classId; ///< ID assigned by BaseObjectRegistry
/**
* Constructor.
* See BaseObject::BaseObject and ModuleObject::ModuleObject for more details.
*
* @param className name of child class.
*/
GPDSelectOnePartonType(const std::string &className);
/**
* Default destructor.
*/
virtual ~GPDSelectOnePartonType();
virtual GPDSelectOnePartonType* clone() const;
virtual void configure(const ElemUtils::Parameters &parameters);
virtual void prepareSubModules(
const std::map<std::string, BaseObjectData>& subModulesData);
/**
* Set underlying GPD module.
*/
const GPDModule* getGPDModule() const;
/**
* Get underlying GPD module.
*/
void setGPDModule(GPDModule* pGPDModule);
/**
* Get parton type.
*/
const std::string& getPartonType() const;
/**
* Set parton type.
*/
void setPartonType(const std::string& partonType);
protected:
/** Copy constructor.
@param other Object to be copied.
*/
GPDSelectOnePartonType(const GPDSelectOnePartonType& other);
virtual PartonDistribution computeH();
private:
GPDModule* m_pGPDModule; ///< GPD module.
std::string m_partonType; ///< Parton type.
};
} /* namespace PARTONS */
#endif /* GPDSELECTONEPARTONTYPE_H */
#include "../../../include/partons/beans/QuarkFlavor.h"
namespace PARTONS {
#include <ElementaryUtils/string_utils/StringUtils.h>
namespace PARTONS {
const std::string QuarkFlavor::QUARK_FLAVOR_TYPE_DB_COLUMN_NAME =
"quark_flavor_type";
......@@ -71,6 +72,28 @@ std::string QuarkFlavor::getShortName() {
}
}
QuarkFlavor::Type QuarkFlavor::fromString(const std::string & quarkFlavorStr) {
QuarkFlavor::Type quarkFlavor = QuarkFlavor::UNDEFINED;
if (ElemUtils::StringUtils::equals(quarkFlavorStr, "u")) {
quarkFlavor = QuarkFlavor::UP;
} else if (ElemUtils::StringUtils::equals(quarkFlavorStr, "d")) {
quarkFlavor = QuarkFlavor::DOWN;
} else if (ElemUtils::StringUtils::equals(quarkFlavorStr, "s")) {
quarkFlavor = QuarkFlavor::STRANGE;
} else if (ElemUtils::StringUtils::equals(quarkFlavorStr, "c")) {
quarkFlavor = QuarkFlavor::CHARM;
} else if (ElemUtils::StringUtils::equals(quarkFlavorStr, "b")) {
quarkFlavor = QuarkFlavor::BOTTOM;
} else if (ElemUtils::StringUtils::equals(quarkFlavorStr, "t")) {
quarkFlavor = QuarkFlavor::TOP;
}
return quarkFlavor;
}
QuarkFlavor::Type QuarkFlavor::getType() const {
return m_type;
}
......
#include "../../../../include/partons/modules/gpd/GPDSelectOnePartonType.h"
#include <ElementaryUtils/logger/CustomException.h>
#include <ElementaryUtils/parameters/GenericType.h>
#include <ElementaryUtils/string_utils/Formatter.h>
#include <iterator>
#include <utility>
#include <vector>
#include "../../../../include/partons/beans/gpd/GPDKinematic.h"
#include "../../../../include/partons/beans/gpd/GPDType.h"
#include "../../../../include/partons/beans/parton_distribution/GluonDistribution.h"
#include "../../../../include/partons/beans/parton_distribution/QuarkDistribution.h"
#include "../../../../include/partons/beans/QuarkFlavor.h"
#include "../../../../include/partons/BaseObjectRegistry.h"
#include "../../../../include/partons/ModuleObjectFactory.h"
#include "../../../../include/partons/Partons.h"
namespace PARTONS {
const unsigned int GPDSelectOnePartonType::classId =
BaseObjectRegistry::getInstance()->registerBaseObject(
new GPDSelectOnePartonType("GPDSelectOnePartonType"));
const std::string GPDSelectOnePartonType::PARAMETER_NAME_SELECTONEPARTONTYPE_PARTONTYPE =
"parton_type";
GPDSelectOnePartonType::GPDSelectOnePartonType(const std::string &className) :
GPDModule(className), m_pGPDModule(0) {
for (int i = static_cast<int>(GPDType::H);
i < static_cast<int>(GPDType::END); i++) {
m_listGPDComputeTypeAvailable.insert(
std::make_pair(static_cast<GPDType::Type>(i),
&GPDModule::computeH));
}
m_MuF2_ref = 1.; //reference scale (not used but should be set to avoid warning)
}
GPDSelectOnePartonType::GPDSelectOnePartonType(
const GPDSelectOnePartonType& other) :
GPDModule(other) {
m_partonType = other.m_partonType;
if (other.m_pGPDModule != 0) {
m_pGPDModule = m_pModuleObjectFactory->cloneModuleObject(
other.m_pGPDModule);
} else {
m_pGPDModule = 0;
}
}
GPDSelectOnePartonType::~GPDSelectOnePartonType() {
if (m_pGPDModule) {
setGPDModule(0);
m_pGPDModule = 0;
}
}
GPDSelectOnePartonType* GPDSelectOnePartonType::clone() const {
return new GPDSelectOnePartonType(*this);
}
void GPDSelectOnePartonType::configure(
const ElemUtils::Parameters &parameters) {
GPDModule::configure(parameters);
if (parameters.isAvailable(
GPDSelectOnePartonType::PARAMETER_NAME_SELECTONEPARTONTYPE_PARTONTYPE)) {
setPartonType(parameters.getLastAvailable().getString());
info(__func__,
ElemUtils::Formatter() << "Parameter "
<< GPDSelectOnePartonType::PARAMETER_NAME_SELECTONEPARTONTYPE_PARTONTYPE
<< " set to "
<< parameters.getLastAvailable().getString());
}
}
void GPDSelectOnePartonType::prepareSubModules(
const std::map<std::string, BaseObjectData>& subModulesData) {
GPDModule::prepareSubModules(subModulesData);
std::map<std::string, BaseObjectData>::const_iterator it;
it = subModulesData.find(GPDModule::GPD_MODULE_CLASS_NAME);
if (it != subModulesData.end()) {
if (m_pGPDModule) {
setGPDModule(0);
m_pGPDModule = 0;
}
if (!m_pGPDModule) {
m_pGPDModule =
Partons::getInstance()->getModuleObjectFactory()->newGPDModule(
(it->second).getModuleClassName());
info(__func__,
ElemUtils::Formatter() << "Configure with GPDModule = "
<< m_pGPDModule->getClassName());
m_pGPDModule->configure((it->second).getParameters());
m_pGPDModule->prepareSubModules((it->second).getSubModules());
}
}
}
PartonDistribution GPDSelectOnePartonType::computeH() {
//check if GPD module set
if (!m_pGPDModule) {
throw ElemUtils::CustomException(getClassName(), __func__,
"GPD module not set");
}
//check if parton type selected
if (m_partonType.empty()) {
throw ElemUtils::CustomException(getClassName(), __func__,
"Parton type not selected");
}
//evaluate
PartonDistribution result = m_pGPDModule->compute(
GPDKinematic(m_x, m_xi, m_t, m_MuF2, m_MuR2),
m_currentGPDComputeType);
//new result
PartonDistribution newResult;
//get list of computed flavors
std::vector<QuarkFlavor::Type> flavorList = result.listTypeOfQuarkFlavor();
//iterator
std::vector<QuarkFlavor::Type>::const_iterator it;
//parton type
if (m_partonType == "g") {
newResult.setGluonDistribution(result.getGluonDistribution());
for (it = flavorList.begin(); it != flavorList.end(); it++) {
newResult.addQuarkDistribution(QuarkDistribution(*it, 0., 0., 0.));
}
} else {
QuarkFlavor::Type quarkFlavor = QuarkFlavor().fromString(m_partonType);
if (quarkFlavor == QuarkFlavor::UNDEFINED) {
throw ElemUtils::CustomException(getClassName(), __func__,
ElemUtils::Formatter()
<< "Parton type is undefined or conversion from string faild: "
<< m_partonType);
}
newResult.setGluonDistribution(GluonDistribution(0.));
for (it = flavorList.begin(); it != flavorList.end(); it++) {
if (*it == quarkFlavor) {
newResult.addQuarkDistribution(
result.getQuarkDistribution(*it));
} else {
newResult.addQuarkDistribution(
QuarkDistribution(*it, 0., 0., 0.));
}
}
}
//return
return newResult;
}
const GPDModule* GPDSelectOnePartonType::getGPDModule() const {
return m_pGPDModule;
}
void GPDSelectOnePartonType::setGPDModule(GPDModule* pGPDModule) {
m_pModuleObjectFactory->updateModulePointerReference(m_pGPDModule,
pGPDModule);
m_pGPDModule = pGPDModule;
}
const std::string& GPDSelectOnePartonType::getPartonType() const {
return m_partonType;
}
void GPDSelectOnePartonType::setPartonType(const std::string& partonType) {
m_partonType = partonType;
}
} /* namespace PARTONS */
Supports Markdown
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