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
24
#include "
CepGen/Core/Exception.h
"
25
#include "
CepGen/Event/Event.h
"
26
#include "
CepGen/EventFilter/EventImporter.h
"
27
#include "
CepGen/Modules/EventImporterFactory.h
"
28
#include "
CepGen/Utils/Collections.h
"
29
#include "
CepGen/Utils/String.h
"
30
#include "
CepGenAddOns/HepMC3Wrapper/HepMC3EventInterface.h
"
31
32
namespace
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
53
static
ParametersDescription
description
() {
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;
70
part.
setRole
(
Particle::Role::CentralSystem
);
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
);
75
part.
setStatus
(hepeup.ISTUP.at(i) < 0 ?
Particle::Status::Propagator
:
Particle::Status::FinalState
);
76
if
(hepeup.ISTUP.at(i) == -9) {
77
part.
setStatus
(
Particle::Status::PrimordialIncoming
);
78
if
(part.
momentum
().
pz
() > 0) {
79
part.
setRole
(
Particle::Role::IncomingBeam1
);
80
id_ip1 = i;
81
pdg_ip1 = hepeup.IDUP.at(i);
82
}
else
{
83
part.
setRole
(
Particle::Role::IncomingBeam2
);
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)
95
part.
setRole
(
Particle::Role::OutgoingBeam1
);
96
else
97
part.
setRole
(
Particle::Role::Parton1
);
98
}
99
if
(
utils::contains
(part.
mothers
(), id_ip2)) {
100
if
(evt[
Particle::Role::OutgoingBeam2
].empty() && hepeup.IDUP.at(i) == (long)pdg_ip2)
101
part.
setRole
(
Particle::Role::OutgoingBeam2
);
102
else
103
part.
setRole
(
Particle::Role::Parton2
);
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
120
REGISTER_EVENT_IMPORTER
(
"lhef_hepmc"
, LHEFHepMCImporter);
Collections.h
EventImporterFactory.h
REGISTER_EVENT_IMPORTER
#define REGISTER_EVENT_IMPORTER(name, obj)
Add a generic import module definition to the factory.
Definition
EventImporterFactory.h:25
EventImporter.h
Event.h
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
HepMC3EventInterface.h
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
CG_INFO
#define CG_INFO(mod)
Definition
Message.h:216
String.h
cepgen::EventImporter
Base event importer module.
Definition
EventImporter.h:30
cepgen::EventImporter::description
static ParametersDescription description()
Definition
EventImporter.h:34
cepgen::EventImporter::setCrossSection
void setCrossSection(const Value &xsec)
Specify the process cross section and uncertainty, in pb.
Definition
EventImporter.h:45
cepgen::Event
Container for the information on the in- and outgoing particles' kinematics.
Definition
Event.h:28
cepgen::Event::addParticle
ParticleRef addParticle(Particle &part, bool replace=false)
Set the information on one particle in the process.
Definition
Event.cpp:323
cepgen::Event::clear
void clear()
Empty the whole event content.
Definition
Event.cpp:90
cepgen::LHEFHepMCImporter
HepMC3 handler for the LHEF file import.
Definition
LHEFHepMCImporter.cpp:36
cepgen::LHEFHepMCImporter::description
static ParametersDescription description()
Definition
LHEFHepMCImporter.cpp:53
cepgen::LHEFHepMCImporter::LHEFHepMCImporter
LHEFHepMCImporter(const ParametersList ¶ms)
Class constructor.
Definition
LHEFHepMCImporter.cpp:39
cepgen::LHEFHepMCImporter::operator>>
bool operator>>(Event &evt) override
Read the next event.
Definition
LHEFHepMCImporter.cpp:60
cepgen::Momentum::pz
double pz() const
Longitudinal momentum (in GeV)
Definition
Momentum.h:120
cepgen::Momentum::fromPxPyPzE
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
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::Particle
Kinematic information for one particle.
Definition
Particle.h:33
cepgen::Particle::momentum
Momentum & momentum()
Retrieve the momentum object associated with this particle Retrieve the momentum object associated wi...
Definition
Particle.h:123
cepgen::Particle::setMomentum
Particle & setMomentum(const Momentum &, bool offshell=false)
Associate a momentum object to this particle.
Definition
Particle.cpp:77
cepgen::Particle::addMother
Particle & addMother(Particle &part)
Set the mother particle.
Definition
Particle.cpp:47
cepgen::Particle::Status::PrimordialIncoming
@ PrimordialIncoming
Incoming beam particle.
cepgen::Particle::Status::FinalState
@ FinalState
Stable, final state particle.
cepgen::Particle::Status::Propagator
@ Propagator
Generic propagator.
cepgen::Particle::mothers
ParticlesIds mothers() const
Identifier to the mother particles.
Definition
Particle.h:144
cepgen::Particle::setRole
Particle & setRole(const Role &role)
Definition
Particle.h:90
cepgen::Particle::IncomingBeam2
@ IncomingBeam2
incoming beam particle
Definition
Particle.h:53
cepgen::Particle::Parton2
@ Parton2
beam incoming parton
Definition
Particle.h:59
cepgen::Particle::OutgoingBeam1
@ OutgoingBeam1
outgoing beam state/particle
Definition
Particle.h:54
cepgen::Particle::IncomingBeam1
@ IncomingBeam1
incoming beam particle
Definition
Particle.h:52
cepgen::Particle::OutgoingBeam2
@ OutgoingBeam2
outgoing beam state/particle
Definition
Particle.h:55
cepgen::Particle::Parton1
@ Parton1
beam incoming parton
Definition
Particle.h:58
cepgen::Particle::CentralSystem
@ CentralSystem
Central particles system.
Definition
Particle.h:56
cepgen::Particle::setStatus
Particle & setStatus(Status status)
Definition
Particle.h:96
cepgen::Particle::setPdgId
Particle & setPdgId(pdgid_t pdg, short ch=0)
Set the PDG identifier (along with the particle's electric charge)
Definition
Particle.cpp:93
cepgen::utils::contains
bool contains(const std::vector< T > &coll, const T &item)
Check if a vector contains an item.
Definition
Collections.h:47
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
cepgen::pdgid_t
unsigned long long pdgid_t
Alias for the integer-like particle PDG id.
Definition
ParticleProperties.h:26
CepGenAddOns
HepMC3Wrapper
LHEFHepMCImporter.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7