Page MenuHomeHEPForge

No OneTemporary

diff --git a/src/HepMCInterface.cc b/src/HepMCInterface.cc
index eb5612e..65783db 100644
--- a/src/HepMCInterface.cc
+++ b/src/HepMCInterface.cc
@@ -1,133 +1,134 @@
#include "RHEJ/HepMCInterface.hh"
#include <cassert>
#ifdef RHEJ_BUILD_WITH_HepMC_VERSION
#include "RHEJ/Event.hh"
#include "HepMC/GenEvent.h"
#include "HepMC/GenVertex.h"
#include "HepMC/GenParticle.h"
#include "HepMC/GenCrossSection.h"
#include "LHEF/LHEF.h"
namespace RHEJ{
namespace {
HepMC::FourVector to_FourVector(Sparticle const & sp){
return {sp.px(), sp.py(), sp.pz(), sp.E()};
}
constexpr int status_in = -1;
constexpr int status_decayed = 3;
constexpr int status_out = 1;
+
+ template<class HepMCClass, typename... Args>
+ auto make_ptr(Args&&... args){
+ #if RHEJ_BUILD_WITH_HepMC_VERSION >= 3
+ return HepMC::make_shared<HepMCClass>(std::forward<Args>(args)...);
+ #else
+ return new HepMCClass(std::forward<Args>(args)...);
+ #endif
+ }
} // namespace anonymous
HepMCInterface::HepMCInterface():
event_count_(0.), tot_weight_(0.), tot_weight2_(0.)
{}
void HepMCInterface::add_weight(double const wt){
++event_count_;
tot_weight_ += wt;
tot_weight2_ += wt * wt;
}
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;
}
-#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)();
+ auto vx = make_ptr<HepMC::GenVertex>();
for(auto const & in: event.incoming()){
vx->add_particle_in(
- array_type(HepMC::GenParticle)(
+ make_ptr<HepMC::GenParticle>(
to_FourVector(in), static_cast<int>(in.type), status_in
)
);
}
for(int i=0; i< (int) event.outgoing().size(); ++i){
auto const & out = event.outgoing()[i];
- auto particle = array_type(HepMC::GenParticle)(
+ auto particle = make_ptr<HepMC::GenParticle>(
to_FourVector(out), static_cast<int>(out.type), status_out
);
const int status = event.decays().count(i)?status_decayed:status_out;
particle->set_status(status);
if( status == status_decayed){
- auto vx_decay = array_type(HepMC::GenVertex)();
+ auto vx_decay = make_ptr<HepMC::GenVertex>();
vx_decay->add_particle_in(particle);
for( auto const & out: event.decays().at(i)){
vx_decay->add_particle_out(
- array_type(HepMC::GenParticle)(
+ make_ptr<HepMC::GenParticle>(
to_FourVector(out), static_cast<int>(out.type), status_out
)
);
}
out_ev.add_vertex(vx_decay);
}
vx->add_particle_out(particle);
}
out_ev.add_vertex(vx);
// weights
EventParameters central_parameters;
if(event.variations().size() == 0){
central_parameters = event.central();
}
else{
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 for weights
// cross section
add_weight(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
}
#else // no HepMC
namespace RHEJ{
HepMCInterface::HepMCInterface(){
throw std::invalid_argument(
"Failed to create HepMCInterface: "
"Reversed HEJ was built without HepMC support"
);
}
}
#endif

File Metadata

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

Event Timeline