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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Aug 18 13:52:34 BST 2011


Author: mkawalec
Date: Thu Aug 18 13:52:34 2011
New Revision: 276

Log:
Added converter classes from Histo2D to Axis2D. Added some comments.

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

Modified: trunk/include/YODA/Axis2D.h
==============================================================================
--- trunk/include/YODA/Axis2D.h	Thu Aug 18 12:15:53 2011	(r275)
+++ trunk/include/YODA/Axis2D.h	Thu Aug 18 13:52:34 2011	(r276)
@@ -125,8 +125,10 @@
     /// It should be noted that there is nothing special about
     /// the initiation stage of Axis2D, and the edges can be added
     /// online if they meet all the requirements of non-degeneracy.
-    /// No merging is supported, and I don't think it should before the support
-    /// for merging for '+' operator (codewise it should be the same thing).
+    ///
+    /// Be aware that adding a Bin to an existing axis created by one of
+    /// constructors wipes out all the outflows since a concept of them is
+    /// no longer meaningful!
     void addBin(const vector<Segment>& binLimits) {
       _mkAxis(binLimits);
       _outflows.resize(0);
@@ -272,7 +274,7 @@
       return _bins;
     }
 
-    /// Get the outflows (const version)
+    /// Get the outflows (non-const version)
     vector<vector<Dbn2D> >& outflows() {
       return _outflows;
     }
@@ -317,7 +319,7 @@
     }
 
     /// Get a bin at given coordinates (const version)
-    const BIN& binByCoord(pair<double, double>& coords) const {
+    BIN& binByCoord(pair<double, double>& coords) const {
       return binByCoord(coords.first, coords.second);
     }
 
@@ -701,19 +703,6 @@
       return true;
     }
 
-
-    /// @brief Function executed when a set of edges is dropped.
-    ///
-    /// It does not have any information about which edge in the set
-    /// had failed the check. If this is needed such additional information
-    /// can be readily implemented.
-    void _dropEdge(vector<Segment>& edges) {
-      /// @todo WTF?! Finish what you start! Does this actually need to exist?
-      assert(0 && "Unimplemented :(");
-      std::cerr << "A set of edges was dropped." << endl;
-    }
-
-
     /// @brief Bin adder
     ///
     /// It contains all the commands that need to executed
@@ -859,7 +848,6 @@
 
         // And check if a bin is a proper one, if it is, add it.
         if (_validateEdge(edges))  _addEdge(edges, _binHashSparse);
-        else _dropEdge(edges);
       }
 
       // Setting all the caches

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Thu Aug 18 12:15:53 2011	(r275)
+++ trunk/include/YODA/Histo2D.h	Thu Aug 18 13:52:34 2011	(r276)
@@ -11,6 +11,7 @@
 #include "YODA/HistoBin1D.h"
 #include "YODA/Dbn2D.h"
 #include "YODA/Axis2D.h"
+#include "YODA/Profile1D.h"
 #include "YODA/Exceptions.h"
 #include "YODA/Histo1D.h"
 
@@ -347,14 +348,41 @@
 
 
     /// @todo Create x-wise and y-wise conversions to Profile1D -- ignore outflows for now, but mark as such
-    /*Profile1D mkProfileX() {
-      throw Exception("To implement!");
+    Profile1D mkProfileX() {
       if (!_axis._isGrid()) throw GridError("Profile1D cannot be made from a histogram that is not a grid!");
 
-      //Profile1D ret;
-      return Profile1D();
+      vector<ProfileBin1D> prof;
+      for(int i = lowEdgeX() + _axis.bin(0).midpoint().first; i < highEdgeX(); i+= _axis.bin(0).widthX()) {
+        HistoBin2D& bin(_axis.binByCoord(i, lowEdgeY()));
+        HistoBin2D composite(bin.xMin(), bin.xMax(), bin.yMin(), bin.yMax()) ;
+        for(int j = lowEdgeY() + _axis.bin(0).midpoint().second; j < highEdgeY(); j += _axis.bin(0).widthY()) {
+          composite += _axis.binByCoord(i, j);
+        }
+      prof.push_back(composite.transformX());
+      }   
+
+      vector<vector<Dbn2D> >& outflows = _axis.outflows();
+      
+      /// Properly setting an underflow
+      Dbn2D underflow;
+      underflow += outflows[0][0]; underflow += outflows[6][0];
+      for(size_t i = 0; i < outflows[7].size(); ++i) {
+        underflow += outflows[7][i];
+      }
+
+      /// Setting an overflow
+      Dbn2D overflow;
+      overflow += outflows[2][0]; overflow += outflows[4][0];
+      for(size_t i = 0; i < outflows[3].size(); ++i) {
+        overflow += outflows[3][i];
+      }
+
+      /// And construct a profile 1D from all this data
+      Profile1D ret(prof, _axis.totalDbn(), underflow, overflow);
+      return ret;
+
     }
-*/
+
 
     //@}
 

Modified: trunk/include/YODA/HistoBin2D.h
==============================================================================
--- trunk/include/YODA/HistoBin2D.h	Thu Aug 18 12:15:53 2011	(r275)
+++ trunk/include/YODA/HistoBin2D.h	Thu Aug 18 13:52:34 2011	(r276)
@@ -2,6 +2,8 @@
 #define YODA_HistoBin2D_h
 
 #include "YODA/Bin2D.h"
+#include "YODA/Dbn1D.h"
+#include "YODA/ProfileBin1D.h"
 #include "YODA/Exceptions.h"
 
 #include <cmath>
@@ -94,6 +96,29 @@
 
     //@}
 
+    /// @name Transformers
+    //@{
+
+    /// @brief Transformer taking X as a primary axis of ProfileBin1D
+    ProfileBin1D transformX() {
+      Dbn1D dbny(_dbn.numEntries(), _dbn.sumW(), _dbn.sumW2(), _dbn.sumWY(), _dbn.sumWY2());
+      Dbn1D dbnx(_dbn.numEntries(), _dbn.sumW(), _dbn.sumW2(), _dbn.sumWX(), _dbn.sumWX2());
+      ProfileBin1D ret(xMin(), xMax(), dbnx, dbny);
+
+      return ret;
+    }
+
+    ProfileBin1D transformY() {
+      Dbn1D dbny(_dbn.numEntries(), _dbn.sumW(), _dbn.sumW2(), _dbn.sumWY(), _dbn.sumWY2());
+      Dbn1D dbnx(_dbn.numEntries(), _dbn.sumW(), _dbn.sumW2(), _dbn.sumWX(), _dbn.sumWX2());
+      ProfileBin1D ret(yMin(), yMax(), dbny, dbnx);
+
+      return ret;
+    }
+
+
+    //@}
+
 
     /// @name Operators
     //@{


More information about the yoda-svn mailing list