5#include "Rivet/Tools/Exceptions.hh"
6#include "Rivet/Tools/PrettyPrint.hh"
7#include "Rivet/Tools/RivetSTL.hh"
8#include "Rivet/Tools/TypeTraits.hh"
26 #if __GNUC__ && __cplusplus && RIVET_NO_DEPRECATION_WARNINGS == 0
27 #define DEPRECATED(x) __attribute__((deprecated(x)))
38 static constexpr double DBL_NAN = std::numeric_limits<double>::quiet_NaN();
47 inline T&
maybe(
const T& x, std::function<
bool(
const T&)> fn,
const T& fallback) {
48 return fn(x) ? x : fallback;
56 struct bad_lexical_cast :
public std::runtime_error {
57 bad_lexical_cast(
const std::string& what)
58 : std::runtime_error(what) { }
62 template <
typename T,
typename U>
71 catch (
const std::exception& e) {
85 inline string&
ireplace_first(
string& str,
const string& patt,
const string& repl) {
86 if (!
contains(str, patt))
return str;
87 str.replace(str.find(patt), patt.size(), repl);
96 return to_str(std::forward<T>(x));
100 template <
typename T>
102 return to_str(std::forward<T>(x));
107 inline string replace_first(
string str,
const string& patt,
const string& repl) {
116 inline string&
ireplace_all(
string& str,
const string& patt,
const string& repl) {
117 if (!
contains(str, patt))
return str;
119 string::size_type it = str.find(patt);
120 if (it == string::npos)
break;
121 str.replace(it, patt.size(), repl);
131 inline string replace_all(
string str,
const string& patt,
const string& repl) {
140 while ((it1 != s1.end()) && (it2 != s2.end())) {
141 if (::toupper(*it1) != ::toupper(*it2)) {
143 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
149 size_t size1 = s1.size(), size2 = s2.size();
151 if (size1 == size2)
return 0;
152 return (size1 < size2) ? -1 : 1;
165 std::transform(out.begin(), out.end(), out.begin(), (int (*)(
int))std::tolower);
173 std::transform(out.begin(), out.end(), out.begin(), (int (*)(
int))std::toupper);
179 inline bool startsWith(
const string& s,
const string& start) {
180 if (s.length() < start.length())
return false;
181 return s.substr(0, start.length()) == start;
186 inline bool endsWith(
const string& s,
const string& end) {
187 if (s.length() < end.length())
return false;
188 return s.substr(s.length() - end.length()) == end;
193 inline string strcat() {
197 template <
typename T,
typename... Ts>
198 inline string strcat(T value, Ts... fargs) {
200 const string strnext = strcat(fargs...);
201 return strnext.empty() ? strthis : strthis + strnext;
206 template <
typename T>
207 inline string join(
const vector<T>& v,
const string& sep =
" ") {
209 for (
size_t i = 0; i < v.size(); ++i) {
210 if (i != 0) rtn += sep;
218 inline string join(
const vector<string>& v,
const string& sep) {
220 for (
size_t i = 0; i < v.size(); ++i) {
221 if (i != 0) rtn += sep;
228 template <
typename T>
229 inline string join(
const set<T>& s,
const string& sep =
" ") {
231 for (
const T& x : s) {
232 if (rtn.size() > 0) rtn += sep;
240 inline string join(
const set<string>& s,
const string& sep) {
242 for (
const string& x : s) {
243 if (rtn.size() > 0) rtn += sep;
250 inline vector<string>
split(
const string& s,
const string& sep) {
254 const size_t delim_pos = tmp.find(sep);
255 if (delim_pos == string::npos)
break;
256 const string dir = tmp.substr(0, delim_pos);
257 if (dir.length()) dirs.push_back(dir);
258 tmp.replace(0, delim_pos + 1,
"");
260 if (tmp.length()) dirs.push_back(tmp);
265 inline string lpad(
const string& s,
size_t width,
const string& padchar =
" ") {
266 if (s.size() >= width)
return s;
267 return string(width - s.size(), padchar[0]) + s;
271 inline string rpad(
const string& s,
size_t width,
const string& padchar =
" ") {
272 if (s.size() >= width)
return s;
273 return s + string(width - s.size(), padchar[0]);
286 return split(path,
":");
293 inline string pathjoin(
const vector<string>& paths) {
294 return join(paths,
":");
298 inline string operator/(
const string& a,
const string& b) {
300 const string anorm = (a.find(
"/") != string::npos) ? a.substr(0, a.find_last_not_of(
"/") + 1) : a;
301 const string bnorm = (b.find(
"/") != string::npos) ? b.substr(b.find_first_not_of(
"/")) : b;
302 return anorm +
"/" + bnorm;
308 return p.substr(
p.rfind(
"/") + 1);
314 return p.substr(0,
p.rfind(
"/"));
320 return f.substr(0, f.rfind(
"."));
326 return f.substr(f.rfind(
".") + 1);
336 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
337 inline unsigned int count(
const CONTAINER& c) {
339 unsigned int rtn = 0;
340 for (
const auto& x : c) {
341 if (
bool(x)) rtn += 1;
353 template <
typename CONTAINER,
356 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
357 inline unsigned int count(
const CONTAINER& c,
const FN& f) {
358 return std::count_if(std::begin(c), std::end(c), f);
363 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
364 inline bool any(
const CONTAINER& c) {
366 for (
const auto& x : c) {
367 if (
bool(x))
return true;
383 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
384 inline bool any(
const CONTAINER& c,
const FN& f) {
385 return std::any_of(std::begin(c), std::end(c), f);
390 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
391 inline bool all(
const CONTAINER& c) {
393 for (
const auto& x : c) {
394 if (!
bool(x))
return false;
410 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
411 inline bool all(
const CONTAINER& c,
const FN& f) {
412 return std::all_of(std::begin(c), std::end(c), f);
417 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
418 inline bool none(
const CONTAINER& c) {
420 for (
const auto& x : c) {
421 if (
bool(x))
return false;
437 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
438 inline bool none(
const CONTAINER& c,
const FN& f) {
439 return std::none_of(std::begin(c), std::end(c), f);
453 template <
typename CONTAINER1,
455 typename FN =
typename std::decay_t<CONTAINER2>::value_type(
456 const typename std::decay_t<CONTAINER1>::value_type::ParticleBase&),
457 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER1>>
458 && is_citerable_v<std::decay_t<CONTAINER2>>>>
459 inline const CONTAINER2& transform(
const CONTAINER1& in, CONTAINER2& out, FN&& f) {
461 out.resize(in.size());
462 std::transform(in.begin(), in.end(), out.begin(), std::forward<FN>(f));
469 template <
typename CONTAINER1,
471 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER1>>>>
472 inline std::vector<RTN> transform(
473 const CONTAINER1& in,
474 const std::function<RTN(
typename CONTAINER1::value_type::ParticleBase)>& f) {
475 std::vector<RTN> out;
476 transform(in, out, f);
488 template <
typename CONTAINER1,
491 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER1>>>>
492 inline T
accumulate(
const CONTAINER1& in,
const T& init,
const FN& f) {
493 const T rtn = std::accumulate(in.begin(), in.end(), init, f);
501 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
502 inline typename CONTAINER::value_type
sum(
const CONTAINER& c) {
503 typename CONTAINER::value_type rtn;
504 for (
const auto& x : c) rtn += x;
511 template <
typename CONTAINER,
513 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
514 inline T
sum(
const CONTAINER& c,
const T& start) {
516 for (
const auto& x : c) {
523 template <
typename CONTAINER,
525 typename FN = T(
const typename std::decay_t<CONTAINER>::value_type::ParticleBase&),
526 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
527 inline T
sum(
const CONTAINER& c, FN&& fn,
const T& start = T()) {
528 auto f = std::function(std::forward<FN>(fn));
530 for (
const auto& x : c) {
540 template <
typename CONTAINER,
542 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
543 inline T&
isum(
const CONTAINER& c, T& out) {
544 for (
const auto& x : c) {
558 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
559 inline T&
isum(
const CONTAINER& c,
const FN& f, T& out) {
560 for (
const auto& x : c) {
570 template <
typename CONTAINER,
572 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
573 inline CONTAINER&
idiscard(CONTAINER& c,
const FN& f) {
574 const auto newend = std::remove_if(std::begin(c), std::end(c), f);
575 c.erase(newend, c.end());
580 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
581 inline CONTAINER&
idiscard(CONTAINER& c,
const typename CONTAINER::value_type& y) {
582 return idiscard(c, [&](
typename CONTAINER::value_type& x) {
return x == y; });
586 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
588 return idiscard(c, [&](
typename CONTAINER::value_type& x) {
return contains(ys, x); });
595 template <
typename CONTAINER,
597 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
598 inline CONTAINER
discard(
const CONTAINER& c,
const FN& f) {
604 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
605 inline CONTAINER
discard(
const CONTAINER& c,
const typename CONTAINER::value_type& y) {
606 return discard(c, [&](
typename CONTAINER::value_type& x) {
return x == y; });
610 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
612 return discard(c, [&](
typename CONTAINER::value_type& x) {
return contains(ys, x); });
621 template <
typename CONTAINER,
624 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
625 inline CONTAINER&
discard(
const CONTAINER& c,
const FN& f, CONTAINER& out) {
631 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
632 inline CONTAINER&
discard(
const CONTAINER& c,
const typename CONTAINER::value_type& y, CONTAINER& out) {
633 return discard(c, [&](
typename CONTAINER::value_type& x) {
return x == y; }, out);
637 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
638 inline CONTAINER&
discard_if_any(
const CONTAINER& c,
const CONTAINER& ys, CONTAINER& out) {
639 return discard(c, [&](
typename CONTAINER::value_type& x) {
return contains(ys, x); }, out);
646 template <
typename CONTAINER,
648 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
649 inline CONTAINER&
iselect(CONTAINER& c,
const FN& f) {
650 auto invf = [&](
const typename CONTAINER::value_type& x) {
659 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
661 return iselect(c, [&](
typename CONTAINER::value_type& x) {
return contains(ys, x); });
668 template <
typename CONTAINER,
670 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
671 inline CONTAINER
select(
const CONTAINER& c,
const FN& f) {
681 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
683 return select(c, [&](
typename CONTAINER::value_type& x) {
return contains(ys, x); });
692 template <
typename CONTAINER,
694 typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
695 inline CONTAINER&
select(
const CONTAINER& c,
const FN& f, CONTAINER& out) {
703 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
704 inline CONTAINER&
select_if_any(
const CONTAINER& c,
const CONTAINER& ys, CONTAINER& out) {
705 return select(c, [&](
typename CONTAINER::value_type& x) {
return contains(ys, x); }, out);
713 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
714 inline CONTAINER
slice(
const CONTAINER& c,
int i,
int j) {
716 const size_t off1 = (i >= 0) ? i : c.size() + i;
717 const size_t off2 = (j >= 0) ? j : c.size() + j;
718 if (off1 > c.size() || off2 > c.size())
throw RangeError(
"Attempting to slice beyond requested offsets");
719 if (off2 < off1)
throw RangeError(
"Requested offsets in invalid order");
720 rtn.resize(off2 - off1);
721 std::copy(c.begin() + off1, c.begin() + off2, rtn.begin());
728 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
729 inline CONTAINER
slice(
const CONTAINER& c,
int i) {
730 return slice(c, i, c.size());
736 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
737 inline CONTAINER
head(
const CONTAINER& c,
int n) {
739 if (n < 0) n = std::max(0, (
int)c.size() + n);
740 n = std::min(n, (
int)c.size());
741 return slice(c, 0, n);
747 template <
typename CONTAINER,
typename = std::enable_if_t<is_citerable_v<std::decay_t<CONTAINER>>>>
748 inline CONTAINER
tail(
const CONTAINER& c,
int n) {
750 if (n < 0) n = std::max(0, (
int)c.size() + n);
751 n = std::min(n, (
int)c.size());
752 return slice(c, c.size() - n);
760 inline double min(
const vector<double>& in,
double errval =
DBL_NAN) {
761 const auto e = std::min_element(in.begin(), in.end());
762 return e != in.end() ? *e : errval;
766 inline double max(
const vector<double>& in,
double errval =
DBL_NAN) {
767 const auto e = std::max_element(in.begin(), in.end());
768 return e != in.end() ? *e : errval;
772 inline pair<double, double>
minmax(
const vector<double>& in,
double errval =
DBL_NAN) {
773 const auto e = std::minmax_element(in.begin(), in.end());
774 const double rtnmin = e.first != in.end() ? *e.first : errval;
775 const double rtnmax = e.second != in.end() ? *e.first : errval;
776 return std::make_pair(rtnmin, rtnmax);
781 inline int min(
const vector<int>& in,
int errval = -1) {
782 const auto e = std::min_element(in.begin(), in.end());
783 return e != in.end() ? *e : errval;
787 inline int max(
const vector<int>& in,
int errval = -1) {
788 const auto e = std::max_element(in.begin(), in.end());
789 return e != in.end() ? *e : errval;
793 inline pair<int, int>
minmax(
const vector<int>& in,
int errval = -1) {
794 const auto e = std::minmax_element(in.begin(), in.end());
795 const double rtnmin = e.first != in.end() ? *e.first : errval;
796 const double rtnmax = e.second != in.end() ? *e.first : errval;
797 return std::make_pair(rtnmin, rtnmax);
811 template <
typename CONTAINER,
812 typename FN = double(
const typename std::decay_t<CONTAINER>::value_type::ParticleBase&),
813 typename = isCIterable<CONTAINER>>
817 double minval = -DBL_MAX,
818 double maxval = DBL_MAX) {
819 auto f = std::function(std::forward<FN>(fn));
822 for (
size_t i = 0; i < c.size(); ++i) {
823 const double val = f(c[i]);
824 if (isnan(val))
continue;
825 if (val < minval || val > maxval)
continue;
826 if (isnan(best) || fabs(val - target) < fabs(best - target)) {
842 template <
typename CONTAINER1,
844 typename FN = double(
const typename std::decay_t<CONTAINER1>::value_type::ParticleBase&,
845 const typename std::decay_t<CONTAINER2>::value_type::ParticleBase&),
846 typename = isCIterable<CONTAINER1, CONTAINER2>>
848 const CONTAINER2& c2,
851 double minval = -DBL_MAX,
852 double maxval = DBL_MAX) {
853 auto f = std::function(std::forward<FN>(fn));
854 pair<int, int> ijbest{-1, -1};
856 for (
size_t i = 0; i < c1.size(); ++i) {
857 for (
size_t j = 0; j < c2.size(); ++j) {
858 const double val = f(c1[i], c2[j]);
859 if (isnan(val))
continue;
860 if (val < minval || val > maxval)
continue;
861 if (isnan(best) || fabs(val - target) < fabs(best - target)) {
878 template <
typename CONTAINER,
880 typename FN = double(
const typename std::decay_t<CONTAINER>::value_type::ParticleBase&,
881 const std::decay_t<T>&),
882 typename = isCIterable<CONTAINER>>
887 double minval = -DBL_MAX,
888 double maxval = DBL_MAX) {
889 pair<int, int> ijbest =
closestMatchIndices(c, vector<T>{x}, std::forward<FN>(fn), target, minval,
902 template <
typename CONTAINER,
typename T,
typename FN,
typename = isCIterable<CONTAINER>>
907 double minval = -DBL_MAX,
908 double maxval = DBL_MAX) {
920 template <
typename T>
922 char* env = getenv(name.c_str());
931 vector<T>
slice(
const vector<T>& v,
int startidx,
int endidx) {
933 if (startidx < 0 || endidx <= startidx || endidx >= v.size())
934 throw RangeError(
"Requested start or end indices incompatible with given vector");
936 auto start = v.begin() + startidx;
937 auto end = v.begin() + endidx;
939 vector<T> output(endidx - startidx);
941 copy(start, end, output.begin());
int closestMatchIndex(const CONTAINER &c, FN &&fn, double target, double minval=-DBL_MAX, double maxval=DBL_MAX)
Return the index from a vector which best matches fn(c[i]) to the target value.
Definition Utils.hh:814
pair< int, int > closestMatchIndices(const CONTAINER1 &c1, const CONTAINER2 &c2, FN &&fn, double target, double minval=-DBL_MAX, double maxval=DBL_MAX)
Return the indices from two vectors which best match fn(c1[i], c2[j]) to the target value.
Definition Utils.hh:847
CONTAINER head(const CONTAINER &c, int n)
Head slice of the n first container elements.
Definition Utils.hh:737
bool any(const CONTAINER &c)
Return true if x is true for any x in container c, otherwise false.
Definition Utils.hh:364
CONTAINER discard_if_any(const CONTAINER &c, const CONTAINER &ys)
Version with several element-equality comparisons in place of a function.
Definition Utils.hh:611
CONTAINER slice(const CONTAINER &c, int i, int j)
Slice of the container elements cf. Python's [i:j] syntax.
Definition Utils.hh:714
T accumulate(const CONTAINER1 &in, const T &init, const FN &f)
A single-container-arg version of std::accumulate, aka reduce.
Definition Utils.hh:492
CONTAINER & idiscard_if_any(CONTAINER &c, const CONTAINER &ys)
Version with several element-equality comparisons in place of a function.
Definition Utils.hh:587
pair< double, double > minmax(const vector< double > &in, double errval=DBL_NAN)
Find the minimum and maximum values in the vector.
Definition Utils.hh:772
bool none(const CONTAINER &c)
Return true if x is false for all x in container c, otherwise false.
Definition Utils.hh:418
CONTAINER tail(const CONTAINER &c, int n)
Tail slice of the n last container elements.
Definition Utils.hh:748
bool all(const CONTAINER &c)
Return true if x is true for all x in container c, otherwise false.
Definition Utils.hh:391
unsigned int count(const CONTAINER &c)
Return number of true elements in the container c .
Definition Utils.hh:337
T & isum(const CONTAINER &c, T &out)
Definition Utils.hh:543
CONTAINER & iselect_if_any(CONTAINER &c, const CONTAINER &ys)
Version with several element-equality comparisons in place of a function.
Definition Utils.hh:660
CONTAINER select_if_any(const CONTAINER &c, const CONTAINER &ys)
Version with several element-equality comparisons in place of a function.
Definition Utils.hh:682
Jets & idiscard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Jets select(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Definition JetUtils.hh:183
Jets & iselect(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Jets discard(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Definition JetUtils.hh:201
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
string dirname(const string &p)
Get the dirname (i.e. path to the penultimate directory) from a path p.
Definition Utils.hh:312
string file_extn(const string &f)
Get the file extension from a filename f.
Definition Utils.hh:324
string pathjoin(const vector< string > &paths)
Join several filesystem paths together with the standard ':' delimiter.
Definition Utils.hh:293
vector< string > pathsplit(const string &path)
Split a path string with colon delimiters.
Definition Utils.hh:285
string basename(const string &p)
Get the basename (i.e. terminal file name) from a path p.
Definition Utils.hh:306
string file_stem(const string &f)
Get the stem (i.e. part without a file extension) from a filename f.
Definition Utils.hh:318
bool endsWith(const string &s, const string &end)
Check whether a string end is found at the end of s.
Definition Utils.hh:186
bool nocase_equals(const string &s1, const string &s2)
Case-insensitive string equality function.
Definition Utils.hh:157
string toStr(T &&x)
Perfect-forwarding alias for to_str() with a more Rivet-user-facing name.
Definition Utils.hh:101
bool startsWith(const string &s, const string &start)
Check whether a string start is found at the start of s.
Definition Utils.hh:179
string & ireplace_all(string &str, const string &patt, const string &repl)
Replace all instances of patt with repl in-place.
Definition Utils.hh:116
string toUpper(const string &s)
Convert a string to upper-case.
Definition Utils.hh:171
string rpad(const string &s, size_t width, const string &padchar=" ")
Right-pad the given string s to width width.
Definition Utils.hh:271
string to_str(const T &x)
Convert any object to a string.
Definition Utils.hh:80
string lpad(const string &s, size_t width, const string &padchar=" ")
Left-pad the given string s to width width.
Definition Utils.hh:265
string toLower(const string &s)
Convert a string to lower-case.
Definition Utils.hh:163
string replace_all(string str, const string &patt, const string &repl)
Replace all instances of patt with repl.
Definition Utils.hh:131
T lexical_cast(const U &in)
Convert between any types via stringstream.
Definition Utils.hh:63
vector< string > split(const string &s, const string &sep)
Split a string on a specified separator string.
Definition Utils.hh:250
string join(const vector< T > &v, const string &sep=" ")
Make a string containing the string representations of each item in v, separated by sep.
Definition Utils.hh:207
string & ireplace_first(string &str, const string &patt, const string &repl)
Replace the first instance of patt with repl in-place.
Definition Utils.hh:85
string replace_first(string str, const string &patt, const string &repl)
Replace the first instance of patt with repl.
Definition Utils.hh:107
int nocase_cmp(const string &s1, const string &s2)
Case-insensitive string comparison function.
Definition Utils.hh:137
T getEnvParam(const std::string name, const T &fallback)
Get a parameter from a named environment variable, with automatic type conversion.
Definition Utils.hh:921
Definition LHCbCommon.hh:9
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 >, signed_if_mixed_t< N1, N2 > > max(N1 a, N2 b)
Get the maximum of two numbers.
Definition MathUtils.hh:124
T sum(const DressedLeptons &c, FN &&fn, const T &start=T())
Generic sum function, adding fn(x) for all x in container c, starting with start.
Definition DressedLepton.hh:66
static constexpr double DBL_NAN
Convenient const for getting the double NaN value.
Definition Utils.hh:38
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 >, signed_if_mixed_t< N1, N2 > > min(N1 a, N2 b)
Get the minimum of two numbers.
Definition MathUtils.hh:113
bool contains(const std::string &s, const std::string &sub)
Does s contain sub as a substring?
Definition RivetSTL.hh:213
T & maybe(const T &x, std::function< bool(const T &)> fn, const T &fallback)
Wrapper for avoiding repetition/recalculation when computing and maybe using a value.
Definition Utils.hh:47
std::string toString(const AnalysisInfo &ai)
String representation.
Error for e.g. use of invalid bin ranges.
Definition Exceptions.hh:23
Exception class for throwing from lexical_cast when a parse goes wrong.
Definition Utils.hh:56