diff --git a/include/HEJ/LesHouchesReader.hh b/include/HEJ/LesHouchesReader.hh index 8a896e0..2987c4d 100644 --- a/include/HEJ/LesHouchesReader.hh +++ b/include/HEJ/LesHouchesReader.hh @@ -1,112 +1,112 @@ /** \file * \brief Header file for reading events in the Les Houches Event File format. * * \authors The HEJ collaboration (see AUTHORS for details) * \date 2019-2020 * \copyright GPLv2 or later */ #pragma once #include #include #include "LHEF/LHEF.h" #include "HEJ/EventReader.hh" #include "HEJ/stream.hh" namespace HEJ { //! Class for reading events from a file in the Les Houches Event File format class LesHouchesReader : public EventReader{ public: //! Contruct object reading from the given file explicit LesHouchesReader(std::string const & filename): stream_{filename}, reader_{stream_} { // always use the newest LHE version reader_.heprup.version = LHEF::HEPRUP().version; - } + } //! Read an event bool read_event() override { return reader_.readEvent(); } //! Access header text std::string const & header() const override { return reader_.headerBlock; } //! Access run information LHEF::HEPRUP const & heprup() const override { return reader_.heprup; } //! Access last read event LHEF::HEPEUP const & hepeup() const override { return reader_.hepeup; } private: istream stream_; LHEF::Reader reader_; protected: //! Underlying reader LHEF::Reader & reader(){ return reader_; } }; /** * @brief Les Houches Event file reader for LHE files created by Sherpa * @details In Sherpa the cross section is given by * sum(weights)/(number of trials). This EventReader converts the * weights such that cross section=sum(weights) * @note Reading from a pipe is not possible! */ class HEJLHEReader : public LesHouchesReader{ public: //! Inialise Reader for a Sherpa LHE file explicit HEJLHEReader(std::string const & filename); bool read_event() override; std::optional number_events() const override { if (Generator==generator::Sherpa) { return num_events_; } else { std::size_t start = header().rfind("Number of Events"); start = header().find_first_of("123456789", start); if(start == std::string::npos) { return {}; } const std::size_t end = header().find_first_not_of("0123456789", start); return std::stoi(header().substr(start, end - start)); } } double scalefactor() override { if (Generator==HEJ::generator::Sherpa) { int num_trials=std::accumulate(num_trials_.begin(),num_trials_.end(),0); return 1./double(num_trials); } else return 1; } bool get_CalcXSECUP() { return CalculateXSECUP; } private: std::vector num_trials_; size_t num_events_; generator Generator; bool CalculateXSECUP; }; } // namespace HEJ