cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
HepMC3Importer.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/GenEvent.h>
20
#include <HepMC3/Print.h>
21
#include <HepMC3/ReaderAscii.h>
22
#include <HepMC3/ReaderHEPEVT.h>
23
#include <HepMC3/Version.h>
24
25
#include <memory>
26
27
#include "
CepGen/Core/Exception.h
"
28
#include "
CepGen/EventFilter/EventImporter.h
"
29
#include "
CepGen/Modules/EventImporterFactory.h
"
30
#include "
CepGenAddOns/HepMC3Wrapper/HepMC3EventInterface.h
"
31
32
namespace
cepgen
{
36
template
<
typename
T>
37
class
HepMC3Importer
final :
public
EventImporter
{
38
public
:
40
explicit
HepMC3Importer
(
const
ParametersList
& params)
41
:
EventImporter
(params), reader_(new T(
steer
<std::string>(
"filename"
))) {
42
if
(!reader_)
43
throw
CG_FATAL
(
"HepMC3Importer"
) <<
"Failed to initialise HepMC reader."
;
44
CG_INFO
(
"HepMC3Importer"
) <<
"Interfacing module initialised "
45
<<
"for HepMC version "
<< HEPMC3_VERSION <<
" and HepMC ASCII file '"
46
<< steer<std::string>(
"filename"
) <<
"'."
;
47
}
48
49
bool
operator>>
(
Event
& evt)
override
{
50
HepMC3::GenEvent event;
51
if
(!reader_->read_event(event))
52
return
false
;
53
if
(!cross_section_retrieved_) {
54
if
(
const
auto
xsec = event.cross_section(); xsec)
55
setCrossSection
(
Value
{xsec->xsec(), xsec->xsec_err()});
56
cross_section_retrieved_ =
true
;
57
}
58
CG_DEBUG
(
"HepMC3Importer"
).log([&event](
auto
& log) { HepMC3::Print::content(log.stream(), event); });
59
evt =
Event
(
static_cast<
const
HepMC3::CepGenEvent
&
>
(event));
60
return
true
;
61
}
62
63
static
ParametersDescription
description
() {
64
auto
desc =
EventImporter::description
();
65
desc.setDescription(
"HepMC3 ASCII file importer module"
);
66
desc.add<std::string>(
"filename"
,
"input.hepmc"
).setDescription(
"Input filename"
);
67
return
desc;
68
}
69
70
private
:
71
void
initialise()
override
{}
72
const
std::unique_ptr<T> reader_;
73
bool
cross_section_retrieved_{
false
};
74
};
75
}
// namespace cepgen
76
typedef
cepgen::HepMC3Importer<HepMC3::ReaderAscii>
HepMC3ImporterASCII
;
77
typedef
cepgen::HepMC3Importer<HepMC3::ReaderHEPEVT>
HepMC3ImporterHEPEVT
;
78
REGISTER_EVENT_IMPORTER
(
"hepmc"
,
HepMC3ImporterASCII
);
79
//REGISTER_EVENT_IMPORTER("hepevt", HepMC3ImporterHEPEVT); // HEPEVT input is still very shaky, disabling it by default
80
#if HEPMC3_VERSION_CODE >= 3001000
81
#include <HepMC3/ReaderAsciiHepMC2.h>
82
typedef
cepgen::HepMC3Importer<HepMC3::ReaderAsciiHepMC2>
HepMC3ImporterHepMC2;
83
REGISTER_EVENT_IMPORTER
(
"hepmc3_hepmc2"
, HepMC3ImporterHepMC2);
84
/*#if HEPMC3_VERSION_CODE >= 3002005 && HEPMC3_USE_COMPRESSION
85
#include <HepMC3/ReaderGZ.h>
86
typedef cepgen::HepMC3Importer<HepMC3::ReaderGZ<HepMC3::ReaderAscii> > HepMC3ImporterAsciiZ;
87
typedef cepgen::HepMC3Importer<HepMC3::ReaderGZ<HepMC3::ReaderHEPEVT> > HepMC3ImporterHEPEVTZ;
88
REGISTER_EVENT_IMPORTER("hepmc_z", HepMC3ImporterAsciiZ);
89
REGISTER_EVENT_IMPORTER("hepevt_z", HepMC3ImporterHEPEVTZ);
90
#endif*/
91
#endif
92
93
/*#ifdef HEPMC3_ROOTIO
94
#include <HepMC3/ReaderRoot.h>
95
#include <HepMC3/ReaderRootTree.h>
96
typedef cepgen::HepMC3Importer<HepMC3::ReaderRoot> HepMC3ImporterRoot;
97
typedef cepgen::HepMC3Importer<HepMC3::ReaderRootTree> HepMC3ImporterRootTree;
98
REGISTER_EVENT_IMPORTER("hepmc_root", HepMC3ImporterRoot);
99
REGISTER_EVENT_IMPORTER("hepmc_root_tree", HepMC3ImporterRootTree);
100
#endif*/
101
102
#ifdef HEPMC3_EXTRA_PLUGINS
103
#include <ConvertExample/include/ReaderDOT.h>
104
#include <ConvertExample/include/ReaderRootTreeOPAL.h>
105
typedef
cepgen::HepMC3Importer<HepMC3::ReaderDOT>
HepMC3ImporterDOT;
106
typedef
cepgen::HepMC3Importer<HepMC3::ReaderRootTreeOPAL>
HepMC3ImporterRootTreeOPAL;
107
REGISTER_EVENT_IMPORTER
(
"hepmc_dot"
, HepMC3ImporterDOT);
108
REGISTER_EVENT_IMPORTER
(
"hepmc_root_tree_opal"
, HepMC3ImporterRootTreeOPAL);
109
#endif
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
HepMC3EventInterface.h
HepMC3ImporterHEPEVT
cepgen::HepMC3Importer< HepMC3::ReaderHEPEVT > HepMC3ImporterHEPEVT
Definition
HepMC3Importer.cpp:77
HepMC3ImporterASCII
cepgen::HepMC3Importer< HepMC3::ReaderAscii > HepMC3ImporterASCII
Definition
HepMC3Importer.cpp:76
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
CG_INFO
#define CG_INFO(mod)
Definition
Message.h:216
HepMC3::CepGenEvent
Interfacing between CepGen and HepMC event definitions.
Definition
HepMC3EventInterface.h:35
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::HepMC3Importer
Handler for the HepMC file output.
Definition
HepMC3Importer.cpp:37
cepgen::HepMC3Importer::description
static ParametersDescription description()
Definition
HepMC3Importer.cpp:63
cepgen::HepMC3Importer::HepMC3Importer
HepMC3Importer(const ParametersList ¶ms)
Class constructor.
Definition
HepMC3Importer.cpp:40
cepgen::HepMC3Importer::operator>>
bool operator>>(Event &evt) override
Read the next event.
Definition
HepMC3Importer.cpp:49
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
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGenAddOns
HepMC3Wrapper
HepMC3Importer.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7