Commit 5a078178 authored by Andrii Verbytskyi's avatar Andrii Verbytskyi Committed by Frank Siegert

Initial version of HepMC3.1 interface.

parent 23b85916
GITTAG = AddOns/HepMC
include ../../git.make
......@@ -7,12 +6,13 @@ HEPMC3_SOURCES = Git_Info.C Output_HepMC3_Genevent.C
HEPMC2_ADDS = Output_HepMC2_Genevent.H Output_HepMC2_Short.H
HEPMC3_ADDS = Output_HepMC3_Genevent.H
pkglib_LTLIBRARIES =
if HEPMC2_SUPPORT
pkglib_LTLIBRARIES = libSherpaHepMCOutput.la
pkglib_LTLIBRARIES += libSherpaHepMCOutput.la
endif
if HEPMC3_SUPPORT
pkglib_LTLIBRARIES = libSherpaHepMC3Output.la
pkglib_LTLIBRARIES += libSherpaHepMC3Output.la
endif
......@@ -23,7 +23,7 @@ libSherpaHepMCOutput_la_LIBADD = @CONDITIONAL_HEPMC2LIBS@
libSherpaHepMC3Output_la_LIBADD = @CONDITIONAL_HEPMC3LIBS@ @CONDITIONAL_ROOTLIBS@
libSherpaHepMCOutput_la_CPPFLAGS = $(AM_CPPFLAGS) @CONDITIONAL_HEPMC2INCS@ @CONDITIONAL_GZIPINCS@
libSherpaHepMC3Output_la_CPPFLAGS = $(AM_CPPFLAGS) @CONDITIONAL_HEPMC3INCS@ @CONDITIONAL_ROOTINCS@
libSherpaHepMC3Output_la_CPPFLAGS = -std=c++11 $(AM_CPPFLAGS) @CONDITIONAL_HEPMC3INCS@ @CONDITIONAL_ROOTINCS@
HEPMC2_EXTRA_DIST = $(HEPMC2_SOURCES)
HEPMC3_EXTRA_DIST = $(HEPMC3_SOURCES)
......
#include "AddOns/HepMC/Output_HepMC3_Genevent.H"
#include "HepMC/GenEvent.h"
#include "HepMC3/GenEvent.h"
#include "HepMC3/GenCrossSection.h"
#include "ATOOLS/Org/Data_Reader.H"
#include "ATOOLS/Org/Shell_Tools.H"
#include "ATOOLS/Org/MyStrStream.H"
#include "ATOOLS/Org/Exception.H"
#include "ATOOLS/Org/My_MPI.H"
#include "ATOOLS/Org/Run_Parameter.H"
#include "ATOOLS/Org/Scoped_Settings.H"
#include "HepMC/Writer.h"
#include "HepMC/WriterAscii.h"
#include "HepMC/WriterHEPEVT.h"
#include "HepMC3/Writer.h"
#include "HepMC3/WriterAscii.h"
#include "HepMC3/WriterAsciiHepMC2.h"
#include "HepMC3/WriterHEPEVT.h"
#ifdef USING__HEPMC3__WRITERROOTTREE
#include "HepMC/WriterRootTree.h"
#include "HepMC3/WriterRootTree.h"
#endif
#ifdef USING__HEPMC3__WRITERROOT
#include "HepMC/WriterRoot.h"
#include "HepMC3/WriterRoot.h"
#endif
using namespace SHERPA;
......@@ -25,59 +28,80 @@ Output_HepMC3_Genevent::Output_HepMC3_Genevent(const Output_Arguments &args) :
Output_Base("HepMC3")
{
m_basename=args.m_outpath+"/"+args.m_outfile;
m_ext=".hepmc3g";
m_iotype
= Settings::GetMainSettings()["HEPMC3_IO_TYPE"].SetDefault(0).Get<int>();
int precision = Settings::GetMainSettings()["HEPMC3_OUTPUT_PRECISION"].SetDefault(12).Get<int>();
#ifdef USING__MPI
if (MPI::COMM_WORLD.Get_size()>1) {
m_basename+="_"+rpa->gen.Variable("RNG_SEED");
}
#endif
switch (m_iotype)
{
case 0:
p_writer=new HepMC::WriterAscii( m_basename);
break;
case 1:
p_writer=new HepMC::WriterHEPEVT(m_basename);
break;
case 2:
THROW(not_implemented, "Asked for HEPMC3_IO_TYPE, which is not yet implemented.");
case 3:
switch (m_iotype)
{
case 0:
{
HepMC::WriterAscii* t_writer=new HepMC::WriterAscii( m_basename);
t_writer->set_precision(precision);
p_writer=t_writer;
}
break;
case 1:
p_writer=new HepMC::WriterHEPEVT( m_basename);
break;
case 2:
{
HepMC::WriterAsciiHepMC2* t_writer=new HepMC::WriterAsciiHepMC2( m_basename);
t_writer->set_precision(precision);
p_writer=t_writer;
}
break;
case 3:
#ifdef USING__HEPMC3__WRITERROOT
p_writer=new HepMC::WriterRoot(m_basename);
#else
THROW(fatal_error,"Asked for Root output, but Sherpa was compiled without Root output support.");
p_writer=new HepMC::WriterRoot(m_basename);
#else
THROW(fatal_error,"Asked for Root output, but Sherpa was compiled without Root output support.");
#endif
break;
case 4:
break;
case 4:
#ifdef USING__HEPMC3__WRITERROOTTREE
p_writer=new HepMC::WriterRootTree(m_basename);
#else
THROW(fatal_error,"Asked for RootTree output, but Sherpa was compiled without RootTree output support.");
p_writer=new HepMC::WriterRootTree(m_basename);
#else
THROW(fatal_error,"Asked for RootTree output, but Sherpa was compiled without RootTree output support.");
#endif
break;
default:
THROW(fatal_error, "Output format HEPMC3_IO_TYPE is undefined.");
break;
}
break;
default:
THROW(fatal_error, "Output format HEPMC3_IO_TYPE is undefined.");
break;
}
p_xs= std::make_shared<HepMC::GenCrossSection>();
m_run_info= std::make_shared<HepMC::GenRunInfo>();
HepMC::GenRunInfo::ToolInfo tool;
tool.name = std::string("SHERPA-MC");
tool.version = std::string(SHERPA_VERSION)+"."+std::string(SHERPA_SUBVERSION);
tool.description = std::string(SHERPA_NAME);
m_run_info->tools().push_back(tool);
}
Output_HepMC3_Genevent::~Output_HepMC3_Genevent()
{
p_writer->close();
}
}
void Output_HepMC3_Genevent::SetXS(const double& xs, const double& xserr)
{
p_xs->set_cross_section(xs, xserr);
}
void Output_HepMC3_Genevent::Output(Blob_List* blobs, const double weight)
void Output_HepMC3_Genevent::Output(Blob_List* blobs)
{
m_hepmc3.Sherpa2HepMC(blobs, weight);
m_hepmc3.Sherpa2HepMC(blobs, m_run_info);
HepMC::GenEvent* q=m_hepmc3.GenEvent();
if (q)
{
q->set_cross_section(p_xs);
if (p_writer) p_writer->write_event(*(q));
}
}
......
......@@ -4,14 +4,17 @@
#include "ATOOLS/Org/CXXFLAGS_PACKAGES.H"
#include "SHERPA/Tools/Output_Base.H"
#include "SHERPA/Tools/HepMC3_Interface.H"
#include <iostream>
#include <memory>
namespace HepMC {
namespace HepMC3 {
class GenEvent;
class GenVertex;
class GenParticle;
class GenCrossSection;
class Writer;
class WriterAscii;
class WriterAsciiHepMC2;
class WriterHEPEVT;
#ifdef USING__HEPMC3__WRITERROOTTREE
class WriterRootTree;
......@@ -20,19 +23,23 @@ namespace HepMC {
class WriterRoot;
#endif
}
namespace HepMC = HepMC3;
namespace SHERPA {
class Output_HepMC3_Genevent : public Output_Base {
HepMC3_Interface m_hepmc3;
HepMC::Writer *p_writer=0;
std::string m_basename, m_ext;
std::shared_ptr<HepMC::GenCrossSection> p_xs;
std::shared_ptr<HepMC::GenRunInfo> m_run_info;
std::string m_basename;
int m_iotype;
public:
Output_HepMC3_Genevent(const Output_Arguments &args);
~Output_HepMC3_Genevent();
void Output(ATOOLS::Blob_List* blobs, double weight);
void SetXS(const double& xs, const double& xserr);
void Output(ATOOLS::Blob_List* blobs);
//void Output(ATOOLS::Blob_List* blobs){ Output(blobs, 1.0);}
void ChangeFile();
};
}
......
......@@ -272,6 +272,7 @@ bool EventInfo::WriteTo(HepMC::GenEvent &evt, const int& idx)
}
evt.set_alphaQCD(m_alphas);
evt.set_alphaQED(m_alpha);
evt.set_event_scale(m_mur2);
return true;
}
......@@ -322,6 +323,8 @@ bool HepMC2_Interface::Sherpa2ShortHepMC(ATOOLS::Blob_List *const blobs,
#endif
Blob *sp(blobs->FindFirst(btp::Signal_Process));
if (!sp) sp=blobs->FindFirst(btp::Hard_Collision);
Blob *mp(blobs->FindFirst(btp::Hard_Collision));
if (!mp) event.set_mpi(-1);
EventInfo evtinfo(sp,weight,
m_usenamedweights,m_extendedweights,m_includemeonlyweights);
// when subevtlist, fill hepmc-subevtlist
......
This diff is collapsed.
#ifndef SHERPA_Tools_HepMC3_Interface_H
#define SHERPA_Tools_HepMC3_Interface_H
#include "ATOOLS/Org/CXXFLAGS_PACKAGES.H"
#ifdef USING__HEPMC3
#include "ATOOLS/Org/CXXFLAGS.H"
#include "ATOOLS/Org/Message.H"
#include "ATOOLS/Phys/Blob.H"
#include "ATOOLS/Phys/NLO_Types.H"
#include "ATOOLS/Phys/NLO_Subevt.H"
#include "ATOOLS/Phys/Weight_Info.H"
#include "PHASIC++/Process/Subprocess_Info.H"
#include "ATOOLS/Phys/Variations.H"
#include <map>
#include <set>
#include <memory>
namespace HepMC {
namespace HepMC3 {
class GenEvent;
class GenVertex;
class GenRunInfo;
class GenParticle;
class GenCrossSection;
class Writer;
class WriterAscii;
class WriterAsciiHepMC2;
class WriterHEPEVT;
#ifdef USING__HEPMC3__WRITERROOTTREE
class WriterRootTree;
......@@ -26,41 +34,52 @@ namespace HepMC {
#ifdef USING__HEPMC3__WRITERROOT
class WriterRoot;
#endif
using GenVertexPtr = std::shared_ptr<GenVertex>;
using GenParticlePtr = std::shared_ptr<GenParticle>;
}
namespace HepMC = HepMC3;
namespace ATOOLS {
class Blob_List;
class Particle;
class ME_Weight_Info;
class NLO_subevtlist;
class PDF_Info;
class Variation_Weights;
}
namespace SHERPA {
class Variation_Weights;
class EventInfo {
class EventInfo3 {
private:
size_t m_usenamedweights, m_extendedweights;
ATOOLS::Blob * p_sp;
bool m_usenamedweights, m_extendedweights;
std::vector<ATOOLS::Variations_Type> m_variationtypes;
std::vector<double> m_orders;
double m_wgt, m_mewgt, m_wgtnorm, m_ntrials, m_pswgt, m_pwgt;
double m_mur2, m_muf12, m_muf22;
double m_mur2, m_muf12, m_muf22, m_muq2;
double m_alphas, m_alpha;
PHASIC::nlo_type::code m_type;
bool m_userhook;
double m_userweight;
ATOOLS::nlo_type::code m_type;
ATOOLS::ME_Weight_Info * p_wgtinfo;
ATOOLS::PDF_Info * p_pdfinfo;
ATOOLS::NLO_subevtlist * p_subevtlist;
Variation_Weights * p_variationweights;
ATOOLS::Variation_Weights * p_variationweights;
void ReadIn(ATOOLS::Blob_Data_Base * &db, std::string name, bool abort);
public:
EventInfo(ATOOLS::Blob * sp, const double &wgt,
bool namedweights, bool minimalweights);
EventInfo(const EventInfo &evtinfo);
~EventInfo() {}
EventInfo3(ATOOLS::Blob * sp, const double &wgt,
bool namedweights,
bool extendedweights,
bool includemeonlyweights);
EventInfo3(const EventInfo3 &evtinfo);
~EventInfo3() {}
bool WriteTo(HepMC::GenEvent &evt, const int& idx=-1);
inline const ATOOLS::NLO_subevtlist * SubEvtList() { return p_subevtlist; }
inline void SetWeight(const double &wgt) { m_wgt=wgt; }
......@@ -75,10 +94,11 @@ namespace SHERPA {
class HepMC3_Interface {
private :
bool m_usenamedweights, m_extendedweights, m_hepmctree;
bool m_usenamedweights, m_extendedweights, m_includemeonlyweights;
bool m_hepmctree;
std::map<ATOOLS::Blob*,HepMC::GenVertex *> m_blob2genvertex;
std::map<ATOOLS::Particle*,HepMC::GenParticle *> m_particle2genparticle;
std::map<ATOOLS::Blob*,HepMC::GenVertexPtr > m_blob2genvertex;
std::map<ATOOLS::Particle*,HepMC::GenParticlePtr> m_particle2genparticle;
std::set<ATOOLS::btp::code> m_ignoreblobs;
HepMC::GenEvent *p_event;
......@@ -93,18 +113,16 @@ namespace SHERPA {
~HepMC3_Interface();
// member functions
bool Sherpa2HepMC(ATOOLS::Blob_List *const blobs, HepMC::GenEvent& event, double weight=1.0);
bool Sherpa2HepMC(ATOOLS::Blob_List *const blobs, double weight=1.0);
bool Sherpa2HepMC(ATOOLS::Blob *, HepMC::GenVertex *& );
bool Sherpa2HepMC(ATOOLS::Particle *, HepMC::GenParticle *&);
bool Sherpa2ShortHepMC(ATOOLS::Blob_List *const blobs,
HepMC::GenEvent& event,
double weight=1.0);
bool Sherpa2ShortHepMC(ATOOLS::Blob_List *const blobs, double weight=1.0);
bool SubEvtList2ShortHepMC(EventInfo &evtinfo);
bool AddCrossSection(HepMC::GenEvent& event,
bool Sherpa2HepMC(ATOOLS::Blob_List *const blobs, HepMC::GenEvent& event);
bool Sherpa2HepMC(ATOOLS::Blob_List *const blobs, std::shared_ptr<HepMC::GenRunInfo> run= std::shared_ptr<HepMC::GenRunInfo>());
bool Sherpa2HepMCBlobtoGenVertex(ATOOLS::Blob *, HepMC::GenVertexPtr &, HepMC::GenEvent& event );
bool Sherpa2HepMC(ATOOLS::Particle *, HepMC::GenParticlePtr &);
bool Sherpa2ShortHepMC(ATOOLS::Blob_List *const blobs, HepMC::GenEvent& event);
bool Sherpa2ShortHepMC(ATOOLS::Blob_List *const blobs);
bool SubEvtList2ShortHepMC(EventInfo3 &evtinfo);
void AddCrossSection(HepMC::GenEvent& event,
const double& xs, const double& err);
// inline functions
......@@ -123,6 +141,8 @@ namespace SHERPA {
inline bool HepMCExtendedWeights() { return m_extendedweights; }
inline void SetHepMCTreeLike(bool x) { m_hepmctree=x; }
inline bool HepMCTreeLike() { return m_hepmctree; }
inline void SetHepMCIncludeMEOnlyVariations(bool x)
{ m_includemeonlyweights=x; }
void DeleteGenSubEventList();
......
......@@ -466,7 +466,7 @@ AC_DEFUN([SHERPA_SETUP_CONFIGURE_OPTIONS],
AC_ARG_ENABLE(
hepmc3root,
AC_HELP_STRING([--enable-hepmc3root], [Enable HepMC (version 3.x) ROOT support]),
AC_HELP_STRING([--enable-hepmc3root], [Enable HepMC (version 3.1+) ROOT support]),
[
case "${enableval}" in
no) AC_MSG_RESULT(HepMC3 ROOT support not enabled); hepmc3root=false ;;
......@@ -487,9 +487,9 @@ AC_DEFUN([SHERPA_SETUP_CONFIGURE_OPTIONS],
yes) if test -d "$HEPMC3DIR"; then
CONDITIONAL_HEPMC3DIR="$HEPMC3DIR"
CONDITIONAL_HEPMC3INCS="-I$HEPMC3DIR/include"
CONDITIONAL_HEPMC3LIBS="-L$HEPMC3DIR/lib -R$HEPMC3DIR/lib -L$HEPMC3DIR/lib64 -R$HEPMC3DIR/lib64 -lHepMC";
CONDITIONAL_HEPMC3LIBS="-L$HEPMC3DIR/lib -R$HEPMC3DIR/lib -L$HEPMC3DIR/lib64 -R$HEPMC3DIR/lib64 -lHepMC3";
if test "$hepmc3root" = "true" ; then
CONDITIONAL_HEPMC3LIBS+=" -lHepMCrootIO"
CONDITIONAL_HEPMC3LIBS+=" -lHepMC3rootIO"
fi
else
AC_MSG_ERROR(\$HEPMC3DIR is not a valid path.);
......@@ -498,19 +498,19 @@ AC_DEFUN([SHERPA_SETUP_CONFIGURE_OPTIONS],
*) if test -d "${enableval}"; then
CONDITIONAL_HEPMC3DIR="${enableval}"
CONDITIONAL_HEPMC3INCS="-I${enableval}/include"
CONDITIONAL_HEPMC3LIBS="-L${enableval}/lib -R${enableval}/lib -L${enableval}/lib64 -R${enableval}/lib64 -lHepMC";
CONDITIONAL_HEPMC3LIBS="-L${enableval}/lib -R${enableval}/lib -L${enableval}/lib64 -R${enableval}/lib64 -lHepMC3";
if test "$hepmc3root" = "true" ; then
CONDITIONAL_HEPMC3LIBS+=" -lHepMCrootIO"
CONDITIONAL_HEPMC3LIBS+=" -lHepMC3rootIO"
fi
else
AC_MSG_ERROR(${enableval} is not a valid path.);
fi;
AC_MSG_RESULT([${CONDITIONAL_HEPMC3DIR}]); hepmc3=true;;
esac
if test -f "$CONDITIONAL_HEPMC3DIR/include/HepMC/WriterRootTree.h"; then
if test -f "$CONDITIONAL_HEPMC3DIR/include/HepMC3/WriterRootTree.h"; then
hepmc3writerroottree=true;
fi;
if test -f "$CONDITIONAL_HEPMC3DIR/include/HepMC/WriterRoot.h"; then
if test -f "$CONDITIONAL_HEPMC3DIR/include/HepMC3/WriterRoot.h"; then
hepmc3writerroot=true;
fi;
......
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