[yoda-svn] r370 - in trunk: . include/YODA

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Fri Aug 26 16:00:59 BST 2011


Author: buckley
Date: Fri Aug 26 16:00:59 2011
New Revision: 370

Log:
Comments about the magic number coord shifts in Axis1D/2D... they are NOT safe.

Modified:
   trunk/TODO
   trunk/include/YODA/Axis1D.h
   trunk/include/YODA/Axis2D.h

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	Fri Aug 26 15:39:23 2011	(r369)
+++ trunk/TODO	Fri Aug 26 16:00:59 2011	(r370)
@@ -8,16 +8,16 @@
 * Rebinning: global rebinning of Axis2D -> Histo2D by integer factor(s) --
   different factors in x and y directions. (MK)
   MK: What if factor%(number of bins in X/Y direction) != 0?
+  AB: Merge the last n < factor bins: see Axis1D.
 
 * Comment, clean, and explain the Axis caching mechanisms and the very complex
   functions that manipulate them. (MK)
   MK: Done?
 
-* Unify the API, especially the order of X/Y parameters in various 
+* Unify the API, especially the order of X/Y parameters in various
   constructors! (MK)
 
-* Fix failing Histo2D test and remove cout printout from Histo2D.h (MK)
-  MK: Cout removed.
+* Fix failing Histo2D test (MK)
 
 * Improve tests Makefile setup to work out the path to the Python build dir. (AB)
 
@@ -44,6 +44,8 @@
 * Bin division: add quadratic / binomial error treatment enum option (AB)
   AB: done... needs to be checked. Add a test that y +- 1 sigma in [0, 1]
 
+* Add Scatter/Point1D (AB)
+
 * Template Bin2D and HistoBin2D on DBN type (Dbn2D/3D) cf. Bin1D<DBN> (MK)
 
 * Profile2D, using Dbn3D (AB/MK)

Modified: trunk/include/YODA/Axis1D.h
==============================================================================
--- trunk/include/YODA/Axis1D.h	Fri Aug 26 15:39:23 2011	(r369)
+++ trunk/include/YODA/Axis1D.h	Fri Aug 26 16:00:59 2011	(r370)
@@ -171,6 +171,7 @@
       // correct answer in the case of coord pointing exactly on an edge.
       // This will never change the answer, since it is *much* smaller than
       // the fuzzyEquals() tolerance!
+      /// @todo No it isn't: the fuzzyEquals tolerance is relative. You don't know that the typical scale of coord isn't 10e-10. This has to go.
       coord += 0.00000000001;
 
       // Search for an edge
@@ -184,8 +185,8 @@
       // a member of the same bin as the one on the right, it means that our point
       // is inside a bin. In such case, announce it providing the index of the
       // bin in question.
-      for(size_t i = index+1; _binHashSparse[i].first == _binHashSparse[index+1].first; ++i){
-        if(_binHashSparse[index].second == _binHashSparse[i].second) {
+      for (size_t i = index+1; _binHashSparse[i].first == _binHashSparse[index+1].first; ++i){
+        if (_binHashSparse[index].second == _binHashSparse[i].second) {
           return _binHashSparse[index].second;
         }
       }

Modified: trunk/include/YODA/Axis2D.h
==============================================================================
--- trunk/include/YODA/Axis2D.h	Fri Aug 26 15:39:23 2011	(r369)
+++ trunk/include/YODA/Axis2D.h	Fri Aug 26 16:00:59 2011	(r370)
@@ -212,9 +212,9 @@
       /// Acquire the starting/ending bins
       HistoBin2D& start = bin(from);
       HistoBin2D& end = bin(to);
-      
+
       /// Set the bin to be added as a starting bin
-      /// and then remove the unneeded starting bin from 
+      /// and then remove the unneeded starting bin from
       /// the list of bins.
       HistoBin2D temp = start;
       eraseBin(from);
@@ -230,7 +230,7 @@
       /// Create a vector that will contain indexes of bins that
       /// will be removed after merging them with our 'main' bin.
       std::vector<size_t> toRemove;
-      
+
       /// Look for lower/upper limit of the merge function operation.
       /// i.e.: search for index of lowEdgeY of starting bin in _binHashSparse
       /// and lowEdgeY of ending bin. This way we don't have to scroll through all
@@ -261,10 +261,10 @@
       std::reverse(toRemove.begin(), toRemove.end());
       foreach(size_t remove, toRemove) eraseBin(remove);
 
-      /// Add edges of our merged bin to _binHashSparse and don't create a default 
+      /// Add edges of our merged bin to _binHashSparse and don't create a default
       /// empty bin.
       _addEdge(temp.edges(), _binHashSparse, false);
-      
+
       /// Add the actual merged bin to the Axis.
       _bins.push_back(temp);
 
@@ -274,23 +274,23 @@
     }
 
     /// Merge a range of bins giving start and end coordinates
-    void mergeBins(double startX, double startY, double endX, double endY){
+    void mergeBins(double startX, double startY, double endX, double endY) {
       mergeBins(binByCoord(startX, startY), binByCoord(endX, endY));
     }
 
     /// Rebin by an interger factor
     void rebin(size_t factorX, size_t factorY) {
-      if(!isGrid) throw GridError("Rebinning by a factor can only act on full grids!");
+      if (!isGrid) throw GridError("Rebinning by a factor can only act on full grids!");
       size_t binsInColumn = _binHashSparse.first.size() -  1;
       size_t binsInRow    = _binHashSparse.second.size() - 1;
-      
+
       throw ("IMPLEMENT!");
     }
 
     /// Reset the axis statistics
     void reset() {
       _dbn.reset();
-      foreach(Bin bin, _bins){
+      foreach(Bin bin, _bins) {
         bin.reset();
       }
     }
@@ -420,16 +420,17 @@
     const int getBinIndex(double coordX, double coordY) const {
       // In case we are just operating on a regular grid
       if (isGrid()) {
+        /// @todo You can't do this... what if the typical scale of coord is 10e-10? This has to go.
         coordX += 0.00000000001;
         coordY += 0.00000000001;
         size_t indexY = (*_binHashSparse.first._cache.lower_bound(approx(coordY))).second;
 
         if (indexY < _binHashSparse.first.size()) {
           foreach(Edge edgeY, _binHashSparse.first[indexY].second) {
-            if (edgeY.second.first < coordX && edgeY.second.second > coordX){
+            if (edgeY.second.first < coordX && edgeY.second.second > coordX) {
               size_t indexX = (*_binHashSparse.second._cache.lower_bound(approx(coordX))).second;
-              if (indexX < _binHashSparse.second.size()){
-                foreach(Edge edgeX, _binHashSparse.second[indexX].second) {
+              if (indexX < _binHashSparse.second.size()) {
+                foreach (Edge edgeX, _binHashSparse.second[indexX].second) {
                   if (edgeX.second.first < coordY && edgeX.second.second > coordY &&
                       (edgeX.first == edgeY.first))
                     return edgeX.first;
@@ -528,9 +529,9 @@
     void scaleXY(double scaleX, double scaleY) {
       // Two loops are put on purpose, just to protect
       // against improper _binHashSparse
-      for(size_t i = 0; i < _binHashSparse.first.size(); ++i){
+      for(size_t i = 0; i < _binHashSparse.first.size(); ++i) {
         _binHashSparse.first[i].first *= scaleY;
-        for(size_t j = 0; j < _binHashSparse.first[i].second.size(); ++j){
+        for(size_t j = 0; j < _binHashSparse.first[i].second.size(); ++j) {
           _binHashSparse.first[i].second[j].second.first  *= scaleX;
           _binHashSparse.first[i].second[j].second.second *= scaleX;
         }
@@ -655,7 +656,7 @@
 
 
     /// Outflow filler
-    /// The function checks which outflow the coordinates are in 
+    /// The function checks which outflow the coordinates are in
     /// and fills the right one.
     void _fillOutflows(double x, double y, double weight) {
       if (x < _lowEdgeX && y > _highEdgeY) _outflows[0][0].fill(x, y, weight);


More information about the yoda-svn mailing list