cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
LHEFHepMCImporter.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/LHEF.h>
20#include <HepMC3/Version.h>
21
22#include <memory>
23
25#include "CepGen/Event/Event.h"
29#include "CepGen/Utils/String.h"
31
32namespace cepgen {
36 class LHEFHepMCImporter final : public EventImporter {
37 public:
39 explicit LHEFHepMCImporter(const ParametersList& params) : EventImporter(params) {
40 if (const auto filename = steer<std::string>("filename"); !filename.empty()) {
41 try {
42 reader_.reset(new LHEF::Reader(filename));
43 } catch (std::runtime_error& err) {
44 throw CG_FATAL("LHEFHepMCImporter") << "Failed to load the LHEF file. Error:\n" << err.what();
45 }
46 CG_INFO("LHEFHepMCImporter") << "Interfacing module initialised "
47 << "for HepMC version " << HEPMC3_VERSION << " and LHEF file '" << filename
48 << "' with version " << reader_->version << ".";
49 } else
50 throw CG_FATAL("LHEFHepMCImporter") << "Failed to retrieve the file name from module builder attributes.";
51 }
52
54 auto desc = EventImporter::description();
55 desc.setDescription("HepMC3 LHEF file importer module");
56 desc.add<std::string>("filename", "input.lhef").setDescription("Input filename");
57 return desc;
58 }
59
60 bool operator>>(Event& evt) override {
61 if (!reader_->readEvent())
62 return false;
63 evt.clear();
64 const auto& hepeup = reader_->hepeup;
65 CG_DEBUG("LHEFHepMCImporter:next").log([&hepeup](auto& log) { hepeup.print(log.stream()); });
66 int id_ip1 = -1, id_ip2 = -1;
67 pdgid_t pdg_ip1{0}, pdg_ip2{0};
68 for (int i = 0; i < hepeup.NUP; ++i) {
69 Particle part;
71 part.setPdgId((long)hepeup.IDUP.at(i));
72 const auto& hepeup_mom = hepeup.PUP.at(i);
73 part.setMomentum(Momentum::fromPxPyPzE(hepeup_mom.at(0), hepeup_mom.at(1), hepeup_mom.at(2), hepeup_mom.at(3)),
74 false);
76 if (hepeup.ISTUP.at(i) == -9) {
78 if (part.momentum().pz() > 0) {
80 id_ip1 = i;
81 pdg_ip1 = hepeup.IDUP.at(i);
82 } else {
84 id_ip2 = i;
85 pdg_ip2 = hepeup.IDUP.at(i);
86 }
87 }
88 const auto& moth = hepeup.MOTHUP.at(i);
89 if (moth.first > 0)
90 part.addMother(evt[moth.first - 1]);
91 if (moth.second > 0)
92 part.addMother(evt[moth.second - 1]);
93 if (utils::contains(part.mothers(), id_ip1)) {
94 if (evt[Particle::Role::OutgoingBeam1].empty() && hepeup.IDUP.at(i) == (long)pdg_ip1)
96 else
98 }
99 if (utils::contains(part.mothers(), id_ip2)) {
100 if (evt[Particle::Role::OutgoingBeam2].empty() && hepeup.IDUP.at(i) == (long)pdg_ip2)
102 else
104 }
105 evt.addParticle(part);
106 }
107 return true;
108 }
109
110 private:
111 void initialise() override {
112 const auto& heprup = reader_->heprup;
113 CG_DEBUG("LHEFHepMCImporter").log([&heprup](auto& log) { heprup.print(log.stream()); });
114 setCrossSection(Value{heprup.XSECUP.at(0), heprup.XERRUP.at(0)});
115 }
116
117 std::unique_ptr<LHEF::Reader> reader_;
118 };
119} // namespace cepgen
120REGISTER_EVENT_IMPORTER("lhef_hepmc", LHEFHepMCImporter);
#define REGISTER_EVENT_IMPORTER(name, obj)
Add a generic import module definition to the factory.
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_DEBUG(mod)
Definition Message.h:220
#define CG_INFO(mod)
Definition Message.h:216
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
ParticleRef addParticle(Particle &part, bool replace=false)
Set the information on one particle in the process.
Definition Event.cpp:323
void clear()
Empty the whole event content.
Definition Event.cpp:90
HepMC3 handler for the LHEF file import.
static ParametersDescription description()
LHEFHepMCImporter(const ParametersList &params)
Class constructor.
bool operator>>(Event &evt) override
Read the next event.
double pz() const
Longitudinal momentum (in GeV)
Definition Momentum.h:120
static Momentum fromPxPyPzE(double px, double py, double pz, double e)
Build a 4-momentum from its four momentum and energy coordinates.
Definition Momentum.cpp:82
A description object for parameters collection.
Kinematic information for one particle.
Definition Particle.h:33
Momentum & momentum()
Retrieve the momentum object associated with this particle Retrieve the momentum object associated wi...
Definition Particle.h:123
Particle & setMomentum(const Momentum &, bool offshell=false)
Associate a momentum object to this particle.
Definition Particle.cpp:77
Particle & addMother(Particle &part)
Set the mother particle.
Definition Particle.cpp:47
@ PrimordialIncoming
Incoming beam particle.
@ FinalState
Stable, final state particle.
@ Propagator
Generic propagator.
ParticlesIds mothers() const
Identifier to the mother particles.
Definition Particle.h:144
Particle & setRole(const Role &role)
Definition Particle.h:90
@ IncomingBeam2
incoming beam particle
Definition Particle.h:53
@ Parton2
beam incoming parton
Definition Particle.h:59
@ OutgoingBeam1
outgoing beam state/particle
Definition Particle.h:54
@ IncomingBeam1
incoming beam particle
Definition Particle.h:52
@ OutgoingBeam2
outgoing beam state/particle
Definition Particle.h:55
@ Parton1
beam incoming parton
Definition Particle.h:58
@ CentralSystem
Central particles system.
Definition Particle.h:56
Particle & setStatus(Status status)
Definition Particle.h:96
Particle & setPdgId(pdgid_t pdg, short ch=0)
Set the PDG identifier (along with the particle's electric charge)
Definition Particle.cpp:93
bool contains(const std::vector< T > &coll, const T &item)
Check if a vector contains an item.
Definition Collections.h:47
Common namespace for this Monte Carlo generator.
unsigned long long pdgid_t
Alias for the integer-like particle PDG id.