cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Limits.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_Limits_h
20#define CepGen_Utils_Limits_h
21
22#include <iosfwd>
23#include <utility>
24#include <vector>
25
26namespace cepgen {
28 class Limits : private std::pair<double, double> {
29 public:
30 Limits(double min = INVALID, double max = INVALID);
31 Limits(const Limits&);
32
33 static Limits constant(double);
34
35 bool operator<(const Limits&) const;
36 Limits operator-() const;
37 Limits& operator=(const Limits&) = default;
39 inline bool operator==(const Limits& oth) const { return *this == (std::pair<double, double>)oth; }
40 inline bool operator!=(const Limits& oth) const { return !operator==(oth); }
41 Limits& operator+=(double);
42 Limits& operator-=(double);
43 Limits& operator*=(double);
44 friend Limits operator+(Limits, double);
45 friend Limits operator-(Limits, double);
46 friend Limits operator*(Limits, double);
47
48 Limits& validate();
49
50 bool hasMin() const;
51 bool hasMax() const;
52 inline double min() const { return first; }
53 inline double& min() { return first; }
54 inline double max() const { return second; }
55 inline double& max() { return second; }
56
57 double x(double v) const;
58 void in(double low, double up);
59 double range() const;
60
61 Limits truncate(const Limits&) const;
62 double trim(double) const;
63 bool contains(double val, bool exclude_boundaries = false) const;
64 Limits& apply(double (*)(double));
65
66 Limits compute(double (*)(double)) const;
68 template <typename F>
69 inline Limits compute(const F& op) const {
70 return Limits{hasMin() ? op(min()) : INVALID, hasMax() ? op(max()) : INVALID};
71 }
72 bool valid() const;
73 inline const std::pair<double, double>& raw() const { return *this; }
74
78 std::vector<double> generate(size_t num_bins, bool log_scale = false) const;
82 std::vector<Limits> split(size_t num_bins, bool log_scale = false) const;
83
84 friend std::ostream& operator<<(std::ostream&, const Limits&);
85
86 static constexpr double INVALID = -999.999;
87 };
88} // namespace cepgen
89
90#endif
Validity interval for a variable.
Definition Limits.h:28
Limits & apply(double(*)(double))
Apply an operator on limits boundaries.
Definition Limits.cpp:147
std::vector< Limits > split(size_t num_bins, bool log_scale=false) const
Split the limits into sub-limits objects.
Definition Limits.cpp:122
double x(double v) const
Find the [0,1] value scaled between minimum and maximum.
Definition Limits.cpp:97
Limits & operator+=(double)
Add a constant to this limit.
Definition Limits.cpp:40
bool operator==(const Limits &oth) const
Definition Limits.h:39
bool operator!=(const Limits &oth) const
Inequality operator.
Definition Limits.h:40
double & max()
Upper limit to apply on the variable.
Definition Limits.h:55
bool operator<(const Limits &) const
Comparison operator.
Definition Limits.cpp:32
bool valid() const
Is there a lower and upper limit?
Definition Limits.cpp:85
friend Limits operator*(Limits, double)
Multiply a limit by a constant.
Definition Limits.cpp:176
static constexpr double INVALID
Invalid value placeholder (single-edged or invalid limits)
Definition Limits.h:86
std::vector< double > generate(size_t num_bins, bool log_scale=false) const
Generate a collection of values from a number of bins.
Definition Limits.cpp:113
Limits operator-() const
Invert this limit.
Definition Limits.cpp:38
double range() const
Full variable range allowed.
Definition Limits.cpp:65
bool hasMin() const
Have a lower limit?
Definition Limits.cpp:73
bool hasMax() const
Have an upper limit?
Definition Limits.cpp:75
Limits & operator*=(double)
Multiply this limit by a constant.
Definition Limits.cpp:52
friend Limits operator+(Limits, double)
Add a constant to a limit.
Definition Limits.cpp:166
double min() const
Lower limit to apply on the variable.
Definition Limits.h:52
friend std::ostream & operator<<(std::ostream &, const Limits &)
Human-readable expression of the limits.
Definition Limits.cpp:156
Limits compute(double(*)(double)) const
Compute a copy of limits with an operator applied on boundaries Compute a copy of limits with an oper...
Definition Limits.cpp:152
double trim(double) const
Limit a value to boundaries.
Definition Limits.cpp:139
Limits & operator-=(double)
Subtract a constant to this limit.
Definition Limits.cpp:46
double & min()
Lower limit to apply on the variable.
Definition Limits.h:53
Limits truncate(const Limits &) const
Truncate limits to minimal/maximal values.
Definition Limits.cpp:130
Limits & validate()
Ensure the limit object is valid by correcting it if necessary.
Definition Limits.cpp:91
bool contains(double val, bool exclude_boundaries=false) const
Check if value is inside limits' boundaries.
Definition Limits.cpp:77
Limits compute(const F &op) const
Definition Limits.h:69
const std::pair< double, double > & raw() const
Raw value of limits.
Definition Limits.h:73
double max() const
Upper limit to apply on the variable.
Definition Limits.h:54
static Limits constant(double)
Build dimension-0 limits (constant)
Definition Limits.cpp:30
Limits & operator=(const Limits &)=default
Assignment operator Equality operator.
void in(double low, double up)
Specify the lower and upper limits on the variable.
Definition Limits.cpp:60
Common namespace for this Monte Carlo generator.