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
21
#include "
CepGen/Core/RunParameters.h
"
22
#include "
CepGen/Event/Event.h
"
23
#include "
CepGen/EventFilter/EventExporter.h
"
24
#include "
CepGen/Modules/EventExporterFactory.h
"
25
#include "
CepGen/Utils/Value.h
"
26
27
using namespace
std;
// account for improper scoping in following include
28
#include <HepMC3/LHEF.h>
29
30
namespace
cepgen
{
34
class
LHEFHepMCHandler
:
public
EventExporter
{
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
41
static
ParametersDescription
description
() {
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
(),
93
(int)
runParameters
().
kinematics
().
incomingBeams
().
negative
().
integerPdgId
()};
94
lhe_output_->heprup.EBMUP = {(double)
runParameters
().
kinematics
().
incomingBeams
().
positive
().
momentum
().
pz
(),
95
(double)
runParameters
().
kinematics
().
incomingBeams
().
negative
().
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
109
REGISTER_EXPORTER
(
"lhef_hepmc"
, LHEFHepMCHandler);
EventExporterFactory.h
REGISTER_EXPORTER
#define REGISTER_EXPORTER(name, obj)
Add a generic export module definition to the factory.
Definition
EventExporterFactory.h:25
EventExporter.h
Event.h
RunParameters.h
Value.h
cepgen::Beam::integerPdgId
spdgid_t integerPdgId() const
Beam particle PDG id Set the beam particle PDG id.
Definition
Beam.h:47
cepgen::Beam::momentum
const Momentum & momentum() const
Beam particle 4-momentum Set the beam particle 4-momentum.
Definition
Beam.h:54
cepgen::EventExporter
Output format handler for events export.
Definition
EventExporter.h:30
cepgen::EventExporter::banner
std::string banner(const std::string &prep="") const
Print a banner containing runtime parameters.
Definition
EventExporter.cpp:32
cepgen::EventHandler::runParameters
const RunParameters & runParameters() const
List of run parameters.
Definition
EventHandler.cpp:44
cepgen::Event
Container for the information on the in- and outgoing particles' kinematics.
Definition
Event.h:28
cepgen::Event::compress
Event compress() const
Compress the event record.
Definition
Event.cpp:115
cepgen::Event::particles
Particles particles() const
Vector of all particles in the event.
Definition
Event.cpp:353
cepgen::Event::metadata
EventMetadata metadata
List of auxiliary information.
Definition
Event.h:136
cepgen::IncomingBeams::positive
const Beam & positive() const
Reference to the positive-z beam information.
Definition
IncomingBeams.h:38
cepgen::IncomingBeams::negative
const Beam & negative() const
Reference to the negative-z beam information.
Definition
IncomingBeams.h:40
cepgen::Kinematics::incomingBeams
IncomingBeams & incomingBeams()
Beam/primary particle kinematics.
Definition
Kinematics.h:36
cepgen::LHEFHepMCHandler
Handler for the LHE file output.
Definition
LHEFHepMCHandler.cpp:34
cepgen::LHEFHepMCHandler::LHEFHepMCHandler
LHEFHepMCHandler(const ParametersList ¶ms)
Definition
LHEFHepMCHandler.cpp:36
cepgen::LHEFHepMCHandler::description
static ParametersDescription description()
Definition
LHEFHepMCHandler.cpp:41
cepgen::LHEFHepMCHandler::operator<<
bool operator<<(const Event &cg_ev) override
Writer operator.
Definition
LHEFHepMCHandler.cpp:49
cepgen::LHEFHepMCHandler::setCrossSection
void setCrossSection(const Value &cross_section) override
Specify the cross section value, in pb.
Definition
LHEFHepMCHandler.cpp:83
cepgen::Momentum::pz
double pz() const
Longitudinal momentum (in GeV)
Definition
Momentum.h:120
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::RunParameters::kinematics
const Kinematics & kinematics() const
Events kinematics for phase space definition.
Definition
RunParameters.cpp:125
cepgen::Steerable::description
static ParametersDescription description()
Description of all object parameters.
Definition
Steerable.cpp:42
cepgen::Steerable::steer
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition
Steerable.h:39
cepgen::Value
A scalar value with its uncertainty.
Definition
Value.h:26
cepgen::Value::uncertainty
double uncertainty() const
Absolute uncertainty around the central value.
Definition
Value.h:35
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGenAddOns
HepMC3Wrapper
LHEFHepMCHandler.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7