|
[Rivet-svn] rivet: 3 new changesetsRivet Mercurial rivet at projects.hepforge.orgTue Apr 24 10:45:02 BST 2018
details: https://rivet.hepforge.org/hg/rivet/rev/b261a87b1b1e branches: release-2-6-x changeset: 6274:b261a87b1b1e user: Andy Buckley <andy at insectnation.org> date: Tue Apr 24 10:39:34 2018 +0100 description: Add isSameSign, isOppSign, isSameFlav, isOppFlav, and isOSSF etc. functions on PIDs and Particles. details: https://rivet.hepforge.org/hg/rivet/rev/551bcc978c50 branches: release-2-6-x changeset: 6275:551bcc978c50 user: Andy Buckley <andy at insectnation.org> date: Tue Apr 24 10:40:07 2018 +0100 description: Fix function signature bug is isMT2 overload. details: https://rivet.hepforge.org/hg/rivet/rev/bc97e42f5348 branches: release-2-6-x changeset: 6276:bc97e42f5348 user: Andy Buckley <andy at insectnation.org> date: Tue Apr 24 10:40:46 2018 +0100 description: Add initializer_list overload for binIndex. Needed for other util functions operating on vectors. diffs (truncated from 135 to 50 lines): --- a/ChangeLog Mon Apr 23 19:35:26 2018 +0100 +++ b/ChangeLog Tue Apr 24 10:40:46 2018 +0100 @@ -1,3 +1,11 @@ +2018-04-24 Andy Buckley <andy.buckley at cern.ch> + + * Add initializer_list overload for binIndex. Needed for other util functions operating on vectors. + + * Fix function signature bug is isMT2 overload. + + * Add isSameSign, isOppSign, isSameFlav, isOppFlav, and isOSSF etc. functions on PIDs and Particles. + 2018-03-27 Andy Buckley <andy.buckley at cern.ch> * Add RatioPlotLogY key to make-plots. Thanks to Antonin Maire. --- a/include/Rivet/Math/MathUtils.hh Mon Apr 23 19:35:26 2018 +0100 +++ b/include/Rivet/Math/MathUtils.hh Tue Apr 24 10:40:46 2018 +0100 @@ -329,6 +329,31 @@ } + /// Actual helper implementation of binIndex (so generic and specific overloading can work) + template <typename NUM, typename CONTAINER> + inline typename std::enable_if<std::is_arithmetic<NUM>::value && std::is_arithmetic<typename CONTAINER::value_type>::value, int>::type + _binIndex(NUM val, const CONTAINER& binedges, bool allow_overflow=false) { + if (val < *begin(binedges)) return -1; ///< Below/out of histo range + // CONTAINER::iterator_type itend = + if (val >= *(end(binedges)-1)) return allow_overflow ? int(binedges.size())-1 : -1; ///< Above/out of histo range + auto it = std::upper_bound(begin(binedges), end(binedges), val); + return std::distance(begin(binedges), --it); + } + + /// @brief Return the bin index of the given value, @a val, given a vector of bin edges + /// + /// An underflow always returns -1. If allow_overflow is false (default) an overflow + /// also returns -1, otherwise it returns the Nedge-1, the index of an inclusive bin + /// starting at the last edge. + /// + /// @note The @a binedges vector must be sorted + /// @todo Use std::common_type<NUM1, NUM2>::type x = val; ? + template <typename NUM1, typename NUM2> + inline typename std::enable_if<std::is_arithmetic<NUM1>::value && std::is_arithmetic<NUM2>::value, int>::type + binIndex(NUM1 val, std::initializer_list<NUM2> binedges, bool allow_overflow=false) { + return _binIndex(val, binedges, allow_overflow); + } + /// @brief Return the bin index of the given value, @a val, given a vector of bin edges /// /// An underflow always returns -1. If allow_overflow is false (default) an overflow @@ -340,10 +365,7 @@ template <typename NUM, typename CONTAINER>
More information about the Rivet-svn mailing list |