cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
HepMC2Importer.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2022-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/GenEvent.h>
20
#include <HepMC/IO_GenEvent.h>
21
#include <HepMC/Version.h>
22
23
#include <memory>
24
25
#include "
CepGen/Core/Exception.h
"
26
#include "
CepGen/EventFilter/EventImporter.h
"
27
#include "
CepGen/Modules/EventImporterFactory.h
"
28
#include "
CepGenAddOns/HepMC2Wrapper/HepMC2EventInterface.h
"
29
30
namespace
cepgen
{
34
class
HepMC2Importer
final :
public
EventImporter
{
35
public
:
37
explicit
HepMC2Importer
(
const
ParametersList
& params)
38
:
EventImporter
(params), reader_(new
HepMC
::IO_GenEvent(
steer
<std::string>(
"filename"
), std::ios::in)) {
39
if
(!reader_)
40
throw
CG_FATAL
(
"HepMC2Importer"
) <<
"Failed to initialise HepMCv2 reader."
;
41
CG_INFO
(
"HepMC2Importer"
) <<
"Interfacing module initialised "
42
<<
"for HepMC version "
<< HEPMC_VERSION <<
" and HepMC ASCII file '"
43
<< steer<std::string>(
"filename"
) <<
"' with I/O state "
<< reader_->rdstate() <<
"."
;
44
}
45
46
bool
operator>>
(
Event
& evt)
override
{
47
HepMC::GenEvent event;
48
if
(!reader_->fill_next_event(&event))
49
return
false
;
50
if
(!cross_section_retrieved_) {
51
if
(
const
auto
xsec = event.cross_section(); xsec)
52
setCrossSection
(
Value
{xsec->cross_section(), xsec->cross_section_error()});
53
cross_section_retrieved_ =
true
;
54
}
55
CG_DEBUG
(
"HepMC2Importer"
).log([&event](
auto
& log) {
event
.print(log.stream()); });
56
evt =
Event
(
static_cast<
const
HepMC::CepGenEvent
&
>
(event));
57
return
true
;
58
}
59
60
static
ParametersDescription
description
() {
61
auto
desc =
EventImporter::description
();
62
desc.setDescription(
"HepMC2 ASCII file importer module"
);
63
desc.add<std::string>(
"filename"
,
"input.hepmc"
).setDescription(
"Input filename"
);
64
return
desc;
65
}
66
67
private
:
68
void
initialise()
override
{}
69
const
std::unique_ptr<HepMC::IO_GenEvent> reader_;
70
bool
cross_section_retrieved_{
false
};
71
};
72
}
// namespace cepgen
73
REGISTER_EVENT_IMPORTER
(
"hepmc2"
, HepMC2Importer);
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
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
HepMC2EventInterface.h
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
CG_INFO
#define CG_INFO(mod)
Definition
Message.h:216
HepMC::CepGenEvent
Interfacing between CepGen and HepMC2 event definitions.
Definition
HepMC2EventInterface.h:34
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::HepMC2Importer
Handler for the HepMC file output.
Definition
HepMC2Importer.cpp:34
cepgen::HepMC2Importer::description
static ParametersDescription description()
Definition
HepMC2Importer.cpp:60
cepgen::HepMC2Importer::HepMC2Importer
HepMC2Importer(const ParametersList ¶ms)
Class constructor.
Definition
HepMC2Importer.cpp:37
cepgen::HepMC2Importer::operator>>
bool operator>>(Event &evt) override
Read the next event.
Definition
HepMC2Importer.cpp:46
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
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
HepMC
Definition
HepMC2EventInterface.cpp:36
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGenAddOns
HepMC2Wrapper
HepMC2Importer.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7