cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
HepMC3Importer.cpp
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2024 Laurent Forthomme
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <HepMC3/GenEvent.h>
20#include <HepMC3/Print.h>
21#include <HepMC3/ReaderAscii.h>
22#include <HepMC3/ReaderHEPEVT.h>
23#include <HepMC3/Version.h>
24
25#include <memory>
26
31
32namespace cepgen {
36 template <typename T>
37 class HepMC3Importer final : public EventImporter {
38 public:
40 explicit HepMC3Importer(const ParametersList& params)
41 : EventImporter(params), reader_(new T(steer<std::string>("filename"))) {
42 if (!reader_)
43 throw CG_FATAL("HepMC3Importer") << "Failed to initialise HepMC reader.";
44 CG_INFO("HepMC3Importer") << "Interfacing module initialised "
45 << "for HepMC version " << HEPMC3_VERSION << " and HepMC ASCII file '"
46 << steer<std::string>("filename") << "'.";
47 }
48
49 bool operator>>(Event& evt) override {
50 HepMC3::GenEvent event;
51 if (!reader_->read_event(event))
52 return false;
53 if (!cross_section_retrieved_) {
54 if (const auto xsec = event.cross_section(); xsec)
55 setCrossSection(Value{xsec->xsec(), xsec->xsec_err()});
56 cross_section_retrieved_ = true;
57 }
58 CG_DEBUG("HepMC3Importer").log([&event](auto& log) { HepMC3::Print::content(log.stream(), event); });
59 evt = Event(static_cast<const HepMC3::CepGenEvent&>(event));
60 return true;
61 }
62
64 auto desc = EventImporter::description();
65 desc.setDescription("HepMC3 ASCII file importer module");
66 desc.add<std::string>("filename", "input.hepmc").setDescription("Input filename");
67 return desc;
68 }
69
70 private:
71 void initialise() override {}
72 const std::unique_ptr<T> reader_;
73 bool cross_section_retrieved_{false};
74 };
75} // namespace cepgen
79//REGISTER_EVENT_IMPORTER("hepevt", HepMC3ImporterHEPEVT); // HEPEVT input is still very shaky, disabling it by default
80#if HEPMC3_VERSION_CODE >= 3001000
81#include <HepMC3/ReaderAsciiHepMC2.h>
82typedef cepgen::HepMC3Importer<HepMC3::ReaderAsciiHepMC2> HepMC3ImporterHepMC2;
83REGISTER_EVENT_IMPORTER("hepmc3_hepmc2", HepMC3ImporterHepMC2);
84/*#if HEPMC3_VERSION_CODE >= 3002005 && HEPMC3_USE_COMPRESSION
85#include <HepMC3/ReaderGZ.h>
86typedef cepgen::HepMC3Importer<HepMC3::ReaderGZ<HepMC3::ReaderAscii> > HepMC3ImporterAsciiZ;
87typedef cepgen::HepMC3Importer<HepMC3::ReaderGZ<HepMC3::ReaderHEPEVT> > HepMC3ImporterHEPEVTZ;
88REGISTER_EVENT_IMPORTER("hepmc_z", HepMC3ImporterAsciiZ);
89REGISTER_EVENT_IMPORTER("hepevt_z", HepMC3ImporterHEPEVTZ);
90#endif*/
91#endif
92
93/*#ifdef HEPMC3_ROOTIO
94#include <HepMC3/ReaderRoot.h>
95#include <HepMC3/ReaderRootTree.h>
96typedef cepgen::HepMC3Importer<HepMC3::ReaderRoot> HepMC3ImporterRoot;
97typedef cepgen::HepMC3Importer<HepMC3::ReaderRootTree> HepMC3ImporterRootTree;
98REGISTER_EVENT_IMPORTER("hepmc_root", HepMC3ImporterRoot);
99REGISTER_EVENT_IMPORTER("hepmc_root_tree", HepMC3ImporterRootTree);
100#endif*/
101
102#ifdef HEPMC3_EXTRA_PLUGINS
103#include <ConvertExample/include/ReaderDOT.h>
104#include <ConvertExample/include/ReaderRootTreeOPAL.h>
105typedef cepgen::HepMC3Importer<HepMC3::ReaderDOT> HepMC3ImporterDOT;
106typedef cepgen::HepMC3Importer<HepMC3::ReaderRootTreeOPAL> HepMC3ImporterRootTreeOPAL;
107REGISTER_EVENT_IMPORTER("hepmc_dot", HepMC3ImporterDOT);
108REGISTER_EVENT_IMPORTER("hepmc_root_tree_opal", HepMC3ImporterRootTreeOPAL);
109#endif
#define REGISTER_EVENT_IMPORTER(name, obj)
Add a generic import module definition to the factory.
#define CG_FATAL(mod)
Definition Exception.h:61
cepgen::HepMC3Importer< HepMC3::ReaderHEPEVT > HepMC3ImporterHEPEVT
cepgen::HepMC3Importer< HepMC3::ReaderAscii > HepMC3ImporterASCII
#define CG_DEBUG(mod)
Definition Message.h:220
#define CG_INFO(mod)
Definition Message.h:216
Interfacing between CepGen and HepMC event definitions.
Base event importer module.
static ParametersDescription description()
void setCrossSection(const Value &xsec)
Specify the process cross section and uncertainty, in pb.
Container for the information on the in- and outgoing particles' kinematics.
Definition Event.h:28
Handler for the HepMC file output.
static ParametersDescription description()
HepMC3Importer(const ParametersList &params)
Class constructor.
bool operator>>(Event &evt) override
Read the next event.
A description object for parameters collection.
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition Steerable.h:39
A scalar value with its uncertainty.
Definition Value.h:26
Common namespace for this Monte Carlo generator.