cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
LHEFHepMCHandler.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 <sstream>
20
22#include "CepGen/Event/Event.h"
25#include "CepGen/Utils/Value.h"
26
27using namespace std; // account for improper scoping in following include
28#include <HepMC3/LHEF.h>
29
30namespace cepgen {
35 public:
36 explicit LHEFHepMCHandler(const ParametersList& params)
37 : EventExporter(params),
38 lhe_output_(new LHEF::Writer(steer<std::string>("filename"))),
39 compress_(steer<bool>("compress")) {}
40
42 auto desc = EventExporter::description();
43 desc.setDescription("HepMC 3-based LHEF output module");
44 desc.add<std::string>("filename", "output.lhe").setDescription("Output filename");
45 desc.add<bool>("compress", false);
46 return desc;
47 }
48
49 bool operator<<(const Event& cg_ev) override {
50 if (!header_initialised_) {
51 lhe_output_->init(); // ensure everything is properly parsed
52 header_initialised_ = true;
53 }
54 auto& hepeup = lhe_output_->hepeup;
55 hepeup.heprup = &lhe_output_->heprup;
56 hepeup.XWGTUP = 1.;
57 hepeup.XPDWUP = std::pair<double, double>(0., 0.);
58 hepeup.SCALUP = 0.;
59 hepeup.AQEDUP = cg_ev.metadata("alphaEM");
60 hepeup.AQCDUP = cg_ev.metadata("alphaS");
61 const auto cg_particles = compress_ ? cg_ev.compress().particles() : cg_ev.particles();
62 hepeup.resize(cg_particles.size());
63 for (unsigned short ip = 0; ip < hepeup.NUP; ++ip) {
64 const auto& cg_part = cg_particles.at(ip);
65 hepeup.IDUP[ip] = cg_part.integerPdgId(); // PDG id
66 hepeup.ISTUP[ip] = (short)cg_part.status(); // status code
67 hepeup.PUP[ip] = {cg_part.momentum().px(),
68 cg_part.momentum().py(),
69 cg_part.momentum().pz(),
70 cg_part.momentum().energy(),
71 cg_part.momentum().mass()};
72 hepeup.MOTHUP[ip] = {// mothers
73 cg_part.mothers().size() > 0 ? *cg_part.mothers().begin() + 1 : 0,
74 cg_part.mothers().size() > 1 ? *cg_part.mothers().rbegin() + 1 : 0};
75 hepeup.ICOLUP[ip] = {0, 0};
76 hepeup.VTIMUP[ip] = 0.; // invariant lifetime
77 hepeup.SPINUP[ip] = 0.;
78 }
79 lhe_output_->writeEvent();
80 return true;
81 }
82
83 void setCrossSection(const Value& cross_section) override {
84 lhe_output_->heprup.XSECUP[0] = (double)cross_section;
85 lhe_output_->heprup.XERRUP[0] = cross_section.uncertainty();
86 }
87
88 private:
89 void initialise() override {
90 lhe_output_->headerBlock() << "<!--\n" << banner() << "\n-->";
91 if (runParameters().hasProcess()) { // run information only specified if process (and kinematics) is specified
92 lhe_output_->heprup.IDBMUP = {(int)runParameters().kinematics().incomingBeams().positive().integerPdgId(),
94 lhe_output_->heprup.EBMUP = {(double)runParameters().kinematics().incomingBeams().positive().momentum().pz(),
96 }
97 lhe_output_->heprup.resize(1);
98 lhe_output_->heprup.XMAXUP[0] = 1.;
99 lhe_output_->heprup.LPRUP[0] = 1;
100 lhe_output_->heprup.XSECUP[0] = 0.; // placeholders
101 lhe_output_->heprup.XERRUP[0] = 0.;
102 }
103
104 const std::unique_ptr<LHEF::Writer> lhe_output_;
105 const bool compress_;
106 bool header_initialised_{false};
107 };
108} // namespace cepgen
109REGISTER_EXPORTER("lhef_hepmc", LHEFHepMCHandler);
#define REGISTER_EXPORTER(name, obj)
Add a generic export module definition to the factory.
spdgid_t integerPdgId() const
Beam particle PDG id Set the beam particle PDG id.
Definition Beam.h:47
const Momentum & momentum() const
Beam particle 4-momentum Set the beam particle 4-momentum.
Definition Beam.h:54
Output format handler for events export.
std::string banner(const std::string &prep="") const
Print a banner containing runtime parameters.
const RunParameters & runParameters() const
List of run parameters.
Container for the information on the in- and outgoing particles' kinematics.
Definition Event.h:28
Event compress() const
Compress the event record.
Definition Event.cpp:115
Particles particles() const
Vector of all particles in the event.
Definition Event.cpp:353
EventMetadata metadata
List of auxiliary information.
Definition Event.h:136
const Beam & positive() const
Reference to the positive-z beam information.
const Beam & negative() const
Reference to the negative-z beam information.
IncomingBeams & incomingBeams()
Beam/primary particle kinematics.
Definition Kinematics.h:36
Handler for the LHE file output.
LHEFHepMCHandler(const ParametersList &params)
static ParametersDescription description()
bool operator<<(const Event &cg_ev) override
Writer operator.
void setCrossSection(const Value &cross_section) override
Specify the cross section value, in pb.
double pz() const
Longitudinal momentum (in GeV)
Definition Momentum.h:120
A description object for parameters collection.
const Kinematics & kinematics() const
Events kinematics for phase space definition.
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.