[Rivet-svn] r3381 - in trunk: include/Rivet/Math src/Projections

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Sep 22 12:28:19 BST 2011


Author: buckley
Date: Thu Sep 22 12:28:19 2011
New Revision: 3381

Log:
Putting intpow back in place... damn, it seemed a good time to sort it out given that Hendrik was already messing in MathUtils.h! Sadly, the all-knowing authors of the STL forgot to make std::pow(int, int) work properly: brilliant.

Modified:
   trunk/include/Rivet/Math/MathUtils.hh
   trunk/src/Projections/Thrust.cc

Modified: trunk/include/Rivet/Math/MathUtils.hh
==============================================================================
--- trunk/include/Rivet/Math/MathUtils.hh	Thu Sep 22 11:23:27 2011	(r3380)
+++ trunk/include/Rivet/Math/MathUtils.hh	Thu Sep 22 12:28:19 2011	(r3381)
@@ -175,10 +175,12 @@
   }
 
   /// A more efficient version of pow for raising numbers to integer powers.
-  /// @deprecated Use std::pow instead
   template <typename Num>
   inline Num intpow(Num val, unsigned int exp) {
-    return std::pow(val, exp);
+    assert(exp >= 0);
+    if (exp == 0) return (Num) 1;
+    else if (exp == 1) return val;
+    return val * intpow(val, exp-1);
   }
 
   /// Find the sign of a number

Modified: trunk/src/Projections/Thrust.cc
==============================================================================
--- trunk/src/Projections/Thrust.cc	Thu Sep 22 11:23:27 2011	(r3380)
+++ trunk/src/Projections/Thrust.cc	Thu Sep 22 12:28:19 2011	(r3381)
@@ -46,11 +46,10 @@
 
   // Do the general case thrust calculation
   void _calcT(const vector<Vector3>& momenta, double& t, Vector3& taxis) {
-    /* This function implements the iterative algorithm as described in the
-     * Pythia manual. We take eight (four) different starting vectors
-     * constructed from the four (three) leading particles to make sure that
-     * we don't find a local maximum.
-     */
+    // This function implements the iterative algorithm as described in the
+    // Pythia manual. We take eight (four) different starting vectors
+    // constructed from the four (three) leading particles to make sure that
+    // we don't find a local maximum.
     vector<Vector3> p = momenta;
     assert(p.size() >= 3);
     unsigned int n = 3;
@@ -58,13 +57,13 @@
     vector<Vector3> tvec;
     vector<double> tval;
     std::sort(p.begin(), p.end(), mod2Cmp);
-    for (unsigned int i=0 ; i<pow(2,n-1) ; i++) {
+    for (int i = 0 ; i < intpow(2, n-1); ++i) {
       // Create an initial vector from the leading four jets
       Vector3 foo(0,0,0);
-      int sign=i;
-      for (unsigned int k=0 ; k<n ; k++) {
-        (sign%2)==1 ? foo+=p[k] : foo-=p[k];
-        sign/=2;
+      int sign = i;
+      for (unsigned int k = 0 ; k < n ; ++k) {
+        (sign % 2) == 1 ? foo += p[k] : foo -= p[k];
+        sign /= 2;
       }
       foo=foo.unit();
 


More information about the Rivet-svn mailing list