cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
MSTWGrid.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2018-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 <cmath>
20
#include <fstream>
21
22
#include "
CepGen/Core/Exception.h
"
23
#include "
CepGen/Core/ParametersList.h
"
24
#include "
CepGen/Modules/StructureFunctionsFactory.h
"
25
#include "
CepGen/StructureFunctions/Parameterisation.h
"
26
#include "
CepGen/Utils/GridHandler.h
"
27
#include "
CepGen/Utils/String.h
"
28
30
namespace
mstw
{
32
class
Grid
final :
public
cepgen::strfun::Parameterisation
,
private
cepgen::GridHandler
<2, 2> {
33
public
:
35
explicit
Grid
(
const
cepgen::ParametersList
& params)
36
:
cepgen
::strfun::
Parameterisation
(params),
cepgen
::
GridHandler
<2, 2>(
cepgen
::GridType::logarithmic) {
37
{
// file readout part
38
const
auto
& grid_path =
steerPath
(
"gridPath"
);
39
std::ifstream file(grid_path, std::ios::binary | std::ios::in);
40
if
(!file.is_open())
41
throw
CG_FATAL
(
"MSTW"
) <<
"Failed to load grid file \""
<< grid_path <<
"\"!"
;
42
43
file.read(
reinterpret_cast<
char
*
>
(&header_),
sizeof
(
header_t
));
44
45
// first checks on the file header
46
47
if
(header_.
magic
!= GOOD_MAGIC)
48
throw
CG_FATAL
(
"MSTW"
) <<
"Wrong magic number retrieved: "
<< header_.
magic
<<
", expecting "
<< GOOD_MAGIC
49
<<
"."
;
50
51
if
(header_.
nucleon
!=
header_t::proton
)
52
throw
CG_FATAL
(
"MSTW"
) <<
"Only proton structure function grids can be retrieved for this purpose!"
;
53
54
// retrieve all points and evaluate grid boundaries
55
56
sfval_t
val{};
57
while
(file.read(
reinterpret_cast<
char
*
>
(&val),
sizeof
(
sfval_t
)))
58
insert
({val.xbj, val.q2}, {val.f2, val.fl});
59
file.close();
60
initialise
();
// initialise the grid after filling its nodes
61
}
62
const
auto
& bounds =
boundaries
();
63
CG_DEBUG
(
"MSTW"
) <<
"MSTW@"
<< header_.
order
<<
" grid evaluator built "
64
<<
"for "
<< header_.
nucleon
<<
" structure functions ("
<< header_.
cl
<<
")\n\t"
65
<<
"xBj in range ["
<< std::pow(10., bounds[0].
min
()) <<
":"
<< std::pow(10., bounds[0].
max
())
66
<<
"], Q² in range ["
<< std::pow(10., bounds[1].
min
()) <<
":"
<< std::pow(10., bounds[1].
max
())
67
<<
"]."
;
68
}
69
70
static
cepgen::ParametersDescription
description
() {
71
auto
desc = Parameterisation::description();
72
desc.setDescription(
"MSTW grid (perturbative)"
);
73
desc.add<std::string>(
"gridPath"
,
"mstw_sf_scan_nnlo.dat"
).setDescription(
"Path to the MSTW grid content"
);
74
return
desc;
75
}
76
78
struct
header_t
{
80
enum
order_t
:
unsigned
short
{
lo
= 0,
nlo
= 1,
nnlo
= 2 };
82
enum
cl_t
:
unsigned
short
{
cl68
= 0,
cl95
= 1 };
84
enum
nucleon_t
:
unsigned
short
{
proton
= 1,
neutron
= 2 };
85
unsigned
int
magic
;
86
order_t
order
;
87
cl_t
cl
;
88
nucleon_t
nucleon
;
89
};
91
struct
sfval_t
{
92
float
q2
{0.};
93
float
xbj
{0.};
94
double
f2
{0.};
95
double
fl
{0.};
96
};
97
99
void
eval
()
override
{
100
const
auto
& val =
cepgen::GridHandler<2, 2>::eval
({
args_
.
xbj
,
args_
.
q2
});
101
setF2
(val.at(0));
102
setFL
(val.at(1));
103
}
105
header_t
header
()
const
{
return
header_; }
106
107
//--- already retrieved from grid, so no need to recompute it
108
Grid
&
computeFL
(
double
,
double
)
override
{
return
*
this
; }
109
Grid
&
computeFL
(
double
,
double
,
double
)
override
{
return
*
this
; }
110
111
private
:
112
static
constexpr
unsigned
int
GOOD_MAGIC = 0x5754534d;
// MSTW in ASCII
113
114
header_t header_ = {};
115
};
116
118
std::ostream&
operator<<
(std::ostream& os,
const
Grid::sfval_t
& val) {
119
return
os <<
cepgen::utils::format
(
120
"xbj = %.4f\tQ² = %.5e GeV²\tF_2 = % .6e\tF_1 = % .6e"
, val.
xbj
, val.
q2
, val.
f2
, val.
fl
);
121
}
122
124
std::ostream&
operator<<
(std::ostream& os,
const
Grid::header_t::order_t
& order) {
125
switch
(order) {
126
case
Grid::header_t::lo
:
127
return
os <<
"LO"
;
128
case
Grid::header_t::nlo
:
129
return
os <<
"nLO"
;
130
case
Grid::header_t::nnlo
:
131
return
os <<
"nnLO"
;
132
}
133
return
os;
134
}
135
137
std::ostream&
operator<<
(std::ostream& os,
const
Grid::header_t::cl_t
& cl) {
138
switch
(cl) {
139
case
Grid::header_t::cl68
:
140
return
os <<
"68% C.L."
;
141
case
Grid::header_t::cl95
:
142
return
os <<
"95% C.L."
;
143
}
144
return
os;
145
}
146
148
std::ostream&
operator<<
(std::ostream& os,
const
Grid::header_t::nucleon_t
& nucl) {
149
switch
(nucl) {
150
case
Grid::header_t::proton
:
151
return
os <<
"proton"
;
152
case
Grid::header_t::neutron
:
153
return
os <<
"neutron"
;
154
}
155
return
os;
156
}
157
}
// namespace mstw
158
using
mstw::Grid
;
159
REGISTER_STRFUN
(
"MSTWGrid"
, 205,
Grid
);
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
GridHandler.h
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
ParametersList.h
String.h
StructureFunctionsFactory.h
REGISTER_STRFUN
#define REGISTER_STRFUN(name, id, obj)
Add a structure functions definition to the list of handled parameterisation.
Definition
StructureFunctionsFactory.h:25
Parameterisation.h
cepgen::GridHandler
A generic class for grid interpolation.
Definition
GridHandler.h:44
cepgen::GridHandler< 2, 2 >::initialise
void initialise()
Initialise the grid and all useful interpolators/accelerators.
Definition
GridHandler.cpp:150
cepgen::GridHandler< 2, 2 >::insert
void insert(coord_t coord, values_t value)
Insert a new value in the grid.
Definition
GridHandler.cpp:129
cepgen::GridHandler< 2, 2 >::boundaries
std::array< Limits, D > boundaries() const
Grid boundaries (collection of (min,max))
Definition
GridHandler.cpp:268
cepgen::GridHandler< 2, 2 >::max
std::array< double, D > max() const
Highest bound of the grid coordinates.
Definition
GridHandler.cpp:288
cepgen::GridHandler::eval
values_t eval(coord_t in_coords) const
Interpolate a point to a given coordinate.
Definition
GridHandler.cpp:37
cepgen::GridHandler< 2, 2 >::min
std::array< double, D > min() const
Lowest bound of the grid coordinates.
Definition
GridHandler.cpp:277
cepgen::GridHandler< 2, 2 >::GridHandler
GridHandler(const GridType &grid_type)
Build a grid interpolator from a grid type.
Definition
GridHandler.cpp:31
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::Steerable::steerPath
std::string steerPath(const std::string &key) const
Retrieve a path from common search paths.
Definition
Steerable.cpp:30
cepgen::strfun::Parameterisation
Base object for the parameterisation of nucleon structure functions.
Definition
Parameterisation.h:30
cepgen::strfun::Parameterisation::args_
Arguments args_
Last couple computed.
Definition
Parameterisation.h:109
cepgen::strfun::Parameterisation::setF2
Parameterisation & setF2(double f2)
Definition
Parameterisation.cpp:83
cepgen::strfun::Parameterisation::Parameterisation
Parameterisation(const ParametersList &)
Definition
Parameterisation.cpp:27
cepgen::strfun::Parameterisation::setFL
Parameterisation & setFL(double fl)
Definition
Parameterisation.cpp:88
mstw::Grid
A grid interpolator.
Definition
MSTWGrid.cpp:32
mstw::Grid::header
header_t header() const
Retrieve the grid's header information.
Definition
MSTWGrid.cpp:105
mstw::Grid::sfval_t::xbj
float xbj
Bjorken's scaling variable.
Definition
MSTWGrid.cpp:93
mstw::Grid::sfval_t::fl
double fl
Longitudinal structure function value.
Definition
MSTWGrid.cpp:95
mstw::Grid::computeFL
Grid & computeFL(double, double) override
Compute the longitudinal structure function for a given point.
Definition
MSTWGrid.cpp:108
mstw::Grid::description
static cepgen::ParametersDescription description()
Definition
MSTWGrid.cpp:70
mstw::Grid::Grid
Grid(const cepgen::ParametersList ¶ms)
Grid MSTW structure functions evaluator.
Definition
MSTWGrid.cpp:35
mstw::Grid::sfval_t::f2
double f2
Transverse structure function value.
Definition
MSTWGrid.cpp:94
mstw::Grid::eval
void eval() override
Compute the structure functions at a given .
Definition
MSTWGrid.cpp:99
mstw::Grid::computeFL
Grid & computeFL(double, double, double) override
Compute the longitudinal structure function for a given point.
Definition
MSTWGrid.cpp:109
mstw::Grid::sfval_t::q2
float q2
four-momentum transfer, in GeV
Definition
MSTWGrid.cpp:92
mstw::Grid::sfval_t
Structure functions value at a given coordinate.
Definition
MSTWGrid.cpp:91
cepgen::utils::format
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition
String.h:61
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
mstw
Martin-Stirling-Thorne-Watt PDFs structure functions.
Definition
MSTWGrid.cpp:30
mstw::operator<<
std::ostream & operator<<(std::ostream &os, const Grid::sfval_t &val)
Human-readable description of a values point.
Definition
MSTWGrid.cpp:118
cepgen::strfun::Parameterisation::Arguments::xbj
double xbj
Definition
Parameterisation.h:60
cepgen::strfun::Parameterisation::Arguments::q2
double q2
Definition
Parameterisation.h:60
mstw::Grid::header_t
Grid header information as parsed from the file.
Definition
MSTWGrid.cpp:78
mstw::Grid::header_t::cl_t
cl_t
Confidence level.
Definition
MSTWGrid.cpp:82
mstw::Grid::header_t::cl68
@ cl68
Definition
MSTWGrid.cpp:82
mstw::Grid::header_t::cl95
@ cl95
Definition
MSTWGrid.cpp:82
mstw::Grid::header_t::nucleon
nucleon_t nucleon
Type of nucleon interpolated.
Definition
MSTWGrid.cpp:88
mstw::Grid::header_t::cl
cl_t cl
Confidence level.
Definition
MSTWGrid.cpp:87
mstw::Grid::header_t::order
order_t order
Interpolation order.
Definition
MSTWGrid.cpp:86
mstw::Grid::header_t::order_t
order_t
Interpolation order.
Definition
MSTWGrid.cpp:80
mstw::Grid::header_t::lo
@ lo
Definition
MSTWGrid.cpp:80
mstw::Grid::header_t::nlo
@ nlo
Definition
MSTWGrid.cpp:80
mstw::Grid::header_t::nnlo
@ nnlo
Definition
MSTWGrid.cpp:80
mstw::Grid::header_t::magic
unsigned int magic
Grid file magic number.
Definition
MSTWGrid.cpp:85
mstw::Grid::header_t::nucleon_t
nucleon_t
Type of nucleon interpolated.
Definition
MSTWGrid.cpp:84
mstw::Grid::header_t::neutron
@ neutron
Definition
MSTWGrid.cpp:84
mstw::Grid::header_t::proton
@ proton
Definition
MSTWGrid.cpp:84
CepGen
StructureFunctions
MSTWGrid.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7