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
27#include "CepGen/Utils/String.h"
28
30namespace 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
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;
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) {
127 return os << "LO";
129 return os << "nLO";
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) {
140 return os << "68% C.L.";
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) {
151 return os << "proton";
153 return os << "neutron";
154 }
155 return os;
156 }
157} // namespace mstw
158using mstw::Grid;
159REGISTER_STRFUN("MSTWGrid", 205, Grid);
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_DEBUG(mod)
Definition Message.h:220
#define REGISTER_STRFUN(name, id, obj)
Add a structure functions definition to the list of handled parameterisation.
A generic class for grid interpolation.
Definition GridHandler.h:44
void initialise()
Initialise the grid and all useful interpolators/accelerators.
void insert(coord_t coord, values_t value)
Insert a new value in the grid.
std::array< Limits, D > boundaries() const
Grid boundaries (collection of (min,max))
std::array< double, D > max() const
Highest bound of the grid coordinates.
values_t eval(coord_t in_coords) const
Interpolate a point to a given coordinate.
std::array< double, D > min() const
Lowest bound of the grid coordinates.
GridHandler(const GridType &grid_type)
Build a grid interpolator from a grid type.
A description object for parameters collection.
std::string steerPath(const std::string &key) const
Retrieve a path from common search paths.
Definition Steerable.cpp:30
Base object for the parameterisation of nucleon structure functions.
Arguments args_
Last couple computed.
Parameterisation & setF2(double f2)
Parameterisation(const ParametersList &)
Parameterisation & setFL(double fl)
A grid interpolator.
Definition MSTWGrid.cpp:32
header_t header() const
Retrieve the grid's header information.
Definition MSTWGrid.cpp:105
float xbj
Bjorken's scaling variable.
Definition MSTWGrid.cpp:93
double fl
Longitudinal structure function value.
Definition MSTWGrid.cpp:95
Grid & computeFL(double, double) override
Compute the longitudinal structure function for a given point.
Definition MSTWGrid.cpp:108
static cepgen::ParametersDescription description()
Definition MSTWGrid.cpp:70
Grid(const cepgen::ParametersList &params)
Grid MSTW structure functions evaluator.
Definition MSTWGrid.cpp:35
double f2
Transverse structure function value.
Definition MSTWGrid.cpp:94
void eval() override
Compute the structure functions at a given .
Definition MSTWGrid.cpp:99
Grid & computeFL(double, double, double) override
Compute the longitudinal structure function for a given point.
Definition MSTWGrid.cpp:109
float q2
four-momentum transfer, in GeV
Definition MSTWGrid.cpp:92
Structure functions value at a given coordinate.
Definition MSTWGrid.cpp:91
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition String.h:61
Common namespace for this Monte Carlo generator.
Martin-Stirling-Thorne-Watt PDFs structure functions.
Definition MSTWGrid.cpp:30
std::ostream & operator<<(std::ostream &os, const Grid::sfval_t &val)
Human-readable description of a values point.
Definition MSTWGrid.cpp:118
Grid header information as parsed from the file.
Definition MSTWGrid.cpp:78
cl_t
Confidence level.
Definition MSTWGrid.cpp:82
nucleon_t nucleon
Type of nucleon interpolated.
Definition MSTWGrid.cpp:88
cl_t cl
Confidence level.
Definition MSTWGrid.cpp:87
order_t order
Interpolation order.
Definition MSTWGrid.cpp:86
order_t
Interpolation order.
Definition MSTWGrid.cpp:80
unsigned int magic
Grid file magic number.
Definition MSTWGrid.cpp:85
nucleon_t
Type of nucleon interpolated.
Definition MSTWGrid.cpp:84