cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.3
A generic central exclusive processes event generator
Loading...
Searching...
No Matches
GridHandler.h
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#ifndef CepGen_Utils_GridHandler_h
20#define CepGen_Utils_GridHandler_h
21
22#include <gsl/gsl_interp.h>
23#include <gsl/gsl_spline.h>
24#include <gsl/gsl_version.h>
25#if defined(GSL_MAJOR_VERSION) && (GSL_MAJOR_VERSION > 2 || (GSL_MAJOR_VERSION == 2 && GSL_MINOR_VERSION >= 1))
26#include <gsl/gsl_interp2d.h>
27#include <gsl/gsl_spline2d.h>
28#define GSL_VERSION_ABOVE_2_1 1
29#endif
30
31#include <array>
32#include <map>
33#include <memory>
34
35#include "CepGen/Utils/Limits.h"
36
37namespace cepgen {
39 enum struct GridType { linear, logarithmic, square };
43 template <size_t D, size_t N = 1>
45 public:
46 typedef std::vector<double> coord_t;
47 typedef std::array<double, N> values_t;
48
49 public:
50 explicit GridHandler(const GridType& grid_type);
51 virtual ~GridHandler() = default;
52
53 values_t eval(coord_t in_coords) const;
54
55 void insert(coord_t coord, values_t value);
56 inline std::map<coord_t, values_t> values() const { return values_raw_; }
57
58 void initialise();
59 std::array<Limits, D> boundaries() const;
60 std::array<double, D> min() const;
61 std::array<double, D> max() const;
62
63 protected:
65 std::map<coord_t, values_t> values_raw_;
67 std::vector<std::unique_ptr<gsl_interp_accel, void (*)(gsl_interp_accel*)> > accel_;
68 std::vector<std::unique_ptr<gsl_spline, void (*)(gsl_spline*)> > splines_1d_;
69#ifdef GSL_VERSION_ABOVE_2_1
71 std::vector<std::unique_ptr<gsl_spline2d, void (*)(gsl_spline2d*)> > splines_2d_;
72#endif
73 std::array<coord_t, D> coords_;
74 std::array<std::unique_ptr<double[]>, N> values_;
75
76 private:
77 void findIndices(const coord_t& coord, coord_t& min, coord_t& max) const;
79 struct gridpoint_t : values_t {
80 gridpoint_t(const values_t& arr) : values_t(arr) {}
81 gridpoint_t operator*(double c) const;
82 gridpoint_t operator+(const gridpoint_t& rhs) const;
83 };
84 bool init_{false};
85 };
86} // namespace cepgen
87
88#endif
A generic class for grid interpolation.
Definition GridHandler.h:44
std::vector< std::unique_ptr< gsl_spline, void(*)(gsl_spline *)> > splines_1d_
Splines for linear interpolations.
Definition GridHandler.h:68
void initialise()
Initialise the grid and all useful interpolators/accelerators.
std::map< coord_t, values_t > values_raw_
List of coordinates and associated value(s) in the grid Grid interpolation accelerator.
Definition GridHandler.h:65
std::array< std::unique_ptr< double[]>, N > values_
Values for all points in the grid.
Definition GridHandler.h:74
void insert(coord_t coord, values_t value)
Insert a new value in the grid.
std::vector< double > coord_t
Coordinates container.
Definition GridHandler.h:46
std::vector< std::unique_ptr< gsl_interp_accel, void(*)(gsl_interp_accel *)> > accel_
Definition GridHandler.h:67
std::array< Limits, D > boundaries() const
Grid boundaries (collection of (min,max))
virtual ~GridHandler()=default
std::array< double, D > max() const
Highest bound of the grid coordinates.
std::array< coord_t, D > coords_
Coordinates building up the grid.
Definition GridHandler.h:73
const GridType grid_type_
Type of interpolation for the grid members.
Definition GridHandler.h:64
values_t eval(coord_t in_coords) const
Interpolate a point to a given coordinate.
std::array< double, N > values_t
Value(s) at a given coordinate.
Definition GridHandler.h:47
std::array< double, D > min() const
Lowest bound of the grid coordinates.
std::map< coord_t, values_t > values() const
List of values in the grid.
Definition GridHandler.h:56
Common namespace for this Monte Carlo generator.
Matrix operator+(const Matrix &lhs, const Matrix &rhs)
Definition Algebra.cpp:237
GridType
Interpolation type for the grid coordinates.
Definition GridHandler.h:39
Momentum operator*(double c, const Momentum &mom)
Definition Momentum.cpp:134