|
[yoda-svn] r505 - in trunk: . include/YODA pyext/yoda/includeblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Jul 19 08:39:30 BST 2012
Author: buckley Date: Thu Jul 19 08:39:29 2012 New Revision: 505 Log: Adding path/title-only AO constructors and making nice Python constructor for Histo2D. Modified: trunk/ChangeLog trunk/include/YODA/Histo1D.h trunk/include/YODA/Histo2D.h trunk/include/YODA/Profile1D.h trunk/include/YODA/Profile2D.h trunk/pyext/yoda/include/30-Scatter2D.pyx trunk/pyext/yoda/include/40-Histo1D.pyx trunk/pyext/yoda/include/40-Histo2D.pyx Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Thu Jul 19 00:46:04 2012 (r504) +++ trunk/ChangeLog Thu Jul 19 08:39:29 2012 (r505) @@ -1,5 +1,7 @@ 2012-07-19 Andy Buckley <andy.buckley at cern.ch> + * Adding path/title-only AO constructors and making nice Python constructor for Histo2D. + * Cython mapping improvements & additions for Point3D + Scatter3D. * Removing mixed symm/asymm constructors on Point*D & Scatter*D classes. Modified: trunk/include/YODA/Histo1D.h ============================================================================== --- trunk/include/YODA/Histo1D.h Thu Jul 19 00:46:04 2012 (r504) +++ trunk/include/YODA/Histo1D.h Thu Jul 19 08:39:29 2012 (r505) @@ -38,9 +38,9 @@ //@{ - /// Default constructor of an invalid histo - Histo1D() - : AnalysisObject("Histo1D", "", ""), + /// Default constructor + Histo1D(const std::string& path="", const std::string& title="") + : AnalysisObject("Histo1D", path, title), _axis() { } @@ -64,6 +64,13 @@ { } + /// Constructor accepting an explicit collection of bins. + Histo1D(const std::vector<Bin>& bins, + const std::string& path="", const std::string& title="") + : AnalysisObject("Histo1D", path, title), + _axis(bins) + { } + /// Copy constructor with optional new path Histo1D(const Histo1D& h, const std::string& path=""); Modified: trunk/include/YODA/Histo2D.h ============================================================================== --- trunk/include/YODA/Histo2D.h Thu Jul 19 00:46:04 2012 (r504) +++ trunk/include/YODA/Histo2D.h Thu Jul 19 08:39:29 2012 (r505) @@ -37,11 +37,18 @@ typedef Histo2DAxis Axis; typedef Axis::Bins Bins; typedef HistoBin2D Bin; - + typedef Axis::Outflows Outflows; /// @name Constructors //@{ + /// Default constructor + Histo2D(const std::string& path="", const std::string& title="") + : AnalysisObject("Histo2D", path, title), + _axis() + { } + + /// Constructor giving range and number of bins. Histo2D(size_t nbinsX, double lowerX, double upperX, size_t nbinsY, double lowerY, double upperY, @@ -59,23 +66,31 @@ { } + /// Constructor accepting an explicit collection of bins. + Histo2D(const std::vector<Bin>& bins, + const std::string& path="", const std::string& title="") + : AnalysisObject("Histo2D", path, title), + _axis(bins) + { } + + /// Copy constructor with optional new path Histo2D(const Histo2D& h, const std::string& path=""); - /// @todo Add binning constructors from Scatter3D (and Profile2D when it exists) + /// @todo Add binning constructors from Scatter3D (and Profile2D?) - /// @todo TODO - // /// @brief State-setting constructor - // /// Mainly intended for internal persistency use. - // Histo2D(const std::vector<HistoBin2D>& bins, - // const std::vector<std::vector<Dbn2D> >& outflows, - // const Dbn2D& totalDbn, - // const std::string& path="", const std::string& title="") - // : AnalysisObject("Histo2D", path, title), - // _axis(bins, outflows, totalDbn) - // { } + /// @brief State-setting constructor + /// + /// Mainly intended for internal persistency use. + Histo2D(const std::vector<HistoBin2D>& bins, + const Dbn2D& totalDbn, + const Outflows& outflows, + const std::string& path="", const std::string& title="") + : AnalysisObject("Histo2D", path, title), + _axis(bins, totalDbn, outflows) + { } //@} Modified: trunk/include/YODA/Profile1D.h ============================================================================== --- trunk/include/YODA/Profile1D.h Thu Jul 19 00:46:04 2012 (r504) +++ trunk/include/YODA/Profile1D.h Thu Jul 19 08:39:29 2012 (r505) @@ -42,8 +42,8 @@ //@{ /// Default constructor - Profile1D() - : AnalysisObject("Profile1D", "", ""), + Profile1D(const std::string& path="", const std::string& title="") + : AnalysisObject("Profile1D", path, title), _axis() { } Modified: trunk/include/YODA/Profile2D.h ============================================================================== --- trunk/include/YODA/Profile2D.h Thu Jul 19 00:46:04 2012 (r504) +++ trunk/include/YODA/Profile2D.h Thu Jul 19 08:39:29 2012 (r505) @@ -36,6 +36,12 @@ /// @name Constructors //@{ + /// Default constructor + Profile2D(const std::string& path="", const std::string& title="") + : AnalysisObject("Profile2D", path, title), + _axis() + { } + /// Constructor giving range and number of bins Profile2D(size_t nbinsX, double lowerX, double upperX, size_t nbinsY, double lowerY, double upperY, Modified: trunk/pyext/yoda/include/30-Scatter2D.pyx ============================================================================== --- trunk/pyext/yoda/include/30-Scatter2D.pyx Thu Jul 19 00:46:04 2012 (r504) +++ trunk/pyext/yoda/include/30-Scatter2D.pyx Thu Jul 19 08:39:29 2012 (r505) @@ -1,7 +1,8 @@ cdef extern from "YODA/Scatter2D.h" namespace "YODA": cdef cppclass cScatter2D "YODA::Scatter2D" (cAnalysisObject): cScatter2D() - cScatter2D(vector[cPoint2D]&, string, string) + cScatter2D(string& path, string& title) + cScatter2D(vector[cPoint2D]&, string& path, string& title) cScatter2D(cScatter2D &s) size_t numPoints() @@ -11,24 +12,27 @@ cdef class Scatter2D(AnalysisObject): + """ + 2D scatter plot / cf. TGraphAsymmErrs. Unlike histograms/profiles, the position and error + values of Scatter points can be set directly. They are the normal type used for reference + data, as well as being the result of some histo combining operations such as division, whose + result is not another valid histo which could meaningfully be filled. + + Several sets of arguments are permitted to the constructor: + + * Scatter2D() -- default constructor. Not usually useful in Python, due to availability of None. + * Scatter2D(points[, path, title]) -- explicit construction from a list of points. + * Scatter2D(xs, ys[, path, title]) -- constructing points from lists of x and y positions (no errs). + * Scatter2D(xs, ys, exs, eys[, path, title]) -- constructing points from lists of x and y positions and errs (errs can be pairs). + * Scatter2D(xs, ys, ex-s, ex+s, ey-s, ey+s[, path, title]) -- constructing points from lists of x and y positions and errs. + + The path and title arguments are optional, and may either be specified via the + positional parameters or via explicit keyword arguments, e.g. path='/foo/bar'. + """ def __init__(self, *args, **kwargs): - """ - Scatter2D constructor. Several sets of arguments are permitted: - - * Scatter2D() -- default constructor. Not usually useful in Python, due to availability of None. - * Scatter2D(points[, path, title]) -- explicit construction from a list of points. - * Scatter2D(xs, ys[, path, title]) -- constructing points from lists of x and y positions (no errs). - * Scatter2D(xs, ys, exs, eys[, path, title]) -- constructing points from lists of x and y positions and errs (errs can be pairs). - * Scatter2D(xs, ys, ex-s, ex+s, ey-s, ey+s[, path, title]) -- constructing points from lists of x and y positions and errs. - - The path and title arguments are optional, and may either be specified via the - positional parameters or via explicit keyword arguments, e.g. path='/foo/bar'. - """ #self._dealloc = True cdef: - # size_t N = len(points) - # int i Point2D item vector[cPoint2D] point_vector cScatter2D* scatter @@ -39,12 +43,12 @@ if "path" in kwargs: path = kwargs["path"] if "title" in kwargs: - path = kwargs["title"] + title = kwargs["title"] ## Trigger different construction methods depending on Python args # TODO: Map copy constructors, esp. the path-resetting one if len(args) == 0: - self.setptr(new cScatter2D()) + self.setptr(new cScatter2D(string(path), string(title))) elif len(args) == 1: for point in args[0]: item = point Modified: trunk/pyext/yoda/include/40-Histo1D.pyx ============================================================================== --- trunk/pyext/yoda/include/40-Histo1D.pyx Thu Jul 19 00:46:04 2012 (r504) +++ trunk/pyext/yoda/include/40-Histo1D.pyx Thu Jul 19 08:39:29 2012 (r505) @@ -2,10 +2,12 @@ cdef cppclass cHisto1D "YODA::Histo1D"(cAnalysisObject): cHisto1D() - cHisto1D(size_t nbins, double lower, double upper, string &path, string &title) - cHisto1D(vector[double] &binedges, string &path, string &title) - cHisto1D(cHisto1D &h, string &path) - cHisto1D(cHisto1D &h) + cHisto1D(string& path, string& title) + cHisto1D(vector[cHistoBin1D]&, string& path, string& title) + cHisto1D(size_t nbins, double lower, double upper, string& path, string& title) + cHisto1D(vector[double]& binedges, string& path, string& title) + cHisto1D(cHisto1D& h, string& path) + cHisto1D(cHisto1D& h) void fill(double x, double weight) void reset() @@ -71,12 +73,12 @@ if "path" in kwargs: path = kwargs["path"] if "title" in kwargs: - path = kwargs["title"] + title = kwargs["title"] ## Trigger different C++ constructors depending on Python args # TODO: Map copy constructors, esp. the path-resetting one if len(args) == 0: - self.setptr(new cHisto1D()) + self.setptr(new cHisto1D(string(path), string(title))) else: if type(args[0]) is list: try: Modified: trunk/pyext/yoda/include/40-Histo2D.pyx ============================================================================== --- trunk/pyext/yoda/include/40-Histo2D.pyx Thu Jul 19 00:46:04 2012 (r504) +++ trunk/pyext/yoda/include/40-Histo2D.pyx Thu Jul 19 08:39:29 2012 (r505) @@ -3,10 +3,13 @@ #cHisto2D operator - (cHisto2D &, cHisto2D &) cdef cppclass cHisto2D "YODA::Histo2D"(cAnalysisObject): + cHisto2D() + cHisto2D(string& path, string& title) cHisto2D(size_t nbinsX, double lowerX, double upperX, size_t nbinsY, double lowerY, double upperY, string& path, string& title) - + cHisto2D(vector[cHistoBin2D]&, string& path, string& title) + cHisto2D(vector[double]& xedges, vector[double]& yedges, string& path, string& title) cHisto2D(cHisto2D& h) void fill(double x, double y, double weight) @@ -49,10 +52,31 @@ cdef class Histo2D(AnalysisObject): - cdef tuple _bins + """ + 2D histogram. Basic histogramming is currently supported, i.e. a two-dimensional bin layout + may be specified, filled, and queried. Outflow distributions around the 8 sides and + corners of the grid are supported, and the bins need not be regularly sized or contiguous: + bins which span rows and/or columns, and gaps between bins are permitted. + + TODO: Bin merging/rebinning is not currently supported (the algorithm has to + be a bit more complex than usual due to the increased number of ways for it + to not work if the bin shapes are irregular.) + + Several sets of arguments are permitted to the constructor: + + * Histo2D() -- default constructor. Not usually useful in Python, due to availability of None. + * Histo2D(bins[, path, title]) -- constructor from a list of bins. + * Histo2D(nx, xlow, xhigh, ny, ylow, yhigh[, path, title]) -- construct a uniform bin grid in both x and y directions. + * Histo2D(xedges, yedges[, path, title]) -- make a regular bin grid with given bin edges in x and y. + + The path and title arguments are optional, and may either be specified via the + positional parameters or via explicit keyword arguments, e.g. path='/foo/bar'. + """ + + # cdef tuple _bins def __cinit__(self): - self._bins = None + # self._bins = None self._dealloc = False @@ -60,18 +84,41 @@ cdef: size_t nbinsX, nbinsY double lowX, highX, lowY, highY + HistoBin2D item + vector[cHistoBin2D] bin_vector + vector[double] xedges + vector[double] yedges char* path = '/' char* title = '' - # TODO: make nice multi-mode constructor - - if len(args) == 6: + ## Permit path and title specification via kwargs + if "path" in kwargs: + path = kwargs["path"] + if "title" in kwargs: + title = kwargs["title"] + + # TODO: Map copy constructor + + if len(args) == 0: + self.setptr(new cHisto2D(string(path), string(title)), True) + elif len(args) == 1: + # Histo2D(bins[, path, title]) + for b in args[0]: + item = b + bin_vector.push_back( item.ptr()[0] ) + self.setptr(new cHisto2D(bin_vector, string(path), string(title))) + elif len(args) == 2: + # Histo2D(xedges, yedges[, path, title]) + for x in args[0]: + xedges.push_back(x) + for y in args[1]: + yedges.push_back(y) + self.setptr(new cHisto2D(xedges, yedges, string(path), string(title))) + elif len(args) == 6: + # Histo2D(nx, xlow, xhigh, ny, ylow, yhigh[, path, title]) -- construct a uniform bin grid in both x and y directions. nbinsX, lowX, highX, nbinsY, lowY, highY = args - - self.setptr( - new cHisto2D(nbinsX, lowX, highX, nbinsY, lowY, highY, - string(path), string(title)), True - ) + self.setptr(new cHisto2D(nbinsX, lowX, highX, nbinsY, lowY, highY, + string(path), string(title)), True) cdef cHisto2D* ptr(self):
More information about the yoda-svn mailing list |