[yoda-svn] r302 - trunk/include/YODA

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Fri Aug 19 10:45:38 BST 2011


Author: mkawalec
Date: Fri Aug 19 10:45:37 2011
New Revision: 302

Log:
Made cutterX/Y oerate on correct under/over flows. Also added getBinRow(size_t), getBinColumn(size_t) for fast, log n, searches of which column/row a bin is a member of (very useful for cutters.

Modified:
   trunk/include/YODA/Axis2D.h
   trunk/include/YODA/Histo2D.h

Modified: trunk/include/YODA/Axis2D.h
==============================================================================
--- trunk/include/YODA/Axis2D.h	Fri Aug 19 10:17:00 2011	(r301)
+++ trunk/include/YODA/Axis2D.h	Fri Aug 19 10:45:37 2011	(r302)
@@ -394,6 +394,9 @@
       // In case we are just operating on a regular grid
       if (isGrid()) {
         /// @todo WTF?! This is bad. No magic numbers! Why would these be unreasonably small offsets?
+        /// These are for the case when user requests a coordinate which is exactly (by the meaning of equals)
+        /// on the edge. Without those the algorithm will crash. 
+        /// I am pretty sure they are fine, as they are well below fuzzyEquals() tolerance.
         coordX += 0.00000000001;
         coordY += 0.00000000001;
         size_t indexY = (*_binHashSparse.first._cache.lower_bound(approx(coordY))).second;
@@ -427,6 +430,29 @@
       return -1;
     }
 
+    /// Fast column number searcher
+    const size_t getBinColumn(size_t index) const {
+
+      /// Check if assumptions are reasonable
+      if(!_isGrid) throw GridError("This operation can only be performed when an array is a grid!");
+      if(index >= _bins.size()) throw RangeError("Index is bigger than the size of bins vector!");
+
+      /// Find the column nuber
+      size_t ret  = (*_binHashSparse.first._cache.lower_bound(approx(bin(index).yMin()))).second;     
+      return ret;
+}
+    
+    /// Fast row number searcher
+    const size_t getBinRow(size_t index) const {
+
+      /// Check if assumptions are reasonable
+      if(!_isGrid) throw GridError("This operation can only be performed when an array is a grid!");
+      if(index >= _bins.size()) throw RangeError("Index is bigger than the size of bins vector!");
+
+      /// Find the column nuber
+      size_t ret  = (*_binHashSparse.second._cache.lower_bound(approx(bin(index).xMin()))).second;     
+      return ret;
+}
 
     /// Check if the axis has a grid structure or not
     bool isGrid() const {

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Fri Aug 19 10:17:00 2011	(r301)
+++ trunk/include/YODA/Histo2D.h	Fri Aug 19 10:45:37 2011	(r302)
@@ -307,14 +307,11 @@
       }
 
       /// Setting under/over flows
-      vector<vector<Dbn2D> >& outflows = _axis.outflows();
       Dbn2D underflow;
-      underflow += outflows[0][0]; underflow += outflows[6][0];
-      for(size_t i=0; i < outflows[7].size(); ++i) underflow += outflows[7][i];
+      underflow += _axis.outflows()[7][_axis.getBinRow(_axis.getBinIndex(lowEdgeX(), atY))];
 
       Dbn2D overflow;
-      overflow += outflows[2][0]; overflow += outflows[4][0];
-      for(size_t i=0; i < outflows[3].size(); ++i) overflow += outflows[3][i];
+      overflow += _axis.outflows()[3][_axis.getBinRow(_axis.getBinIndex(lowEdgeX(), atY))];
 
       return Histo1D(tempBins, _axis.totalDbn().transformX(), underflow.transformX(), overflow.transformX(), path, title);
 
@@ -339,15 +336,11 @@
       }
 
       /// Setting under/over flows
-      vector<vector<Dbn2D> >& outflows = _axis.outflows();
       Dbn2D underflow;
-      underflow += outflows[0][0]; underflow += outflows[2][0];
-      for(size_t i=0; i < outflows[1].size(); ++i) underflow += outflows[1][i];
+      underflow += _axis.outflows()[1][_axis.getBinColumn(_axis.getBinIndex(atX, lowEdgeY()))];
 
       Dbn2D overflow;
-      overflow += outflows[6][0]; overflow += outflows[4][0];
-      for(size_t i=0; i < outflows[5].size(); ++i) overflow += outflows[5][i];
-
+      overflow += _axis.outflows()[5][_axis.getBinColumn(_axis.getBinIndex(atX, lowEdgeY()))];
       Dbn2D total = _axis.totalDbn();
 
       /// Making sure that we rotate our distributions, as we are cutting paralell to Y axis now


More information about the yoda-svn mailing list