[Rivet-svn] r4329 - in trunk/include/Rivet: Math Tools

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu May 30 12:59:06 BST 2013


Author: buckley
Date: Thu May 30 12:59:06 2013
New Revision: 4329

Log:
Adding a couple of minor Utils.hh and MathUtils.hh features

Modified:
   trunk/include/Rivet/Math/MathUtils.hh
   trunk/include/Rivet/Tools/Utils.hh

Modified: trunk/include/Rivet/Math/MathUtils.hh
==============================================================================
--- trunk/include/Rivet/Math/MathUtils.hh	Thu May 30 11:54:24 2013	(r4328)
+++ trunk/include/Rivet/Math/MathUtils.hh	Thu May 30 12:59:06 2013	(r4329)
@@ -174,6 +174,11 @@
     return sqrt(a*a + b*b + c*c);
   }
 
+  /// Return a/b, or @a fail if b = 0
+  inline double divide(double num, double den, double fail=0.0) {
+    return (!isZero(den)) ? num/den : fail;
+  }
+
   /// A more efficient version of pow for raising numbers to integer powers.
   template <typename Num>
   inline Num intpow(Num val, unsigned int exp) {
@@ -270,7 +275,7 @@
   /// NB. The arg ordering and the meaning of the nbins variable is "histogram-like",
   /// as opposed to the Numpy/Matlab version, and the start and end arguments are expressed
   /// in "normal" space.
-  inline vector<double> BWspace(size_t nbins, double start, double end, 
+  inline vector<double> BWspace(size_t nbins, double start, double end,
 				double mu, double gamma) {
     assert(end >= start);
     assert(nbins > 0);

Modified: trunk/include/Rivet/Tools/Utils.hh
==============================================================================
--- trunk/include/Rivet/Tools/Utils.hh	Thu May 30 11:54:24 2013	(r4328)
+++ trunk/include/Rivet/Tools/Utils.hh	Thu May 30 12:59:06 2013	(r4329)
@@ -20,6 +20,14 @@
     return lexical_cast<string>(x);
   }
 
+  /// @brief Convert any object to a string
+  ///
+  /// An alias for to_str() with a more "Rivety" mixedCase name.
+  template <typename T>
+  inline std::string toString(const T& x) {
+    return to_str(x);
+  }
+
 
   /// Case-insensitive string comparison function
   ///


More information about the Rivet-svn mailing list