diff --git a/include/HEJ/EventReader.hh b/include/HEJ/EventReader.hh index a9c623c..43c861f 100644 --- a/include/HEJ/EventReader.hh +++ b/include/HEJ/EventReader.hh @@ -1,55 +1,55 @@ /** \file * \brief Header file for event reader interface * * This header defines an abstract base class for reading events from files. * * \authors The HEJ collaboration (see AUTHORS for details) * \date 2019-2022 * \copyright GPLv2 or later */ #pragma once #include #include #include #include namespace LHEF { class HEPEUP; class HEPRUP; } namespace HEJ { //! Abstract base class for reading events from files struct EventReader { //! Read an event virtual bool read_event() = 0; //! Access header text virtual std::string const & header() const = 0; //! Access run information virtual LHEF::HEPRUP const & heprup() const = 0; //! Access last read event virtual LHEF::HEPEUP const & hepeup() const = 0; //! Guess number of events from header virtual std::optional number_events() const = 0; - virtual double scalefactor() { + virtual double scalefactor() const { return 1.; }; virtual ~EventReader() = default; }; //! Factory function for event readers /** * @param filename The name of the input file * @returns A pointer to an instance of an EventReader * for the input file */ std::unique_ptr make_reader(std::string const & filename); } // namespace HEJ diff --git a/include/HEJ/LesHouchesReader.hh b/include/HEJ/LesHouchesReader.hh index 087ac14..9f7cc31 100644 --- a/include/HEJ/LesHouchesReader.hh +++ b/include/HEJ/LesHouchesReader.hh @@ -1,88 +1,88 @@ /** \file * \brief Header file for reading events in the Les Houches Event File format. * * \authors The HEJ collaboration (see AUTHORS for details) * \date 2019-2022 * \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); //! Read an event bool read_event() override; //! 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; } std::optional number_events() const override { 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 { + double scalefactor() const override { if (generator_==Generator::Sherpa) { const std::size_t num_trials = std::accumulate( num_trials_.begin(), num_trials_.end(), 0 ); return 1./static_cast(num_trials); } else return 1.; } private: enum class Generator{ HEJ, HEJFOG, Sherpa, MG, unknown }; bool calculate_XSECUP() { return calculate_XSECUP_; } Generator get_generator( LHEF::HEPRUP const & heprup, std::string const & header ); istream stream_; LHEF::Reader reader_; std::vector num_trials_; Generator generator_; bool calculate_XSECUP_; }; } // namespace HEJ