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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed Dec 7 21:29:15 GMT 2011


Author: buckley
Date: Wed Dec  7 21:29:15 2011
New Revision: 419

Log:
Adding an outflows() accessor to Histo2D.

Modified:
   trunk/ChangeLog
   trunk/include/YODA/Histo2D.h
   trunk/include/YODA/Profile2D.h
   trunk/pyext/yoda/Makefile.am
   trunk/pyext/yoda/include/20-Dbn2D.pyx
   trunk/pyext/yoda/include/40-Histo1D.pyx
   trunk/pyext/yoda/include/40-Histo2D.pyx

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Wed Dec  7 14:58:04 2011	(r418)
+++ trunk/ChangeLog	Wed Dec  7 21:29:15 2011	(r419)
@@ -1,5 +1,7 @@
 2011-12-07  Andy Buckley  <andy.buckley at cern.ch>
 
+	* Adding an outflows() accessor to Histo2D.
+
 	* Writing out total dbn lines for Histo1D and Profile1D in the
 	YODA format, and now writing out the 'cross-terms' for Profile1D,
 	too.

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Wed Dec  7 14:58:04 2011	(r418)
+++ trunk/include/YODA/Histo2D.h	Wed Dec  7 21:29:15 2011	(r419)
@@ -271,6 +271,17 @@
       return _axis.totalDbn();
     }
 
+
+    /// Access outflows (non-const)
+    std::vector<std::vector<Dbn2D> >& outflows() {
+      return _axis.outflows();
+    }
+
+    /// Access outflows (const)
+    const std::vector<std::vector<Dbn2D> >& outflows() const {
+      return _axis.outflows();
+    }
+
     //@}
 
 

Modified: trunk/include/YODA/Profile2D.h
==============================================================================
--- trunk/include/YODA/Profile2D.h	Wed Dec  7 14:58:04 2011	(r418)
+++ trunk/include/YODA/Profile2D.h	Wed Dec  7 21:29:15 2011	(r419)
@@ -178,12 +178,12 @@
 
 
     /// Access outflows (non-const)
-    std::vector<std::vector<Dbn3D> > outflows() {
+    std::vector<std::vector<Dbn3D> >& outflows() {
       return _axis.outflows();
     }
 
     /// Access outflows (const)
-    std::vector<std::vector<Dbn3D> > outflows() const {
+    const std::vector<std::vector<Dbn3D> >& outflows() const {
       return _axis.outflows();
     }
 

Modified: trunk/pyext/yoda/Makefile.am
==============================================================================
--- trunk/pyext/yoda/Makefile.am	Wed Dec  7 14:58:04 2011	(r418)
+++ trunk/pyext/yoda/Makefile.am	Wed Dec  7 21:29:15 2011	(r419)
@@ -4,7 +4,7 @@
 yoda.cpp: yoda.pyx
 	$(PYTHON) -m cython --cplus yoda.pyx
 
-yoda.pyx: include/00-imports.pyx include/10-AnalysisObject.pyx include/20-Dbn1D.pyx include/20-Point2D.pyx include/30-HistoBin1D.pyx include/30-HistoBin2D.pyx include/30-Reader.pyx include/30-Scatter2D.pyx include/40-Histo1D.pyx include/40-Histo2D.pyx include/40-WriterAIDA.pyx include/99-ReaderAIDA.pyx
+yoda.pyx: include/00-imports.pyx include/10-AnalysisObject.pyx include/20-Dbn1D.pyx include/20-Dbn2D.pyx include/20-Point2D.pyx include/30-HistoBin1D.pyx include/30-HistoBin2D.pyx include/30-Reader.pyx include/30-Scatter2D.pyx include/40-Histo1D.pyx include/40-Histo2D.pyx include/40-WriterAIDA.pyx include/99-ReaderAIDA.pyx
 	cat include/*.pyx > yoda.pyx
 
 clean-local:

Modified: trunk/pyext/yoda/include/20-Dbn2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/20-Dbn2D.pyx	Wed Dec  7 14:58:04 2011	(r418)
+++ trunk/pyext/yoda/include/20-Dbn2D.pyx	Wed Dec  7 21:29:15 2011	(r419)
@@ -2,6 +2,7 @@
     cdef cppclass cDbn2D "Dbn2D":
         pass
 
+
 cdef class Dbn2D:
     cdef cDbn2D *thisptr
     cdef bool _dealloc
@@ -23,3 +24,10 @@
 
     cdef cDbn2D* ptr(self):
         return self.thisptr
+
+
+cdef Dbn2D Dbn2D_fromptr(cDbn2D *ptr, dealloc=False):
+    # Construct a Python Dbn2D from a pointer to a cDbn2D,
+    # without calling __init__ and excessive memory allocation
+    cdef Dbn2D dbn = Dbn2D.__new__(Dbn2D)
+    return dbn.setptr(ptr, dealloc)

Modified: trunk/pyext/yoda/include/40-Histo1D.pyx
==============================================================================
--- trunk/pyext/yoda/include/40-Histo1D.pyx	Wed Dec  7 14:58:04 2011	(r418)
+++ trunk/pyext/yoda/include/40-Histo1D.pyx	Wed Dec  7 21:29:15 2011	(r419)
@@ -145,17 +145,16 @@
         unless the copy() method is called on a bin.
 
         """
-
         cdef size_t numbins = self.ptr().numBins()
         cdef size_t i
         cdef HistoBin1D bin
 
         out = []
-
-        for i in range(numbins):
+        for i in xrange(numbins):
             bin = HistoBin1D_fromptr(& self.ptr().bins()[i])
             out.append(bin)
-        self.ptr().bins()
+        # TODO: Why was this here?
+        # self.ptr().bins()
 
         return out
 
@@ -190,7 +189,6 @@
         Return the Distribution1D object representing the total distribution.
 
         """
-        cdef HistoBin1D bin
         return Dbn1D_fromptr(&self.ptr().totalDbn())
 
 
@@ -202,7 +200,6 @@
         Return the Distribution1D object representing the underflow.
 
         """
-        cdef HistoBin1D bin
         return Dbn1D_fromptr(&self.ptr().underflow())
 
 
@@ -214,7 +211,6 @@
         Return the Distribution1D object representing the overflow.
 
         """
-        cdef HistoBin1D bin
         return Dbn1D_fromptr(&self.ptr().overflow())
 
 

Modified: trunk/pyext/yoda/include/40-Histo2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/40-Histo2D.pyx	Wed Dec  7 14:58:04 2011	(r418)
+++ trunk/pyext/yoda/include/40-Histo2D.pyx	Wed Dec  7 21:29:15 2011	(r419)
@@ -18,10 +18,14 @@
 
         # Bin Accessors
         size_t numBins()
+        size_t numBinsX()
+        size_t numBinsY()
+
         double lowEdgeX()
         double lowEdgeY()
         double highEdgeX()
         double highEdgeY()
+        vector[vector[cDbn2D]] &outflows()
         cDbn2D &totalDbn()
 
         vector[cHistoBin2D] &bins()
@@ -33,6 +37,7 @@
         double integral(bool includeoverflows)
         double sumW(bool includeoverflows)
         double sumW2(bool includeoverflows)
+
         double xMean(bool includeoverflows)
         double yMean(bool includeoverflows)
 
@@ -42,6 +47,7 @@
         double xStdDev(bool includeoverflows)
         double yStdDev(bool includeoverflows)
 
+
 cdef class Histo2D(AnalysisObject):
     cdef tuple _bins
 
@@ -49,6 +55,7 @@
         self._bins = None
         self._dealloc = False
 
+
     def __init__(self, *args, **kwargs):
         cdef:
             size_t nbinsX, nbinsY
@@ -64,26 +71,33 @@
                              string(path), string(title)), True
             )
 
+
     cdef cHisto2D* ptr(self):
         return <cHisto2D *> self.thisptr
 
+
     def fill(self, double x, double y, double weight=1.0):
         self.ptr().fill(x, y, weight)
 
+
     def reset(self):
         """Reset the histogram but leave the bin structure"""
         self.ptr().reset()
 
+
     def scaleW(self, double factor):
         """Scale the histogram and its statistics by given factor"""
         self.ptr().scaleW(factor)
 
+
     def mergeBins(self, size_t a, size_t b):
         self.ptr().mergeBins(a, b)
 
+
     def rebin(self, int a, int b):
         self.ptr().rebin(a, b)
 
+
     @property
     def bins(self):
         cdef size_t numbins = self.ptr().numBins()
@@ -95,75 +109,121 @@
 
         return self._bins
 
+
     @property
     def lowEdgeX(self):
         return self.ptr().lowEdgeX()
 
+
     @property
     def lowEdgeY(self):
         return self.ptr().lowEdgeY()
 
+
     @property
     def highEdgeX(self):
         return self.ptr().highEdgeX()
 
+
     @property
     def highEdgeY(self):
         return self.ptr().highEdgeY()
 
-    def underflow(self):
-        pass
+
+    @property
+    def totalDbn(self):
+        """
+        h.totalDbn -> Distribution2D
+
+        Return the Distribution2D object representing the total distribution.
+
+        """
+        return Dbn2D_fromptr(&self.ptr().totalDbn())
+
+
+    def outflows(self):
+        cdef size_t numofsX = self.ptr().numBinsX()
+        cdef size_t numofsY = self.ptr().numBinsY()
+        cdef size_t i
+        cdef Dbn2D of
+
+        out = []
+        for i in xrange(numofsX):
+            for j in xrange(numofsY):
+                of = Dbn2D_fromptr(&self.ptr().outflows()[i][j])
+                out.append(bin)
+        # TODO: Why was this here?
+        # self.ptr().outflows()
+        return out
+
 
     def __delitem__(self, size_t ix):
         self.ptr().eraseBin(ix)
 
+
     def __getitem__(self, size_t ix):
         return HistoBin2D().set(self.ptr().bins()[ix])
 
+
     def integral(self, bool overflows=True):
         return self.ptr().integral(overflows)
 
+
     def sumW(self, bool overflows=True):
         return self.ptr().sumW(overflows)
 
+
     def sumW2(self, bool overflows=True):
         return self.ptr().sumW2(overflows)
 
+
+    def mean(self, bool overflows=True):
+        cdef cHisto2D *s = self.ptr()
+        return (s.xMean(overflows), s.yMean(overflows))
+
+
     def variance(self, bool overflows=True):
         cdef cHisto2D *s = self.ptr()
         return (s.xVariance(overflows), s.yVariance(overflows))
 
+
     def stdDev(self, bool overflows=True):
         cdef cHisto2D *s = self.ptr()
         return (s.xStdDev(overflows), s.yStdDev(overflows))
 
-    """def __add__(Histo2D a, Histo2D b):
-        cdef cHisto2D *res
-        res = new cHisto2D(a.ptr()[0] + b.ptr()[0])
-        return Histo2D().setptr(res)
-
-    def __sub__(Histo2D a, Histo2D b):
-        cdef cHisto2D *res
-        res = new cHisto2D(a.ptr()[0] - b.ptr()[0])
-        return Histo2D().setptr(res)
-
-    def __mul__(x, y):
-        cdef cHisto2D *res
-        tx, ty = type(x), type(y)
-        if (tx is int or tx is float) and ty is Histo2D:
-            histo = <Histo2D> y; factor = <Histo2D> x
-        elif tx is Histo2D and (ty is int or ty is float):
-            histo = <Histo2D> x; factor = <Histo2D> y
-        else:
-            raise RuntimeError('Cannot multiply %r by %r' % (tx, ty))
-
-        res = new cHisto2D(histo.ptr()[0])
-        res.scaleW(factor)
-        return Histo2D().setptr(res)"""
+
+
+    # def __add__(Histo2D a, Histo2D b):
+    #     cdef cHisto2D *res
+    #     res = new cHisto2D(a.ptr()[0] + b.ptr()[0])
+    #     return Histo2D().setptr(res)
+
+
+    # def __sub__(Histo2D a, Histo2D b):
+    #     cdef cHisto2D *res
+    #     res = new cHisto2D(a.ptr()[0] - b.ptr()[0])
+    #     return Histo2D().setptr(res)
+
+
+    # def __mul__(x, y):
+    #     cdef cHisto2D *res
+    #     tx, ty = type(x), type(y)
+    #     if (tx is int or tx is float) and ty is Histo2D:
+    #         histo = <Histo2D> y; factor = <Histo2D> x
+    #     elif tx is Histo2D and (ty is int or ty is float):
+    #         histo = <Histo2D> x; factor = <Histo2D> y
+    #     else:
+    #         raise RuntimeError('Cannot multiply %r by %r' % (tx, ty))
+
+    #     res = new cHisto2D(histo.ptr()[0])
+    #     res.scaleW(factor)
+    #     return Histo2D().setptr(res)
+
 
     def __repr__(self):
         return 'Histo2D%r' % self.bins
 
+
 cdef Histo2D Histo2D_fromptr(cHisto2D *ptr, dealloc=False):
     # Construct a Python Histo2D from a pointer to a cHisto2D,
     # without calling __init__ and excessive memory allocation


More information about the yoda-svn mailing list