Beispiel #1
0
def tree2array(tree,
               branches=None,
               N=None,
               offset=0,
               include_weight=False,
               weight_name='weight',
               weight_dtype='f4'):
    """
    convert PyROOT TTree *tree* to numpy structured array
    see :func:`root2array` for details on parameter
    """
    import ROOT
    if not isinstance(tree, ROOT.TTree):
        raise TypeError("tree must be a ROOT.TTree")

    if hasattr(ROOT, 'AsCapsule'):
        #o = ROOT.AsCapsule(tree)
        # this will cause tons of compilation issue
        raise NotImplementedError()
        #return _librootnumpy.root2array_from_capsule(o, branches)
    cobj = ROOT.AsCObject(tree)
    arr = _librootnumpy.root2array_fromCObj(cobj, branches, N, offset)
    if include_weight:
        arr = _add_weight_field(arr, tree, weight_name, weight_dtype)
    return arr
Beispiel #2
0
def tree2array(tree,
               branches=None,
               selection=None,
               start=None,
               stop=None,
               step=None,
               include_weight=False,
               weight_name='weight'):
    """
    Convert a tree into a numpy structured array.
    Refer to the type conversion table :ref:`here <conversion_table>`.

    Parameters
    ----------

    treename : str
        Name of the tree to convert.

    branches : list of str, optional (default=None)
        List of branch names to include as columns of the array.
        If None or empty then include all branches than can be converted in the
        first tree.
        If branches contains duplicate branches, only the first one is used.

    selection : str, optional (default=None)
        Only include entries fulfilling this condition.

    start, stop, step: int, optional (default=None)
        The meaning of the ``start``, ``stop`` and ``step``
        parameters is the same as for Python slices.
        If a range is supplied (by setting some of the
        ``start``, ``stop`` or ``step`` parameters), only the entries in that
        range and fulfilling the ``selection`` condition (if defined) are used.

    include_weight : bool, optional (default=False)
        Include a column containing the tree weight.

    weight_name : str, optional (default='weight')
        The field name for the weight column if ``include_weight=True``.

    See Also
    --------
    root2array

    """
    import ROOT
    if not isinstance(tree, ROOT.TTree):
        raise TypeError("tree must be a ROOT.TTree")
    # will need AsCapsule for Python 3
    cobj = ROOT.AsCObject(tree)
    arr = _librootnumpy.root2array_fromCObj(
        cobj, branches, selection,
        start, stop, step,
        include_weight,
        weight_name)
    return arr
Beispiel #3
0
def tree2array(tree,
               branches=None,
               entries=None,
               offset=0,
               selection=None,
               include_weight=False,
               weight_name='weight',
               weight_dtype='f4'):
    """
    Convert a tree into a numpy structured array.
    Refer to the type conversion table :ref:`here <conversion_table>`.

    Parameters
    ----------
    treename : str
        Name of the tree to convert.
    branches : list of str, optional (default=None)
        List of branch names to include as columns of the array.
        If None or empty then include all branches than can be converted in the
        first tree.
        If branches contains duplicate branches, only the first one is used.
    entries : int, optional (default=None)
        Maximum number of entries that will be converted from the chained
        trees. If None then convert all entries. If a selection is applied then
        fewer entries may be converted.
    offset : int, optional (default=0):
        Offset from the beginning of the chained trees where conversion will
        begin.
    selection : str, optional (default=None)
        Only include entries passing a cut expression.
    include_weight : bool, optional (default=False)
        Include a column containing the tree weight.
    weight_name : str, optional (default='weight')
        The field name for the weight column if ``include_weight=True``.
    weight_dtype : NumPy dtype, optional (default='f4')
        The datatype to use for the weight column if ``include_weight=True``.

    See Also
    --------
    root2array

    """
    import ROOT
    if not isinstance(tree, ROOT.TTree):
        raise TypeError("tree must be a ROOT.TTree")
    if hasattr(ROOT, 'AsCapsule'):
        #o = ROOT.AsCapsule(tree)
        # this will cause tons of compilation issue
        raise NotImplementedError()
        #return _librootnumpy.root2array_from_capsule(o, branches)
    cobj = ROOT.AsCObject(tree)
    arr = _librootnumpy.root2array_fromCObj(
        cobj, branches, entries, offset, selection)
    if include_weight:
        arr = _add_weight_field(arr, tree, weight_name, weight_dtype)
    return arr
Beispiel #4
0
def tree2array(tree,
               branches=None,
               selection=None,
               start=None,
               stop=None,
               step=None,
               include_weight=False,
               weight_name='weight'):
    """Convert a tree into a numpy structured array.

    Refer to the type conversion table :ref:`here <conversion_table>`.

    Parameters
    ----------
    tree : ROOT TTree instance
        The ROOT TTree to convert into an array.
    branches : list of str, optional (default=None)
        List of branch names to include as columns of the array. If None or
        empty then include all branches than can be converted in the first
        tree. If branches contains duplicate branches, only the first one is
        used.
    selection : str, optional (default=None)
        Only include entries fulfilling this condition.
    start, stop, step: int, optional (default=None)
        The meaning of the ``start``, ``stop`` and ``step`` parameters is the
        same as for Python slices. If a range is supplied (by setting some of
        the ``start``, ``stop`` or ``step`` parameters), only the entries in
        that range and fulfilling the ``selection`` condition (if defined) are
        used.
    include_weight : bool, optional (default=False)
        Include a column containing the tree weight.
    weight_name : str, optional (default='weight')
        The field name for the weight column if ``include_weight=True``.

    See Also
    --------
    root2array

    """
    import ROOT
    if not isinstance(tree, ROOT.TTree):
        raise TypeError("tree must be a ROOT.TTree")
    # will need AsCapsule for Python 3
    cobj = ROOT.AsCObject(tree)
    arr = _librootnumpy.root2array_fromCObj(
        cobj, branches, selection,
        start, stop, step,
        include_weight,
        weight_name)
    return arr
Beispiel #5
0
def tree2array(tree, branches=None, N=None, offset=0):
    """
    convert PyROOT TTree *tree* to numpy structured array
    see :func:`root2array` for details on parameter
    """
    import ROOT
    if not isinstance(tree, ROOT.TTree):
        raise TypeError("tree must be a ROOT.TTree")

    if hasattr(ROOT, 'AsCapsule'):
        #o = ROOT.AsCapsule(tree)
        # this will cause tons of compilation issue
        raise NotImplementedError()
        #return _librootnumpy.root2array_from_capsule(o, branches)
    else:
        o = ROOT.AsCObject(tree)
        return _librootnumpy.root2array_fromCObj(o, branches, N, offset)
Beispiel #6
0
def tree2array(tree, branches=None, N=None, offset=0,
        include_weight=False,
        weight_name='weight',
        weight_dtype='f4'):
    """
    convert PyROOT TTree *tree* to numpy structured array
    see :func:`root2array` for details on parameter
    """
    import ROOT
    if not isinstance(tree, ROOT.TTree):
        raise TypeError("tree must be a ROOT.TTree")

    if hasattr(ROOT, 'AsCapsule'):
        #o = ROOT.AsCapsule(tree)
        # this will cause tons of compilation issue
        raise NotImplementedError()
        #return _librootnumpy.root2array_from_capsule(o, branches)
    cobj = ROOT.AsCObject(tree)
    arr = _librootnumpy.root2array_fromCObj(cobj, branches, N, offset)
    if include_weight:
        arr = _add_weight_field(arr, tree, weight_name, weight_dtype)
    return arr