[Rivet-svn] r4122 - in branches/2012-06-aidarivet: . include/Rivet include/Rivet/Math

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Fri Feb 1 17:34:49 GMT 2013


Author: buckley
Date: Fri Feb  1 17:34:49 2013
New Revision: 4122

Log:
Fixes to Vector3::azimuthalAngle and Vector3::polarAngle calculation (using the mapAngle functions). Adding an element to the PhiMapping enum and a new mapAngle(angle, mapping) function.

Modified:
   branches/2012-06-aidarivet/ChangeLog
   branches/2012-06-aidarivet/include/Rivet/Exceptions.hh
   branches/2012-06-aidarivet/include/Rivet/Math/MathHeader.hh
   branches/2012-06-aidarivet/include/Rivet/Math/MathUtils.hh
   branches/2012-06-aidarivet/include/Rivet/Math/Vector3.hh

Modified: branches/2012-06-aidarivet/ChangeLog
==============================================================================
--- branches/2012-06-aidarivet/ChangeLog	Fri Feb  1 17:34:44 2013	(r4121)
+++ branches/2012-06-aidarivet/ChangeLog	Fri Feb  1 17:34:49 2013	(r4122)
@@ -1,3 +1,9 @@
+2013-02-01  Andy Buckley  <andy.buckley at cern.ch>
+
+	* Adding an element to the PhiMapping enum and a new mapAngle(angle, mapping) function.
+
+	* Fixes to Vector3::azimuthalAngle and Vector3::polarAngle calculation (using the mapAngle functions).
+
 2013-01-25  Frank Siegert  <frank.siegert at cern.ch>
 
 	* Split MC_*JETS analyses into three separate bits:

Modified: branches/2012-06-aidarivet/include/Rivet/Exceptions.hh
==============================================================================
--- branches/2012-06-aidarivet/include/Rivet/Exceptions.hh	Fri Feb  1 17:34:44 2013	(r4121)
+++ branches/2012-06-aidarivet/include/Rivet/Exceptions.hh	Fri Feb  1 17:34:49 2013	(r4122)
@@ -41,6 +41,7 @@
 
 
   /// @brief Errors relating to event/bin weights
+  ///
   /// Arises in computing statistical quantities because e.g. the bin
   /// weight is zero or negative.
   class WeightError : public Error {
@@ -49,6 +50,13 @@
   };
 
 
+  /// @brief Error specialisation for where the problem is between the chair and computer.
+  class UserError : public Error {
+  public:
+    UserError(const std::string& what) : Error(what) {}
+  };
+
+
 }
 
 #endif

Modified: branches/2012-06-aidarivet/include/Rivet/Math/MathHeader.hh
==============================================================================
--- branches/2012-06-aidarivet/include/Rivet/Math/MathHeader.hh	Fri Feb  1 17:34:44 2013	(r4121)
+++ branches/2012-06-aidarivet/include/Rivet/Math/MathHeader.hh	Fri Feb  1 17:34:49 2013	(r4122)
@@ -1,6 +1,7 @@
 #ifndef RIVET_Math_MathHeader
 #define RIVET_Math_MathHeader
 
+#include "Rivet/Exceptions.hh"
 #include <stdexcept>
 #include <string>
 #include <ostream>
@@ -59,7 +60,7 @@
   enum RapScheme { PSEUDORAPIDITY = 0, ETA = 0, RAPIDITY = 1, YRAP = 1 };
 
   /// Enum for range of \f$ \phi \f$ to be mapped into
-  enum PhiMapping { MINUSPI_PLUSPI, ZERO_2PI };
+  enum PhiMapping { MINUSPI_PLUSPI, ZERO_2PI, ZERO_PI };
 
 }
 

Modified: branches/2012-06-aidarivet/include/Rivet/Math/MathUtils.hh
==============================================================================
--- branches/2012-06-aidarivet/include/Rivet/Math/MathUtils.hh	Fri Feb  1 17:34:44 2013	(r4121)
+++ branches/2012-06-aidarivet/include/Rivet/Math/MathUtils.hh	Fri Feb  1 17:34:49 2013	(r4122)
@@ -399,6 +399,20 @@
     return rtn;
   }
 
+  /// Map an angle into the enum-specified range.
+  inline double mapAngle(double angle, PhiMapping mapping) {
+    switch (mapping) {
+    case MINUSPI_PLUSPI:
+      return mapAngleMPiToPi(angle);
+    case ZERO_2PI:
+      return mapAngle0To2Pi(angle);
+    case ZERO_PI:
+      return mapAngle0To2Pi(angle);
+    default:
+      throw Rivet::UserError("The specified phi mapping scheme is not implemented");
+    }
+  }
+
   //@}
 
 

Modified: branches/2012-06-aidarivet/include/Rivet/Math/Vector3.hh
==============================================================================
--- branches/2012-06-aidarivet/include/Rivet/Math/Vector3.hh	Fri Feb  1 17:34:44 2013	(r4121)
+++ branches/2012-06-aidarivet/include/Rivet/Math/Vector3.hh	Fri Feb  1 17:34:49 2013	(r4122)
@@ -124,34 +124,9 @@
       // If this is a null vector, return zero rather than let atan2 set an error state
       if (Rivet::isZero(mod2())) return 0.0;
 
-      // Calculate the arctan and correct for numerical boundary cases
-      double value = atan2( y(), x() );
-      if (value > 2*PI || value < -2*PI){
-        value = fmod(value, 2*PI);
-      }
-      if (value <= -PI) value += 2*PI;
-      if (value >   PI) value -= 2*PI;
-
-      // Return in the requested range
-      switch (mapping) {
-      case MINUSPI_PLUSPI:
-        assert(value > -PI && value <= PI);
-        return value;
-      case ZERO_2PI:
-        if (value >= 0) {
-          assert(value >= 0 && value < 2*PI);
-          return value;
-        } else if (Rivet::isZero(value)) {
-          value = 0.0;
-          return value;
-        } else {
-          value = 2*PI + value;
-          assert(value >= 0 && value < 2*PI);
-          return value;
-        }
-      default:
-        throw std::runtime_error("The specified phi mapping scheme is not yet implemented");
-      }
+      // Calculate the arctan and return in the requested range
+      const double value = atan2( y(), x() );
+      return mapAngle(value, mapping);
     }
 
     /// Synonym for azimuthalAngle.
@@ -162,9 +137,8 @@
     /// Angle subtended by the vector and the z-axis.
     double polarAngle() const {
       // Get number beween [0,PI]
-      double polarangle = atan2(polarRadius(), z());
-      assert(polarangle >= -PI && polarangle <= PI);
-      return polarangle;
+      const double polarangle = atan2(polarRadius(), z());
+      return mapAngle0ToPi(polarangle);
     }
 
     /// Synonym for polarAngle


More information about the Rivet-svn mailing list