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
"
24
#include "
CepGen/EventFilter/EventExporter.h
"
25
#include "
CepGen/Modules/EventExporterFactory.h
"
26
#include "
CepGen/Utils/Message.h
"
27
#include "
CepGen/Utils/Value.h
"
28
#include "
CepGenAddOns/HepMC2Wrapper/HepMC2EventInterface.h
"
29
30
using namespace
HepMC
;
31
32
namespace
cepgen
{
37
template
<
typename
T>
38
class
HepMC2Handler
:
public
EventExporter
{
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
46
static
ParametersDescription
description
() {
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"
83
typedef
cepgen::HepMC2Handler<IO_GenEvent>
HepMC2GenEventHandler
;
84
typedef
cepgen::HepMC2Handler<IO_AsciiParticles>
HepMC2AsciiHandler
;
85
REGISTER_EXPORTER
(
"hepmc2"
,
HepMC2GenEventHandler
);
86
REGISTER_EXPORTER
(
"hepmc2_ascii"
,
HepMC2AsciiHandler
);
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
HepMC2EventInterface.h
HepMC2GenEventHandler
cepgen::HepMC2Handler< IO_GenEvent > HepMC2GenEventHandler
Definition
HepMC2Handler.cpp:83
HepMC2AsciiHandler
cepgen::HepMC2Handler< IO_AsciiParticles > HepMC2AsciiHandler
Definition
HepMC2Handler.cpp:84
Message.h
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
CG_INFO
#define CG_INFO(mod)
Definition
Message.h:216
Value.h
HepMC::CepGenEvent
Interfacing between CepGen and HepMC2 event definitions.
Definition
HepMC2EventInterface.h:34
cepgen::EventExporter
Output format handler for events export.
Definition
EventExporter.h:30
cepgen::EventExporter::event_num_
unsigned long long event_num_
Event index.
Definition
EventExporter.h:41
cepgen::Event
Container for the information on the in- and outgoing particles' kinematics.
Definition
Event.h:28
cepgen::HepMC2Handler
Handler for the HepMC file output.
Definition
HepMC2Handler.cpp:38
cepgen::HepMC2Handler::HepMC2Handler
HepMC2Handler(const ParametersList ¶ms)
Definition
HepMC2Handler.cpp:40
cepgen::HepMC2Handler::description
static ParametersDescription description()
Definition
HepMC2Handler.cpp:46
cepgen::HepMC2Handler::setCrossSection
void setCrossSection(const Value &cross_section) override
Specify the cross section value, in pb.
Definition
HepMC2Handler.cpp:65
cepgen::HepMC2Handler::operator<<
bool operator<<(const Event &cg_evt) override
Writer operator.
Definition
HepMC2Handler.cpp:54
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
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
HepMC
Definition
HepMC2EventInterface.cpp:36
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGenAddOns
HepMC2Wrapper
HepMC2Handler.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7