Page MenuHomeHEPForge

No OneTemporary

diff --git a/include/RHEJ/HepMCInterface.hh b/include/RHEJ/HepMCInterface.hh
index 00fb8aa..9e43bbd 100644
--- a/include/RHEJ/HepMCInterface.hh
+++ b/include/RHEJ/HepMCInterface.hh
@@ -1,44 +1,38 @@
/** \file HepMCInterface.hh
* \brief Converts HEJ events into HepMC::GenEvents
*/
-#ifdef RHEJ_BUILD_WITH_HepMC_VERSION
#pragma once
#include <cstddef>
-#if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
-#include "HepMC/GenRunInfo.h"
-#endif
+#include "LHEF/LHEF.h"
-namespace LHEF{
- struct HEPRUP;
-}
namespace HepMC{
class GenEvent;
class GenCrossSection;
+ class GenRunInfo;
}
namespace RHEJ{
class Event;
class HepMCInterface{
public:
- HepMCInterface(LHEF::HEPRUP &);
+ HepMCInterface(LHEF::HEPRUP &&);
HepMC::GenEvent operator()(Event const & event, size_t const weight_index = 0);
private:
- size_t event_count;
- double tot_weight;
- double tot_weight2;
- public:
+ size_t event_count_;
+ double tot_weight_;
+ double tot_weight2_;
void add_event(double const wt);
- #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
- HepMC::shared_ptr<HepMC::GenRunInfo> runinfo;
- HepMC::shared_ptr<HepMC::GenCrossSection> cross_section();
- #else
- HepMC::GenCrossSection cross_section();
- #endif
+
+ LHEF::HEPRUP heprup_;
+ public:
+
+ HepMC::GenCrossSection cross_section() const;
+ HepMC::GenRunInfo init_runinfo();
+
+
};
}
-
-#endif
diff --git a/src/HepMCInteface.cc b/src/HepMCInteface.cc
index 95e9a79..ace8424 100644
--- a/src/HepMCInteface.cc
+++ b/src/HepMCInteface.cc
@@ -1,171 +1,180 @@
#include "RHEJ/HepMCInterface.hh"
+#include <cassert>
+
#ifdef RHEJ_BUILD_WITH_HepMC_VERSION
#include "RHEJ/Event.hh"
#include "RHEJ/Version.hh"
#include "HepMC/GenEvent.h"
#include "HepMC/GenVertex.h"
#include "HepMC/GenParticle.h"
#include "HepMC/GenCrossSection.h"
#if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
#include "HepMC/LHEFAttributes.h"
#endif
#include "LHEF/LHEF.h"
namespace RHEJ{
- namespace {
- HepMC::FourVector to_FourVector(Sparticle const & sp){
- return {sp.px(), sp.py(), sp.pz(), sp.E()};
- }
- #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
+ namespace {
+ HepMC::FourVector to_FourVector(Sparticle const & sp){
+ return {sp.px(), sp.py(), sp.pz(), sp.E()};
+ }
+ #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
void add_generator_tag(LHEF::HEPRUP & heprup){
heprup.generators.emplace_back(LHEF::XMLTag{});
heprup.generators.back().name = Version::package_name();
heprup.generators.back().version = Version::String();
}
void reset_weight_info(LHEF::HEPRUP & heprup){
- heprup.IDWTUP = -4;
+ heprup.IDWTUP = 2;
// use placeholders for unknown init block values
// we can overwrite them after processing all events
heprup.XSECUP = {0.};
heprup.XERRUP = {0.};
heprup.XMAXUP = {0.};
}
+ #endif // HepMC 3
+ } // namespace anonymous
+
+ HepMCInterface::HepMCInterface(LHEF::HEPRUP && heprup):
+ event_count_(0.), tot_weight_(0.), tot_weight2_(0.),
+ heprup_(heprup)
+ {
+ #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3 // TODO remove
+ std::cout << "HepMC 3" << std::endl;
+ #else // HepMC 2
+ std::cout << "HepMC 2" << std::endl;
+ #endif
+ }
+
+#if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
+ HepMC::GenRunInfo HepMCInterface::init_runinfo(){
+ add_generator_tag(heprup_);
+ reset_weight_info(heprup_);
+ HepMC::GenRunInfo runinfo;
- HepMC::shared_ptr<HepMC::GenRunInfo> & add_HEPRUP(
- HepMC::shared_ptr<HepMC::GenRunInfo> & runinfo, LHEF::HEPRUP heprup
- ){
- //@TODO something in here gives a stackfault
- add_generator_tag(heprup);
- reset_weight_info(heprup);
auto hepr = HepMC::make_shared<HepMC::HEPRUPAttribute>();
- hepr->heprup = std::move(heprup);
- runinfo->add_attribute(std::string("HEPRUP"), hepr);
+ hepr->heprup = heprup_;
+ runinfo.add_attribute(std::string("HEPRUP"), hepr);
for (int i = 0, N = hepr->heprup.generators.size(); i < N; ++i ){
HepMC::GenRunInfo::ToolInfo tool;
tool.name = hepr->heprup.generators[i].name;
tool.version = hepr->heprup.generators[i].version;
tool.description = hepr->heprup.generators[i].contents;
- runinfo->tools().push_back(tool);
+ runinfo.tools().push_back(tool);
}
return runinfo;
}
- #endif // HepMC 3
- } // namespace anonymous
-
-#if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
- HepMCInterface::HepMCInterface(LHEF::HEPRUP & heprup):
- event_count(0.), tot_weight(0.), tot_weight2(0.),
- runinfo(add_HEPRUP(runinfo, std::move(heprup)))
- {}
-#else
- HepMCInterface::HepMCInterface(LHEF::HEPRUP &):
- event_count(0.), tot_weight(0.), tot_weight2(0.)
- {}
#endif
- void HepMCInterface::add_event(double const wt){
- ++event_count;
- tot_weight += wt;
- tot_weight2 += wt * wt;
- }
-
-#if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
- HepMC::shared_ptr<HepMC::GenCrossSection> HepMCInterface::cross_section(){
- auto xs = HepMC::make_shared<HepMC::GenCrossSection>();
- xs->set_cross_section(tot_weight, sqrt(tot_weight2));
- return xs;
+ void HepMCInterface::add_event(double const wt){
+ ++event_count_;
+ tot_weight_ += wt;
+ tot_weight2_ += wt * wt;
}
-#else
- HepMC::GenCrossSection HepMCInterface::cross_section(){
- HepMC::GenCrossSection xs;
- xs.set_cross_section(tot_weight, sqrt(tot_weight2));
- return xs;
+
+ HepMC::GenCrossSection HepMCInterface::cross_section() const {
+ HepMC::GenCrossSection xs;
+ #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
+ xs.set_cross_section(tot_weight_, sqrt(tot_weight2_), event_count_);
+ // TODO add number of attempted events
+ #else // HepMC 2
+ xs.set_cross_section(tot_weight_, sqrt(tot_weight2_));
+ #endif
+ return xs;
}
-#endif
#if RHEJ_BUILD_WITH_HepMC_VERSION >= 3 // TODO better way?
#define array_type(x) HepMC::make_shared<x>
#else // HepMC 2
#define array_type(x) new x
+ // TODO check that this doesn't create lost memory
#endif
HepMC::GenEvent HepMCInterface::operator()(Event const & event, size_t const weight_index){
HepMC::GenEvent out_ev{HepMC::Units::GEV, HepMC::Units::MM};
auto vx = array_type(HepMC::GenVertex)();
for(auto const & in: event.incoming()){
vx->add_particle_in(
array_type(HepMC::GenParticle)(
to_FourVector(in), static_cast<int>(in.type), -1
)
);
}
for(int i=0; i< (int) event.outgoing().size(); ++i){
auto const & out = event.outgoing()[i];
auto particle = array_type(HepMC::GenParticle)(
to_FourVector(out), static_cast<int>(out.type), +1
);
for(auto const & decay: event.decays()){
if( i == decay.first ){
particle->set_status(+3);
auto vx_decay= array_type(HepMC::GenVertex)();
vx_decay->add_particle_in(particle);
for( auto const & out: decay.second){
vx_decay->add_particle_out(
array_type(HepMC::GenParticle)(
to_FourVector(out), static_cast<int>(out.type), +1
)
);
}
out_ev.add_vertex(vx_decay);
break;
}
}
vx->add_particle_out(particle);
}
out_ev.add_vertex(vx);
/// weights
- std::cout << event.variations().size() << std::endl;
EventParameters central_parameters;
if(event.variations().size() == 0){
- central_parameters = event.central();
+ central_parameters = event.central();
}
else{
- central_parameters = event.variations(weight_index);
+ central_parameters = event.variations(weight_index);
}
out_ev.weights().push_back(central_parameters.weight);
for(auto const & var: event.variations()){
out_ev.weights().push_back(var.weight);
}
- /// @TODO add name list
-
- #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
- std::cout << "Hep MC 3" << std::endl;
- #else // HepMC 2
- std::cout << "Hep MC 2" << std::endl;
- out_ev.set_signal_process_id(event.type()+1); // "+1": conistent with lhe
- out_ev.set_event_scale(central_parameters.mur); // event scale
- #endif
- /// cross section
- add_event(central_parameters.weight);
-
- // out_ev.set_event_number(genInfo_.event_count); /// event number
-
- out_ev.set_cross_section( cross_section() );
-
- /// @TODO add alphaQCD (need function) and alphaQED
- /// @TODO output pdf (currently not avaiable from event alone)
- return out_ev;
- }
+ /// @TODO add name list
+ /// cross section and weight
+ add_event(central_parameters.weight);
+
+ #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
+ out_ev.set_cross_section(
+ HepMC::make_shared<HepMC::GenCrossSection>(cross_section()) );
+ #else // HepMC 2
+ out_ev.set_cross_section( cross_section() );
+ out_ev.set_signal_process_id(event.type()+1); // "+1": conistent with lhe
+ out_ev.set_event_scale(central_parameters.mur);
+ #endif
+
+ out_ev.set_event_number(event_count_);
+
+
+ /// @TODO add alphaQCD (need function) and alphaQED
+ /// @TODO output pdf (currently not avaiable from event alone)
+ return out_ev;
+ }
#undef array_type
}
-#endif // HepMC
+#else // no HepMC
+namespace RHEJ{
+ HepMCInterface::HepMCInterface(LHEF::HEPRUP &&){
+ throw std::invalid_argument(
+ "Failed to create HepMC writer: "
+ "Reversed HEJ was built without HepMC support"
+ );
+ }
+}
+#endif
diff --git a/src/HepMCWriter.cc b/src/HepMCWriter.cc
index c2f003d..6c747d3 100644
--- a/src/HepMCWriter.cc
+++ b/src/HepMCWriter.cc
@@ -1,118 +1,105 @@
#include "RHEJ/HepMCWriter.hh"
#include <cassert>
#ifdef RHEJ_BUILD_WITH_HepMC_VERSION
#if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
#include "HepMC/WriterAscii.h"
#else
#include "HepMC/IO_GenEvent.h"
#endif
#include "HepMC/GenVertex.h"
#include "HepMC/GenParticle.h"
#include "RHEJ/utility.hh"
#include "RHEJ/Event.hh"
#include "RHEJ/exceptions.hh"
#include "RHEJ/HepMCInterface.hh"
namespace RHEJ{
-#if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
struct HepMCWriter::HepMCWriterImpl{
HepMCInterface hepmc_;
+ #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
+
HepMC::WriterAscii writer_;
HepMCWriterImpl(
std::string const & file, LHEF::HEPRUP && heprup
):
- hepmc_(heprup),
- writer_{file, hepmc_.runinfo}
+ hepmc_(std::move(heprup)),
+ writer_{file, HepMC::make_shared<HepMC::GenRunInfo>(hepmc_.init_runinfo())}
{}
- HepMCWriterImpl & operator=(HepMCWriterImpl const & other) = delete;
- HepMCWriterImpl(HepMCWriterImpl const & other) = delete;
- HepMCWriterImpl & operator=(HepMCWriterImpl && other) = delete;
- HepMCWriterImpl(HepMCWriterImpl && other) = delete;
-
~HepMCWriterImpl(){
writer_.close();
}
- void write(Event const & ev){
- auto out_ev = hepmc_(ev);
- writer_.write_event(out_ev);
- }
- };
-
- void HepMCWriter::HepMCWriterImplDeleter::operator()(HepMCWriterImpl* p) {
- delete p;
- }
-
-#else // HepMC 2
-
- struct HepMCWriter::HepMCWriterImpl{
+ #else // HepMC 2
HepMC::IO_GenEvent writer_;
- HepMCInterface hepmc_;
HepMCWriterImpl(
std::string const & file, LHEF::HEPRUP && heprup
):
- writer_{file},
- hepmc_(heprup)
+ hepmc_(std::move(heprup)),
+ writer_{file}
{}
+ #endif
HepMCWriterImpl & operator=(HepMCWriterImpl const & other) = delete;
HepMCWriterImpl(HepMCWriterImpl const & other) = delete;
HepMCWriterImpl & operator=(HepMCWriterImpl && other) = delete;
HepMCWriterImpl(HepMCWriterImpl && other) = delete;
void write(Event const & ev){
auto out_ev = hepmc_(ev);
+ #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
+ writer_.write_event(out_ev);
+ #else // HepMC 2
+ // auto hepmc_.init_runinfo();
writer_.write_event(&out_ev);
+ #endif
}
};
void HepMCWriter::HepMCWriterImplDeleter::operator()(HepMCWriterImpl* p) {
delete p;
}
-#endif // HepMC 2
-
HepMCWriter::HepMCWriter(std::string const & file, LHEF::HEPRUP heprup):
impl_{std::unique_ptr<HepMCWriterImpl, HepMCWriterImplDeleter>{
new HepMCWriterImpl(file, std::move(heprup))
}}
{}
void HepMCWriter::write(Event const & ev){
impl_->write(ev);
}
} // namespace RHEJ
#else // no HepMC
namespace RHEJ{
class HepMCWriter::HepMCWriterImpl{};
HepMCWriter::HepMCWriter(std::string const &, LHEF::HEPRUP){
throw std::invalid_argument(
"Failed to create HepMC writer: "
"Reversed HEJ was built without HepMC support"
);
}
void HepMCWriter::write(Event const &){
assert(false);
}
void HepMCWriter::HepMCWriterImplDeleter::operator()(HepMCWriterImpl* p) {
delete p;
}
}
#endif

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jan 21, 1:45 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4243513
Default Alt Text
(12 KB)

Event Timeline