cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
HepMC2Handler.cpp
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2016-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 <HepMC/Version.h>
20
21#include <memory>
22
23#include "CepGen/Event/Event.h"
27#include "CepGen/Utils/Value.h"
29
30using namespace HepMC;
31
32namespace cepgen {
37 template <typename T>
39 public:
40 explicit HepMC2Handler(const ParametersList& params)
41 : EventExporter(params), output_(new T(steer<std::string>("filename").c_str())), xs_(new GenCrossSection) {
42 CG_INFO("HepMC") << "Interfacing module initialised "
43 << "for HepMC version " << HEPMC_VERSION << ".";
44 }
45
47 auto desc = EventExporter::description();
48 desc.setDescription("HepMC2 ASCII file output module");
49 desc.add<std::string>("filename", "output.hepmc").setDescription("Output filename");
50 return desc;
51 }
52
54 bool operator<<(const Event& cg_evt) override {
55 CepGenEvent event(cg_evt);
56 event.set_cross_section(*xs_);
57 event.set_event_number(event_num_++);
58 output_->write_event(&event);
59 CG_DEBUG("HepMC2Handler").log([&event](auto& log) {
60 log << "\n";
61 event.print(log.stream());
62 });
63 return true;
64 }
65 void setCrossSection(const Value& cross_section) override {
66 xs_->set_cross_section((double)cross_section, cross_section.uncertainty());
67 }
68
69 private:
70 void initialise() override {}
71
72 const std::unique_ptr<T> output_;
73 const std::shared_ptr<GenCrossSection> xs_;
74 };
75} // namespace cepgen
76
77//----------------------------------------------------------------------
78// Defining the various templated plugins made available by this
79// specific version of HepMC (v2 and below)
80//----------------------------------------------------------------------
81#include "HepMC/IO_AsciiParticles.h"
82#include "HepMC/IO_GenEvent.h"
#define REGISTER_EXPORTER(name, obj)
Add a generic export module definition to the factory.
cepgen::HepMC2Handler< IO_GenEvent > HepMC2GenEventHandler
cepgen::HepMC2Handler< IO_AsciiParticles > HepMC2AsciiHandler
#define CG_DEBUG(mod)
Definition Message.h:220
#define CG_INFO(mod)
Definition Message.h:216
Interfacing between CepGen and HepMC2 event definitions.
Output format handler for events export.
unsigned long long event_num_
Event index.
Container for the information on the in- and outgoing particles' kinematics.
Definition Event.h:28
Handler for the HepMC file output.
HepMC2Handler(const ParametersList &params)
static ParametersDescription description()
void setCrossSection(const Value &cross_section) override
Specify the cross section value, in pb.
bool operator<<(const Event &cg_evt) override
Writer operator.
A description object for parameters collection.
static ParametersDescription description()
Description of all object parameters.
Definition Steerable.cpp:42
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
double uncertainty() const
Absolute uncertainty around the central value.
Definition Value.h:35
Common namespace for this Monte Carlo generator.