Skip to content
Snippets Groups Projects
Commit a88b0111 authored by Jan Steggemann's avatar Jan Steggemann
Browse files

Initial import

parents
No related branches found
No related tags found
No related merge requests found
#common cmake stuff
cmake_minimum_required (VERSION 2.6)
project (pxl-module)
#Add the path to the FindPXL.cmake file here - or copy it to the module
#directory and use the line below
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
#name of the pxl-module
SET(PXLMODULENAME Pythia8Module)
#files to be added to the module library
add_library(${PXLMODULENAME} MODULE
Pythia8Generator.cpp
)
#check for pxl
FIND_PACKAGE(PXL)
FIND_PACKAGE(Pythia8)
#insert needed plugins here
#ADD_PXL_PLUGIN(pxl-astro)
ADD_PXL_PLUGIN(pxl-core)
ADD_PXL_PLUGIN(pxl-hep)
ADD_PXL_PLUGIN(pxl-modules)
#add additional external libraries as needed
include_directories(
${PXL_INCLUDE_DIRS} ${Pythia8_INCLUDE_DIRS}
)
link_directories(
${PXL_LIBRARIES} ${Pythia8_LIBRARIES}
)
target_link_libraries (${PXLMODULENAME}
${PXL_LIBRARIES} ${Pythia8_LIBRARIES}
)
SET_TARGET_PROPERTIES(${PXLMODULENAME} PROPERTIES COMPILE_FLAGS -fPIC)
#set install destination
INSTALL(TARGETS ${PXLMODULENAME} LIBRARY DESTINATION
${PXL_PLUGIN_INSTALL_PATH})
# - Try to find Pythia8
# Once done, this will define
#
# Pythia8_FOUND - system has Pythia8
# Pythia8_INCLUDE_DIRS - the Pythia8 include directories
# Pythia8_LIBRARIES - link these to use Pythia8
# Note that this only configures the Pythia8-core system to add a Pythia8
# plugin, use the Pythia8_ADD_PLUGIN(name), where name is e.g. Pythia8-astro
# Use pkg-config to get hints about paths
FIND_PACKAGE(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(Pythia8_PKGCONF Pythia8)
SET(Pythia8_PLUGIN_INSTALL_PATH $ENV{HOME}/${Pythia8_PLUGIN_INSTALL_PATH})
endif (PKG_CONFIG_FOUND)
# Include dir
find_path(Pythia8_INCLUDE_DIRS
NAMES Pythia.h
HINTS ${Pythia8_PKGCONF_INCLUDE_DIRS} /usr/local/include /Users/jan/Software/pythia8165/include/
)
# library
find_library(Pythia8_LIBRARIES
NAMES pythia8
HINTS ${Pythia8_PKGCONF_LIBRARY_DIRS} /usr/local/lib /Users/jan/Software/pythia8165/lib/
)
#include "pxl/hep.hh"
#include "pxl/core.hh"
#include "pxl/core/macros.hh"
#include "pxl/core/PluginManager.hh"
#include "pxl/modules/Module.hh"
#include "pxl/modules/ModuleFactory.hh"
#include "pxl/modules.hh"
#include "pxl/core/Event.hh"
#include "pxl/hep/EventView.hh"
#include "pxl/hep/Particle.hh"
#include "Pythia.h"
#include<cmath>
#include<string>
#include<vector>
#include <map>
#include <algorithm>
#include <sstream>
static pxl::Logger logger("Pythia8Generator");
class Pythia8Generator : public pxl::Module
{
private:
Pythia8::Pythia pythia8;
int64_t counter;
int64_t coll_particle1;
int64_t coll_particle2;
double cme;
int64_t numberOfObjects;
bool running;
public:
// every Module needs a unique type
static const std::string &getStaticType()
{
static std::string type ("Pythia8Generator");
return type;
}
// static and dynamic methods are needed
const std::string &getType() const
{
return getStaticType();
}
Pythia8Generator(): Module()
{
addOption("number"," ",(int64_t)10);
addOption("colliding particle 1"," ",(int64_t)11);
addOption("colliding particle 2"," ",(int64_t)-11);
addOption("center mass energy"," ",200.0);
addOption("select hard process"," ",true);
addOption("select sub processes"," ",false);
addOption("select ISR"," ",false);
addOption("select FSR"," ",false);
addSource("out","");
running = true;
}
~Pythia8Generator()
{
}
void beginJob()
{
getOption("number",numberOfObjects);
pythia8.readString("WeakZ0:gmZmode=2");
pythia8.readString("WeakBosonExchange:all=on");
pythia8.readString("WeakSingleBoson:all=on");
pythia8.readString("WeakBosonAndParton:all=on");
pythia8.readString("PhaseSpace:mHatMin=50");
pythia8.readString("PhaseSpace:mHatMax=150");
getOption("colliding particle 1",coll_particle1);
getOption("colliding particle 2",coll_particle2);
getOption("center mass energy",cme);
pythia8.init(coll_particle1, coll_particle2, cme);
}
void beginRun()
{
}
bool isRunnable() const
{
return running;
}
bool analyse(pxl::Sink* sink)
{
if (counter < numberOfObjects)
{
counter+=1;
//logger.log(pxl::LOG_LEVEL_INFO,getName(), ": Generating object: ",counter, "/", numberOfObjects);
pythia8.next();
Pythia8::Event pEvent = pythia8.event;
int num = pEvent.size();
pxl::Event* event = new pxl::Event();
pxl::EventView* eventView = new pxl::EventView();
eventView->setName("Generated");
event->insertObject(eventView);
map<int, pxl::Particle*> idMap;
for (int cnt=0; cnt<num;++cnt) {
Pythia8::Particle particle = pEvent[cnt];
int status = particle.status();
if (fabs(status)>=0 && fabs(status)<=120)
{
pxl::Particle* pxl_part = new pxl::Particle();
pxl_part->setName(particle.name());
pxl_part->setP4(particle.px(),particle.py(),particle.pz(),particle.e());
pxl_part->setUserRecord("status",status);
eventView->insertObject(pxl_part);
idMap[cnt]=pxl_part;
}
}
map<int, pxl::Particle*>::iterator it;
/*
for ( it=idMap.begin() ; it != idMap.end(); it++ )
std::cout << (*it).first << " => " << (*it).second << std::endl;
*/
for (int cnt=0; cnt<num;++cnt) {
Pythia8::Particle particle = pEvent[cnt];
if (idMap.find(cnt)!=idMap.end()) {
int mother1ID = particle.mother1();
//std::cout<<"mother1:"<<mother1ID<<std::endl;
if (mother1ID>0) {
if (idMap.find(mother1ID)!=idMap.end()) {
//std::cout<<"\tfound:"<<mother1ID<<std::endl;
(idMap[mother1ID])->linkDaughter(idMap[cnt]);
}
}
int mother2ID = particle.mother2();
//std::cout<<"mother2:"<<mother2ID<<std::endl;
if (mother2ID>0) {
if (idMap.find(mother2ID)!=idMap.end()) {
//std::cout<<"\tfound:"<<mother2ID<<std::endl;
(idMap[mother2ID])->linkDaughter(idMap[cnt]);
}
}
}
}
(getSource("out"))->setTargets(event);
return (getSource("out"))->processTargets();
}
running = false;
return false;
}
void endRun()
{
}
void endJob()
{
}
};
PXL_MODULE_INIT(Pythia8Generator)
PXL_PLUGIN_INIT
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment